From 848d32bd3f141f0c14abfec38d4cf27eedd1f0a5 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 28 Mar 2003 17:08:35 +0000 Subject: [PATCH] Set spacing to mono if every encoded glyph is the same width --- fontconfig/fcfreetype.h | 3 +++ src/fcfreetype.c | 46 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/fontconfig/fcfreetype.h b/fontconfig/fcfreetype.h index 037d7e1..d300e79 100644 --- a/fontconfig/fcfreetype.h +++ b/fontconfig/fcfreetype.h @@ -29,6 +29,9 @@ FT_UInt FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4); +FcCharSet * +FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing); + FcCharSet * FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks); diff --git a/src/fcfreetype.c b/src/fcfreetype.c index c4d4cfc..7a9e32d 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -128,6 +128,7 @@ FcFreeTypeQuery (const FcChar8 *file, FT_Library ftLibrary; FcChar8 *family; FcChar8 *style; + int spacing; TT_OS2 *os2; TT_Header *head; const FcChar8 *exclusiveLang = 0; @@ -577,7 +578,7 @@ FcFreeTypeQuery (const FcChar8 *file, /* * Compute the unicode coverage for the font */ - cs = FcFreeTypeCharSet (face, blanks); + cs = FcFreeTypeCharSetAndSpacing (face, blanks, &spacing); if (!cs) goto bail1; @@ -601,6 +602,10 @@ FcFreeTypeQuery (const FcChar8 *file, if (!FcPatternAddLangSet (pat, FC_LANG, ls)) goto bail2; + if (spacing != FC_PROPORTIONAL) + if (!FcPatternAddInteger (pat, FC_SPACING, spacing)) + goto bail2; + /* * Drop our reference to the charset */ @@ -1217,7 +1222,8 @@ FcFreeTypeCharIndex (FT_Face face, FcChar32 ucs4) static FcBool FcFreeTypeCheckGlyph (FT_Face face, FcChar32 ucs4, - FT_UInt glyph, FcBlanks *blanks) + FT_UInt glyph, FcBlanks *blanks, + FT_Pos *advance) { FT_Int load_flags = FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; FT_GlyphSlot slot; @@ -1239,6 +1245,8 @@ FcFreeTypeCheckGlyph (FT_Face face, FcChar32 ucs4, if (!glyph) return FcFalse; + *advance = slot->metrics.horiAdvance; + switch (slot->format) { case ft_glyph_format_bitmap: /* @@ -1269,7 +1277,7 @@ FcFreeTypeCheckGlyph (FT_Face face, FcChar32 ucs4, } FcCharSet * -FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks) +FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing) { FcChar32 page, off, max, ucs4; #ifdef CHECK @@ -1281,6 +1289,8 @@ FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks) int o; int i; FT_UInt glyph; + FT_Pos advance, all_advance = 0; + FcBool has_advance = FcFalse, fixed_advance = FcTrue; fcs = FcCharSetCreate (); if (!fcs) @@ -1301,8 +1311,16 @@ FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks) { ucs4 = map->ent[i].bmp; glyph = FT_Get_Char_Index (face, map->ent[i].encode); - if (glyph && FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks)) + if (glyph && + FcFreeTypeCheckGlyph (face, ucs4, glyph, blanks, &advance)) { + if (!has_advance) + { + has_advance = FcTrue; + all_advance = advance; + } + else if (advance != all_advance) + fixed_advance = FcFalse; leaf = FcCharSetFindLeafCreate (fcs, ucs4); if (!leaf) goto bail1; @@ -1342,8 +1360,15 @@ FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks) { glyph = FT_Get_Char_Index (face, ucs4); if (glyph && FcFreeTypeCheckGlyph (face, ucs4, - glyph, blanks)) + glyph, blanks, &advance)) { + if (!has_advance) + { + has_advance = FcTrue; + all_advance = advance; + } + else if (advance != all_advance) + fixed_advance = FcFalse; if (!leaf) { leaf = FcCharSetFindLeafCreate (fcs, ucs4); @@ -1391,6 +1416,10 @@ FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks) printf ("Bitmap extra char 0x%x\n", ucs4); } #endif + if (fixed_advance) + *spacing = FC_MONO; + else + *spacing = FC_PROPORTIONAL; return fcs; bail1: FcCharSetDestroy (fcs); @@ -1398,3 +1427,10 @@ bail0: return 0; } +FcCharSet * +FcFreeTypeCharSet (FT_Face face, FcBlanks *blanks) +{ + int spacing; + + return FcFreeTypeCharSetAndSpacing (face, blanks, &spacing); +}