Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pdf2htmlEX/src/ArgParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class ArgParser
T * location, const Tv & default_value,
const char * description, bool dont_show_default);

virtual void parse (const char * arg) const;
virtual void show_usage (std::ostream & out) const;
void parse (const char * arg) const override;
void show_usage (std::ostream & out) const override;

private:
T * location;
Expand Down
73 changes: 2 additions & 71 deletions pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ void CairoBackgroundRenderer::beginTextObject(GfxState *state)
CairoOutputDev::beginTextObject(state);
}

void CairoBackgroundRenderer::beginString(GfxState *state, const GooString * str)
void CairoBackgroundRenderer::beginString(GfxState *state, const std::string & str)
{
if (param.proof == 2)
proof_begin_string(state, this);
CairoOutputDev::beginString(state, str->toStr());
CairoOutputDev::beginString(state, str);
}

void CairoBackgroundRenderer::endTextObject(GfxState *state)
Expand Down Expand Up @@ -234,75 +234,6 @@ string CairoBackgroundRenderer::build_bitmap_path(int id)
// "o" for "PDF Object"
return string(html_renderer->str_fmt("%s/o%d.jpg", param.dest_dir.c_str(), id));
}
// Override CairoOutputDev::setMimeData() and dump bitmaps in SVG to external files.
void CairoBackgroundRenderer::setMimeData(GfxState *state, Stream *str, Object *ref, GfxImageColorMap *colorMap, cairo_surface_t *image)
{
if (param.svg_embed_bitmap)
{
CairoOutputDev::setMimeData(state, str, ref, colorMap, image, cairo_image_surface_get_height (image));
return;
}

// TODO dump bitmaps in other formats.
if (str->getKind() != strDCT)
return;

// TODO inline image?
if (ref == nullptr || !ref->isRef())
return;

// We only dump rgb or gray jpeg without /Decode array.
//
// Although jpeg support CMYK, PDF readers do color conversion incompatibly with most other
// programs (including browsers): other programs invert CMYK color if 'Adobe' marker (app14) presents
// in a jpeg file; while PDF readers don't, they solely rely on /Decode array to invert color.
// It's a bit complicated to decide whether a CMYK jpeg is safe to dump, so we don't dump at all.
// See also:
// JPEG file embedded in PDF (CMYK) https://forums.adobe.com/thread/975777
// http://stackoverflow.com/questions/3123574/how-to-convert-from-cmyk-to-rgb-in-java-correctly
//
// In PDF, jpeg stream objects can also specify other color spaces like DeviceN and Separation,
// It is also not safe to dump them directly.
Object obj = str->getDict()->lookup("ColorSpace");
if (!obj.isName() || (strcmp(obj.getName(), "DeviceRGB") && strcmp(obj.getName(), "DeviceGray")) )
{
//obj.free();
return;
}
//obj.free();
obj = str->getDict()->lookup("Decode");
if (obj.isArray())
{
//obj.free();
return;
}
//obj.free();

int imgId = ref->getRef().num;
auto uri = strdup((char*) html_renderer->str_fmt("o%d.jpg", imgId));
auto st = cairo_surface_set_mime_data(image, CAIRO_MIME_TYPE_URI,
(unsigned char*) uri, strlen(uri), free, uri);
if (st)
{
free(uri);
return;
}
bitmaps_in_current_page.push_back(imgId);

if(bitmaps_ref_count.find(imgId) != bitmaps_ref_count.end())
return;

bitmaps_ref_count[imgId] = 0;

char *strBuffer;
int len;
if (getStreamData(str->getNextStream(), &strBuffer, &len))
{
ofstream imgfile(build_bitmap_path(imgId), ofstream::binary);
imgfile.write(strBuffer, len);
free(strBuffer);
}
}

} // namespace pdf2htmlEX

Expand Down
19 changes: 8 additions & 11 deletions pdf2htmlEX/src/BackgroundRenderer/CairoBackgroundRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,27 @@ class CairoBackgroundRenderer : public BackgroundRenderer, CairoOutputDev
public:
CairoBackgroundRenderer(HTMLRenderer * html_renderer, const Param & param);

virtual ~CairoBackgroundRenderer();
~CairoBackgroundRenderer() override;

virtual void init(PDFDoc * doc);
virtual bool render_page(PDFDoc * doc, int pageno);
virtual void embed_image(int pageno);
void init(PDFDoc * doc) override;
bool render_page(PDFDoc * doc, int pageno) override;
void embed_image(int pageno) override;

// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual bool interpretType3Chars() { return !param.process_type3; }
bool interpretType3Chars() override { return !param.process_type3; }

virtual void drawChar(GfxState *state, double x, double y,
void drawChar(GfxState *state, double x, double y,
double dx, double dy,
double originX, double originY,
CharCode code, int nBytes, const Unicode *u, int uLen);
CharCode code, int nBytes, const Unicode *u, int uLen) override;

//for proof
void beginTextObject(GfxState *state);
void beginString(GfxState *state, const GooString * str);
void beginString(GfxState *state, const std::string & str);
void endTextObject(GfxState *state);
void updateRender(GfxState *state);

