summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Levitt <nlevitt@gmail.com>2003-09-06 19:40:41 +0000
committerNoah Levitt <nlevitt@gmail.com>2003-09-06 19:40:41 +0000
commita05d257fb3b2cf37c6c633029b308a76fe61b9c2 (patch)
treea1b2e05bd22e2d455f935e2e6983d180a94dca0f
parent3ef32bcdc4662fbc10bc5217ea7849cd31480d73 (diff)
Add new spacing value FC_DUAL (dual-width, as some CJK fonts). (bug #111)
When checking for monospace and dual-width fonts, allow roughly a 3% variance in the advances.
-rw-r--r--ChangeLog13
-rw-r--r--doc/fontconfig-devel.sgml4
-rw-r--r--doc/fontconfig-user.sgml3
-rw-r--r--fontconfig/fontconfig.h1
-rw-r--r--src/fcfreetype.c55
-rw-r--r--src/fcname.c1
6 files changed, 63 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 79ca94a..b36b3d8 100644
--- 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
diff --git a/doc/fontconfig-devel.sgml b/doc/fontconfig-devel.sgml
index e695fbb..b2fd21c 100644
--- a/doc/fontconfig-devel.sgml
+++ b/doc/fontconfig-devel.sgml
@@ -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
diff --git a/doc/fontconfig-user.sgml b/doc/fontconfig-user.sgml
index 450be52..60dc31d 100644
--- a/doc/fontconfig-user.sgml
+++ b/doc/fontconfig-user.sgml
@@ -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
diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h
index 3cd7967..cb5f95f 100644
--- a/fontconfig/fontconfig.h
+++ b/fontconfig/fontconfig.h
@@ -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
diff --git a/src/fcfreetype.c b/src/fcfreetype.c
index c2d00a9..054e208 100644
--- a/src/fcfreetype.c
+++ b/src/fcfreetype.c
@@ -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;
diff --git a/src/fcname.c b/src/fcname.c
index 0219d16..b15b8fb 100644
--- a/src/fcname.c
+++ b/src/fcname.c
@@ -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, },