summaryrefslogtreecommitdiff
path: root/Build/source
diff options
context:
space:
mode:
authorJjgod Jiang <gzjjgod@gmail.com>2015-05-23 15:21:43 +0000
committerJjgod Jiang <gzjjgod@gmail.com>2015-05-23 15:21:43 +0000
commita021e65b0bd57ef13dd1f6481799a545696c76ab (patch)
tree5d75d6694c1900a2be3439d3c51ba667832ab3dc /Build/source
parentd3b46ffb72d570d2ac4b35a0d424a02c431497e5 (diff)
Fix Type1 font encoding and metrics
git-svn-id: svn://tug.org/texlive/trunk@37480 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source')
-rw-r--r--Build/source/texk/dvipdfm-x/ChangeLog4
-rw-r--r--Build/source/texk/dvipdfm-x/dvi.c65
2 files changed, 65 insertions, 4 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog
index 5fb4200b29d..8d85551c347 100644
--- a/Build/source/texk/dvipdfm-x/ChangeLog
+++ b/Build/source/texk/dvipdfm-x/ChangeLog
@@ -1,3 +1,7 @@
+2015-05-23 Jiang Jiang <gzjjgod@gmail.com>
+
+ * dvi.c: Fix Type1 font encoding and metrics.
+
2015-05-21 Karl Berry <karl@tug.org>
* version 20150515 for TL'15.
diff --git a/Build/source/texk/dvipdfm-x/dvi.c b/Build/source/texk/dvipdfm-x/dvi.c
index 464a58a234d..4377894bfac 100644
--- a/Build/source/texk/dvipdfm-x/dvi.c
+++ b/Build/source/texk/dvipdfm-x/dvi.c
@@ -65,6 +65,9 @@
#include "pdfximage.h"
#include "tt_aux.h"
#include "tt_table.h"
+#include "t1_load.h"
+#include "t1_char.h"
+#include "cff_dict.h"
#endif
#define DVI_STACK_DEPTH_MAX 256u
@@ -148,6 +151,7 @@ static struct loaded_font
int ascent;
int descent;
unsigned unitsPerEm;
+ cff_font *cffont;
unsigned numGlyphs;
int layout_dir;
float extend;
@@ -964,7 +968,35 @@ dvi_locate_native_font (const char *filename, uint32_t index,
loaded_fonts[cur_id].type = NATIVE;
free(fontmap_key);
- if (is_type1 == 0) {
+ if (is_type1) {
+ cff_font *cffont;
+
+ fp = DPXFOPEN(filename, DPX_RES_TYPE_T1FONT);
+ if (!fp)
+ return -1;
+
+ if (!is_pfb(fp))
+ ERROR("Failed to read Type 1 font \"%s\".", filename);
+
+ cffont = t1_load_font(NULL, 0, fp);
+ if (!cffont)
+ ERROR("Failed to read Type 1 font \"%s\".", filename);
+
+ loaded_fonts[cur_id].cffont = cffont;
+
+ if (cff_dict_known(cffont->topdict, "FontBBox")) {
+ loaded_fonts[cur_id].ascent = cff_dict_get(cffont->topdict, "FontBBox", 3);
+ loaded_fonts[cur_id].descent = cff_dict_get(cffont->topdict, "FontBBox", 1);
+ } else {
+ loaded_fonts[cur_id].ascent = 690;
+ loaded_fonts[cur_id].descent = -190;
+ }
+
+ loaded_fonts[cur_id].unitsPerEm = 1000;
+ loaded_fonts[cur_id].numGlyphs = cffont->num_glyphs;
+
+ DPXFCLOSE(fp);
+ } else {
if (is_dfont)
sfont = dfont_open(fp, index);
else
@@ -1628,14 +1660,34 @@ do_glyphs (void)
for (i = 0; i < slen; i++) {
glyph_id = get_buffered_unsigned_pair(); /* freetype glyph index */
if (glyph_id < font->numGlyphs) {
- unsigned advance = (font->hvmt)[glyph_id].advance;
+ unsigned advance;
+ double ascent = (double)font->ascent;
+ double descent = (double)font->descent;
+
+ if (font->cffont) {
+ /* Type1 glyph id is FreeType glyph index + 1. */
+ glyph_id += 1;
+ cff_index *cstrings = font->cffont->cstrings;
+ t1_ginfo gm;
+
+ t1char_get_metrics(cstrings->data + cstrings->offset[glyph_id] - 1,
+ cstrings->offset[glyph_id + 1] - cstrings->offset[glyph_id],
+ font->cffont->subrs[0], &gm);
+
+ advance = font->layout_dir == 0 ? gm.wx : gm.wy;
+ ascent = gm.bbox.ury;
+ descent = gm.bbox.lly;
+ } else {
+ advance = font->hvmt[glyph_id].advance;
+ }
+
glyph_width = (double)font->size * (double)advance / (double)font->unitsPerEm;
glyph_width = glyph_width * font->extend;
if (dvi_is_tracking_boxes()) {
pdf_rect rect;
- height = (double)font->size * (double)font->ascent / (double)font->unitsPerEm;
- depth = (double)font->size * -(double)font->descent / (double)font->unitsPerEm;
+ height = (double)font->size * ascent / (double)font->unitsPerEm;
+ depth = (double)font->size * -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);
}
@@ -1927,6 +1979,11 @@ dvi_close (void)
RELEASE(loaded_fonts[i].hvmt);
loaded_fonts[i].hvmt = NULL;
+
+ if (loaded_fonts[i].cffont != NULL)
+ cff_close(loaded_fonts[i].cffont);
+
+ loaded_fonts[i].cffont = NULL;
}
#endif