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

Proof mode: stroke and fill texts to improve visibility.

This commit is contained in:
Duan Yao 2014-06-27 16:11:42 +08:00
parent aa15515247
commit 0b82165543
9 changed files with 70 additions and 14 deletions

View File

@ -299,7 +299,8 @@ Print debug information.
.TP .TP
.B --proof <0|1|2> (Default: 0) .B --proof <0|1|2> (Default: 0)
Output a proof version. If a positive value is specified, texts are drawn on both text layer and background image for comparision. Output a proof version. If a positive value is specified, texts are drawn on both text layer and background image for comparision.
If 2 is specified, texts on background are in different colors, usually red for filling, blue for stroking. If 2 is specified, texts on background are in different colors. If png/jpg background format is used,
a higher hdpi/vdpi (e.g. 288) is recommended for legibility.
.SS Meta .SS Meta

View File

@ -49,7 +49,7 @@ BackgroundRenderer * BackgroundRenderer::getFallbackBackgroundRenderer(HTMLRende
return nullptr; return nullptr;
} }
void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev) void BackgroundRenderer::proof_begin_text_object(GfxState *state, OutputDev * dev)
{ {
if (!proof_state) if (!proof_state)
{ {
@ -59,28 +59,66 @@ void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev)
proof_state->setStrokeColorSpace(new GfxDeviceRGBColorSpace()); proof_state->setStrokeColorSpace(new GfxDeviceRGBColorSpace());
} }
Color fc, sc, red(1, 0, 0), green(0, 1, 0), blue(0, 0, 1), yellow(1, 1, 0); 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);
}
void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev)
{
int render = proof_state->getRender();
if (render == 3 || state->getRender() == 3) // hidden
return;
double lx = state->getFontSize() / 50, ly = lx;
tm_transform(state->getTextMat(), lx, ly, true);
proof_state->setLineWidth(std::min(fabs(lx), fabs(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;
const Color *pfc, *psc;
state->getFillRGB(&fc.rgb); state->getFillRGB(&fc.rgb);
state->getStrokeRGB(&sc.rgb); state->getStrokeRGB(&sc.rgb);
fc = fc.distance(red) > 0.4 ? red : green; if (render == 0 || render == 2) //has fill
sc = sc.distance(blue) > 0.4 ? blue : yellow; pfc = fc.distance(red) > 0.4 ? &red : &green;
else
pfc = &red;
if (render == 1 || render == 2) // has stroke
psc = sc.distance(blue) > 0.4 ? &blue : &yellow;
else if(render == 0) // fill only
psc = &white;
else
psc = &blue;
GfxColor gfc, gsc;
pfc->get_gfx_color(gfc);
psc->get_gfx_color(gsc);
proof_state->setFillColor(&gfc);
proof_state->setStrokeColor(&gsc);
if (state->getFillColorSpace()->getMode() != csDeviceRGB) if (state->getFillColorSpace()->getMode() != csDeviceRGB)
dev->updateFillColorSpace(proof_state.get()); dev->updateFillColorSpace(proof_state.get());
if (state->getStrokeColorSpace()->getMode() != csDeviceRGB) if (state->getStrokeColorSpace()->getMode() != csDeviceRGB)
dev->updateStrokeColorSpace(proof_state.get()); dev->updateStrokeColorSpace(proof_state.get());
GfxColor gfc, gsc;
fc.get_gfx_color(gfc); dev->updateLineWidth(proof_state.get());
sc.get_gfx_color(gsc);
proof_state->setFillColor(&gfc);
proof_state->setStrokeColor(&gsc);
dev->updateFillColor(proof_state.get()); dev->updateFillColor(proof_state.get());
dev->updateStrokeColor(proof_state.get()); dev->updateStrokeColor(proof_state.get());
state->setRender(2); // fill & stroke
dev->updateRender(state);
} }
void BackgroundRenderer::proof_end_text_object(GfxState *state, OutputDev * dev) 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->updateFillColorSpace(state);
dev->updateStrokeColorSpace(state); dev->updateStrokeColorSpace(state);
dev->updateFillColor(state); dev->updateFillColor(state);

View File

@ -39,6 +39,7 @@ public:
// for proof output // for proof output
protected: protected:
void proof_begin_text_object(GfxState * state, OutputDev * dev);
void proof_begin_string(GfxState * state, OutputDev * dev); void proof_begin_string(GfxState * state, OutputDev * dev);
void proof_end_text_object(GfxState * state, OutputDev * dev); void proof_end_text_object(GfxState * state, OutputDev * dev);
private: private:

View File

@ -65,6 +65,13 @@ void CairoBackgroundRenderer::drawChar(GfxState *state, double x, double y,
} }
} }
void CairoBackgroundRenderer::beginTextObject(GfxState *state)
{
if (param.proof == 2)
proof_begin_text_object(state, this);
CairoOutputDev::beginTextObject(state);
}
void CairoBackgroundRenderer::beginString(GfxState *state, GooString * str) void CairoBackgroundRenderer::beginString(GfxState *state, GooString * str)
{ {
if (param.proof == 2) if (param.proof == 2)

View File

@ -45,6 +45,7 @@ public:
CharCode code, int nBytes, Unicode *u, int uLen); CharCode code, int nBytes, Unicode *u, int uLen);
//for proof //for proof
void beginTextObject(GfxState *state);
void beginString(GfxState *state, GooString * str); void beginString(GfxState *state, GooString * str);
void endTextObject(GfxState *state); void endTextObject(GfxState *state);

