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:
parent
f8d8a58deb
commit
aa15515247
@ -49,23 +49,12 @@ BackgroundRenderer * BackgroundRenderer::getFallbackBackgroundRenderer(HTMLRende
|
|||||||
return nullptr;
|
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)
|
if (!proof_state)
|
||||||
{
|
{
|
||||||
PDFRectangle rect(0, 0, state->getPageWidth(), state->getPageHeight());
|
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->setFillColorSpace(new GfxDeviceRGBColorSpace());
|
||||||
proof_state->setStrokeColorSpace(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;
|
sc = sc.distance(blue) > 0.4 ? blue : yellow;
|
||||||
|
|
||||||
if (state->getFillColorSpace()->getMode() != csDeviceRGB)
|
if (state->getFillColorSpace()->getMode() != csDeviceRGB)
|
||||||
dev->updateFillColorSpace(proof_state);
|
dev->updateFillColorSpace(proof_state.get());
|
||||||
if (state->getStrokeColorSpace()->getMode() != csDeviceRGB)
|
if (state->getStrokeColorSpace()->getMode() != csDeviceRGB)
|
||||||
dev->updateStrokeColorSpace(proof_state);
|
dev->updateStrokeColorSpace(proof_state.get());
|
||||||
GfxColor gfc, gsc;
|
GfxColor gfc, gsc;
|
||||||
fc.get_gfx_color(gfc);
|
fc.get_gfx_color(gfc);
|
||||||
sc.get_gfx_color(gsc);
|
sc.get_gfx_color(gsc);
|
||||||
proof_state->setFillColor(&gfc);
|
proof_state->setFillColor(&gfc);
|
||||||
proof_state->setStrokeColor(&gsc);
|
proof_state->setStrokeColor(&gsc);
|
||||||
dev->updateFillColor(proof_state);
|
dev->updateFillColor(proof_state.get());
|
||||||
dev->updateStrokeColor(proof_state);
|
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->updateFillColorSpace(state);
|
||||||
dev->updateStrokeColorSpace(state);
|
dev->updateStrokeColorSpace(state);
|
||||||
dev->updateFillColor(state);
|
dev->updateFillColor(state);
|
||||||
|
@ -10,9 +10,11 @@
|
|||||||
#define BACKGROUND_RENDERER_H__
|
#define BACKGROUND_RENDERER_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class PDFDoc;
|
class PDFDoc;
|
||||||
class GfxState;
|
class GfxState;
|
||||||
|
class OutputDev;
|
||||||
|
|
||||||
namespace pdf2htmlEX {
|
namespace pdf2htmlEX {
|
||||||
|
|
||||||
@ -27,8 +29,8 @@ public:
|
|||||||
// Currently only svg bg format might need a bitmap fallback.
|
// Currently only svg bg format might need a bitmap fallback.
|
||||||
static BackgroundRenderer * getFallbackBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param);
|
static BackgroundRenderer * getFallbackBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param);
|
||||||
|
|
||||||
BackgroundRenderer(): proof_state(nullptr) {}
|
BackgroundRenderer() {}
|
||||||
virtual ~BackgroundRenderer();
|
virtual ~BackgroundRenderer() {}
|
||||||
|
|
||||||
virtual void init(PDFDoc * doc) = 0;
|
virtual void init(PDFDoc * doc) = 0;
|
||||||
//return true on success, false otherwise (e.g. need a fallback)
|
//return true on success, false otherwise (e.g. need a fallback)
|
||||||
@ -37,10 +39,10 @@ public:
|
|||||||
|
|
||||||
// for proof output
|
// for proof output
|
||||||
protected:
|
protected:
|
||||||
void proof_begin_string(GfxState *state);
|
void proof_begin_string(GfxState * state, OutputDev * dev);
|
||||||
void proof_end_text_object(GfxState *state);
|
void proof_end_text_object(GfxState * state, OutputDev * dev);
|
||||||
private:
|
private:
|
||||||
GfxState * proof_state;
|
std::unique_ptr<GfxState> proof_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pdf2htmlEX
|
} // namespace pdf2htmlEX
|
||||||
|
@ -68,14 +68,14 @@ void CairoBackgroundRenderer::drawChar(GfxState *state, double x, double y,
|
|||||||
void CairoBackgroundRenderer::beginString(GfxState *state, GooString * str)
|
void CairoBackgroundRenderer::beginString(GfxState *state, GooString * str)
|
||||||
{
|
{
|
||||||
if (param.proof == 2)
|
if (param.proof == 2)
|
||||||
proof_begin_string(state);
|
proof_begin_string(state, this);
|
||||||
CairoOutputDev::beginString(state, str);
|
CairoOutputDev::beginString(state, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CairoBackgroundRenderer::endTextObject(GfxState *state)
|
void CairoBackgroundRenderer::endTextObject(GfxState *state)
|
||||||
{
|
{
|
||||||
if (param.proof == 2)
|
if (param.proof == 2)
|
||||||
proof_end_text_object(state);
|
proof_end_text_object(state, this);
|
||||||
CairoOutputDev::endTextObject(state);
|
CairoOutputDev::endTextObject(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,14 +93,14 @@ void SplashBackgroundRenderer::drawChar(GfxState *state, double x, double y,
|
|||||||
void SplashBackgroundRenderer::beginString(GfxState *state, GooString * str)
|
void SplashBackgroundRenderer::beginString(GfxState *state, GooString * str)
|
||||||
{
|
{
|
||||||
if (param.proof == 2)
|
if (param.proof == 2)
|
||||||
proof_begin_string(state);
|
proof_begin_string(state, this);
|
||||||
SplashOutputDev::beginString(state, str);
|
SplashOutputDev::beginString(state, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SplashBackgroundRenderer::endTextObject(GfxState *state)
|
void SplashBackgroundRenderer::endTextObject(GfxState *state)
|
||||||
{
|
{
|
||||||
if (param.proof == 2)
|
if (param.proof == 2)
|
||||||
proof_end_text_object(state);
|
proof_end_text_object(state, this);
|
||||||
SplashOutputDev::endTextObject(state);
|
SplashOutputDev::endTextObject(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user