From 84b096655143a13e60e12925d8a04bc972271384 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Fri, 20 Sep 2013 20:30:46 +0800 Subject: [PATCH] set correct width --- src/HTMLRenderer/font.cc | 29 ++++++++--------------------- src/util/ffw.c | 6 ++++-- src/util/ffw.h | 3 ++- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/HTMLRenderer/font.cc b/src/HTMLRenderer/font.cc index e3056e8..18d3a4d 100644 --- a/src/HTMLRenderer/font.cc +++ b/src/HTMLRenderer/font.cc @@ -241,9 +241,6 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) cairo_surface_set_fallback_resolution(surface, param.h_dpi, param.v_dpi); cairo_t * cr = cairo_create(surface); - //debug - std::cerr << "debug " << code << std::endl; - std::cerr << "pdf width " << ((Gfx8BitFont*)font)->getWidth(code) << std::endl; /* cairo_set_font_size(cr, scale); cairo_set_font_face(cr, cur_font->getFontFace()); @@ -254,6 +251,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) double ox, oy; ox = oy = 0.0; + auto glyph_width = ((Gfx8BitFont*)font)->getWidth(code); // manually draw the char to get the metrics // adapted from _render_type3_glyph of poppler { @@ -285,6 +283,12 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) // set ctm cairo_set_matrix(cr, &ctm); + // calculate the position of origin + cairo_matrix_transform_point(&ctm, &ox, &oy); + // calculate glyph width + double dummy = 0; + cairo_matrix_transform_point(&ctm, &glyph_width, &dummy); + // draw the glyph auto output_dev = new CairoOutputDev(); output_dev->setCairo(cr); @@ -306,23 +310,6 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) auto glyph_index = cur_font->getGlyph(code, nullptr, 0); gfx->display(char_procs->getVal(glyph_index, &char_proc_obj)); - double wx, wy; - output_dev->getType3GlyphWidth(&wx, &wy); - cairo_matrix_transform_distance(&m1, &wx, &wy); - std::cerr << "wx " << wx << " wy " << wy << std::endl; - - if(output_dev->hasType3GlyphBBox()) - { - double *bbox = output_dev->getType3GlyphBBox(); - - cairo_matrix_transform_point (&m1, &bbox[0], &bbox[1]); - cairo_matrix_transform_point (&m1, &bbox[2], &bbox[3]); - std::cerr << "*bbox"; - for(int i = 0; i < 4; ++i) - std::cerr << ' ' << bbox[i]; - std::cerr << std::endl; - } - char_proc_obj.free(); delete gfx; delete output_dev; @@ -345,7 +332,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) throw string("Error in cairo: ") + cairo_status_to_string(status); } - ffw_import_svg_glyph(code, glyph_filename.c_str(), ox / GLYPH_DUMP_EM_SIZE, oy / GLYPH_DUMP_EM_SIZE); + ffw_import_svg_glyph(code, glyph_filename.c_str(), ox / GLYPH_DUMP_EM_SIZE, 1.0 - oy / GLYPH_DUMP_EM_SIZE, glyph_width / GLYPH_DUMP_EM_SIZE); } string font_filename = (char*)str_fmt("%s/f%llx.ttf", param.tmp_dir.c_str(), fn_id); diff --git a/src/util/ffw.c b/src/util/ffw.c index 84bcd4e..01228df 100644 --- a/src/util/ffw.c +++ b/src/util/ffw.c @@ -425,7 +425,7 @@ void ffw_set_widths(int * width_list, int mapping_len, } } -void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy) +void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy, double width) { int enc = SFFindSlot(cur_fv->sf, cur_fv->map, code, ""); if(enc == -1) @@ -439,7 +439,7 @@ void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy) if(!ok) err("Import SVG glyph failed"); - // correct the origin + // correct origin and width { int a = cur_fv->sf->ascent; int d = cur_fv->sf->descent; @@ -450,6 +450,8 @@ void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy) transform[4] = -ox * (a+d); transform[5] = -oy * (a+d) + d; FVTrans(cur_fv, sc, transform, NULL, fvt_alllayers | fvt_dontmovewidth); + + SCSynchronizeWidth(sc, floor(width * (a+d) + 0.5), sc->width, cur_fv); } } diff --git a/src/util/ffw.h b/src/util/ffw.h index fcb57dc..1beddfd 100644 --- a/src/util/ffw.h +++ b/src/util/ffw.h @@ -63,7 +63,8 @@ void ffw_set_widths(int * width_list, int mapping_len, //////////////////////// // others // (ox,oy) is the position of the true origin, fractions related to em_size -void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy); +// also true for glyph_width +void ffw_import_svg_glyph(int code, const char * filename, double ox, double oy, double glyph_width); void ffw_auto_hint(void); void ffw_override_fstype(void);