Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Incoming #706

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ option(ENABLE_SVG "Enable SVG support, for generating SVG background images and

include_directories(${CMAKE_SOURCE_DIR}/src)

set(PDF2HTMLEX_VERSION "0.14.6")
set(PDF2HTMLEX_VERSION "0.15.0")
set(ARCHIVE_NAME pdf2htmlex-${PDF2HTMLEX_VERSION})
add_custom_target(dist
COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
Expand Down
11 changes: 11 additions & 0 deletions src/HTMLRenderer/font.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ string HTMLRenderer::dump_type3_font (GfxFont * font, FontInfo & info)
#endif
}

namespace {

void output_map_file_header(std::ostream& out) {
out << "glyph_code mapped_code unicode" << std::endl;
}

} // namespace

void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only)
{
if(param.debug)
Expand Down Expand Up @@ -528,6 +536,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
ffw_reencode_glyph_order();

GfxCIDFont * _font = dynamic_cast<GfxCIDFont*>(font);
assert(_font != nullptr);

// To locate CID2GID for the font
// as in CairoFontEngine.cc
Expand Down Expand Up @@ -574,6 +583,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
map_filename = (char*)str_fmt("%s/f%llx.map", param.tmp_dir.c_str(), info.id);
tmp_files.add(map_filename);
map_outf.open(map_filename);
output_map_file_header(map_outf);
}

unordered_set<int> codeset;
Expand Down Expand Up @@ -650,6 +660,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
{
map_outf.close();
map_outf.open(map_filename);
output_map_file_header(map_outf);
}
continue;
}
Expand Down
15 changes: 10 additions & 5 deletions src/HTMLRenderer/general.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,13 @@ void HTMLRenderer::process(PDFDoc *doc)
for(int i = param.first_page; i <= param.last_page ; ++i)
{
if (param.tmp_file_size_limit != -1 && tmp_files.get_total_size() > param.tmp_file_size_limit * 1024) {
cerr << "Stop processing, reach max size\n";
if(param.quiet == 0)
cerr << "Stop processing, reach max size\n";
break;
}

cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
if (param.quiet == 0)
cerr << "Working: " << (i-param.first_page) << "/" << page_count << '\r' << flush;

if(param.split_pages)
{
Expand Down Expand Up @@ -153,9 +155,11 @@ void HTMLRenderer::process(PDFDoc *doc)
f_curpage = nullptr;
}
}
if(page_count >= 0)
if(page_count >= 0 && param.quiet == 0)
cerr << "Working: " << page_count << "/" << page_count;
cerr << endl;

if(param.quiet == 0)
cerr << endl;

////////////////////////
// Process Outline
Expand All @@ -167,7 +171,8 @@ void HTMLRenderer::process(PDFDoc *doc)
bg_renderer = nullptr;
fallback_bg_renderer = nullptr;

cerr << endl;
if(param.quiet == 0)
cerr << endl;
}

