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

Proof mode: take care of render mode change inside text object; fix line width calculation in case of rotaion transform.

This commit is contained in:
Duan Yao 2014-06-28 14:55:01 +08:00
parent 0b82165543
commit 55def41bcd
6 changed files with 27 additions and 8 deletions

View File

@ -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

View File

@ -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<GfxState> proof_state;
};

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);