From 09203f61a483762c16f649e797e2439337e8939b Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Sat, 21 Sep 2013 13:56:57 +0800 Subject: [PATCH] new option --process-type3 --- pdf2htmlEX.1.in | 7 +++++++ src/HTMLRenderer/font.cc | 11 ++++++----- src/pdf2htmlEX.cc | 10 ++++++++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pdf2htmlEX.1.in b/pdf2htmlEX.1.in index c1e8de7..830b209 100644 --- a/pdf2htmlEX.1.in +++ b/pdf2htmlEX.1.in @@ -184,6 +184,13 @@ Clear the fstype bits in TTF/OTF fonts. Turn this on if Internet Explorer complains about 'Permission must be Installable' AND you have permission to do so. +.TP +.B --process-type3 <0|1> (Default: 0) +If turned on, pdf2htmlEX will try to convert Type 3 fonts such that text can be rendered natively in HTML. +Otherwise all text with Type 3 fonts will be rendered as image. + +This feature is highly experimental. + .SS Text .TP diff --git a/src/HTMLRenderer/font.cc b/src/HTMLRenderer/font.cc index f94c4df..54c4e38 100644 --- a/src/HTMLRenderer/font.cc +++ b/src/HTMLRenderer/font.cc @@ -210,10 +210,10 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) tm_transform_bbox(font_matrix, transformed_bbox); double transformed_bbox_width = transformed_bbox[2] - transformed_bbox[0]; double transformed_bbox_height = transformed_bbox[3] - transformed_bbox[1]; - // we want the glyphs is rendered in a box of size around 100 x 100 - // for rectangles, the longer edge should be 100 info.font_size_scale = std::max(transformed_bbox_width, transformed_bbox_height); + // we want the glyphs is rendered in a box of size around GLYPH_DUMP_EM_SIZE x GLYPH_DUMP_EM_SIZE + // for rectangles, the longer edge should be GLYPH_DUMP_EM_SIZE const double GLYPH_DUMP_EM_SIZE = 100.0; double scale = GLYPH_DUMP_EM_SIZE / info.font_size_scale; @@ -242,6 +242,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) auto glyph_width = ((Gfx8BitFont*)font)->getWidth(code); +#if 1 { // pain the glyph cairo_set_font_face(cr, cur_font->getFontFace()); @@ -273,8 +274,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) double dummy = 0; cairo_matrix_transform_distance(&m2, &glyph_width, &dummy); } - - /* +#else { // manually draw the char to get the metrics // adapted from _render_type3_glyph of poppler @@ -308,6 +308,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) // calculate the position of origin cairo_matrix_transform_point(&ctm, &ox, &oy); + oy -= transformed_bbox_height * scale; // calculate glyph width double dummy = 0; cairo_matrix_transform_distance(&ctm, &glyph_width, &dummy); @@ -337,7 +338,7 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info) delete gfx; delete output_dev; } - */ +#endif { auto status = cairo_status(cr); diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 2df3568..91547db 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -146,6 +146,7 @@ void parse_options (int argc, char **argv) .add("stretch-narrow-glyph", ¶m.stretch_narrow_glyph, 0, "stretch narrow glyphs instead of padding them") .add("squeeze-wide-glyph", ¶m.squeeze_wide_glyph, 1, "shrink wide glyphs instead of truncating them") .add("override-fstype", ¶m.override_fstype, 0, "clear the fstype bits in TTF/OTF fonts") + .add("process-type3", ¶m.process_type3, 0, "convert Type 3 fonts for web (experimental)") // text .add("heps", ¶m.h_eps, 1.0, "horizontal threshold for merging text, in pixels") @@ -299,8 +300,13 @@ void check_param() exit(EXIT_FAILURE); } - //test - param.process_type3 = 1; +#if not ENABLE_SVG + if(param.process_type3) + { + cerr << "process-type3 is enabled, however SVG support is not built in this version of pdf2htmlEX." << endl; + exit(EXIT_FAILURE); + } +#endif } int main(int argc, char **argv)