View File

@ -90,6 +90,13 @@ void SplashBackgroundRenderer::drawChar(GfxState *state, double x, double y,
} }
} }
void SplashBackgroundRenderer::beginTextObject(GfxState *state)
{
if (param.proof == 2)
proof_begin_text_object(state, this);
SplashOutputDev::beginTextObject(state);
}
void SplashBackgroundRenderer::beginString(GfxState *state, GooString * str) void SplashBackgroundRenderer::beginString(GfxState *state, GooString * str)
{ {
if (param.proof == 2) if (param.proof == 2)

View File

@ -61,6 +61,7 @@ public:
} }
//for proof //for proof
void beginTextObject(GfxState *state);
void beginString(GfxState *state, GooString * str); void beginString(GfxState *state, GooString * str);
void endTextObject(GfxState *state); void endTextObject(GfxState *state);

View File

@ -33,14 +33,14 @@ ostream & operator << (ostream & out, const Color & color)
return out; return out;
} }
void Color::get_gfx_color(GfxColor & gc) void Color::get_gfx_color(GfxColor & gc) const
{ {
gc.c[0] = rgb.r; gc.c[0] = rgb.r;
gc.c[1] = rgb.g; gc.c[1] = rgb.g;
gc.c[2] = rgb.b; gc.c[2] = rgb.b;
} }
double Color::distance(const Color & other) double Color::distance(const Color & other) const
{ {
double dr = (double)rgb.r - other.rgb.r, double dr = (double)rgb.r - other.rgb.r,
dg = (double)rgb.g - other.rgb.g, dg = (double)rgb.g - other.rgb.g,

View File

@ -26,9 +26,9 @@ struct Color
return true; return true;
return ((rgb.r == c.rgb.r) && (rgb.g == c.rgb.g) && (rgb.b == c.rgb.b)); return ((rgb.r == c.rgb.r) && (rgb.g == c.rgb.g) && (rgb.b == c.rgb.b));
} }
void get_gfx_color(GfxColor & gc); void get_gfx_color(GfxColor & gc) const;
// Color distance, [0,1]. // Color distance, [0,1].
double distance(const Color & other); double distance(const Color & other) const;
}; };
std::ostream & operator << (std::ostream & out, const Color & color); std::ostream & operator << (std::ostream & out, const Color & color);