Skip to content

Commit 01f546e

Browse files
committed
logic for hinting
1 parent 9847860 commit 01f546e

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

pdf2htmlEX.1.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ Specify a ratio greater than 1 would resolve this issue, however it might freeze
9595
For some versions of Firefox, however, there will be a problem when the font size is too large, in which case a smaller value should be specified here.
9696
.TP
9797
.B --auto-hint <0|1> (Default: 0)
98-
If set to 1, hints will be generated for the fonts.
98+
If set to 1, hints will be generated for the fonts using fontforge.
9999

100-
This switch is experimental which may break other things.
100+
This may be overrided by --external-hint-tool. This switch is experimental which may break other things.
101101
.TP
102102
.B --tounicode <-1|0|1> (Default: 0)
103103
A ToUnicode map may be provided for each font in PDF which indicates the 'meaning' of the characters. However often there is better "ToUnicode" info in Type 0/1 fonts, and sometimes the ToUnicode map provided is wrong.
@@ -122,7 +122,7 @@ If it's empty, the file name will be determined automatically.
122122
Specify the suffix and format of fonts extracted from the PDF file. They should be consistent.
123123
.TP
124124
.B --external-hint-tool <tool> (Default: "")
125-
If specified, the tool will be called in order to enhanced hinting for fonts.
125+
If specified, the tool will be called in order to enhanced hinting for fonts, this will override --auto-hint.
126126

127127
The tool will be called as '<tool> <in.suffix> <out.suffix>', where suffix will be the same as specified for --font-suffix.
128128
.TP

src/HTMLRenderer/text.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
161161
void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only)
162162
{
163163
ffw_load_font(filepath.c_str());
164-
if(param->auto_hint)
165-
ffw_auto_hint();
166-
167164
int * code2GID = nullptr;
168165
int code2GID_len = 0;
169166
int maxcode = 0;
@@ -184,7 +181,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
184181

185182
const char * used_map = nullptr;
186183

187-
ffw_metric(&info.ascent, &info.descent, &info.em_size);
184+
info.em_size = ffw_get_em_size();
188185

189186
if(param->debug)
190187
{
@@ -415,7 +412,16 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
415412
rename(fn.c_str(), tmp_fn.c_str());
416413
if(system((char*)str_fmt("%s \"%s\" \"%s\"", param->external_hint_tool.c_str(), tmp_fn.c_str(), fn.c_str())) != 0)
417414
{
418-
rename(tmp_fn.c_str(), fn.c_str());
415+
if(param->auto_hint)
416+
{
417+
ffw_load_font(tmp_fn.c_str());
418+
ffw_auto_hint();
419+
ffw_save(fn.c_str());
420+
}
421+
else
422+
{
423+
rename(tmp_fn.c_str(), fn.c_str());
424+
}
419425
}
420426
}
421427

@@ -425,7 +431,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
425431
*/
426432
rename(fn.c_str(), tmp_fn.c_str());
427433
ffw_load_font(tmp_fn.c_str());
428-
ffw_metric(&info.ascent, &info.descent, &info.em_size);
434+
ffw_metric(&info.ascent, &info.descent);
429435
ffw_save(fn.c_str());
430436
ffw_close();
431437

src/ffw.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,12 @@ void ffw_close(void)
215215
cur_fv = NULL;
216216
}
217217

218-
void ffw_metric(double * ascent, double * descent, int * em_size)
218+
int ffw_get_em_size(void)
219+
{
220+
return cur_fv->sf->ascent + cur_fv->sf->descent;
221+
}
222+
223+
void ffw_metric(double * ascent, double * descent)
219224
{
220225
SplineFont * sf = cur_fv->sf;
221226
struct pfminfo * info = &sf->pfminfo;
@@ -227,8 +232,6 @@ void ffw_metric(double * ascent, double * descent, int * em_size)
227232
DBounds bb;
228233
SplineFontFindBounds(sf, &bb);
229234

230-
*em_size = sf->ascent + sf->descent;
231-
232235
/*
233236
printf("bb %lf %lf\n", bb.maxy, bb.miny);
234237
printf("_ %d %d\n", sf->ascent, sf->descent);

src/include/ffw.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ void ffw_cidflatten(void);
3030
void ffw_save(const char * filename);
3131
void ffw_close(void);
3232

33+
int ffw_get_em_size(void);
3334
// fix metrics and get them
34-
void ffw_metric(double * ascent, double * descent, int * em_size);
35+
void ffw_metric(double * ascent, double * descent);
3536

3637
void ffw_set_widths(int * width_list, int mapping_len);
3738

0 commit comments

Comments
 (0)