From 210aef28ac574cefab31a79da0e9a050f1ed8bb9 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Tue, 7 Aug 2012 01:52:31 +0800 Subject: [PATCH] better scripting; working on encoding --- bin/convert.pe | 1 + bin/pdf2htmlEX | 17 ++++++++++++++--- src/HTMLRenderer.cc | 43 ++++++++----------------------------------- src/HTMLRenderer.h | 6 ++---- 4 files changed, 25 insertions(+), 42 deletions(-) diff --git a/bin/convert.pe b/bin/convert.pe index 6c195bf..aa0c124 100644 --- a/bin/convert.pe +++ b/bin/convert.pe @@ -1,2 +1,3 @@ Open($1); +Reencode("unicode"); Generate($1:r+".ttf"); diff --git a/bin/pdf2htmlEX b/bin/pdf2htmlEX index 7261b0e..38d66f6 100755 --- a/bin/pdf2htmlEX +++ b/bin/pdf2htmlEX @@ -6,11 +6,22 @@ SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"/ # Execute ${SCRIPT_DIR}/pdftohtmlEX $* +echo -n "Converting fonts: " + for f in *.ttf; do - fontforge -script "${SCRIPT_DIR}/convert.pe" $f 2>/dev/null + if [ -f $f ]; then + fontforge -script "${SCRIPT_DIR}/convert.pe" $f 2>/dev/null + echo -n "." + fi done for f in *.pfa; do - fontforge -script "${SCRIPT_DIR}/convert.pe" $f 2>/dev/null -# rm $f + if [ -f $f ]; then + fontforge -script "${SCRIPT_DIR}/convert.pe" $f 2>/dev/null + rm $f + echo -n "." + fi done + +echo +echo "Done." diff --git a/src/HTMLRenderer.cc b/src/HTMLRenderer.cc index 67c53be..991ebbc 100644 --- a/src/HTMLRenderer.cc +++ b/src/HTMLRenderer.cc @@ -143,20 +143,16 @@ void TextString::addChars(GfxState *state, double x, double y, height += dy; } -void TextString::addChar(GfxState *state, double x, double y, - double dx, double dy, Unicode u) +void TextString::addUnicodes(GfxState *state, double x, double y, + double dx, double dy, Unicode * u, int uLen) { + /* if (0 < u && u != 9 && u < 32) // skip non-printable not-tab character return; + */ - /* - if (unicodes.empty()) - { - this->x = x; - this->y = y; - } - */ - unicodes.push_back(u); + for(int i = 0; i < uLen; ++i) + unicodes.push_back(u[i]); width += dx; height += dy; @@ -226,7 +222,6 @@ void HTMLRenderer::process(PDFDoc *doc) delete bg_renderer; std::cerr << std::endl; - std::cerr << "Done." << std::endl; } void HTMLRenderer::startPage(int pageNum, GfxState *state) @@ -459,29 +454,12 @@ void HTMLRenderer::drawChar(GfxState *state, double x, double y, double originX, double originY, CharCode code, int nBytes, Unicode *u, int uLen) { - double x1, y1, w1, h1; - - x1 = x; - y1 = y; - // if it is hidden, then return if ((state->getRender() & 3) == 3) return ; - w1 = dx - state->getCharSpace() * state->getHorizScaling(), - h1 = dy; - - cur_string->addChars(state, x1, y1, w1, h1, code, nBytes); - - /* - if (uLen != 0) { - w1 /= uLen; - h1 /= uLen; - } - for (int i = 0; i < uLen; ++i) { - cur_string->addChar(state, x1 + i*w1, y1 + i*h1, w1, h1, u[i]); - } - */ + //cur_string->addChars(state, x, y, dx, dy, code, nBytes); + cur_string->addUnicodes(state, x, y, dx, dy, u, uLen); } // TODO @@ -546,11 +524,6 @@ long long HTMLRenderer::install_font(GfxFont * font) return new_fn_id; } - //debug - { - std::cerr << "install font: " << new_fn_id << ' ' << font->getID()->num << std::endl; - } - string new_fn = (boost::format("f%|1$x|") % new_fn_id).str(); if(font->getType() == fontType3) { diff --git a/src/HTMLRenderer.h b/src/HTMLRenderer.h index f39aedc..dd1fe54 100644 --- a/src/HTMLRenderer.h +++ b/src/HTMLRenderer.h @@ -52,11 +52,9 @@ class TextString void addChars(GfxState * state, double x, double y, double dx, double dy, CharCode code, int nbytes); - - // Add a character to the string. - void addChar(GfxState *state, double x, double y, + void addUnicodes(GfxState *state, double x, double y, double dx, double dy, - Unicode u); + Unicode *u, int uLen); double getX() const {return x;} double getY() const {return y;} double getWidth() const {return width;}