From bea951c1e5f5e79c44b5a4a1ba1fd0a69d7a005d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 26 Nov 2013 11:30:14 +0100 Subject: Add fz_advance_glyph and fz_encode_character functions. --- source/fitz/font.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'source/fitz') diff --git a/source/fitz/font.c b/source/fitz/font.c index d201f441..d8ee7b49 100644 --- a/source/fitz/font.c +++ b/source/fitz/font.c @@ -2,6 +2,7 @@ #include #include FT_FREETYPE_H +#include FT_ADVANCES_H #include FT_STROKER_H #define MAX_BBOX_TABLE_SIZE 4096 @@ -1234,3 +1235,48 @@ int fz_glyph_cacheable(fz_context *ctx, fz_font *font, int gid) return 1; return (font->t3flags[gid] & FZ_DEVFLAG_UNCACHEABLE) == 0; } + +static float +fz_advance_ft_glyph(fz_context *ctx, fz_font *font, int gid) +{ + FT_Fixed adv; + int mask = FT_LOAD_NO_SCALE | FT_LOAD_IGNORE_TRANSFORM; + + if (font->ft_substitute && font->width_table && gid < font->width_count) + return font->width_table[gid]; + + FT_Get_Advance(font->ft_face, gid, mask, &adv); + return (float) adv / ((FT_Face)font->ft_face)->units_per_EM; +} + +static float +fz_advance_t3_glyph(fz_context *ctx, fz_font *font, int gid) +{ + if (gid < 0 || gid > 255) + return 0; + return font->t3widths[gid]; +} + +float +fz_advance_glyph(fz_context *ctx, fz_font *font, int gid) +{ + if (font->ft_face) + return fz_advance_ft_glyph(ctx, font, gid); + if (font->t3procs) + return fz_advance_t3_glyph(ctx, font, gid); + return 0; +} + +static int +fz_encode_ft_character(fz_context *ctx, fz_font *font, int ucs) +{ + return FT_Get_Char_Index(font->ft_face, ucs); +} + +int +fz_encode_character(fz_context *ctx, fz_font *font, int ucs) +{ + if (font->ft_face) + return fz_encode_ft_character(ctx, font, ucs); + return ucs; +} -- cgit v1.2.3