1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-05 01:28:39 +00:00

Code cleaning.

This commit is contained in:
Duan Yao 2014-06-17 11:59:45 +08:00
parent fdbc70401f
commit ac8208a693
3 changed files with 18 additions and 11 deletions

View File

@ -38,8 +38,7 @@ CairoBackgroundRenderer::~CairoBackgroundRenderer()
{
if (itr->second == 0)
{
string path;
html_renderer->tmp_files.add(this->build_bitmap_path(itr->first, path));
html_renderer->tmp_files.add(this->build_bitmap_path(itr->first));
}
}
}
@ -101,7 +100,7 @@ bool CairoBackgroundRenderer::render_page(PDFDoc * doc, int pageno)
cairo_t * cr = cairo_create(surface);
setCairo(cr);
bitmaps_in_current_page.resize(0);
bitmaps_in_current_page.clear();
bool process_annotation = param.process_annotation;
doc->displayPage(this, pageno, param.h_dpi, param.v_dpi,
@ -189,10 +188,10 @@ void CairoBackgroundRenderer::embed_image(int pageno)
f_page << "\"/>";
}
string & CairoBackgroundRenderer::build_bitmap_path(int id, string & path)
string CairoBackgroundRenderer::build_bitmap_path(int id)
{
// "po" for "PDF Object"
return path = html_renderer->str_fmt("%s/po-%d.jpg", param.dest_dir.c_str(), 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(Stream *str, Object *ref, cairo_surface_t *image)
@ -212,7 +211,7 @@ void CairoBackgroundRenderer::setMimeData(Stream *str, Object *ref, cairo_surfac
return;
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,
(unsigned char*) uri, strlen(uri), free, uri);
if (st)
@ -231,8 +230,7 @@ void CairoBackgroundRenderer::setMimeData(Stream *str, Object *ref, cairo_surfac
int len;
if (getStreamData(str->getNextStream(), &strBuffer, &len))
{
string path;
ofstream imgfile(build_bitmap_path(imgId, path), ofstream::binary);
ofstream imgfile(build_bitmap_path(imgId), ofstream::binary);
imgfile.write(strBuffer, len);
free(strBuffer);
}

View File

@ -55,7 +55,7 @@ protected:
private:
// convert bitmap stream id to bitmap file name. No pageno prefix,
// 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>
// note: if a svg bg fallbacks to bitmap bg, its bitmaps are not taken into account.
std::unordered_map<int, int> bitmaps_ref_count;

View File

@ -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
unique_ptr<ImgWriter> writer;
if(format == "png")
if(false) { }
#ifdef ENABLE_LIBPNG
else if(format == "png")
{
writer = unique_ptr<ImgWriter>(new PNGWriter);
}
#endif
#ifdef ENABLE_LIBJPEG
else if(format == "jpg")
{
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))
throw "Cannot initialize PNGWriter";