1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00

Merge branch 'devv'

This commit is contained in:
Lu Wang 2012-08-10 01:18:49 +08:00
commit c187dc06f0
5 changed files with 70 additions and 22 deletions

View File

@ -14,8 +14,8 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wunused-function")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb")
add_executable(pdftohtmlEX src/pdftohtmlEX.cc src/HTMLRenderer.cc src/HTMLRenderer.h src/BackgroundRenderer.cc src/BackgroundRenderer.h src/Consts.h)
target_link_libraries(pdftohtmlEX poppler boost_program_options)

View File

@ -12,7 +12,9 @@ if [ -f convert.pe ]; then
echo -n "Converting fonts: "
fontforge -script convert.pe 2>/dev/null
echo "."
# rm convert.pe
rm convert.pe
fi
rm *.encoding 2>/dev/null
echo "Done."

View File

@ -22,6 +22,7 @@
#include <fofi/FoFiType1C.h>
#include <fofi/FoFiTrueType.h>
#include <splash/SplashBitmap.h>
#include <CharCodeToUnicode.h>
#include "HTMLRenderer.h"
#include "BackgroundRenderer.h"
@ -87,9 +88,11 @@ void HTMLRenderer::process(PDFDoc *doc)
std::cerr.flush();
}
std::cerr << std::endl;
std::cerr << "Processing Others: ";
if(param->process_nontext)
{
// Render non-text objects as image
std::cerr << "Processing Others: ";
// copied from poppler
SplashColor color;
color[0] = color[1] = color[2] = 255;
@ -108,8 +111,8 @@ void HTMLRenderer::process(PDFDoc *doc)
std::cerr.flush();
}
delete bg_renderer;
std::cerr << std::endl;
}
}
void HTMLRenderer::startPage(int pageNum, GfxState *state)
@ -303,6 +306,7 @@ void HTMLRenderer::drawString(GfxState * state, GooString * s)
//debug
//real pos & hori_scale
if(0)
{
html_fout << "\"";
double x,y;
@ -438,6 +442,45 @@ void HTMLRenderer::install_embedded_font (GfxFont * font, long long fn_id)
{
//generate script for fontforge
fontscript_fout << boost::format("Open(\"%1%(%2%)\",1)") % param->input_filename % font->getName()->getCString() << endl;
if(font->hasToUnicodeCMap() && (font->getType() == fontTrueType))
{
char * buf;
int buflen;
FoFiTrueType * ttf;
if((buf = font->readEmbFontFile(xref, &buflen)))
{
if((ttf = FoFiTrueType::make(buf, buflen)))
{
auto ctg = dynamic_cast<Gfx8BitFont*>(font)->getCodeToGIDMap(ttf);
auto ctu = font->getToUnicode();
ofstream map_fout((boost::format("f%|1$x|.encoding") % fn_id).str().c_str());
for(int i = 0; i < 256; ++i)
{
int code = ctg[i];
Unicode * u;
auto n = ctu->mapToUnicode(i, &u);
// not sure what to do when n > 1
if(n > 0)
{
map_fout << boost::format("0x%|1$X|") % code;
for(int j = 0; j < n; ++j)
map_fout << boost::format(" 0x%|1$X|") % u[j];
map_fout << boost::format(" # 0x%|1$X|") % i << endl;
}
}
fontscript_fout << boost::format("LoadEncodingFile(\"f%|1$x|.encoding\", \"f%|1$x|\")") % fn_id << endl;
fontscript_fout << boost::format("Reencode(\"f%|1$x|\", 1)") % fn_id << endl;
ctu->decRefCnt();
delete ttf;
}
gfree(buf);
}
}
fontscript_fout << boost::format("Generate(\"f%|1$x|.ttf\")") % fn_id << endl;
export_remote_font(fn_id, ".ttf", "truetype", font);

View File

@ -19,6 +19,8 @@ struct Param
double h_dpi, v_dpi;
double h_eps, v_eps;
int process_nontext;
};

View File

@ -125,6 +125,7 @@ po::variables_map parse_options (int argc, char **argv)
("vdpi", po::value<double>(&param.v_dpi)->default_value(72.0), "vertical DPI")
("heps", po::value<double>(&param.h_eps)->default_value(1.0), "max tolerated horizontal offset (in pixels)")
("veps", po::value<double>(&param.v_eps)->default_value(1.0), "max tolerated vertical offset (in pixels)")
("process-nontext", po::value<int>(&param.process_nontext)->default_value(1), "process nontext objects")
;
opt_hidden.add_options()