mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
fix suffix
This commit is contained in:
parent
a2fe6d3c5e
commit
ec6ce4d888
@ -58,7 +58,7 @@ Special thanks to Arthur Titeica for the [AUR Package](https://aur.archlinux.org
|
||||
* GCC >= 4.4.6
|
||||
* libpoppler with xpdf header >= 0.20.2 (compile with --enable-xpdf-headers)
|
||||
* Install libpng (and headers) BEFORE you compile libpoppler if you want background images generated
|
||||
* boost c++ library (program options, filesystem, system(which is actually required by filesystem))
|
||||
* boost c++ library (program options)
|
||||
* fontforge (with header files)
|
||||
|
||||
#### Compiling
|
||||
|
@ -155,12 +155,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
|
||||
|
||||
void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only)
|
||||
{
|
||||
string suffix;
|
||||
{
|
||||
size_t idx = filepath.rfind('.');
|
||||
if((idx != string::npos) && (idx+1 < suffix.size()))
|
||||
suffix = filepath.substr(idx+1);
|
||||
}
|
||||
string suffix = get_suffix(filepath);
|
||||
|
||||
for(auto iter = suffix.begin(); iter != suffix.end(); ++iter)
|
||||
*iter = tolower(*iter);
|
||||
@ -173,7 +168,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
|
||||
Gfx8BitFont * font_8bit = nullptr;
|
||||
|
||||
info.use_tounicode = ((suffix == ".ttf") || (param->tounicode >= 0));
|
||||
info.use_tounicode = (is_truetype_suffix(suffix) || (param->tounicode >= 0));
|
||||
|
||||
if(!get_metric_only)
|
||||
{
|
||||
@ -199,7 +194,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
{
|
||||
font_8bit = dynamic_cast<Gfx8BitFont*>(font);
|
||||
maxcode = 0xff;
|
||||
if((suffix == ".ttf") || (suffix == ".ttc") || (suffix == ".otf"))
|
||||
if(is_truetype_suffix(suffix))
|
||||
{
|
||||
ff_reencode_glyph_order();
|
||||
FoFiTrueType *fftt = nullptr;
|
||||
@ -252,7 +247,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
{
|
||||
maxcode = 0xffff;
|
||||
|
||||
if(suffix == ".ttf")
|
||||
if(is_truetype_suffix(suffix))
|
||||
{
|
||||
ff_reencode_glyph_order();
|
||||
|
||||
@ -297,7 +292,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
if(!used_map[i])
|
||||
continue;
|
||||
|
||||
if((suffix != ".ttf") && (font_8bit != nullptr) && (font_8bit->getCharName(i) == nullptr))
|
||||
if(is_truetype_suffix(suffix) && (font_8bit != nullptr) && (font_8bit->getCharName(i) == nullptr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -165,14 +165,9 @@ int main(int argc, char **argv)
|
||||
|
||||
if(param.output_filename == "")
|
||||
{
|
||||
size_t idx = param.input_filename.rfind('/');
|
||||
if(idx == string::npos)
|
||||
idx = 0;
|
||||
else
|
||||
++ idx;
|
||||
const string s =param.input_filename.substr(idx);
|
||||
const string s = get_filename(param.input_filename);
|
||||
|
||||
if((s.size() >= 4) && (s.compare(s.size() - 4, 4, ".pdf") == 0))
|
||||
if(get_suffix(param.input_filename) == ".pdf")
|
||||
{
|
||||
param.output_filename = s.substr(0, s.size() - 4) + ".html";
|
||||
}
|
||||
|
31
src/util.cc
31
src/util.cc
@ -97,7 +97,7 @@ Unicode check_unicode(Unicode * u, int len, CharCode code, GfxFont * font)
|
||||
return unicode_from_font(code, font);
|
||||
}
|
||||
|
||||
void outputUnicodes(std::ostream & out, const Unicode * u, int uLen)
|
||||
void outputUnicodes(ostream & out, const Unicode * u, int uLen)
|
||||
{
|
||||
for(int i = 0; i < uLen; ++i)
|
||||
{
|
||||
@ -140,13 +140,13 @@ void create_directories(string path)
|
||||
create_directories(path.substr(0, idx));
|
||||
}
|
||||
|
||||
int r = ::mkdir(path.c_str(), S_IRWXU);
|
||||
int r = mkdir(path.c_str(), S_IRWXU);
|
||||
if(r != 0)
|
||||
{
|
||||
if(errno == EEXIST)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
if((::stat(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
||||
if((stat(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode))
|
||||
return;
|
||||
}
|
||||
|
||||
@ -154,3 +154,28 @@ void create_directories(string path)
|
||||
}
|
||||
}
|
||||
|
||||
bool is_truetype_suffix(const string & suffix)
|
||||
{
|
||||
return (suffix == ".ttf") || (suffix == ".ttc") || (suffix == ".otf");
|
||||
}
|
||||
|
||||
string get_filename (const string & path)
|
||||
{
|
||||
size_t idx = path.rfind('/');
|
||||
if(idx == string::npos)
|
||||
return path;
|
||||
else if (idx == path.size() - 1)
|
||||
return "";
|
||||
return path.substr(idx + 1);
|
||||
}
|
||||
|
||||
string get_suffix(const string & path)
|
||||
{
|
||||
string fn = get_filename(path);
|
||||
size_t idx = fn.rfind('.');
|
||||
if(idx == string::npos)
|
||||
return "";
|
||||
else
|
||||
return fn.substr(idx);
|
||||
}
|
||||
|
||||
|
@ -207,4 +207,9 @@ private:
|
||||
|
||||
void create_directories(std::string path);
|
||||
|
||||
bool is_truetype_suffix(const std::string & suffix);
|
||||
|
||||
std::string get_filename(const std::string & path);
|
||||
std::string get_suffix(const std::string & path);
|
||||
|
||||
#endif //UTIL_H__
|
||||
|
Loading…
Reference in New Issue
Block a user