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.
This commit is contained in:
Noah Levitt 2003-09-06 19:40:41 +00:00
parent 3ef32bcdc4
commit a05d257fb3
6 changed files with 63 additions and 14 deletions

View File

@ -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

View 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

View 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

View 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

View 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;

View 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, },