diff options
Diffstat (limited to 'xc/lib/Xft/xftglyphs.c')
-rw-r--r-- | xc/lib/Xft/xftglyphs.c | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/xc/lib/Xft/xftglyphs.c b/xc/lib/Xft/xftglyphs.c index 1e99d4727..c400f821d 100644 --- a/xc/lib/Xft/xftglyphs.c +++ b/xc/lib/Xft/xftglyphs.c @@ -1,5 +1,5 @@ /* - * $XFree86: xc/lib/Xft/xftglyphs.c,v 1.1 2000/11/29 08:39:23 keithp Exp $ + * $XFree86: xc/lib/Xft/xftglyphs.c,v 1.3 2000/12/03 19:03:22 keithp Exp $ * * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc. * @@ -53,6 +53,7 @@ XftGlyphLoad (Display *dpy, #ifdef FREETYPE2 FT_Error error; FT_ULong charcode; + FT_UInt glyphindex; FT_GlyphSlot glyph; XGlyphInfo *gi; Glyph g; @@ -83,19 +84,45 @@ XftGlyphLoad (Display *dpy, while (nglyph--) { charcode = (FT_ULong) *glyphs++; - error = FT_Load_Char (font->face, charcode, 0/*|FT_LOAD_NO_HINTING */); + if (font->encoded) + { + glyphindex = FT_Get_Char_Index (font->face, charcode); + if (!glyphindex) + continue; + } + else + glyphindex = (FT_UInt) charcode; + error = FT_Load_Glyph (font->face, glyphindex, 0/*|FT_LOAD_NO_HINTING */); if (error) continue; -#define FLOOR(x) ((x) & -64) -#define CEIL(x) (((x)+63) & -64) -#define TRUNC(x) ((x) >> 6) +#define FLOOR(x) ((x) & -64) +#define CEIL(x) (((x)+63) & -64) +#define TRUNC(x) ((x) >> 6) +#define ROUND(x) (((x)+32) & -64) glyph = font->face->glyph; left = FLOOR( glyph->metrics.horiBearingX ); right = CEIL( glyph->metrics.horiBearingX + glyph->metrics.width ); width = TRUNC(right - left); + /* + * Try to keep monospace fonts ink-inside + */ + if (font->monospace) + { + if (TRUNC(right) > font->max_advance_width) + { + int adjust; + + adjust = right - (font->max_advance_width << 6); + if (adjust > left) + adjust = left; + left -= adjust; + right -= adjust; + width = font->max_advance_width; + } + } top = CEIL( glyph->metrics.horiBearingY ); bottom = FLOOR( glyph->metrics.horiBearingY - glyph->metrics.height ); @@ -204,9 +231,9 @@ XftGlyphLoad (Display *dpy, gi->x = -TRUNC(left); gi->y = TRUNC(top); if (font->monospace) - gi->xOff = font->face->max_advance_width * font->size / (64 * font->face->units_per_EM); + gi->xOff = font->max_advance_width; else - gi->xOff = ((glyph->metrics.horiAdvance + 0x20) >> 6); + gi->xOff = TRUNC(ROUND(glyph->metrics.horiAdvance)); gi->yOff = 0; g = charcode; @@ -330,3 +357,18 @@ XftGlyphCheck (Display *dpy, } #endif } + +Bool +XftFreeTypeGlyphExists (Display *dpy, + XftFontStruct *font, + unsigned int glyph) +{ +#ifdef FREETYPE2 + if (font->encoded) + return FT_Get_Char_Index (font->face, (FT_ULong) glyph) != 0; + else + return glyph && glyph <= font->face->num_glyphs; +#else + return False; +#endif +} |