Here's a patch that fixes the TTF importer to use metrics calculations for ascender/descender/leading that more closely match those used by the Adobe tools (flash, mxmlc). Freetype (incorrectly) defaults to using the Hhea metrics, whereas Adobe defaults to the OS/2 metrics.
Piers.
diff -r swfmill-0.3.0.orig\src\swft\swft_import_ttf.cpp
swfmill-0.3.0\src\swft\swft_import_ttf.cpp
16a17,18
> #include <freetype/tttables.h>
>
63a71,100
> //#define FWORD_SCALE (1<<16)
> #define FWORD_SCALE (1)
>
> void getVerticalMetrics (FT_Face face, int SCALING_FACTOR, int &ascender, int
> &descender, int &lineGap)
> {
> unsigned char *pOS2 = (unsigned char *) FT_Get_Sfnt_Table(face,
> ft_sfnt_os2);
> if (pOS2)
> {
> ascender = (short) (pOS2 [76] | (pOS2 [77] << 8)) * FWORD_SCALE;
> descender = (short) (pOS2 [78] | (pOS2 [79] << 8)) *
> FWORD_SCALE;
> lineGap = (short) (pOS2 [74] | (pOS2 [75] << 8)) * FWORD_SCALE;
> }
> else
> {
> unsigned char *pHhea = (unsigned char *)
> FT_Get_Sfnt_Table(face, ft_sfnt_hhea);
> if (pHhea)
> {
> ascender = (short) (pHhea [4] | (pHhea [5] << 8));
> descender = -(short) (pHhea [6] | (pHhea [7] << 8));
> lineGap = (short) (pHhea [8] | (pHhea [9] << 8));
> }
> }
>
> /*
> printf ("ascender: %i\n", ascender / FWORD_SCALE);
> printf ("descender: %i\n", descender / FWORD_SCALE);
> printf ("lineGap: %i\n", lineGap / FWORD_SCALE);
> */
> }
>
83a121,122
> const int SCALING_FACTOR = 1024;
>
99c138,139
< FT_Set_Char_Size(face, (1024<<6), (1024<<6), 72, 72);
---
> FT_Set_Pixel_Sizes(face, SCALING_FACTOR, SCALING_FACTOR);
150c190,196
< #define SCALING_FACTOR ((int)1024)
---
> {
> int ascender, descender, lineGap;
> getVerticalMetrics (face, SCALING_FACTOR, ascender, descender,
> lineGap);
> tag->setascent (ascender * SCALING_FACTOR / (face->units_per_EM
> * FWORD_SCALE));
> tag->setdescent (descender * SCALING_FACTOR /
> (face->units_per_EM * FWORD_SCALE));
> tag->setleading (lineGap * SCALING_FACTOR / (face->units_per_EM
> * FWORD_SCALE));
> }
152,156d197
< tag->setascent( 1+((SCALING_FACTOR * face->ascender) /
face->units_per_EM) );
< tag->setdescent( 1+((SCALING_FACTOR * labs(face->descender)) /
face->units_per_EM) );
< tag->setleading( 0 ) ;// (1+(SCALING_FACTOR * face->ascender) /
face->units_per_EM) + (1+(SCALING_FACTOR * labs(face->descender)) /
face->units_per_EM) );
< //1+(SCALING_FACTOR * face->height) /
face->units_per_EM );
<
271a313,315
>
> const int SCALING_FACTOR = 1024 * 20;
>
288c332
< FT_Set_Char_Size(face, (1024<<6) * 20, (1024<<6) * 20, 72, 72);
---
> FT_Set_Char_Size(face, SCALING_FACTOR << 6, SCALING_FACTOR << 6, 72,
> 72);
339,344c383,389
< #define SCALING_FACTOR ((int)1024)
<
< tag->setascent( (1+((SCALING_FACTOR * face->ascender) /
face->units_per_EM)) * 20 );
< tag->setdescent( (1+((SCALING_FACTOR * labs(face->descender)) /
face->units_per_EM)) * 20 );
< tag->setleading( 0 ) ;// (1+(SCALING_FACTOR * face->ascender) /
face->units_per_EM) + (1+(SCALING_FACTOR * labs(face->descender)) /
face->units_per_EM) );
< //1+(SCALING_FACTOR * face->height) /
face->units_per_EM );
---
> {
> int ascender, descender, lineGap;
> getVerticalMetrics (face, SCALING_FACTOR, ascender, descender,
> lineGap);
> tag->setascent (ascender * SCALING_FACTOR / (face->units_per_EM
> * FWORD_SCALE));
> tag->setdescent (descender * SCALING_FACTOR /
> (face->units_per_EM * FWORD_SCALE));
> tag->setleading (lineGap * SCALING_FACTOR / (face->units_per_EM
> * FWORD_SCALE));
> }
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ swfmill mailing list [email protected] http://osflash.org/mailman/listinfo/swfmill_osflash.org
