From: Sandro S. <st...@us...> - 2009-12-01 20:10:02
|
Update of /cvsroot/ming/ming/src/blocks In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv31770/src/blocks Modified Files: font.c font.h text.c Log Message: Commit patch by "Nick Lewis" <Nic...@at...> to fix use of the same font in a text and a textfield. Also add a C version of a testcase for this (bindings versions to be done) Index: font.c =================================================================== RCS file: /cvsroot/ming/ming/src/blocks/font.c,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** font.c 28 Sep 2008 16:53:59 -0000 1.59 --- font.c 1 Dec 2009 20:09:43 -0000 1.60 *************** *** 142,146 **** for (i = 0; i < inst->nGlyphs; ++i) { ! SWFShape shape = font->shapes[inst->codeTable[i]]; offset = SWFOutput_getLength(buffer) + tablen; SWFOutput_writeGlyphShape(buffer, shape); --- 142,147 ---- for (i = 0; i < inst->nGlyphs; ++i) { ! int glyph = SWFFont_findGlyphCode(font,inst->codeTable[i]); ! SWFShape shape = font->shapes[glyph]; offset = SWFOutput_getLength(buffer) + tablen; SWFOutput_writeGlyphShape(buffer, shape); *************** *** 162,166 **** for (i = 0; i < inst->nGlyphs; ++i) { ! unsigned short code = font->glyphToCode[inst->codeTable[i]]; if (inst->flags & SWF_FONT_WIDECODES) SWFOutput_writeUInt16(buffer, code); --- 163,167 ---- for (i = 0; i < inst->nGlyphs; ++i) { ! unsigned short code = inst->codeTable[i]; if (inst->flags & SWF_FONT_WIDECODES) SWFOutput_writeUInt16(buffer, code); *************** *** 174,183 **** SWFOutput_writeUInt16(buffer, font->descent); SWFOutput_writeUInt16(buffer, font->leading); ! for (i = 0; i < inst->nGlyphs; ++i) ! SWFOutput_writeSInt16(buffer, ! font->advances[inst->codeTable[i]]); ! ! for (i = 0; i < inst->nGlyphs; ++i) ! { SWFOutput_writeRect(buffer, SWFFont_getGlyphBounds(font, inst->codeTable[i])); SWFOutput_byteAlign(buffer); } --- 175,185 ---- SWFOutput_writeUInt16(buffer, font->descent); SWFOutput_writeUInt16(buffer, font->leading); ! for (i = 0; i < inst->nGlyphs; ++i) { ! int glyph = SWFFont_findGlyphCode(font,inst->codeTable[i]); ! SWFOutput_writeSInt16(buffer,font->advances[glyph]); ! } ! for (i = 0; i < inst->nGlyphs; ++i) { ! int glyph = SWFFont_findGlyphCode(font,inst->codeTable[i]); ! SWFOutput_writeRect(buffer, SWFFont_getGlyphBounds(font, glyph)); SWFOutput_byteAlign(buffer); } *************** *** 465,469 **** } ! static int SWFFont_findGlyphCode(SWFFont font, unsigned short c) { --- 467,471 ---- } ! int SWFFont_findGlyphCode(SWFFont font, unsigned short c) { *************** *** 610,615 **** ! static int ! SWFFontCharacter_findCharCode(SWFFontCharacter font, unsigned short c) { // return the index in font->codeTable for the given character --- 612,617 ---- ! int ! SWFFontCharacter_findGlyphCode(SWFFontCharacter font, unsigned short c) { // return the index in font->codeTable for the given character *************** *** 633,640 **** SWFFontCharacter_addCharToTable(fc, charcode); } - - for (i = 0; i < fc->nGlyphs; ++i) - fc->codeTable[i] = - SWFFont_findGlyphCode(font, fc->codeTable[i]); } --- 635,638 ---- *************** *** 658,683 **** } ! // translate text records' strings into lists of font char codes ! ! text = font->textList; ! ! while ( text != NULL ) ! { ! len = SWFTextRecord_getString(text->text, &string); ! ! for ( i=0; i<len; ++i ) ! { ! int code = SWFFontCharacter_findCharCode(font, string[i]); ! ! if ( code >= 0 ) ! string[i] = (unsigned short)code; ! ! // XXX - else? ! } ! ! text = text->next; ! } ! ! // translate codeTable's char codes into glyph codes for ( i=0; i<font->nGlyphs; ++i ) --- 656,660 ---- } ! // check availability of a font glyph for each fontchar codetable entry for ( i=0; i<font->nGlyphs; ++i ) *************** *** 693,697 **** SWF_error("Stopped\n"); } - font->codeTable[i] = code; } } --- 670,673 ---- *************** *** 841,847 **** unsigned short ! SWFFontCharacter_getGlyphCode(SWFFontCharacter font, unsigned short c) { ! return font->codeTable[c]; } --- 817,834 ---- unsigned short ! SWFFontCharacter_getGlyphCode(SWFFontCharacter font, unsigned short glyphcode) { ! if ( glyphcode >= font->nGlyphs ) ! SWF_error("SWFFontCharacter_getGlyphCode: No such row in codeTable"); ! return font->codeTable[glyphcode]; ! } ! ! unsigned short ! SWFFont_getGlyphCode(SWFFont font, unsigned short glyphcode) ! { ! if ( glyphcode >= font->nGlyphs ) ! SWF_error("SWFFont_getGlyphCode: glyphcode >= nGlyphs"); ! ! return font->glyphToCode[glyphcode]; } Index: text.c =================================================================== RCS file: /cvsroot/ming/ming/src/blocks/text.c,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** text.c 16 Feb 2009 17:55:10 -0000 1.42 --- text.c 1 Dec 2009 20:09:44 -0000 1.43 *************** *** 661,665 **** } ! glyph = SWFFontCharacter_getGlyphCode(fontchar, widestring[0]); for ( i=0; i<len; ++i ) --- 661,665 ---- } ! glyph = SWFFont_findGlyphCode(font, widestring[0]); for ( i=0; i<len; ++i ) *************** *** 674,678 **** if ( i < len-1 ) ! { nextglyph = SWFFontCharacter_getGlyphCode(fontchar, widestring[i+1]); adv += SWFFont_getCharacterKern(font, glyph, nextglyph); glyph = nextglyph; --- 674,678 ---- if ( i < len-1 ) ! { nextglyph = SWFFont_findGlyphCode(font, widestring[i+1]); adv += SWFFont_getCharacterKern(font, glyph, nextglyph); glyph = nextglyph; *************** *** 792,802 **** int minX, maxX, minY, maxY; ! unsigned short code = ! SWFFontCharacter_getGlyphCode(fontchar, textRecord->string[i]); ! ! glyphBounds = SWFFont_getGlyphBounds(font, code); SWFRect_getBounds(glyphBounds, &minX, &maxX, &minY, &maxY); ! SWFOutput_writeBits(out, textRecord->string[i], nGlyphBits); SWFOutput_writeBits(out, textRecord->advance[i], text->nAdvanceBits); --- 792,806 ---- int minX, maxX, minY, maxY; ! unsigned short font_glyphcode = ! SWFFont_findGlyphCode(font, textRecord->string[i]); ! glyphBounds = SWFFont_getGlyphBounds(font,font_glyphcode); SWFRect_getBounds(glyphBounds, &minX, &maxX, &minY, &maxY); ! int fontchar_glyphcode = ! SWFFontCharacter_findGlyphCode(fontchar, textRecord->string[i]); ! if (fontchar_glyphcode < 0) { ! SWF_error("SWFText_resolveCodes: no suitable glyph available (in dumped font)"); ! } ! SWFOutput_writeBits(out, (unsigned short) fontchar_glyphcode, nGlyphBits); SWFOutput_writeBits(out, textRecord->advance[i], text->nAdvanceBits); Index: font.h =================================================================== RCS file: /cvsroot/ming/ming/src/blocks/font.h,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** font.h 10 Jul 2008 19:40:34 -0000 1.29 --- font.h 1 Dec 2009 20:09:43 -0000 1.30 *************** *** 160,166 **** --- 160,176 ---- void SWFFontCharacter_addTextToList(SWFFontCharacter font, SWFTextRecord text); + /* swf codetable: glyph --> char */ unsigned short SWFFontCharacter_getGlyphCode(SWFFontCharacter font, unsigned short c); + /* swf codetable: char --> glyph */ + int SWFFontCharacter_findGlyphCode(SWFFontCharacter font, unsigned short c); + + /* source font: glyph --> char */ + unsigned short SWFFont_getGlyphCode(SWFFont font, unsigned short c); + + /* source font: char --> glyph */ + int SWFFont_findGlyphCode(SWFFont font, unsigned short c); + void SWFFont_buildReverseMapping(SWFFont font); |