protected:
virtual void setMimeData(GfxState *state, Stream *str, Object *ref, GfxImageColorMap *colorMap, cairo_surface_t *image);

protected:
HTMLRenderer * html_renderer;
const Param & param;
Expand Down
4 changes: 2 additions & 2 deletions pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ void SplashBackgroundRenderer::beginTextObject(GfxState *state)
SplashOutputDev::beginTextObject(state);
}

void SplashBackgroundRenderer::beginString(GfxState *state, const GooString * str)
void SplashBackgroundRenderer::beginString(GfxState *state, const std::string & str)
{
if (param.proof == 2)
proof_begin_string(state, this);
SplashOutputDev::beginString(state, str->toStr());
SplashOutputDev::beginString(state, str);
}

void SplashBackgroundRenderer::endTextObject(GfxState *state)
Expand Down
18 changes: 8 additions & 10 deletions pdf2htmlEX/src/BackgroundRenderer/SplashBackgroundRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,24 @@ class SplashBackgroundRenderer : public BackgroundRenderer, SplashOutputDev
//format: "png" or "jpg", or "" for a default format
SplashBackgroundRenderer(const std::string & format, HTMLRenderer * html_renderer, const Param & param);

virtual ~SplashBackgroundRenderer() { }

virtual void init(PDFDoc * doc);
virtual bool render_page(PDFDoc * doc, int pageno);
virtual void embed_image(int pageno);
void init(PDFDoc * doc) override;
bool render_page(PDFDoc * doc, int pageno) override;
void embed_image(int pageno) override;

// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual bool interpretType3Chars() { return !param.process_type3; }
bool interpretType3Chars() override { return !param.process_type3; }

virtual void startPage(int pageNum, GfxState *state, XRef *xrefA);
void startPage(int pageNum, GfxState *state, XRef *xrefA) override;

virtual void drawChar(GfxState *state, double x, double y,
void drawChar(GfxState *state, double x, double y,
double dx, double dy,
double originX, double originY,
CharCode code, int nBytes, const Unicode *u, int uLen);
CharCode code, int nBytes, const Unicode *u, int uLen) override;

//for proof
void beginTextObject(GfxState *state);
void beginString(GfxState *state, const GooString * str);
void beginString(GfxState *state, const std::string & str);
void endTextObject(GfxState *state);
void updateRender(GfxState *state);

Expand Down
86 changes: 43 additions & 43 deletions pdf2htmlEX/src/HTMLRenderer/HTMLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace pdf2htmlEX {
struct HTMLRenderer : OutputDev
{
HTMLRenderer(const char* progPath, Param & param);
virtual ~HTMLRenderer();
~HTMLRenderer() override;

void process(PDFDoc * doc);

Expand All @@ -88,102 +88,102 @@ struct HTMLRenderer : OutputDev

// Does this device use upside-down coordinates?
// (Upside-down means (0,0) is the top left corner of the page.)
virtual bool upsideDown() { return false; }
bool upsideDown() override { return false; }

// Does this device use drawChar() or drawString()?
virtual bool useDrawChar() { return false; }
bool useDrawChar() override { return false; }

// Does this device use functionShadedFill(), axialShadedFill(), and
// radialShadedFill()? If this returns false, these shaded fills
// will be reduced to a series of other drawing operations.
virtual bool useShadedFills(int type) { return (type == 2) ? true: false; }
bool useShadedFills(int type) override { return (type == 2) ? true: false; }

// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual bool interpretType3Chars() { return false; }
bool interpretType3Chars() override { return false; }

// Does this device need non-text content?
virtual bool needNonText() { return (param.process_nontext) ? true: false; }
bool needNonText() override { return (param.process_nontext) ? true: false; }

// Does this device need to clip pages to the crop box even when the
// box is the crop box?
virtual bool needClipToCropBox() { return true; }
bool needClipToCropBox() override { return true; }

virtual void setDefaultCTM(const double *ctm);
void setDefaultCTM(const std::array<double, 6> &ctm) override;

// Start a page.
virtual void startPage(int pageNum, GfxState *state, XRef * xref);
void startPage(int pageNum, GfxState *state, XRef * xref) override;

// End a page.
virtual void endPage();
void endPage() override;

/*
* To optimize false alarms
* We just mark as changed, and recheck if they have been changed when we are about to output a new string
*/

virtual void restoreState(GfxState * state);
void restoreState(GfxState * state) override;

virtual void saveState(GfxState *state);
void saveState(GfxState *state) override;

virtual void updateAll(GfxState * state);
void updateAll(GfxState * state) override;

virtual void updateRise(GfxState * state);
virtual void updateTextPos(GfxState * state);
virtual void updateTextShift(GfxState * state, double shift);
void updateRise(GfxState * state) override;
void updateTextPos(GfxState * state) override;
void updateTextShift(GfxState * state, double shift) override;

virtual void updateFont(GfxState * state);
virtual void updateCTM(GfxState * state, double m11, double m12, double m21, double m22, double m31, double m32);
virtual void updateTextMat(GfxState * state);
virtual void updateHorizScaling(GfxState * state);
void updateFont(GfxState * state) override;
void updateCTM(GfxState * state, double m11, double m12, double m21, double m22, double m31, double m32) override;
void updateTextMat(GfxState * state) override;
void updateHorizScaling(GfxState * state) override;

virtual void updateCharSpace(GfxState * state);
virtual void updateWordSpace(GfxState * state);
void updateCharSpace(GfxState * state) override;
void updateWordSpace(GfxState * state) override;

virtual void updateRender(GfxState * state);
void updateRender(GfxState * state) override;

virtual void updateFillColorSpace(GfxState * state);
virtual void updateStrokeColorSpace(GfxState * state);
virtual void updateFillColor(GfxState * state);
virtual void updateStrokeColor(GfxState * state);
void updateFillColorSpace(GfxState * state) override;
void updateStrokeColorSpace(GfxState * state) override;
void updateFillColor(GfxState * state) override;
void updateStrokeColor(GfxState * state) override;


/*
* Rendering
*/

virtual void clip(GfxState * state);
virtual void eoClip(GfxState * state);
virtual void clipToStrokePath(GfxState * state);
void clip(GfxState * state) override;
void eoClip(GfxState * state) override;
void clipToStrokePath(GfxState * state) override;

virtual void drawString(GfxState * state, const GooString * s);
void drawString(GfxState * state, const std::string& s) override;

virtual void drawImage(GfxState * state, Object * ref, Stream * str,
void drawImage(GfxState * state, Object * ref, Stream * str,
int width, int height, GfxImageColorMap * colorMap,
bool interpolate, const int *maskColors, bool inlineImg);
bool interpolate, const int *maskColors, bool inlineImg) override;

virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
int width, int height,
GfxImageColorMap *colorMap,
bool interpolate,
Stream *maskStr,
int maskWidth, int maskHeight,
GfxImageColorMap *maskColorMap,
bool maskInterpolate);
bool maskInterpolate) override;

virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
virtual bool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax);
void stroke(GfxState *state) override;
void fill(GfxState *state) override;
void eoFill(GfxState *state) override;
bool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax) override;

virtual void beginTransparencyGroup(GfxState * /*state*/, const double * /*bbox*/,
void beginTransparencyGroup(GfxState * /*state*/, const std::array<double, 4> & /*bbox*/,
GfxColorSpace * /*blendingColorSpace*/,
bool /*isolated*/, bool /*knockout*/,
bool /*forSoftMask*/);
virtual void endTransparencyGroup(GfxState * /*state*/);
bool /*forSoftMask*/) override;
void endTransparencyGroup(GfxState * /*state*/) override;


virtual void processLink(AnnotLink * al);
void processLink(AnnotLink * al) override;

/*
* Covered text handling.
Expand Down
2 changes: 1 addition & 1 deletion pdf2htmlEX/src/HTMLRenderer/draw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool HTMLRenderer::axialShadedFill(GfxState *state, GfxAxialShading *shading, do
return true;
}

void HTMLRenderer::beginTransparencyGroup(GfxState *state, const double *bbox,
void HTMLRenderer::beginTransparencyGroup(GfxState *state, const std::array<double, 4> &bbox,
GfxColorSpace *blendingColorSpace,
bool isolated, bool knockout,
bool forSoftMask) {
Expand Down
4 changes: 2 additions & 2 deletions pdf2htmlEX/src/HTMLRenderer/general.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ bool HTMLRenderer::renderPage(PDFDoc *doc, int pageno)
return false;
}

void HTMLRenderer::setDefaultCTM(const double *ctm)
void HTMLRenderer::setDefaultCTM(const std::array<double, 6> &ctm)
{
memcpy(default_ctm, ctm, sizeof(default_ctm));
memcpy(default_ctm, ctm.data(), sizeof(default_ctm));
}

void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
Expand Down
10 changes: 5 additions & 5 deletions pdf2htmlEX/src/HTMLRenderer/text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ using std::none_of;
using std::cerr;
using std::endl;

void HTMLRenderer::drawString(GfxState * state, const GooString * s)
void HTMLRenderer::drawString(GfxState * state, const std::string& s)
{
if(s->empty())
if(s.empty())
return;

auto font = state->getFont();
Expand Down Expand Up @@ -58,8 +58,8 @@ void HTMLRenderer::drawString(GfxState * state, const GooString * s)

// Now ready to output
// get the unicodes
const char *p = s->c_str();
int len = s->size();
const char *p = s.c_str();
int len = s.size();

//accumulated displacement of chars in this string, in text object space
double dx = 0;
Expand Down Expand Up @@ -188,7 +188,7 @@ void HTMLRenderer::drawString(GfxState * state, const GooString * s)

bool HTMLRenderer::is_char_covered(int index)
{
auto covered = covered_text_detector.get_chars_covered();
const auto& covered = covered_text_detector.get_chars_covered();
if (index < 0 || index >= (int)covered.size())
{
std::cerr << "Warning: HTMLRenderer::is_char_covered: index out of bound: "
Expand Down
Loading
Loading