void HTMLRenderer::setDefaultCTM(double *ctm)
Expand Down
110 changes: 54 additions & 56 deletions src/HTMLRenderer/link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,73 +56,70 @@ static string get_linkdest_detail_str(LinkDest * dest, Catalog * catalog, int &
// dec
sout << "[" << pageno;

if(dest)
switch(dest->getKind())
{
switch(dest->getKind())
{
case destXYZ:
{
sout << ",\"XYZ\",";
if(dest->getChangeLeft())
sout << (dest->getLeft());
else
sout << "null";
sout << ",";
if(dest->getChangeTop())
sout << (dest->getTop());
else
sout << "null";
sout << ",";
if(dest->getChangeZoom())
sout << (dest->getZoom());
else
sout << "null";
}
break;
case destFit:
sout << ",\"Fit\"";
break;
case destFitH:
sout << ",\"FitH\",";
if(dest->getChangeTop())
sout << (dest->getTop());
else
sout << "null";
break;
case destFitV:
sout << ",\"FitV\",";
case destXYZ:
{
sout << ",\"XYZ\",";
if(dest->getChangeLeft())
sout << (dest->getLeft());
else
sout << "null";
break;
case destFitR:
sout << ",\"FitR\","
<< (dest->getLeft()) << ","
<< (dest->getBottom()) << ","
<< (dest->getRight()) << ","
<< (dest->getTop());
break;
case destFitB:
sout << ",\"FitB\"";
break;
case destFitBH:
sout << ",\"FitBH\",";
sout << ",";
if(dest->getChangeTop())
sout << (dest->getTop());
else
sout << "null";
break;
case destFitBV:
sout << ",\"FitBV\",";
if(dest->getChangeLeft())
sout << (dest->getLeft());
sout << ",";
if(dest->getChangeZoom())
sout << (dest->getZoom());
else
sout << "null";
break;
default:
break;
}
}
break;
case destFit:
sout << ",\"Fit\"";
break;
case destFitH:
sout << ",\"FitH\",";
if(dest->getChangeTop())
sout << (dest->getTop());
else
sout << "null";
break;
case destFitV:
sout << ",\"FitV\",";
if(dest->getChangeLeft())
sout << (dest->getLeft());
else
sout << "null";
break;
case destFitR:
sout << ",\"FitR\","
<< (dest->getLeft()) << ","
<< (dest->getBottom()) << ","
<< (dest->getRight()) << ","
<< (dest->getTop());
break;
case destFitB:
sout << ",\"FitB\"";
break;
case destFitBH:
sout << ",\"FitBH\",";
if(dest->getChangeTop())
sout << (dest->getTop());
else
sout << "null";
break;
case destFitBV:
sout << ",\"FitBV\",";
if(dest->getChangeLeft())
sout << (dest->getLeft());
else
sout << "null";
break;
default:
break;
}
sout << "]";

Expand Down Expand Up @@ -166,6 +163,7 @@ string HTMLRenderer::get_linkaction_str(LinkAction * action, string & detail)
case actionURI:
{
auto * real_action = dynamic_cast<LinkURI*>(action);
assert(real_action != nullptr);
dest_str = real_action->getURI()->getCString();
}
break;
Expand Down
7 changes: 3 additions & 4 deletions src/HTMLTextLine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,12 @@ void HTMLTextLine::optimize_normal(std::vector<HTMLTextLine*> & lines)
new_offsets.reserve(offsets.size());

auto offset_iter1 = offsets.begin();
for(auto state_iter2 = states.begin(), state_iter1 = state_iter2++;
state_iter1 != states.end();
++state_iter1, ++state_iter2)
for(auto state_iter1 = states.begin(); state_iter1 != states.end(); ++state_iter1)
{
const auto state_iter2 = std::next(state_iter1);
const size_t text_idx1 = state_iter1->start_idx;
const size_t text_idx2 = (state_iter2 == states.end()) ? text.size() : state_iter2->start_idx;
size_t text_count = text_idx2 - text_idx1;
const size_t text_count = text_idx2 - text_idx1;

// there might be some offsets before the first state
while((offset_iter1 != offsets.end())
Expand Down
1 change: 1 addition & 0 deletions src/Param.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct Param
std::string tmp_dir;
int debug;
int proof;
int quiet;

std::string input_filename, output_filename;
};
Expand Down
9 changes: 6 additions & 3 deletions src/Preprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void Preprocessor::process(PDFDoc * doc)
int page_count = (param.last_page - param.first_page + 1);
for(int i = param.first_page; i <= param.last_page ; ++i)
{
cerr << "Preprocessing: " << (i-param.first_page) << "/" << page_count << '\r' << flush;
if(param.quiet == 0)
cerr << "Preprocessing: " << (i - param.first_page) << "/" << page_count << '\r' << flush;

doc->displayPage(this, i, DEFAULT_DPI, DEFAULT_DPI,
0,
Expand All @@ -54,9 +55,11 @@ void Preprocessor::process(PDFDoc * doc)
false, // printing
nullptr, nullptr, nullptr, nullptr);
}
if(page_count >= 0)
if(page_count >= 0 && param.quiet == 0)
cerr << "Preprocessing: " << page_count << "/" << page_count;
cerr << endl;

if(param.quiet == 0)
cerr << endl;
}

void Preprocessor::drawChar(GfxState *state, double x, double y,
Expand Down
4 changes: 2 additions & 2 deletions src/StateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class StateManager<double, Imp>

// Be careful about the mixed usage of Matrix and const double *
// the input is usually double *, which might be changed, so we have to copy the content out
// in the map we use Matrix instead of double * such that the array may be automatically release when deconstructing
// in the map we use Matrix instead of double * such that the array may be automatically release when destructing
template <class Imp>
class StateManager<Matrix, Imp>
{
Expand All @@ -96,7 +96,7 @@ class StateManager<Matrix, Imp>
// return id
long long install(const double * new_value) {
Matrix m;
memcpy(m.m, new_value, sizeof(m.m));
memcpy(m.m, new_value, 4 * sizeof(double));
auto iter = value_map.lower_bound(m);
if((iter != value_map.end()) && (tm_equal(m.m, iter->first.m, 4)))
{
Expand Down
13 changes: 7 additions & 6 deletions src/pdf2htmlEX.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void prepare_directories()

errno = 0;

unique_ptr<char> pBuf(new char[tmp_dir.size() + 1]);
unique_ptr<char[]> pBuf(new char[tmp_dir.size() + 1]);
strcpy(pBuf.get(), tmp_dir.c_str());
auto p = mkdtemp(pBuf.get());
if(p == nullptr)
Expand Down Expand Up @@ -160,7 +160,7 @@ void parse_options (int argc, char **argv)
.add("process-form", &param.process_form, 0, "include text fields and radio buttons")
.add("printing", &param.printing, 1, "enable printing support")
.add("fallback", &param.fallback, 0, "output in fallback mode")
.add("tmp-file-size-limit", &param.tmp_file_size_limit, -1, "Maximum size (in KB) used by temporary files, -1 for no limit.")
.add("tmp-file-size-limit", &param.tmp_file_size_limit, -1, "Maximum size (in KB) used by temporary files, -1 for no limit")

// fonts
.add("embed-external-font", &param.embed_external_font, 1, "embed local match for external fonts")
Expand All @@ -186,8 +186,8 @@ void parse_options (int argc, char **argv)
// background image
.add("bg-format", &param.bg_format, "png", "specify background image format")
.add("svg-node-count-limit", &param.svg_node_count_limit, -1, "if node count in a svg background image exceeds this limit,"
" fall back this page to bitmap background; negative value means no limit.")
.add("svg-embed-bitmap", &param.svg_embed_bitmap, 1, "1: embed bitmaps in svg background; 0: dump bitmaps to external files if possible.")
" fall back this page to bitmap background; negative value means no limit")
.add("svg-embed-bitmap", &param.svg_embed_bitmap, 1, "1: embed bitmaps in svg background; 0: dump bitmaps to external files if possible")

// encryption
.add("owner-password,o", &param.owner_password, "", "owner password (for encrypted files)", true)
Expand All @@ -196,11 +196,12 @@ void parse_options (int argc, char **argv)

// misc.
.add("clean-tmp", &param.clean_tmp, 1, "remove temporary files after conversion")
.add("tmp-dir", &param.tmp_dir, param.tmp_dir, "specify the location of temporary directory.")
.add("tmp-dir", &param.tmp_dir, param.tmp_dir, "specify the location of temporary directory")
.add("data-dir", &param.data_dir, param.data_dir, "specify data directory")
.add("poppler-data-dir", &param.poppler_data_dir, param.poppler_data_dir, "specify poppler data directory")
.add("debug", &param.debug, 0, "print debugging information")
.add("proof", &param.proof, 0, "texts are drawn on both text layer and background for proof.")
.add("proof", &param.proof, 0, "texts are drawn on both text layer and background for proof")
.add("quiet", &param.quiet, 0, "perform operations quietly")

// meta
.add("version,v", "print copyright and version info", &show_version_and_exit)
Expand Down
4 changes: 3 additions & 1 deletion src/util/unicode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Unicode unicode_from_font (CharCode code, GfxFont * font)
{
if(!font->isCIDFont())
{
char * cname = dynamic_cast<Gfx8BitFont*>(font)->getCharName(code);
auto * font2 = dynamic_cast<Gfx8BitFont*>(font);
assert(font2 != nullptr);
char * cname = font2->getCharName(code);
// may be untranslated ligature
if(cname)
{
Expand Down