1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-08 19:00:33 +00:00

add a font preprocessor

This commit is contained in:
Lu Wang 2012-09-07 00:58:23 +08:00
parent ab9dd287e6
commit 45b54d18c4
8 changed files with 30 additions and 6 deletions

View File

@ -66,6 +66,8 @@ add_executable(pdf2htmlEX
src/ff/ff.c src/ff/ff.c
src/BackgroundRenderer.h src/BackgroundRenderer.h
src/BackgroundRenderer.cc src/BackgroundRenderer.cc
src/FontPreprocessor.h
src/FontPreprocessor.cc
src/Consts.h src/Consts.h
src/Consts.cc src/Consts.cc
src/util.h src/util.h

2
TODO
View File

@ -1,3 +1,5 @@
disable annotation
valgrind valgrind
re-encoded only used glyphs re-encoded only used glyphs

View File

@ -24,7 +24,7 @@ public:
allowAntialiasA) { } allowAntialiasA) { }
virtual ~BackgroundRenderer() { } virtual ~BackgroundRenderer() { }
void drawChar(GfxState *state, double x, double y, virtual void drawChar(GfxState *state, double x, double y,
double dx, double dy, double dx, double dy,
double originX, double originY, double originX, double originY,
CharCode code, int nBytes, Unicode *u, int uLen); CharCode code, int nBytes, Unicode *u, int uLen);

View File

@ -30,7 +30,7 @@
#include "Param.h" #include "Param.h"
#include "util.h" #include "util.h"
#include "FontPreprocessor.h"
/* /*
* Naming Convention * Naming Convention
@ -124,6 +124,7 @@ class HTMLRenderer : public OutputDev
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// misc // misc
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
void add_tmp_file (const std::string & fn); void add_tmp_file (const std::string & fn);
void clean_tmp_files (); void clean_tmp_files ();
boost::filesystem::path dump_embedded_font (GfxFont * font, long long fn_id); boost::filesystem::path dump_embedded_font (GfxFont * font, long long fn_id);
@ -333,6 +334,7 @@ class HTMLRenderer : public OutputDev
// for font reencoding // for font reencoding
int32_t * cur_mapping; int32_t * cur_mapping;
char ** cur_mapping2; char ** cur_mapping2;
FontPreprocessor font_preprocessor;
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// styles & resources // styles & resources

View File

@ -51,12 +51,20 @@ HTMLRenderer::~HTMLRenderer()
void HTMLRenderer::process(PDFDoc *doc) void HTMLRenderer::process(PDFDoc *doc)
{ {
cerr << "Working: ";
xref = doc->getXRef(); xref = doc->getXRef();
BackgroundRenderer * bg_renderer = nullptr; cerr << "Preprocessing: ";
for(int i = param->first_page; i <= param->last_page ; ++i)
{
doc->displayPage(&font_preprocessor, i, param->h_dpi, param->v_dpi,
0, true, false, false,
nullptr, nullptr, nullptr, nullptr);
cerr << "." << flush;
}
cerr << endl;
cerr << "Working: ";
BackgroundRenderer * bg_renderer = nullptr;
if(param->process_nontext) if(param->process_nontext)
{ {
// Render non-text objects as image // Render non-text objects as image

View File

@ -25,7 +25,7 @@ const FontInfo * HTMLRenderer::install_font(GfxFont * font)
{ {
assert(sizeof(long long) == 2*sizeof(int)); assert(sizeof(long long) == 2*sizeof(int));
long long fn_id = (font == nullptr) ? 0 : *reinterpret_cast<long long*>(font->getID()); long long fn_id = (font == nullptr) ? 0 : hash_ref(font->getID());
auto iter = font_name_map.find(fn_id); auto iter = font_name_map.find(fn_id);
if(iter != font_name_map.end()) if(iter != font_name_map.end())

View File

@ -217,8 +217,12 @@ void HTMLRenderer::embed_font(const path & filepath, GfxFont * font, FontInfo &
memset(cur_mapping2, 0, 256 * sizeof(char*)); memset(cur_mapping2, 0, 256 * sizeof(char*));
const char * used_map = font_preprocessor.get_code_map(hash_ref(font->getID()));
for(int i = 0; i < 256; ++i) for(int i = 0; i < 256; ++i)
{ {
if(!used_map[i]) continue;
auto cn = font_8bit->getCharName(i); auto cn = font_8bit->getCharName(i);
if(cn == nullptr) if(cn == nullptr)
{ {

View File

@ -21,6 +21,7 @@
#include <CharTypes.h> #include <CharTypes.h>
#include <UTF8.h> #include <UTF8.h>
#include <GlobalParams.h> #include <GlobalParams.h>
#include <Object.h>
#include "Consts.h" #include "Consts.h"
@ -49,6 +50,11 @@ static inline bool _tm_equal(const double * tm1, const double * tm2, int size =
return true; return true;
} }
static inline long long hash_ref(const Ref * id)
{
return (((long long)(id->num)) << (sizeof(id->gen)*8)) | (id->gen);
}
/* /*
* http://en.wikipedia.org/wiki/HTML_decimal_character_rendering * http://en.wikipedia.org/wiki/HTML_decimal_character_rendering
*/ */