From 55def41bcd436e4129ebe9994982bf8a90e0eb9f Mon Sep 17 00:00:00 2001 From: Duan Yao Date: Sat, 28 Jun 2014 14:55:01 +0800 Subject: [PATCH] Proof mode: take care of render mode change inside text object; fix line width calculation in case of rotaion transform. --- src/BackgroundRenderer/BackgroundRenderer.cc | 18 ++++++++++-------- src/BackgroundRenderer/BackgroundRenderer.h | 1 + .../CairoBackgroundRenderer.cc | 7 +++++++ .../CairoBackgroundRenderer.h | 1 + .../SplashBackgroundRenderer.cc | 7 +++++++ .../SplashBackgroundRenderer.h | 1 + 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/BackgroundRenderer/BackgroundRenderer.cc b/src/BackgroundRenderer/BackgroundRenderer.cc index f75e1b4..c5c5601 100644 --- a/src/BackgroundRenderer/BackgroundRenderer.cc +++ b/src/BackgroundRenderer/BackgroundRenderer.cc @@ -59,23 +59,21 @@ void BackgroundRenderer::proof_begin_text_object(GfxState *state, OutputDev * de proof_state->setStrokeColorSpace(new GfxDeviceRGBColorSpace()); } - int render = state->getRender(); - // Save original render mode in proof_state, and restore in proof_end_text_object() // This is due to poppler's OutputDev::updateRender() actually has no effect, we have to // modify state directly, see proof_begin_string(). - proof_state->setRender(render); + proof_state->setRender(state->getRender()); } void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev) { int render = proof_state->getRender(); - if (render == 3 || state->getRender() == 3) // hidden + if (render == 3) // hidden return; - double lx = state->getFontSize() / 50, ly = lx; + double lx = state->getFontSize() / 70, ly = lx; tm_transform(state->getTextMat(), lx, ly, true); - proof_state->setLineWidth(std::min(fabs(lx), fabs(ly))); + proof_state->setLineWidth(sqrt(lx * lx + ly * ly)); static const Color red(1, 0, 0), green(0, 1, 0), blue(0, 0, 1), yellow(1, 1, 0), white(1, 1, 1); Color fc, sc; @@ -111,13 +109,11 @@ void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev) dev->updateStrokeColor(proof_state.get()); state->setRender(2); // fill & stroke - dev->updateRender(state); } void BackgroundRenderer::proof_end_text_object(GfxState *state, OutputDev * dev) { state->setRender(proof_state->getRender()); - dev->updateRender(state); dev->updateLineWidth(state); dev->updateFillColorSpace(state); dev->updateStrokeColorSpace(state); @@ -125,4 +121,10 @@ void BackgroundRenderer::proof_end_text_object(GfxState *state, OutputDev * dev) dev->updateStrokeColor(state); } +void BackgroundRenderer::proof_update_render(GfxState *state, OutputDev * dev) +{ + // Save render mode in proof_state in cases it is changed inside a text object + proof_state->setRender(state->getRender()); +} + } // namespace pdf2htmlEX diff --git a/src/BackgroundRenderer/BackgroundRenderer.h b/src/BackgroundRenderer/BackgroundRenderer.h index 95a25d7..01675be 100644 --- a/src/BackgroundRenderer/BackgroundRenderer.h +++ b/src/BackgroundRenderer/BackgroundRenderer.h @@ -42,6 +42,7 @@ protected: void proof_begin_text_object(GfxState * state, OutputDev * dev); void proof_begin_string(GfxState * state, OutputDev * dev); void proof_end_text_object(GfxState * state, OutputDev * dev); + void proof_update_render(GfxState * state, OutputDev * dev); private: std::unique_ptr proof_state; }; diff --git a/src/BackgroundRenderer/CairoBackgroundRenderer.cc b/src/BackgroundRenderer/CairoBackgroundRenderer.cc index b2733c2..7debc03 100644 --- a/src/BackgroundRenderer/CairoBackgroundRenderer.cc +++ b/src/BackgroundRenderer/CairoBackgroundRenderer.cc @@ -86,6 +86,13 @@ void CairoBackgroundRenderer::endTextObject(GfxState *state) CairoOutputDev::endTextObject(state); } +void CairoBackgroundRenderer::updateRender(GfxState *state) +{ + if (param.proof == 2) + proof_update_render(state, this); + CairoOutputDev::updateRender(state); +} + void CairoBackgroundRenderer::init(PDFDoc * doc) { startDoc(doc); diff --git a/src/BackgroundRenderer/CairoBackgroundRenderer.h b/src/BackgroundRenderer/CairoBackgroundRenderer.h index b2d2f14..2d3667d 100644 --- a/src/BackgroundRenderer/CairoBackgroundRenderer.h +++ b/src/BackgroundRenderer/CairoBackgroundRenderer.h @@ -48,6 +48,7 @@ public: void beginTextObject(GfxState *state); void beginString(GfxState *state, GooString * str); void endTextObject(GfxState *state); + void updateRender(GfxState *state); protected: virtual void setMimeData(Stream *str, Object *ref, cairo_surface_t *image); diff --git a/src/BackgroundRenderer/SplashBackgroundRenderer.cc b/src/BackgroundRenderer/SplashBackgroundRenderer.cc index b7dc686..6b7f68c 100644 --- a/src/BackgroundRenderer/SplashBackgroundRenderer.cc +++ b/src/BackgroundRenderer/SplashBackgroundRenderer.cc @@ -111,6 +111,13 @@ void SplashBackgroundRenderer::endTextObject(GfxState *state) SplashOutputDev::endTextObject(state); } +void SplashBackgroundRenderer::updateRender(GfxState *state) +{ + if (param.proof == 2) + proof_update_render(state, this); + SplashOutputDev::updateRender(state); +} + void SplashBackgroundRenderer::init(PDFDoc * doc) { startDoc(doc); diff --git a/src/BackgroundRenderer/SplashBackgroundRenderer.h b/src/BackgroundRenderer/SplashBackgroundRenderer.h index 11d9534..8e064e7 100644 --- a/src/BackgroundRenderer/SplashBackgroundRenderer.h +++ b/src/BackgroundRenderer/SplashBackgroundRenderer.h @@ -64,6 +64,7 @@ public: void beginTextObject(GfxState *state); void beginString(GfxState *state, GooString * str); void endTextObject(GfxState *state); + void updateRender(GfxState *state); protected: void dump_image(const char * filename, int x1, int y1, int x2, int y2);