diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2013-11-26 11:30:14 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2013-11-26 11:30:14 +0100 |
commit | bea951c1e5f5e79c44b5a4a1ba1fd0a69d7a005d (patch) | |
tree | 454e2fa06f474afb68bccdda70ad293c3c0b028f /source/fitz | |
parent | ea9b6544654e4ac0853c35730924ed31f24ceeba (diff) | |
download | mupdf-bea951c1e5f5e79c44b5a4a1ba1fd0a69d7a005d.tar.xz |
Add fz_advance_glyph and fz_encode_character functions.
Diffstat (limited to 'source/fitz')
-rw-r--r-- | source/fitz/font.c | 46 |
1 files changed, 46 insertions, 0 deletions
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 <ft2build.h> #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; +} |