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

Improve coding style of proof mode.

This commit is contained in:
Duan Yao 2014-06-27 11:35:00 +08:00
parent f8d8a58deb
commit aa15515247
4 changed files with 18 additions and 31 deletions

View File

@ -49,23 +49,12 @@ BackgroundRenderer * BackgroundRenderer::getFallbackBackgroundRenderer(HTMLRende
return nullptr;
}
BackgroundRenderer::~BackgroundRenderer()
void BackgroundRenderer::proof_begin_string(GfxState *state, OutputDev * dev)
{
//delete proof_state
if (proof_state)
delete proof_state;
}
void BackgroundRenderer::proof_begin_string(GfxState *state)
{
auto dev = (OutputDev*) dynamic_cast<SplashBackgroundRenderer*>(this);
if (!dev)
dev = (OutputDev*) dynamic_cast<CairoBackgroundRenderer*>(this);
if (!proof_state)
{
PDFRectangle rect(0, 0, state->getPageWidth(), state->getPageHeight());
proof_state = new GfxState(state->getHDPI(), state->getVDPI(), &rect, state->getRotate(), dev->upsideDown());
proof_state.reset(new GfxState(state->getHDPI(), state->getVDPI(), &rect, state->getRotate(), dev->upsideDown()));
proof_state->setFillColorSpace(new GfxDeviceRGBColorSpace());
proof_state->setStrokeColorSpace(new GfxDeviceRGBColorSpace());
}
@ -78,24 +67,20 @@ void BackgroundRenderer::proof_begin_string(GfxState *state)
sc = sc.distance(blue) > 0.4 ? blue : yellow;
if (state->getFillColorSpace()->getMode() != csDeviceRGB)
dev->updateFillColorSpace(proof_state);
dev->updateFillColorSpace(proof_state.get());
if (state->getStrokeColorSpace()->getMode() != csDeviceRGB)
dev->updateStrokeColorSpace(proof_state);
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->updateFillColor(proof_state);
dev->updateStrokeColor(proof_state);
dev->updateFillColor(proof_state.get());
dev->updateStrokeColor(proof_state.get());
}
void BackgroundRenderer::proof_end_text_object(GfxState *state)
void BackgroundRenderer::proof_end_text_object(GfxState *state, OutputDev * dev)
{
auto dev = (OutputDev*) dynamic_cast<SplashBackgroundRenderer*>(this);
if (!dev)
dev = (OutputDev*) dynamic_cast<CairoBackgroundRenderer*>(this);
dev->updateFillColorSpace(state);
dev->updateStrokeColorSpace(state);
dev->updateFillColor(state);

View File

@ -10,9 +10,11 @@
#define BACKGROUND_RENDERER_H__
#include <string>
#include <memory>
class PDFDoc;
class GfxState;
class OutputDev;
namespace pdf2htmlEX {
@ -27,8 +29,8 @@ public:
// Currently only svg bg format might need a bitmap fallback.
static BackgroundRenderer * getFallbackBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param);
BackgroundRenderer(): proof_state(nullptr) {}
virtual ~BackgroundRenderer();
BackgroundRenderer() {}
virtual ~BackgroundRenderer() {}
virtual void init(PDFDoc * doc) = 0;
//return true on success, false otherwise (e.g. need a fallback)
@ -37,10 +39,10 @@ public:
// for proof output
protected:
void proof_begin_string(GfxState *state);
void proof_end_text_object(GfxState *state);
void proof_begin_string(GfxState * state, OutputDev * dev);
void proof_end_text_object(GfxState * state, OutputDev * dev);
private:
GfxState * proof_state;
std::unique_ptr<GfxState> proof_state;
};
} // namespace pdf2htmlEX

View File

@ -68,14 +68,14 @@ void CairoBackgroundRenderer::drawChar(GfxState *state, double x, double y,
void CairoBackgroundRenderer::beginString(GfxState *state, GooString * str)
{
if (param.proof == 2)
proof_begin_string(state);
proof_begin_string(state, this);
CairoOutputDev::beginString(state, str);
}
void CairoBackgroundRenderer::endTextObject(GfxState *state)
{
if (param.proof == 2)
proof_end_text_object(state);
proof_end_text_object(state, this);
CairoOutputDev::endTextObject(state);
}

View File

@ -93,14 +93,14 @@ void SplashBackgroundRenderer::drawChar(GfxState *state, double x, double y,
void SplashBackgroundRenderer::beginString(GfxState *state, GooString * str)
{
if (param.proof == 2)
proof_begin_string(state);
proof_begin_string(state, this);
SplashOutputDev::beginString(state, str);
}
void SplashBackgroundRenderer::endTextObject(GfxState *state)
{
if (param.proof == 2)
proof_end_text_object(state);
proof_end_text_object(state, this);
SplashOutputDev::endTextObject(state);
}