Bug 47

Summary: fontconfig should retrieve type 1 font information from FontInfo dictionary
Product: fontconfig Reporter: Gerard Escalante <g2>
Component: libraryAssignee: Keith Packard <keithp>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: high    
Version: 2.1   
Hardware: x86 (IA32)   
OS: Linux (All)   
URL: http://freetype.sourceforge.net/freetype2/docs/reference/ft2-type1_tables.html#FT_Get_PS_Font_Info
Whiteboard:
i915 platform: i915 features:
Attachments: Patch to make fontconfig read the FontInfo dictionary
Improved patch - no memory leak

Description Gerard Escalante 2003-03-15 21:28:12 UTC
I've noticed the recent addition to fontconfig, where it now uses the 
usWeightclass value to set font weight.  However, my system uses mainly Type 
1 fonts, and I have had the problem of apps like Qt/KDE not recognizing all 
the different faces, because of only two different weight values. 
 
I'm not too sure whether this is appropriate, but I've made a patch against 
fontconfig CVS which makes fontconfig read the Type 1 FontInfo dictionary. 
The design is somewhat parallel to the usWeightclass setup. It seems to work 
fine on my system, however,I have never coded anything for freetype, so I 
hope that it's done correctly.   
 
 
--------- start of Type1-fontconfig.patch 
 
--- fontconfig-cvs/src/fcfreetype.c     2003-03-15 23:29:45.000000000 -0500 
+++ fontconfig/src/fcfreetype.c 2003-03-15 23:59:44.000000000 -0500 
@@ -31,6 +31,7 @@ 
 #include <freetype/tttables.h> 
 #include <freetype/ftsnames.h> 
 #include <freetype/ttnameid.h> 
+#include <freetype/t1tables.h> 
 
 /* 
  * Keep Han languages separated by eliminating languages 
@@ -129,6 +130,7 @@ 
     FcChar8        *family; 
     FcChar8        *style; 
     TT_OS2         *os2; 
+    PS_FontInfoRec  *psfontinfo; 
     TT_Header      *head; 
     const FcChar8   *exclusiveLang = 0; 
     FT_SfntName            sname; 
@@ -563,6 +565,51 @@ 
        case 9: width = FC_WIDTH_ULTRAEXPANDED; break; 
        } 
     } 
+ 
+    /* 
+     * Type 1: Check for FontInfo dictionary information 
+     */ 
+    psfontinfo  = malloc(sizeof(PS_FontInfoRec)); 
+    if (FT_Get_PS_Font_Info(face, psfontinfo) == 0) 
+    { 
+        if (strcasecmp("thin", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_THIN; 
+        else if (strcasecmp("extralight", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_EXTRALIGHT; 
+        else if (strcasecmp("ultralight", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_ULTRALIGHT; 
+        else if (strcasecmp("light", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_LIGHT; 
+        else if (strcasecmp("regular", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_REGULAR; 
+        else if (strcasecmp("normal", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_REGULAR; 
+        else if (strcasecmp("medium", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_MEDIUM; 
+        else if (strcasecmp("demibold", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_DEMIBOLD; 
+        else if (strcasecmp("semibold", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_DEMIBOLD; 
+        else if (strcasecmp("extrabold", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_EXTRABOLD; 
+        else if (strcasecmp("ultrabold", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_EXTRABOLD; 
+        else if (strcasecmp("bold", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_BOLD; 
+        else if (strcasecmp("black", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_BLACK; 
+        else if (strcasecmp("heavy", psfontinfo->weight) == 0) 
+            weight = FC_WEIGHT_BLACK; 
+ 
+        if (psfontinfo->is_fixed_pitch) 
+            if (!FcPatternAddInteger (pat, FC_SPACING, FC_MONO)) 
+                goto bail1; 
+ 
+        if (psfontinfo->italic_angle < 0) 
+            slant = FC_SLANT_ITALIC; 
+        else if (psfontinfo->italic_angle >= 0) 
+            slant = FC_SLANT_ROMAN; 
+    } 
 
     if (!FcPatternAddInteger (pat, FC_SLANT, slant)) 
        goto bail1; 
 
--------- end of Type1-fontconfig.patch
Comment 1 Gerard Escalante 2003-03-15 21:32:00 UTC
Created attachment 31 [details] [review]
Patch to make fontconfig read the FontInfo dictionary
Comment 2 Keith Packard 2003-03-15 21:49:52 UTC
Cool.  Is there also width information in that table? It would be nice to
distinguish between condensed and regular versions of the same face.

Also, looks like you're leaking memory here; you might as well have a local
PS_FontInfoRec variable and pass it's address rather than calling malloc.

If you'll change that, I'll apply the patch.
Comment 3 Gerard Escalante 2003-03-16 08:08:15 UTC
Created attachment 32 [details] [review]
Improved patch - no memory leak
Comment 4 Gerard Escalante 2003-03-16 08:19:27 UTC
Fixed the memory leak. 
 
And as far as I can tell, the table doesn't hold width values.  As far as I can 
figure out, the only way you can tell the width of a Type 1 font is from the 
style name.  It could be done by text parsing within the style, but I don't 
know whether that's a good idea or not.  What do you think? 
Comment 5 Keith Packard 2003-04-11 15:17:21 UTC
Thanks very much! This fixed bug #46 as well.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.