mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +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:
parent
edb0ddacea
commit
5681fe11c0
@ -37,7 +37,10 @@ CairoBackgroundRenderer::~CairoBackgroundRenderer()
|
||||
for(auto itr = bitmaps_ref_count.begin(); itr != bitmaps_ref_count.end(); ++itr)
|
||||
{
|
||||
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 << "\"/>";
|
||||
}
|
||||
|
||||
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.
|
||||
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;
|
||||
|
||||
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,
|
||||
(unsigned char*) uri, strlen(uri), free, uri);
|
||||
if (st)
|
||||
@ -227,8 +231,8 @@ void CairoBackgroundRenderer::setMimeData(Stream *str, Object *ref, cairo_surfac
|
||||
int len;
|
||||
if (getStreamData(str->getNextStream(), &strBuffer, &len))
|
||||
{
|
||||
string path = get_bitmap_path(imgId);
|
||||
ofstream imgfile(path, ofstream::binary);
|
||||
string path;
|
||||
ofstream imgfile(build_bitmap_path(imgId, path), ofstream::binary);
|
||||
imgfile.write(strBuffer, len);
|
||||
free(strBuffer);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <cairo-svg.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "pdf2htmlEX-config.h"
|
||||
|
||||
@ -54,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.
|
||||
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>
|
||||
// note: if a svg bg fallbacks to bitmap bg, its bitmaps are not taken into account.
|
||||
std::unordered_map<int, int> bitmaps_ref_count;
|
||||
|
Loading…
Reference in New Issue
Block a user