mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
Code cleaning.
This commit is contained in:
parent
ba1358c241
commit
d09a47d84f
@ -38,8 +38,7 @@ CairoBackgroundRenderer::~CairoBackgroundRenderer()
|
|||||||
{
|
{
|
||||||
if (itr->second == 0)
|
if (itr->second == 0)
|
||||||
{
|
{
|
||||||
string path;
|
html_renderer->tmp_files.add(this->build_bitmap_path(itr->first));
|
||||||
html_renderer->tmp_files.add(this->build_bitmap_path(itr->first, path));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +100,7 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
|
|||||||
cairo_t * cr = cairo_create(surface);
|
cairo_t * cr = cairo_create(surface);
|
||||||
setCairo(cr);
|
setCairo(cr);
|
||||||
|
|
||||||
bitmaps_in_current_page.resize(0);
|
bitmaps_in_current_page.clear();
|
||||||
|
|
||||||
bool process_annotation = param.process_annotation;
|
bool process_annotation = param.process_annotation;
|
||||||
doc->displayPage(this, pageno, param.h_dpi, param.v_dpi,
|
doc->displayPage(this, pageno, param.h_dpi, param.v_dpi,
|
||||||
@ -189,10 +188,10 @@ void CairoBackgroundRenderer::embed_image(int pageno)
|
|||||||
f_page << "\"/>";
|
f_page << "\"/>";
|
||||||
}
|
}
|
||||||
|
|
||||||
string & CairoBackgroundRenderer::build_bitmap_path(int id, string & path)
|
string CairoBackgroundRenderer::build_bitmap_path(int id)
|
||||||
{
|
{
|
||||||
// "po" for "PDF Object"
|
// "o" for "PDF Object"
|
||||||
return path = html_renderer->str_fmt("%s/po-%d.jpg", param.dest_dir.c_str(), id);
|
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.
|
// Override CairoOutputDev::setMimeData() and dump bitmaps in SVG to external files.
|
||||||
void CairoBackgroundRenderer::setMimeData(Stream *str, Object *ref, cairo_surface_t *image)
|
void CairoBackgroundRenderer::setMimeData(Stream *str, Object *ref, cairo_surface_t *image)
|
||||||
@ -212,7 +211,7 @@ void CairoBackgroundRenderer::setMimeData(Stream *str, Object *ref, cairo_surfac
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
int imgId = ref->getRef().num;
|
int imgId = ref->getRef().num;
|
||||||
auto uri = strdup((char*) html_renderer->str_fmt("po-%d.jpg", imgId));
|
auto uri = strdup((char*) html_renderer->str_fmt("o%d.jpg", imgId));
|
||||||
auto st = cairo_surface_set_mime_data(image, CAIRO_MIME_TYPE_URI,
|
auto st = cairo_surface_set_mime_data(image, CAIRO_MIME_TYPE_URI,
|
||||||
(unsigned char*) uri, strlen(uri), free, uri);
|
(unsigned char*) uri, strlen(uri), free, uri);
|
||||||
if (st)
|
if (st)
|
||||||
@ -231,8 +230,7 @@ void CairoBackgroundRenderer::setMimeData(Stream *str, Object *ref, cairo_surfac
|
|||||||
int len;
|
int len;
|
||||||
if (getStreamData(str->getNextStream(), &strBuffer, &len))
|
if (getStreamData(str->getNextStream(), &strBuffer, &len))
|
||||||
{
|
{
|
||||||
string path;
|
ofstream imgfile(build_bitmap_path(imgId), ofstream::binary);
|
||||||
ofstream imgfile(build_bitmap_path(imgId, path), ofstream::binary);
|
|
||||||
imgfile.write(strBuffer, len);
|
imgfile.write(strBuffer, len);
|
||||||
free(strBuffer);
|
free(strBuffer);
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
// convert bitmap stream id to bitmap file name. No pageno prefix,
|
// convert bitmap stream id to bitmap file name. No pageno prefix,
|
||||||
// because a bitmap may be shared by multiple pages.
|
// because a bitmap may be shared by multiple pages.
|
||||||
std::string & build_bitmap_path(int id, std::string & path);
|
std::string build_bitmap_path(int id);
|
||||||
// map<id_of_bitmap_stream, usage_count_in_all_svgs>
|
// map<id_of_bitmap_stream, usage_count_in_all_svgs>
|
||||||
// note: if a svg bg fallbacks to bitmap bg, its bitmaps are not taken into account.
|
// note: if a svg bg fallbacks to bitmap bg, its bitmaps are not taken into account.
|
||||||
std::unordered_map<int, int> bitmaps_ref_count;
|
std::unordered_map<int, int> bitmaps_ref_count;
|
||||||
|
@ -177,14 +177,23 @@ void SplashBackgroundRenderer::dump_image(const char * filename, int x1, int y1,
|
|||||||
// use unique_ptr to auto delete the object upon exception
|
// use unique_ptr to auto delete the object upon exception
|
||||||
unique_ptr<ImgWriter> writer;
|
unique_ptr<ImgWriter> writer;
|
||||||
|
|
||||||
if(format == "png")
|
if(false) { }
|
||||||
|
#ifdef ENABLE_LIBPNG
|
||||||
|
else if(format == "png")
|
||||||
{
|
{
|
||||||
writer = unique_ptr<ImgWriter>(new PNGWriter);
|
writer = unique_ptr<ImgWriter>(new PNGWriter);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_LIBJPEG
|
||||||
else if(format == "jpg")
|
else if(format == "jpg")
|
||||||
{
|
{
|
||||||
writer = unique_ptr<ImgWriter>(new JpegWriter);
|
writer = unique_ptr<ImgWriter>(new JpegWriter);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw string("Image format not supported: ") + format;
|
||||||
|
}
|
||||||
|
|
||||||
if(!writer->init(f, width, height, param.h_dpi, param.v_dpi))
|
if(!writer->init(f, width, height, param.h_dpi, param.v_dpi))
|
||||||
throw "Cannot initialize PNGWriter";
|
throw "Cannot initialize PNGWriter";
|
||||||
|
Loading…
Reference in New Issue
Block a user