diff --git a/pdf2htmlEX.1.in b/pdf2htmlEX.1.in index e84d668..f708532 100644 --- a/pdf2htmlEX.1.in +++ b/pdf2htmlEX.1.in @@ -35,7 +35,7 @@ Specify owner password .B -u, --user-password Specify user password .TP -.B --dest-dir (Default: ".") +.B --dest-dir (Default: .) Specify destination folder .TP .B --data-dir (Default: @CMAKE_INSTALL_PREFIX@/share/pdf2htmlEX) @@ -117,15 +117,21 @@ Treat space characters as offsets, which may increase the size of the output. Turn it on if space characters are not displayed correctly, or you want to remove positional spaces. .TP -.B --css-filename (Default: "") +.B --stretch-narrow-glyph <0|1> (Default: 0) +If set to 1, glyphs narrower than described in PDF will be strecth; otherwise space will be padded to the right of the glyphs +.TP +.B --squeeze_wide_glyph <0|1> (Default: 0) +If set to 1, glyphs wider than described in PDF will be squeezed; otherwise it will be truncated. +.TP +.B --css-filename (Default: ) Specify the filename of the generated css file, if not embedded. If it's empty, the file name will be determined automatically. .TP -.B --font-suffix (Default: ".ttf"), --font-format (Default: "truetype") +.B --font-suffix (Default: .ttf), --font-format (Default: truetype) Specify the suffix and format of fonts extracted from the PDF file. They should be consistent. .TP -.B --external-hint-tool (Default: "") +.B --external-hint-tool (Default: ) If specified, the tool will be called in order to enhanced hinting for fonts, this will precede --auto-hint. The tool will be called as ' ', where suffix will be the same as specified for --font-suffix. @@ -141,10 +147,10 @@ If switched off, intermediate files won't be cleaned in the end. .B pdf2htmlEX /path/to/file.pdf Convert file.pdf into file.html .TP -.B pdf2htmlEX --tmp-dir tmp --clean-tmp 0 --debug 1 /path/to/file.pdf +.B pdf2htmlEX --clean-tmp 0 --debug 1 /path/to/file.pdf Convert file.pdf and leave all intermediate files. .TP -.B pdf2htmlEX --dest-dir out --single-html 0 --debug 1 /path/to/file.pdf +.B pdf2htmlEX --dest-dir out --single-html 0 /path/to/file.pdf Convert file.pdf into out/file.html and leave font/image files separated. .SH COPYRIGHT diff --git a/src/HTMLRenderer/text.cc b/src/HTMLRenderer/text.cc index 9743fd0..47a24ec 100644 --- a/src/HTMLRenderer/text.cc +++ b/src/HTMLRenderer/text.cc @@ -398,7 +398,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo } } - ffw_set_widths(width_list, max_key + 1); + ffw_set_widths(width_list, max_key + 1, param->stretch_narrow_glyph, param->squeeze_wide_glyph); ffw_reencode_raw(cur_mapping, max_key + 1, 1); if(ctu) diff --git a/src/ffw.c b/src/ffw.c index 99deb30..dc8e913 100644 --- a/src/ffw.c +++ b/src/ffw.c @@ -19,6 +19,8 @@ #include "ffw.h" +static real EPS=1e-6; + static inline int min(int a, int b) { return (aselected, 1, cur_fv->map->enccount); // remove kern FVRemoveKerns(cur_fv); FVRemoveVKerns(cur_fv); - // remove bearing - // TODO: optimize this, merge the transform matrix with width setting (below) - //FVSetWidthScript(cur_fv, wt_lbearing, 0, 0); - //FVSetWidthScript(cur_fv, wt_rbearing, 0, 0); + */ SplineFont * sf = cur_fv->sf; @@ -333,12 +335,12 @@ void ffw_set_widths(int * width_list, int mapping_len) DBounds bb; SplineCharFindBounds(sc, &bb); - // TODO: add an option double glyph_width = bb.maxx - bb.minx; - if(glyph_width > width_list[i]) + if((glyph_width > EPS) + && (((glyph_width > width_list[i] + EPS) && (squeeze_wide)) + || ((glyph_width < width_list[i] - EPS) && (stretch_narrow)))) { - real transform[6]; - transform[0] = ((double)width_list[i]) / glyph_width; + real transform[6]; transform[0] = ((double)width_list[i]) / glyph_width; transform[3] = 1.0; transform[1] = transform[2] = transform[4] = transform[5] = 0; FVTrans(cur_fv, sc, transform, NULL, fvt_alllayers | fvt_dontmovewidth); diff --git a/src/include/Param.h b/src/include/Param.h index 02548dc..db90188 100644 --- a/src/include/Param.h +++ b/src/include/Param.h @@ -40,9 +40,13 @@ struct Param double h_eps, v_eps; double space_threshold; double font_size_multiplier; + int auto_hint; int tounicode; int space_as_offset; + + int stretch_narrow_glyph; + int squeeze_wide_glyph; std::string css_filename; std::string font_suffix, font_format; diff --git a/src/include/ffw.h b/src/include/ffw.h index 6a1f27a..939f241 100644 --- a/src/include/ffw.h +++ b/src/include/ffw.h @@ -34,7 +34,7 @@ int ffw_get_em_size(void); // fix metrics and get them void ffw_metric(double * ascent, double * descent); -void ffw_set_widths(int * width_list, int mapping_len); +void ffw_set_widths(int * width_list, int mapping_len, int stretch_narrow, int squeeze_wide); void ffw_auto_hint(void); diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 5197026..c712df0 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -41,6 +41,8 @@ void show_usage_and_exit(const char * dummy = nullptr) cerr << "Options:" << endl; argparser.show_usage(cerr); cerr << endl; + cerr << "Run 'man pdf2htmlEX' for detailed information" << endl; + cerr << endl; exit(EXIT_FAILURE); } @@ -79,6 +81,8 @@ void parse_options (int argc, char **argv) .add("auto-hint", ¶m.auto_hint, 0, "Whether to generate hints for fonts") .add("tounicode", ¶m.tounicode, 0, "Specify how to deal with ToUnicode map, 0 for auto, 1 for forced, -1 for disabled") .add("space-as-offset", ¶m.space_as_offset, 0, "treat space characters as offsets") + .add("stretch_narrow_glyph", ¶m.stretch_narrow_glyph, 0, "stretch narrow glyphs instead of padding space") + .add("squeeze_wide_glyph", ¶m.squeeze_wide_glyph, 0, "squeeze wide glyphs instead of truncating") .add("css-filename", ¶m.css_filename, "", "Specify the file name of the generated css file") .add("font-suffix", ¶m.font_suffix, ".ttf", "suffix for extracted font files")