mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
remove special handling of base 14 fonts
This commit is contained in:
parent
8bad93c8e5
commit
bcf3bd793e
4
TODO
4
TODO
@ -1,5 +1,9 @@
|
||||
- dots issue
|
||||
- AdobeXML*.pdf
|
||||
- font issue
|
||||
- cjkmix2*.pdf
|
||||
- space issue
|
||||
- python简明*.pdf
|
||||
- smarter space-as-offset
|
||||
- show hints about possible useful parameters
|
||||
- optimization levels
|
||||
|
@ -133,18 +133,11 @@ Output in fallback mode, for better accuracy and browser compatibility, but the
|
||||
|
||||
.SS Fonts
|
||||
|
||||
.TP
|
||||
.B --embed-base-font <0|1> (Default: 1)
|
||||
Whether to embed base 14 fonts.
|
||||
|
||||
There are several base font defined in PDF standards, which are supposed to be provided by the PDF reader.
|
||||
|
||||
If this switch is on, local matched font will be used and embedded; otherwise only font names are exported such that web browsers may try to find proper fonts themselves.
|
||||
|
||||
.TP
|
||||
.B --embed-external-font <0|1> (Default: 1)
|
||||
Similar as `--embed-base-font` but for non-base fonts. If this switch is off, the corresponding fonts must be installed in the client side.
|
||||
Specify whether the local matched fonts, for fonts not embedded in PDF, should be embedded into HTML.
|
||||
|
||||
If this switch is off, only font names are exported such that web browsers may try to find proper fonts themselves, and that might cause issues about incorrect font metrics.
|
||||
|
||||
.TP
|
||||
.B --font-suffix <suffix> (Default: .ttf)
|
||||
|
@ -152,7 +152,6 @@ protected:
|
||||
*
|
||||
* In PDF: (install_*)
|
||||
* embedded font: fonts embedded in PDF
|
||||
* base font: standard 14 fonts defined in PDF spec
|
||||
* external font: fonts that have only names provided in PDF, the viewer should find a local font to match with
|
||||
*
|
||||
* In HTML: (export_*)
|
||||
@ -165,7 +164,6 @@ protected:
|
||||
void embed_font(const std::string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only = false);
|
||||
const FontInfo * install_font(GfxFont * font);
|
||||
void install_embedded_font(GfxFont * font, FontInfo & info);
|
||||
void install_base_font(GfxFont * font, GfxFontLoc * font_loc, FontInfo & info);
|
||||
void install_external_font (GfxFont * font, FontInfo & info);
|
||||
void export_remote_font(const FontInfo & info, const std::string & suffix, GfxFont * font);
|
||||
void export_remote_default_font(long long fn_id);
|
||||
|
@ -326,6 +326,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: add an option to load the table?
|
||||
ffw_cidflatten();
|
||||
}
|
||||
}
|
||||
@ -612,7 +613,12 @@ const FontInfo * HTMLRenderer::install_font(GfxFont * font)
|
||||
return &new_font_info;
|
||||
}
|
||||
|
||||
if(auto * font_loc = font->locateFont(xref, gTrue))
|
||||
/*
|
||||
* The 2nd parameter of locateFont should be true only for PS
|
||||
* which does not make much sense in our case
|
||||
* If we specify gFalse here, font_loc->locaType cannot be gfxFontLocResident
|
||||
*/
|
||||
if(auto * font_loc = font->locateFont(xref, gFalse))
|
||||
{
|
||||
switch(font_loc -> locType)
|
||||
{
|
||||
@ -620,14 +626,13 @@ const FontInfo * HTMLRenderer::install_font(GfxFont * font)
|
||||
new_font_info.is_embeded = true;
|
||||
install_embedded_font(font, new_font_info);
|
||||
break;
|
||||
case gfxFontLocResident:
|
||||
std::cerr << "Warning: Base 14 fonts should not be specially handled now. Please report a bug!" << std::endl;
|
||||
/* fall through */
|
||||
case gfxFontLocExternal:
|
||||
new_font_info.is_embeded = false;
|
||||
install_external_font(font, new_font_info);
|
||||
break;
|
||||
case gfxFontLocResident:
|
||||
new_font_info.is_embeded = false;
|
||||
install_base_font(font, font_loc, new_font_info);
|
||||
break;
|
||||
default:
|
||||
cerr << "TODO: other font loc" << endl;
|
||||
export_remote_default_font(new_fn_id);
|
||||
@ -658,55 +663,6 @@ void HTMLRenderer::install_embedded_font(GfxFont * font, FontInfo & info)
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLRenderer::install_base_font(GfxFont * font, GfxFontLoc * font_loc, FontInfo & info)
|
||||
{
|
||||
string psname(font_loc->path->getCString());
|
||||
string basename = psname.substr(0, psname.find('-'));
|
||||
|
||||
GfxFontLoc * localfontloc = font->locateFont(xref, gFalse);
|
||||
if(param.embed_base_font)
|
||||
{
|
||||
if(localfontloc != nullptr)
|
||||
{
|
||||
embed_font(localfontloc->path->getCString(), font, info);
|
||||
export_remote_font(info, param.font_suffix, font);
|
||||
delete localfontloc;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "Cannot embed base font: f" << hex << info.id << dec << ' ' << psname << endl;
|
||||
// fallback to exporting by name
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
string cssfont;
|
||||
auto iter = BASE_14_FONT_CSS_FONT_MAP.find(basename);
|
||||
if(iter == BASE_14_FONT_CSS_FONT_MAP.end())
|
||||
{
|
||||
cerr << "PS Font: " << basename << " not found in the base 14 font map" << endl;
|
||||
cssfont = "";
|
||||
}
|
||||
else
|
||||
cssfont = iter->second;
|
||||
|
||||
// still try to get an idea of read ascent/descent
|
||||
if(localfontloc != nullptr)
|
||||
{
|
||||
// fill in ascent/descent only, do not embed
|
||||
embed_font(string(localfontloc->path->getCString()), font, info, true);
|
||||
delete localfontloc;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.ascent = font->getAscent();
|
||||
info.descent = font->getDescent();
|
||||
}
|
||||
|
||||
export_local_font(info, font, psname, cssfont);
|
||||
}
|
||||
|
||||
void HTMLRenderer::install_external_font(GfxFont * font, FontInfo & info)
|
||||
{
|
||||
string fontname(font->getName()->getCString());
|
||||
|
@ -37,7 +37,6 @@ struct Param
|
||||
int fallback;
|
||||
|
||||
// fonts
|
||||
int embed_base_font;
|
||||
int embed_external_font;
|
||||
std::string font_suffix;
|
||||
int decompose_ligature;
|
||||
|
@ -36,6 +36,12 @@ using namespace pdf2htmlEX;
|
||||
Param param;
|
||||
ArgParser argparser;
|
||||
|
||||
void deprecated_embed_base_font(const char * dummy = nullptr)
|
||||
{
|
||||
cerr << "--embed-base-font is deprecated. Use --embed-external-font instead." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void show_usage_and_exit(const char * dummy = nullptr)
|
||||
{
|
||||
cerr << "Usage: pdf2htmlEX [options] <input.pdf> [<output.html>]" << endl;
|
||||
@ -82,7 +88,6 @@ void parse_options (int argc, char **argv)
|
||||
.add("fallback", ¶m.fallback, 0, "output in fallback mode")
|
||||
|
||||
// fonts
|
||||
.add("embed-base-font", ¶m.embed_base_font, 1, "embed local match for standard 14 fonts")
|
||||
.add("embed-external-font", ¶m.embed_external_font, 1, "embed local match for external fonts")
|
||||
.add("font-suffix", ¶m.font_suffix, ".ttf", "suffix for embedded font files (.ttf,.otf,.woff,.svg)")
|
||||
.add("decompose-ligature", ¶m.decompose_ligature, 0, "decompose ligatures, such as \uFB01 -> fi")
|
||||
@ -117,6 +122,9 @@ void parse_options (int argc, char **argv)
|
||||
.add("version,v", "print copyright and version info", &show_version_and_exit)
|
||||
.add("help,h", "print usage information", &show_usage_and_exit)
|
||||
|
||||
// deprecated
|
||||
.add("embed-base-font", "", &deprecated_embed_base_font)
|
||||
|
||||
.add("", ¶m.input_filename, "", "")
|
||||
.add("", ¶m.output_filename, "", "")
|
||||
;
|
||||
|
@ -14,14 +14,6 @@ using std::string;
|
||||
|
||||
const double ID_MATRIX[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
|
||||
|
||||
const map<string, string> BASE_14_FONT_CSS_FONT_MAP({
|
||||
{ "Courier", "Courier,monospace" },
|
||||
{ "Helvetica", "Helvetica,Arial,\"Nimbus Sans L\",sans-serif" },
|
||||
{ "Times", "Times,\"Time New Roman\",\"Nimbus Roman No9 L\",serif" },
|
||||
{ "Symbol", "Symbol,\"Standard Symbols L\"" },
|
||||
{ "ZapfDingbats", "ZapfDingbats,\"Dingbats\"" },
|
||||
});
|
||||
|
||||
const map<string, string> GB_ENCODED_FONT_NAME_MAP({
|
||||
{"\xCB\xCE\xCC\xE5", "SimSun"},
|
||||
{"\xBA\xDA\xCC\xE5", "SimHei"},
|
||||
|
@ -21,8 +21,6 @@ static const double EPS = 1e-6;
|
||||
static const double DEFAULT_DPI = 72.0;
|
||||
extern const double ID_MATRIX[6];
|
||||
|
||||
// PDF base 14 font name -> CSS font name
|
||||
extern const std::map<std::string, std::string> BASE_14_FONT_CSS_FONT_MAP;
|
||||
// For GB encoded font names
|
||||
extern const std::map<std::string, std::string> GB_ENCODED_FONT_NAME_MAP;
|
||||
// map to embed files into html
|
||||
|
Loading…
Reference in New Issue
Block a user