mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
merge filodej
This commit is contained in:
parent
462e8dc541
commit
a5ccc7f073
@ -154,6 +154,7 @@ add_executable(pdf2htmlEX
|
||||
src/HTMLRenderer/link.cc
|
||||
src/include/namespace.h
|
||||
src/HTMLRenderer/LineBuffer.cc
|
||||
src/HTMLRenderer/TmpFiles.cc
|
||||
src/include/ffw.h
|
||||
src/ffw.c
|
||||
src/include/BackgroundRenderer.h
|
||||
|
48
src/HTMLRenderer/TmpFiles.cc
Normal file
48
src/HTMLRenderer/TmpFiles.cc
Normal file
@ -0,0 +1,48 @@
|
||||
#include "TmpFiles.h"
|
||||
#include "Param.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
|
||||
TmpFiles::TmpFiles( Param const& param_ )
|
||||
: param( param_ )
|
||||
{
|
||||
}
|
||||
|
||||
TmpFiles::~TmpFiles()
|
||||
{
|
||||
clean();
|
||||
}
|
||||
|
||||
void TmpFiles::add(const string & fn)
|
||||
{
|
||||
if(!param.clean_tmp)
|
||||
return;
|
||||
|
||||
if(tmp_files.insert(fn).second && param.debug)
|
||||
cerr << "Add new temporary file: " << fn << endl;
|
||||
}
|
||||
|
||||
void TmpFiles::clean()
|
||||
{
|
||||
if(!param.clean_tmp)
|
||||
return;
|
||||
|
||||
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter)
|
||||
{
|
||||
const string & fn = *iter;
|
||||
remove(fn.c_str());
|
||||
if(param.debug)
|
||||
cerr << "Remove temporary file: " << fn << endl;
|
||||
}
|
||||
|
||||
remove(param.tmp_dir.c_str());
|
||||
if(param.debug)
|
||||
cerr << "Remove temporary directory: " << param.tmp_dir << endl;
|
||||
}
|
||||
|
||||
|
||||
} // namespace pdf2htmlEX
|
@ -38,6 +38,7 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
||||
,line_opened(false)
|
||||
,line_buf(this)
|
||||
,preprocessor(param)
|
||||
,tmp_files(*param)
|
||||
,image_count(0)
|
||||
,param(param)
|
||||
{
|
||||
@ -56,7 +57,6 @@ HTMLRenderer::HTMLRenderer(const Param * param)
|
||||
HTMLRenderer::~HTMLRenderer()
|
||||
{
|
||||
ffw_finalize();
|
||||
clean_tmp_files();
|
||||
delete [] cur_mapping;
|
||||
delete [] cur_mapping2;
|
||||
delete [] width_list;
|
||||
@ -94,7 +94,7 @@ void HTMLRenderer::process(PDFDoc *doc)
|
||||
{
|
||||
auto fn = str_fmt("%s/p%x.png", (param->single_html ? param->tmp_dir : param->dest_dir).c_str(), i);
|
||||
if(param->single_html)
|
||||
add_tmp_file((char*)fn);
|
||||
tmp_files.add((char*)fn);
|
||||
|
||||
bg_renderer->render_page(doc, i, (char*)fn);
|
||||
}
|
||||
@ -280,7 +280,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||
: str_fmt("%s/%s", param->dest_dir.c_str(), param->css_filename.c_str());
|
||||
|
||||
if(param->single_html && (!param->split_pages))
|
||||
add_tmp_file((char*)fn);
|
||||
tmp_files.add((char*)fn);
|
||||
|
||||
css_path = (char*)fn,
|
||||
css_fout.open(css_path, ofstream::binary);
|
||||
@ -301,7 +301,7 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||
* Otherwise just generate it
|
||||
*/
|
||||
auto fn = str_fmt("%s/__pages", param->tmp_dir.c_str());
|
||||
add_tmp_file((char*)fn);
|
||||
tmp_files.add((char*)fn);
|
||||
|
||||
html_path = (char*)fn;
|
||||
html_fout.open(html_path, ofstream::binary);
|
||||
@ -392,33 +392,6 @@ void HTMLRenderer::fix_stream (std::ostream & out)
|
||||
out << hex << fixed;
|
||||
}
|
||||
|
||||
void HTMLRenderer::add_tmp_file(const string & fn)
|
||||
{
|
||||
if(!param->clean_tmp)
|
||||
return;
|
||||
|
||||
if(tmp_files.insert(fn).second && param->debug)
|
||||
cerr << "Add new temporary file: " << fn << endl;
|
||||
}
|
||||
|
||||
void HTMLRenderer::clean_tmp_files()
|
||||
{
|
||||
if(!param->clean_tmp)
|
||||
return;
|
||||
|
||||
for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter)
|
||||
{
|
||||
const string & fn = *iter;
|
||||
remove(fn.c_str());
|
||||
if(param->debug)
|
||||
cerr << "Remove temporary file: " << fn << endl;
|
||||
}
|
||||
|
||||
remove(param->tmp_dir.c_str());
|
||||
if(param->debug)
|
||||
cerr << "Remove temporary directory: " << param->tmp_dir << endl;
|
||||
}
|
||||
|
||||
void HTMLRenderer::embed_file(ostream & out, const string & path, const string & type, bool copy)
|
||||
{
|
||||
string fn = get_filename(path);
|
||||
|
@ -127,7 +127,7 @@ string HTMLRenderer::dump_embedded_font (GfxFont * font, long long fn_id)
|
||||
obj.streamReset();
|
||||
|
||||
filepath = (char*)str_fmt("%s/f%llx%s", param->tmp_dir.c_str(), fn_id, suffix.c_str());
|
||||
add_tmp_file(filepath);
|
||||
tmp_files.add(filepath);
|
||||
|
||||
ofstream outf(filepath, ofstream::binary);
|
||||
if(!outf)
|
||||
@ -171,7 +171,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
if(param->debug)
|
||||
{
|
||||
auto fn = str_fmt("%s/__raw_font_%lld", param->tmp_dir.c_str(), info.id, param->font_suffix.c_str());
|
||||
add_tmp_file((char*)fn);
|
||||
tmp_files.add((char*)fn);
|
||||
ofstream((char*)fn, ofstream::binary) << ifstream(filepath).rdbuf();
|
||||
}
|
||||
|
||||
@ -437,9 +437,9 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
*
|
||||
*/
|
||||
string cur_tmp_fn = (char*)str_fmt("%s/__tmp_font1%s", param->tmp_dir.c_str(), param->font_suffix.c_str());
|
||||
add_tmp_file(cur_tmp_fn);
|
||||
tmp_files.add(cur_tmp_fn);
|
||||
string other_tmp_fn = (char*)str_fmt("%s/__tmp_font2%s", param->tmp_dir.c_str(), param->font_suffix.c_str());
|
||||
add_tmp_file(other_tmp_fn);
|
||||
tmp_files.add(other_tmp_fn);
|
||||
|
||||
ffw_save(cur_tmp_fn.c_str());
|
||||
|
||||
@ -482,7 +482,7 @@ void HTMLRenderer::embed_font(const string & filepath, GfxFont * font, FontInfo
|
||||
info.id, param->font_suffix.c_str());
|
||||
|
||||
if(param->single_html)
|
||||
add_tmp_file(fn);
|
||||
tmp_files.add(fn);
|
||||
|
||||
ffw_load_font(cur_tmp_fn.c_str());
|
||||
ffw_metric(&info.ascent, &info.descent);
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "Param.h"
|
||||
#include "util.h"
|
||||
#include "Preprocessor.h"
|
||||
#include "TmpFiles.h"
|
||||
|
||||
/*
|
||||
* Naming Convention
|
||||
@ -156,8 +157,6 @@ class HTMLRenderer : public OutputDev
|
||||
// set flags
|
||||
void fix_stream (std::ostream & out);
|
||||
|
||||
void add_tmp_file (const std::string & fn);
|
||||
void clean_tmp_files ();
|
||||
std::string dump_embedded_font (GfxFont * font, long long fn_id);
|
||||
void embed_font(const std::string & filepath, GfxFont * font, FontInfo & info, bool get_metric_only = false);
|
||||
|
||||
@ -408,6 +407,7 @@ class HTMLRenderer : public OutputDev
|
||||
char ** cur_mapping2;
|
||||
int * width_list;
|
||||
Preprocessor preprocessor;
|
||||
TmpFiles tmp_files;
|
||||
|
||||
// for string formatting
|
||||
string_formatter str_fmt;
|
||||
@ -431,7 +431,6 @@ class HTMLRenderer : public OutputDev
|
||||
const Param * param;
|
||||
std::ofstream html_fout, css_fout;
|
||||
std::string html_path, css_path;
|
||||
std::set<std::string> tmp_files;
|
||||
|
||||
static const std::string MANIFEST_FILENAME;
|
||||
};
|
||||
|
29
src/include/TmpFiles.h
Normal file
29
src/include/TmpFiles.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef TMPFILES_H__
|
||||
#define TMPFILES_H__
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include "Param.h"
|
||||
|
||||
namespace pdf2htmlEX {
|
||||
|
||||
class TmpFiles
|
||||
{
|
||||
public:
|
||||
explicit TmpFiles( Param const& param );
|
||||
virtual ~TmpFiles();
|
||||
|
||||
void add(std::string const& fn);
|
||||
|
||||
private:
|
||||
void clean();
|
||||
|
||||
private:
|
||||
Param const& param;
|
||||
std::set<std::string> tmp_files;
|
||||
|
||||
};
|
||||
|
||||
} // namespace pdf2htmlEX
|
||||
|
||||
#endif //TMPFILES_H__
|
Loading…
Reference in New Issue
Block a user