diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2015-02-21 15:05:24 +0000 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2015-02-21 15:05:24 +0000 |
commit | fbacf8fd2a4e22df4f740fa28cc1da0d556e957f (patch) | |
tree | de953728222b20635fba5a77176081afe4db80b2 /Build/source/texk | |
parent | 76f588e8f00d736a9c635576b5b83ae0fa208616 (diff) |
Load glyph advances without FreeType
git-svn-id: svn://tug.org/texlive/trunk@36333 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk')
-rw-r--r-- | Build/source/texk/dvipdfm-x/ChangeLog | 6 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/dvi.c | 63 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/fontmap.c | 46 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/fontmap.h | 8 |
4 files changed, 54 insertions, 69 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog index 48d811eb868..c5c89d2da49 100644 --- a/Build/source/texk/dvipdfm-x/ChangeLog +++ b/Build/source/texk/dvipdfm-x/ChangeLog @@ -1,3 +1,9 @@ +2015-02-21 Akira Kakuto <kakuto@fuk.kindai.ac.jp> + + * dvi.c: Read glyph advances without the need for FreeType, based on + patch by Clerk Ma. + * fontmap.c, fontmap.h: Stop loading FreeType fonts. + 2015-02-16 Akira Kakuto <kakuto@fuk.kindai.ac.jp> * jpegimage.c: Fix jpeg_get_density(). diff --git a/Build/source/texk/dvipdfm-x/dvi.c b/Build/source/texk/dvipdfm-x/dvi.c index 5d983b12084..47b66c70c8d 100644 --- a/Build/source/texk/dvipdfm-x/dvi.c +++ b/Build/source/texk/dvipdfm-x/dvi.c @@ -62,7 +62,7 @@ #ifdef XETEX #include "pdfximage.h" -#include FT_ADVANCES_H +#include "tt_table.h" #endif #define DVI_STACK_DEPTH_MAX 256u @@ -142,7 +142,11 @@ static struct loaded_font int source; /* Source is either DVI or VF */ #ifdef XETEX uint32_t rgba_color; - FT_Face ft_face; + struct tt_longMetrics *hvmt; + FWord ascent; + FWord descent; + USHORT unitsPerEm; + USHORT numGlyphs; int layout_dir; float extend; float slant; @@ -914,6 +918,11 @@ dvi_locate_native_font (const char *filename, uint32_t index, int cur_id = -1; fontmap_rec *mrec; char *fontmap_key = malloc(strlen(filename) + 40); // CHECK this is enough + FILE *fp; + sfnt *sfont; + struct tt_head_table *head; + struct tt_maxp_table *maxp; + struct tt_hhea_table *hhea; if (verbose) MESG("<%s@%.2fpt", filename, ptsize * dvi2pts); @@ -937,7 +946,24 @@ dvi_locate_native_font (const char *filename, uint32_t index, loaded_fonts[cur_id].type = NATIVE; free(fontmap_key); - loaded_fonts[cur_id].ft_face = mrec->opt.ft_face; + fp = fopen(filename, "rb"); + sfont = sfnt_open(fp); + sfnt_read_table_directory(sfont, 0); + head = tt_read_head_table(sfont); + maxp = tt_read_maxp_table(sfont); + hhea = tt_read_hhea_table(sfont); + sfnt_locate_table(sfont, layout_dir == 0 ? "hmtx" : "vmtx"); + loaded_fonts[cur_id].ascent = hhea->ascent; + loaded_fonts[cur_id].descent = hhea->descent; + loaded_fonts[cur_id].unitsPerEm = head->unitsPerEm; + loaded_fonts[cur_id].numGlyphs = maxp->numGlyphs; + loaded_fonts[cur_id].hvmt = tt_read_longMetrics(sfont, maxp->numGlyphs, hhea->numOfLongHorMetrics, hhea->numOfExSideBearings); + RELEASE(hhea); + RELEASE(maxp); + RELEASE(head); + sfnt_close(sfont); + fclose(fp); + loaded_fonts[cur_id].layout_dir = layout_dir; loaded_fonts[cur_id].extend = mrec->opt.extend; loaded_fonts[cur_id].slant = mrec->opt.slant; @@ -1566,24 +1592,15 @@ do_glyphs (void) for (i = 0; i < slen; i++) { glyph_id = get_buffered_unsigned_pair(); /* freetype glyph index */ - if (glyph_id < font->ft_face->num_glyphs) { - FT_Error error; - FT_Fixed advance; - int flags = FT_LOAD_NO_SCALE; - - if (font->layout_dir == 1) - flags |= FT_LOAD_VERTICAL_LAYOUT; - - error = FT_Get_Advance(font->ft_face, glyph_id, flags, &advance); - if (error) - advance = 0; + if (glyph_id < font->numGlyphs) { + USHORT advance = (font->hvmt)[glyph_id].advance; + glyph_width = (double)font->size * (double)advance / (double)font->unitsPerEm; + glyph_width = glyph_width * font->extend; - glyph_width = (double)font->size * (double)advance / (double)font->ft_face->units_per_EM; - glyph_width = glyph_width * font->extend; if (dvi_is_tracking_boxes()) { pdf_rect rect; - height = (double)font->size * (double)font->ft_face->ascender / (double)font->ft_face->units_per_EM; - depth = (double)font->size * -(double)font->ft_face->descender / (double)font->ft_face->units_per_EM; + height = (double)font->size * (double)font->ascent / (double)font->unitsPerEm; + depth = (double)font->size * -(double)font->descent / (double)font->unitsPerEm; pdf_dev_set_rect(&rect, dvi_state.h + xloc[i], -dvi_state.v - yloc[i], glyph_width, height, depth); pdf_doc_expand_box(&rect); } @@ -1868,6 +1885,16 @@ dvi_close (void) page_loc = NULL; num_pages = 0; +#ifdef XETEX + for (i = 0; i < num_loaded_fonts; i++) + { + if (loaded_fonts[i].hvmt != NULL) + RELEASE(loaded_fonts[i].hvmt); + + loaded_fonts[i].hvmt = NULL; + } +#endif + if (loaded_fonts) RELEASE(loaded_fonts); loaded_fonts = NULL; diff --git a/Build/source/texk/dvipdfm-x/fontmap.c b/Build/source/texk/dvipdfm-x/fontmap.c index 32b93823ab8..14e37955f7a 100644 --- a/Build/source/texk/dvipdfm-x/fontmap.c +++ b/Build/source/texk/dvipdfm-x/fontmap.c @@ -35,11 +35,6 @@ #include "fontmap.h" -#ifdef XETEX -#include "ft2build.h" -#include FT_FREETYPE_H -#endif - /* CIDFont */ static char *strip_options (const char *map_name, fontmap_opt *opt); @@ -82,10 +77,6 @@ pdf_init_fontmap_record (fontmap_rec *mrec) mrec->opt.style = FONTMAP_STYLE_NONE; mrec->opt.stemv = -1; /* not given explicitly by an option */ -#ifdef XETEX - mrec->opt.ft_face = NULL; -#endif - mrec->opt.cff_charsets = NULL; } @@ -153,10 +144,6 @@ pdf_copy_fontmap_record (fontmap_rec *dst, const fontmap_rec *src) dst->opt.style = src->opt.style; dst->opt.stemv = src->opt.stemv; -#ifdef XETEX - dst->opt.ft_face = src->opt.ft_face; -#endif - dst->opt.cff_charsets = src->opt.cff_charsets; } @@ -1049,13 +1036,13 @@ pdf_load_fontmap_file (const char *filename, int mode) #ifdef XETEX static int -pdf_insert_native_fontmap_record (const char *path, int index, FT_Face face, +pdf_insert_native_fontmap_record (const char *path, int index, int layout_dir, int extend, int slant, int embolden) { char *fontmap_key; fontmap_rec *mrec; - ASSERT(path || face); + ASSERT(path); fontmap_key = malloc(strlen(path) + 40); // CHECK sprintf(fontmap_key, "%s/%d/%c/%d/%d/%d", path, index, layout_dir == 0 ? 'H' : 'V', extend, slant, embolden); @@ -1070,7 +1057,6 @@ pdf_insert_native_fontmap_record (const char *path, int index, FT_Face face, mrec->enc_name = mstrdup(layout_dir == 0 ? "Identity-H" : "Identity-V"); mrec->font_name = (path != NULL) ? mstrdup(path) : NULL; mrec->opt.index = index; - mrec->opt.ft_face = face; if (layout_dir != 0) mrec->opt.flags |= FONTMAP_OPT_VERT; @@ -1090,38 +1076,12 @@ pdf_insert_native_fontmap_record (const char *path, int index, FT_Face face, return 0; } -static FT_Library ftLib; - int pdf_load_native_font (const char *filename, unsigned long index, int layout_dir, int extend, int slant, int embolden) { - char *q; - FT_Face face = NULL; - int error = -1; - - if (FT_Init_FreeType(&ftLib) != 0) { - ERROR("FreeType initialization failed."); - return error; - } - - /* try loading the filename directly */ - error = FT_New_Face(ftLib, filename, index, &face); - - /* if failed, try locating the file in the TEXMF tree */ - if ( error && - ( (q = dpx_find_opentype_file(filename)) != NULL - || (q = dpx_find_truetype_file(filename)) != NULL - || (q = dpx_find_type1_file(filename)) != NULL - || (q = dpx_find_dfont_file(filename)) != NULL) ) { - error = FT_New_Face(ftLib, q, index, &face); - RELEASE(q); - } - - if (error == 0) - error = pdf_insert_native_fontmap_record(filename, index, face, + return pdf_insert_native_fontmap_record(filename, index, layout_dir, extend, slant, embolden); - return error; } #endif /* XETEX */ diff --git a/Build/source/texk/dvipdfm-x/fontmap.h b/Build/source/texk/dvipdfm-x/fontmap.h index cc18e5a0e38..85557cf77de 100644 --- a/Build/source/texk/dvipdfm-x/fontmap.h +++ b/Build/source/texk/dvipdfm-x/fontmap.h @@ -35,11 +35,6 @@ #define FONTMAP_STYLE_ITALIC 2 #define FONTMAP_STYLE_BOLDITALIC 3 -#ifdef XETEX -#include "ft2build.h" -#include FT_FREETYPE_H -#endif - /* Options */ typedef struct fontmap_opt { /* Synthetic font */ @@ -58,9 +53,6 @@ typedef struct fontmap_opt { int index; /* TTC index */ int style; /* ,Bold, etc. */ int stemv; /* StemV value especially for CJK fonts */ -#ifdef XETEX - FT_Face ft_face; -#endif } fontmap_opt; typedef struct fontmap_rec { |