mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
new option for fixing glyph width
This commit is contained in:
parent
dafc4b86dd
commit
c8133d64e3
@ -35,7 +35,7 @@ Specify owner password
|
||||
.B -u, --user-password <password>
|
||||
Specify user password
|
||||
.TP
|
||||
.B --dest-dir <dir> (Default: ".")
|
||||
.B --dest-dir <dir> (Default: .)
|
||||
Specify destination folder
|
||||
.TP
|
||||
.B --data-dir <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 <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 <filename> (Default: <none>)
|
||||
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 <suffix> (Default: ".ttf"), --font-format <format> (Default: "truetype")
|
||||
.B --font-suffix <suffix> (Default: .ttf), --font-format <format> (Default: truetype)
|
||||
Specify the suffix and format of fonts extracted from the PDF file. They should be consistent.
|
||||
.TP
|
||||
.B --external-hint-tool <tool> (Default: "")
|
||||
.B --external-hint-tool <tool> (Default: <none>)
|
||||
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 '<tool> <in.suffix> <out.suffix>', 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
|
||||
|
@ -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)
|
||||
|
20
src/ffw.c
20
src/ffw.c
@ -19,6 +19,8 @@
|
||||
|
||||
#include "ffw.h"
|
||||
|
||||
static real EPS=1e-6;
|
||||
|
||||
static inline int min(int a, int b)
|
||||
{
|
||||
return (a<b)?a:b;
|
||||
@ -294,16 +296,16 @@ void ffw_metric(double * ascent, double * descent)
|
||||
/*
|
||||
* TODO:bitmap, reference have not been considered in this function
|
||||
*/
|
||||
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)
|
||||
{
|
||||
/*
|
||||
* Disabled, because it causes crashing
|
||||
|
||||
memset(cur_fv->selected, 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);
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user