]> git.wh0rd.org - fontconfig.git/commitdiff
Set spacing to mono if every encoded glyph is the same width
authorKeith Packard <keithp@keithp.com>
Fri, 28 Mar 2003 17:08:35 +0000 (17:08 +0000)
committerKeith Packard <keithp@keithp.com>
Fri, 28 Mar 2003 17:08:35 +0000 (17:08 +0000)
fontconfig/fcfreetype.h
src/fcfreetype.c

index 037d7e10577fe8a5304cf6d4eeb49a7264742044..d300e79e2b65fc6a28aba2d20599e19e6707cab4 100644 (file)
@@ -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);
 
index c4d4cfc627f5f029826b81fcd53b7246328ebc04..7a9e32d2a4dca301be6c48fc2ca60ad1708e29ad 100644 (file)
@@ -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);
+}