1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-07 18:30:34 +00:00

Fix bad usage of html_renderer->str_fmt() in get_bitmap_path(); add prefix to bitmap file name.

This commit is contained in:
Duan Yao 2014-06-11 22:19:17 +08:00 committed by Lu Wang
parent ca3a777451
commit 24a6f1fee8
2 changed files with 12 additions and 7 deletions

View File

@ -37,7 +37,10 @@ CairoBackgroundRenderer::~CairoBackgroundRenderer()
for(auto itr = bitmaps_ref_count.begin(); itr != bitmaps_ref_count.end(); ++itr) for(auto itr = bitmaps_ref_count.begin(); itr != bitmaps_ref_count.end(); ++itr)
{ {
if (itr->second == 0) if (itr->second == 0)
html_renderer->tmp_files.add(this->get_bitmap_path(itr->first)); {
string path;
html_renderer->tmp_files.add(this->build_bitmap_path(itr->first, path));
}
} }
} }
@ -186,9 +189,10 @@ void CairoBackgroundRenderer::embed_image(int pageno)
f_page << "\"/>"; f_page << "\"/>";
} }
const char* CairoBackgroundRenderer::get_bitmap_path(int id) string & CairoBackgroundRenderer::build_bitmap_path(int id, string & path)
{ {
return html_renderer->str_fmt("%s/%d.jpg", param.dest_dir.c_str(), id); // "po" for "PDF Object"
return path = html_renderer->str_fmt("%s/po-%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)
@ -208,7 +212,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("%d.jpg", imgId)); auto uri = strdup((char*) html_renderer->str_fmt("po-%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)
@ -227,8 +231,8 @@ 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 = get_bitmap_path(imgId); string path;
ofstream imgfile(path, ofstream::binary); ofstream imgfile(build_bitmap_path(imgId, path), ofstream::binary);
imgfile.write(strBuffer, len); imgfile.write(strBuffer, len);
free(strBuffer); free(strBuffer);
} }

View File

@ -14,6 +14,7 @@
#include <cairo-svg.h> #include <cairo-svg.h>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <string>
#include "pdf2htmlEX-config.h" #include "pdf2htmlEX-config.h"
@ -54,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.
const char* get_bitmap_path(int id); std::string & build_bitmap_path(int id, std::string & path);
// 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;