diff --git a/pdf2htmlEX.1.in b/pdf2htmlEX.1.in
index 026e88b..3d1d3bb 100644
--- a/pdf2htmlEX.1.in
+++ b/pdf2htmlEX.1.in
@@ -299,7 +299,8 @@ Print debug information.
.TP
.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.
-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
diff --git a/src/BackgroundRenderer/BackgroundRenderer.cc b/src/BackgroundRenderer/BackgroundRenderer.cc
index a5dda2f..f75e1b4 100644
--- a/src/BackgroundRenderer/BackgroundRenderer.cc
+++ b/src/BackgroundRenderer/BackgroundRenderer.cc
@@ -49,7 +49,7 @@ BackgroundRenderer * BackgroundRenderer::getFallbackBackgroundRenderer(HTMLRende
return nullptr;
}
-void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev)
+void BackgroundRenderer::proof_begin_text_object(GfxState *state, OutputDev * dev)
{
if (!proof_state)
{
@@ -59,28 +59,66 @@ void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev)
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->getStrokeRGB(&sc.rgb);
- fc = fc.distance(red) > 0.4 ? red : green;
- sc = sc.distance(blue) > 0.4 ? blue : yellow;
+ if (render == 0 || render == 2) //has fill
+ 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)
dev->updateFillColorSpace(proof_state.get());
if (state->getStrokeColorSpace()->getMode() != csDeviceRGB)
dev->updateStrokeColorSpace(proof_state.get());
- GfxColor gfc, gsc;
- fc.get_gfx_color(gfc);
- sc.get_gfx_color(gsc);
- proof_state->setFillColor(&gfc);
- proof_state->setStrokeColor(&gsc);
+
+ dev->updateLineWidth(proof_state.get());
dev->updateFillColor(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)
{
+ state->setRender(proof_state->getRender());
+ dev->updateRender(state);
+ dev->updateLineWidth(state);
dev->updateFillColorSpace(state);
dev->updateStrokeColorSpace(state);
dev->updateFillColor(state);
diff --git a/src/BackgroundRenderer/BackgroundRenderer.h b/src/BackgroundRenderer/BackgroundRenderer.h
index 6ae9bf5..95a25d7 100644
--- a/src/BackgroundRenderer/BackgroundRenderer.h
+++ b/src/BackgroundRenderer/BackgroundRenderer.h
@@ -39,6 +39,7 @@ public:
// for proof output
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);
private:
diff --git a/src/BackgroundRenderer/CairoBackgroundRenderer.cc b/src/BackgroundRenderer/CairoBackgroundRenderer.cc
index e5371b6..b2733c2 100644
--- a/src/BackgroundRenderer/CairoBackgroundRenderer.cc
+++ b/src/BackgroundRenderer/CairoBackgroundRenderer.cc
@@ -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)
{
if (param.proof == 2)
diff --git a/src/BackgroundRenderer/CairoBackgroundRenderer.h b/src/BackgroundRenderer/CairoBackgroundRenderer.h
index 68d9123..b2d2f14 100644
--- a/src/BackgroundRenderer/CairoBackgroundRenderer.h
+++ b/src/BackgroundRenderer/CairoBackgroundRenderer.h
@@ -45,6 +45,7 @@ public:
CharCode code, int nBytes, Unicode *u, int uLen);
//for proof
+ void beginTextObject(GfxState *state);
void beginString(GfxState *state, GooString * str);
void endTextObject(GfxState *state);
diff --git a/src/BackgroundRenderer/SplashBackgroundRenderer.cc b/src/BackgroundRenderer/SplashBackgroundRenderer.cc
index b4cfc01..b7dc686 100644
--- a/src/BackgroundRenderer/SplashBackgroundRenderer.cc
+++ b/src/BackgroundRenderer/SplashBackgroundRenderer.cc
@@ -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)
{
if (param.proof == 2)
diff --git a/src/BackgroundRenderer/SplashBackgroundRenderer.h b/src/BackgroundRenderer/SplashBackgroundRenderer.h
index 205c201..11d9534 100644
--- a/src/BackgroundRenderer/SplashBackgroundRenderer.h
+++ b/src/BackgroundRenderer/SplashBackgroundRenderer.h
@@ -61,6 +61,7 @@ public:
}
//for proof
+ void beginTextObject(GfxState *state);
void beginString(GfxState *state, GooString * str);
void endTextObject(GfxState *state);
diff --git a/src/Color.cc b/src/Color.cc
index 07781a7..6a344e5 100644
--- a/src/Color.cc
+++ b/src/Color.cc
@@ -33,14 +33,14 @@ ostream & operator << (ostream & out, const Color & color)
return out;
}
-void Color::get_gfx_color(GfxColor & gc)
+void Color::get_gfx_color(GfxColor & gc) const
{
gc.c[0] = rgb.r;
gc.c[1] = rgb.g;
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,
dg = (double)rgb.g - other.rgb.g,
diff --git a/src/Color.h b/src/Color.h
index 2e8c7d8..a2d2415 100644
--- a/src/Color.h
+++ b/src/Color.h
@@ -26,9 +26,9 @@ struct Color
return true;
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].
- double distance(const Color & other);
+ double distance(const Color & other) const;
};
std::ostream & operator << (std::ostream & out, const Color & color);