]> git.wh0rd.org - fontconfig.git/commitdiff
Add new spacing value FC_DUAL (dual-width, as some CJK fonts). (bug #111)
authorNoah Levitt <nlevitt@gmail.com>
Sat, 6 Sep 2003 19:40:41 +0000 (19:40 +0000)
committerNoah Levitt <nlevitt@gmail.com>
Sat, 6 Sep 2003 19:40:41 +0000 (19:40 +0000)
When checking for monospace and dual-width fonts, allow roughly a 3%
    variance in the advances.

ChangeLog
doc/fontconfig-devel.sgml
doc/fontconfig-user.sgml
fontconfig/fontconfig.h
src/fcfreetype.c
src/fcname.c

index 79ca94a6d218084d08817c2d1fde260d66476ac9..b36b3d8a637febe1d6e26c49cd8bb7bbdfe2c7e9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2003-09-06  Noah Levitt  <nlevitt@columbia.edu>
+
+       * doc/fontconfig-devel.sgml:
+       * doc/fontconfig-user.sgml:
+       * fontconfig/fontconfig.h:
+       * src/fcname.c:
+       * src/fcfreetype.c (FcFreeTypeCharSetAndSpacing): Add new spacing
+       value FC_DUAL (dual-width, as some CJK fonts). (bug #111)
+
+       * src/fcfreetype.c (FcFreeTypeCharSetAndSpacing): When checking for
+       monospace and dual-width fonts, allow roughly a 3% variance in the
+       advances.
+
 2003-08-31  Manish Singh  <yosh@gimp.org>
 
        * src/fccfg.c (FcConfigAppFontClear): Support passing NULL to
index e695fbb55866f1fc7d66d23e16213c1e865efd38..b2fd21c573382cd79a8d0a51b2531ad7865fc92e 100644 (file)
@@ -139,8 +139,8 @@ convenience for the applications rendering mechanism.
     aspect         FC_ASPECT            Double  Stretches glyphs horizontally
                                                 before hinting
     pixelsize      FC_PIXEL_SIZE        Double  Pixel size
-    spacing        FC_SPACING           Int     Proportional, monospace or
-                                                charcell
+    spacing        FC_SPACING           Int     Proportional, dual-width,
+                                                monospace or charcell
     foundry        FC_FOUNDRY           String  Font foundry name
     antialias      FC_ANTIALIAS         Bool    Whether glyphs can be
                                                 antialiased
index 450be524b9bc9009e7902aaf7f783306b782c870..60dc31d4d18cec77fe5a7bdc7bfabb5de6818b64 100644 (file)
@@ -98,7 +98,7 @@ convenience for the applications rendering mechanism.
   size            Double  Point size
   aspect          Double  Stretches glyphs horizontally before hinting
   pixelsize       Double  Pixel size
-  spacing         Int     Proportional, monospace or charcell
+  spacing         Int     Proportional, dual-width, monospace or charcell
   foundry         String  Font foundry name
   antialias       Bool    Whether glyphs can be antialiased
   hinting         Bool    Whether the rasterizer should use hinting
@@ -349,6 +349,7 @@ symbolic names for common font values:
   italic          slant           100
   oblique         slant           110
   proportional    spacing         0
+  dual            spacing         90
   mono            spacing         100
   charcell        spacing         110
   unknown         rgba            0
index 3cd7967ddea0673e155d03715278d1ffb2fba7c9..cb5f95f3ac79dc94d1e90b057b5ede939b1d738c 100644 (file)
@@ -128,6 +128,7 @@ typedef int         FcBool;
 #define FC_WIDTH_ULTRAEXPANDED     200
 
 #define FC_PROPORTIONAL                    0
+#define FC_DUAL                            90
 #define FC_MONO                            100
 #define FC_CHARCELL                110
 
index c2d00a9bfca415f5a73faea3bcac6ac4c45cd4b8..054e208ae191a4ed534971867b353b0b8cf1c33b 100644 (file)
@@ -1807,6 +1807,8 @@ FcFreeTypeCheckGlyph (FT_Face face, FcChar32 ucs4,
     return FcFalse;
 }
 
+#define APPROXIMATELY_EQUAL(x,y) (ABS ((x) - (y)) <= MAX (ABS (x), ABS (y)) / 33)
+
 FcCharSet *
 FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
 {
@@ -1820,8 +1822,8 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
     int                    o;
     int                    i;
     FT_UInt        glyph;
-    FT_Pos         advance, all_advance = 0;
-    FcBool         has_advance = FcFalse, fixed_advance = FcTrue;
+    FT_Pos         advance, advance_one = 0, advance_two = 0;
+    FcBool         has_advance = FcFalse, fixed_advance = FcTrue, dual_advance = FcFalse;
 
     fcs = FcCharSetCreate ();
     if (!fcs)
@@ -1851,10 +1853,20 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
                    if (!has_advance)
                    {
                        has_advance = FcTrue;
-                       all_advance = advance;
+                       advance_one = advance;
                    }
-                   else if (advance != all_advance)
-                       fixed_advance = FcFalse;
+                   else if (!APPROXIMATELY_EQUAL (advance, advance_one))
+                    {
+                        if (fixed_advance)
+                        {
+                            dual_advance = FcTrue;
+                            fixed_advance = FcFalse;
+                            advance_two = advance;
+                        }
+                        else if (!APPROXIMATELY_EQUAL (advance, advance_two))
+                            dual_advance = FcFalse;
+                    }
+
                    leaf = FcCharSetFindLeafCreate (fcs, ucs4);
                    if (!leaf)
                        goto bail1;
@@ -1899,10 +1911,20 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
                        if (!has_advance)
                        {
                            has_advance = FcTrue;
-                           all_advance = advance;
+                           advance_one = advance;
                        }
-                       else if (advance != all_advance)
-                           fixed_advance = FcFalse;
+                       else if (!APPROXIMATELY_EQUAL (advance, advance_one))
+                        {
+                            if (fixed_advance)
+                            {
+                                dual_advance = FcTrue;
+                                fixed_advance = FcFalse;
+                                advance_two = advance;
+                            }
+                            else if (!APPROXIMATELY_EQUAL (advance, advance_two))
+                                dual_advance = FcFalse;
+                        }
+
                        if (!leaf)
                        {
                            leaf = FcCharSetFindLeafCreate (fcs, ucs4);
@@ -1956,10 +1978,19 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
                    if (!has_advance)
                    {
                        has_advance = FcTrue;
-                       all_advance = advance;
+                       advance_one = advance;
                    }
-                   else if (advance != all_advance)
-                       fixed_advance = FcFalse;
+                   else if (!APPROXIMATELY_EQUAL (advance, advance_one))
+                    {
+                        if (fixed_advance)
+                        {
+                            dual_advance = FcTrue;
+                            fixed_advance = FcFalse;
+                            advance_two = advance;
+                        }
+                        else if (!APPROXIMATELY_EQUAL (advance, advance_two))
+                            dual_advance = FcFalse;
+                    }
                    leaf = FcCharSetFindLeafCreate (fcs, ucs4);
                    if (!leaf)
                        goto bail1;
@@ -1993,6 +2024,8 @@ FcFreeTypeCharSetAndSpacing (FT_Face face, FcBlanks *blanks, int *spacing)
 #endif
     if (fixed_advance)
        *spacing = FC_MONO;
+    else if (dual_advance && APPROXIMATELY_EQUAL (2 * MIN (advance_one, advance_two), MAX (advance_one, advance_two)))
+        *spacing = FC_DUAL;
     else
        *spacing = FC_PROPORTIONAL;
     return fcs;
index 0219d16760b8cd4b4a718b0938d464a0f43e5469..b15b8fb6702845e76083e9873160baaf33f5ad69 100644 (file)
@@ -167,6 +167,7 @@ static const FcConstant _FcBaseConstants[] = {
     { (FcChar8 *) "ultraexpanded",  "width",   FC_WIDTH_ULTRAEXPANDED },
     
     { (FcChar8 *) "proportional",   "spacing",  FC_PROPORTIONAL, },
+    { (FcChar8 *) "dual",          "spacing",  FC_DUAL, },
     { (FcChar8 *) "mono",          "spacing",  FC_MONO, },
     { (FcChar8 *) "charcell",      "spacing",  FC_CHARCELL, },