mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 13:00:08 +00:00
Merge remote-tracking branch 'origin/lazyload'
This commit is contained in:
commit
b6df9d5763
@ -1,5 +1,6 @@
|
|||||||
Developing v0.9
|
Developing v0.9
|
||||||
|
|
||||||
|
* Lazy loading of entire pages
|
||||||
* Licensed changed
|
* Licensed changed
|
||||||
- Additional terms for usage in online services
|
- Additional terms for usage in online services
|
||||||
- Remove GPLv2
|
- Remove GPLv2
|
||||||
|
@ -39,11 +39,6 @@ pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({
|
|||||||
container_id : 'page-container',
|
container_id : 'page-container',
|
||||||
sidebar_id : 'sidebar',
|
sidebar_id : 'sidebar',
|
||||||
outline_id : 'outline',
|
outline_id : 'outline',
|
||||||
page_urls : [
|
|
||||||
"""
|
|
||||||
$page_urls
|
|
||||||
"""
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
"""
|
"""
|
||||||
@ -54,7 +49,7 @@ $page_urls
|
|||||||
<body>
|
<body>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# The sidbar
|
# The sidebar
|
||||||
# By default this is hidden, pdf2htmlEX.js will add the 'opened' class if it is not empty
|
# By default this is hidden, pdf2htmlEX.js will add the 'opened' class if it is not empty
|
||||||
# You can add a class 'opened' here if you want it always opened or you don't use pdf2htmlEX.js
|
# You can add a class 'opened' here if you want it always opened or you don't use pdf2htmlEX.js
|
||||||
# e.g.
|
# e.g.
|
||||||
|
@ -18,6 +18,7 @@ var pdf2htmlEX = (function(){
|
|||||||
link : '@CSS_LINK_CN@',
|
link : '@CSS_LINK_CN@',
|
||||||
__dummy__ : 'no comma'
|
__dummy__ : 'no comma'
|
||||||
};
|
};
|
||||||
|
var DEFAULT_PAGES_TO_PRELOAD = 3;
|
||||||
|
|
||||||
var pdf2htmlEX = new Object();
|
var pdf2htmlEX = new Object();
|
||||||
|
|
||||||
@ -40,24 +41,36 @@ var pdf2htmlEX = (function(){
|
|||||||
var Page = function(page, container) {
|
var Page = function(page, container) {
|
||||||
if(page == undefined) return;
|
if(page == undefined) return;
|
||||||
|
|
||||||
|
this.loaded = false;
|
||||||
this.p = $(page);
|
this.p = $(page);
|
||||||
|
|
||||||
|
this.container = container;
|
||||||
|
|
||||||
this.n = parseInt(this.p.attr('data-page-no'), 16);
|
this.n = parseInt(this.p.attr('data-page-no'), 16);
|
||||||
this.b = $('.'+CSS_CLASS_NAMES['page_content_box'], this.p);
|
this.b = $('.'+CSS_CLASS_NAMES['page_content_box'], this.p);
|
||||||
|
this.d = this.p.parents('.'+CSS_CLASS_NAMES['page_decoration']);
|
||||||
|
|
||||||
/*
|
this.h = this.p.height(); // Need to make rescale work when page_content_box is not loaded, yet
|
||||||
* scale ratios
|
this.w = this.p.width();
|
||||||
*
|
|
||||||
* default_r : the first one
|
|
||||||
* set_r : last set
|
|
||||||
* cur_r : currently using
|
|
||||||
*/
|
|
||||||
this.default_r = this.set_r = this.cur_r = this.p.height() / this.b.height();
|
|
||||||
|
|
||||||
this.data = JSON.parse($($('.'+CSS_CLASS_NAMES['page_data'], this.p)[0]).attr('data-data'));
|
// if page is loaded
|
||||||
|
if (this.b[0]) {
|
||||||
|
/*
|
||||||
|
* scale ratios
|
||||||
|
*
|
||||||
|
* default_r : the first one
|
||||||
|
* set_r : last set
|
||||||
|
* cur_r : currently using
|
||||||
|
*/
|
||||||
|
this.default_r = this.set_r = this.cur_r = this.p.height() / this.b.height();
|
||||||
|
|
||||||
this.ctm = this.data.ctm;
|
this.data = JSON.parse($($('.'+CSS_CLASS_NAMES['page_data'], this.p)[0]).attr('data-data'));
|
||||||
this.ictm = invert(this.ctm);
|
|
||||||
this.container = container;
|
this.ctm = this.data.ctm;
|
||||||
|
this.ictm = invert(this.ctm);
|
||||||
|
|
||||||
|
this.loaded = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
$.extend(Page.prototype, {
|
$.extend(Page.prototype, {
|
||||||
/* hide & show are for contents, the page frame is still there */
|
/* hide & show are for contents, the page frame is still there */
|
||||||
@ -67,6 +80,7 @@ var pdf2htmlEX = (function(){
|
|||||||
show : function(){
|
show : function(){
|
||||||
if(Math.abs(this.set_r - this.cur_r) > EPS) {
|
if(Math.abs(this.set_r - this.cur_r) > EPS) {
|
||||||
this.cur_r = this.set_r;
|
this.cur_r = this.set_r;
|
||||||
|
//TODO make it cross-browser compliant
|
||||||
this.b.css('transform', 'scale('+this.cur_r.toFixed(3)+')');
|
this.b.css('transform', 'scale('+this.cur_r.toFixed(3)+')');
|
||||||
}
|
}
|
||||||
this.b.addClass('opened');
|
this.b.addClass('opened');
|
||||||
@ -116,7 +130,8 @@ var pdf2htmlEX = (function(){
|
|||||||
this.container_id = config['container_id'];
|
this.container_id = config['container_id'];
|
||||||
this.sidebar_id = config['sidebar_id'];
|
this.sidebar_id = config['sidebar_id'];
|
||||||
this.outline_id = config['outline_id'];
|
this.outline_id = config['outline_id'];
|
||||||
this.page_urls = config['page_urls'];
|
this.pages_to_preload = config['pages_to_preload'] || DEFAULT_PAGES_TO_PRELOAD;
|
||||||
|
this.pages_loading = {};
|
||||||
this.init_before_loading_content();
|
this.init_before_loading_content();
|
||||||
|
|
||||||
var _ = this;
|
var _ = this;
|
||||||
@ -141,7 +156,7 @@ var pdf2htmlEX = (function(){
|
|||||||
if(this.outline.children().length > 0) {
|
if(this.outline.children().length > 0) {
|
||||||
this.sidebar.addClass('opened');
|
this.sidebar.addClass('opened');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.find_pages();
|
this.find_pages();
|
||||||
|
|
||||||
// register schedule rendering
|
// register schedule rendering
|
||||||
@ -153,14 +168,7 @@ var pdf2htmlEX = (function(){
|
|||||||
// handle links
|
// handle links
|
||||||
this.container.add(this.outline).on('click', '.'+CSS_CLASS_NAMES['link'], this, this.link_handler);
|
this.container.add(this.outline).on('click', '.'+CSS_CLASS_NAMES['link'], this, this.link_handler);
|
||||||
|
|
||||||
// disable background image draging
|
|
||||||
$('img', this.container).on('dragstart', function(e){return false;});
|
|
||||||
|
|
||||||
this.render();
|
this.render();
|
||||||
|
|
||||||
// load split pages
|
|
||||||
// has no effect if --split-pages is 0
|
|
||||||
this.load_page(0);
|
|
||||||
},
|
},
|
||||||
find_pages : function() {
|
find_pages : function() {
|
||||||
var new_pages = new Array();
|
var new_pages = new Array();
|
||||||
@ -172,19 +180,62 @@ var pdf2htmlEX = (function(){
|
|||||||
}
|
}
|
||||||
this.pages = new_pages;
|
this.pages = new_pages;
|
||||||
},
|
},
|
||||||
load_page : function(idx) {
|
load_page : function(idx, pages_to_preload, successCallback, errorCallback) {
|
||||||
if(idx < this.page_urls.length){
|
if (idx >= this.pages.length)
|
||||||
var _ = this;
|
return; // Page does not exist
|
||||||
|
|
||||||
|
if (this.pages[idx].loaded)
|
||||||
|
return; // Page is loaded
|
||||||
|
|
||||||
|
if (this.pages_loading[idx])
|
||||||
|
return; // Page is already loading
|
||||||
|
|
||||||
|
var page_no_hex = idx.toString(16);
|
||||||
|
var $pf = this.container.find('#' + CSS_CLASS_NAMES['page_frame'] + page_no_hex);
|
||||||
|
if($pf.length == 0)
|
||||||
|
return; // Page does not exist
|
||||||
|
|
||||||
|
var _ = this;
|
||||||
|
|
||||||
|
var url = $pf.data('page-url');
|
||||||
|
if (url && url.length > 0) {
|
||||||
|
this.pages_loading[idx] = true; // Set semaphore
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: this.page_urls[idx],
|
url: url,
|
||||||
dataType: 'text'
|
dataType: 'text'
|
||||||
}).done(function(data){
|
}).done(function(data){
|
||||||
$('#'+_.container_id).append(data);
|
_.pages[idx].p.parent().replaceWith(data);
|
||||||
_.find_pages();
|
|
||||||
_.schedule_render();
|
var $new_pf = _.container.find('#' + CSS_CLASS_NAMES['page_frame'] + page_no_hex);
|
||||||
_.load_page(idx+1);
|
_.pages[idx] = new Page($new_pf, _.container);
|
||||||
|
_.pages[idx].rescale(_.scale);
|
||||||
|
_.schedule_render();
|
||||||
|
|
||||||
|
// disable background image dragging
|
||||||
|
$new_pf.find('.'+CSS_CLASS_NAMES['background_image']).on('dragstart', function(e){return false;});
|
||||||
|
|
||||||
|
// Reset loading token
|
||||||
|
delete _.pages_loading[idx];
|
||||||
|
|
||||||
|
if (successCallback) successCallback();
|
||||||
|
}
|
||||||
|
).fail(function(jqXHR, textStatus, errorThrown){
|
||||||
|
console.error('error loading page ' + idx + ': ' + textStatus);
|
||||||
|
|
||||||
|
// Reset loading token
|
||||||
|
delete _.pages_loading[idx];
|
||||||
|
|
||||||
|
if (errorCallback) errorCallback();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Concurrent prefetch of the next pages
|
||||||
|
if (pages_to_preload === undefined)
|
||||||
|
pages_to_preload = this.pages_to_preload;
|
||||||
|
|
||||||
|
if (--pages_to_preload > 0)
|
||||||
|
_.load_page(idx+1, pages_to_preload);
|
||||||
|
|
||||||
},
|
},
|
||||||
pre_hide_pages : function() {
|
pre_hide_pages : function() {
|
||||||
/* pages might have not been loaded yet, so add a CSS rule */
|
/* pages might have not been loaded yet, so add a CSS rule */
|
||||||
@ -211,7 +262,10 @@ var pdf2htmlEX = (function(){
|
|||||||
for(var i in pl) {
|
for(var i in pl) {
|
||||||
var p = pl[i];
|
var p = pl[i];
|
||||||
if(p.is_nearly_visible()){
|
if(p.is_nearly_visible()){
|
||||||
p.show();
|
if (p.loaded) {
|
||||||
|
p.show();
|
||||||
|
} else
|
||||||
|
this.load_page(p.n);
|
||||||
} else {
|
} else {
|
||||||
p.hide();
|
p.hide();
|
||||||
}
|
}
|
||||||
@ -284,7 +338,6 @@ var pdf2htmlEX = (function(){
|
|||||||
},
|
},
|
||||||
|
|
||||||
link_handler : function (e) {
|
link_handler : function (e) {
|
||||||
console.log('here');
|
|
||||||
var _ = e.data;
|
var _ = e.data;
|
||||||
var t = $(e.currentTarget);
|
var t = $(e.currentTarget);
|
||||||
|
|
||||||
@ -345,11 +398,26 @@ var pdf2htmlEX = (function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ok) {
|
if(ok) {
|
||||||
pos = transform(target_page.ctm, pos);
|
var transform_and_scroll = function() {
|
||||||
if(upside_down) {
|
pos = transform(target_page.ctm, pos);
|
||||||
pos[1] = target_page.height() - pos[1];
|
if(upside_down) {
|
||||||
|
pos[1] = target_page.height() - pos[1];
|
||||||
|
}
|
||||||
|
_.scroll_to(detail[0], pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target_page.loaded) {
|
||||||
|
transform_and_scroll();
|
||||||
|
} else {
|
||||||
|
// Scroll to the exact position once loaded.
|
||||||
|
_.load_page(target_page.n, 1, function() {
|
||||||
|
target_page = _.pages[target_page.n]; // Refresh reference
|
||||||
|
transform_and_scroll();
|
||||||
|
});
|
||||||
|
|
||||||
|
// In the meantime page gets loaded, scroll approximately position for maximum responsiveness.
|
||||||
|
_.scroll_to(detail[0], [0,0]);
|
||||||
}
|
}
|
||||||
_.scroll_to(detail[0], pos);
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -308,8 +308,6 @@ protected:
|
|||||||
|
|
||||||
Preprocessor preprocessor;
|
Preprocessor preprocessor;
|
||||||
TmpFiles tmp_files;
|
TmpFiles tmp_files;
|
||||||
// for splitted pages
|
|
||||||
std::vector<std::string> page_filenames;
|
|
||||||
|
|
||||||
// for string formatting
|
// for string formatting
|
||||||
StringFormatter str_fmt;
|
StringFormatter str_fmt;
|
||||||
@ -318,6 +316,8 @@ protected:
|
|||||||
std::ofstream fs;
|
std::ofstream fs;
|
||||||
std::string path;
|
std::string path;
|
||||||
} f_outline, f_pages, f_css;
|
} f_outline, f_pages, f_css;
|
||||||
|
std::ofstream * f_curpage;
|
||||||
|
std::string cur_page_filename;
|
||||||
|
|
||||||
static const std::string MANIFEST_FILENAME;
|
static const std::string MANIFEST_FILENAME;
|
||||||
};
|
};
|
||||||
|
@ -370,50 +370,50 @@ void HTMLRenderer::css_draw_rectangle(double x, double y, double w, double h, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f_pages.fs << "<div class=\"" << CSS::CSS_DRAW_CN
|
(*f_curpage) << "<div class=\"" << CSS::CSS_DRAW_CN
|
||||||
<< ' ' << CSS::TRANSFORM_MATRIX_CN << all_manager.transform_matrix.install(new_tm)
|
<< ' ' << CSS::TRANSFORM_MATRIX_CN << all_manager.transform_matrix.install(new_tm)
|
||||||
<< "\" style=\"";
|
<< "\" style=\"";
|
||||||
|
|
||||||
if(line_color)
|
if(line_color)
|
||||||
{
|
{
|
||||||
f_pages.fs << "border-color:" << *line_color << ";";
|
(*f_curpage) << "border-color:" << *line_color << ";";
|
||||||
|
|
||||||
f_pages.fs << "border-width:";
|
(*f_curpage) << "border-width:";
|
||||||
for(int i = 0; i < line_width_count; ++i)
|
for(int i = 0; i < line_width_count; ++i)
|
||||||
{
|
{
|
||||||
if(i > 0) f_pages.fs << ' ';
|
if(i > 0) (*f_curpage) << ' ';
|
||||||
|
|
||||||
double lw = line_width_array[i] * scale;
|
double lw = line_width_array[i] * scale;
|
||||||
f_pages.fs << round(lw);
|
(*f_curpage) << round(lw);
|
||||||
if(is_positive(lw)) f_pages.fs << "px";
|
if(is_positive(lw)) (*f_curpage) << "px";
|
||||||
}
|
}
|
||||||
f_pages.fs << ";";
|
(*f_curpage) << ";";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f_pages.fs << "border:none;";
|
(*f_curpage) << "border:none;";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fill_color)
|
if(fill_color)
|
||||||
{
|
{
|
||||||
f_pages.fs << "background-color:" << (*fill_color) << ";";
|
(*f_curpage) << "background-color:" << (*fill_color) << ";";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f_pages.fs << "background-color:transparent;";
|
(*f_curpage) << "background-color:transparent;";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(style_function)
|
if(style_function)
|
||||||
{
|
{
|
||||||
style_function(style_function_data, f_pages.fs);
|
style_function(style_function_data, (*f_curpage));
|
||||||
}
|
}
|
||||||
|
|
||||||
f_pages.fs << "bottom:" << round(y) << "px;"
|
(*f_curpage) << "bottom:" << round(y) << "px;"
|
||||||
<< "left:" << round(x) << "px;"
|
<< "left:" << round(x) << "px;"
|
||||||
<< "width:" << round(w * scale) << "px;"
|
<< "width:" << round(w * scale) << "px;"
|
||||||
<< "height:" << round(h * scale) << "px;";
|
<< "height:" << round(h * scale) << "px;";
|
||||||
|
|
||||||
f_pages.fs << "\"></div>";
|
(*f_curpage) << "\"></div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,12 +112,12 @@ void HTMLRenderer::process(PDFDoc *doc)
|
|||||||
{
|
{
|
||||||
string filled_template_filename = (char*)str_fmt(param.page_filename.c_str(), i);
|
string filled_template_filename = (char*)str_fmt(param.page_filename.c_str(), i);
|
||||||
auto page_fn = str_fmt("%s/%s", param.dest_dir.c_str(), filled_template_filename.c_str());
|
auto page_fn = str_fmt("%s/%s", param.dest_dir.c_str(), filled_template_filename.c_str());
|
||||||
f_pages.fs.open((char*)page_fn, ofstream::binary);
|
f_curpage = new ofstream((char*)page_fn, ofstream::binary);
|
||||||
if(!f_pages.fs)
|
if(!(*f_curpage))
|
||||||
throw string("Cannot open ") + (char*)page_fn + " for writing";
|
throw string("Cannot open ") + (char*)page_fn + " for writing";
|
||||||
set_stream_flags(f_pages.fs);
|
set_stream_flags((*f_curpage));
|
||||||
|
|
||||||
page_filenames.push_back(filled_template_filename);
|
cur_page_filename = filled_template_filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(param.process_nontext)
|
if(param.process_nontext)
|
||||||
@ -139,7 +139,8 @@ void HTMLRenderer::process(PDFDoc *doc)
|
|||||||
|
|
||||||
if(param.split_pages)
|
if(param.split_pages)
|
||||||
{
|
{
|
||||||
f_pages.fs.close();
|
delete f_curpage;
|
||||||
|
f_curpage = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(page_count >= 0)
|
if(page_count >= 0)
|
||||||
@ -180,7 +181,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
|||||||
|
|
||||||
long long wid = all_manager.width.install(pageWidth);
|
long long wid = all_manager.width.install(pageWidth);
|
||||||
long long hid = all_manager.height.install(pageHeight);
|
long long hid = all_manager.height.install(pageHeight);
|
||||||
f_pages.fs
|
(*f_curpage)
|
||||||
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
|
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
|
||||||
<< " " << CSS::WIDTH_CN << wid
|
<< " " << CSS::WIDTH_CN << wid
|
||||||
<< " " << CSS::HEIGHT_CN << hid
|
<< " " << CSS::HEIGHT_CN << hid
|
||||||
@ -192,9 +193,29 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
|||||||
<< " " << CSS::PAGE_CONTENT_BOX_CN << pageNum
|
<< " " << CSS::PAGE_CONTENT_BOX_CN << pageNum
|
||||||
<< "\">";
|
<< "\">";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When split_pages is on, f_curpage points to the current page file
|
||||||
|
* and we want to output empty frames in f_pages.fs
|
||||||
|
*/
|
||||||
|
if(param.split_pages)
|
||||||
|
{
|
||||||
|
f_pages.fs
|
||||||
|
<< "<div class=\"" << CSS::PAGE_DECORATION_CN
|
||||||
|
<< " " << CSS::WIDTH_CN << wid
|
||||||
|
<< " " << CSS::HEIGHT_CN << hid
|
||||||
|
<< "\">"
|
||||||
|
<< "<div id=\"" << CSS::PAGE_FRAME_CN << pageNum
|
||||||
|
<< "\" class=\"" << CSS::PAGE_FRAME_CN
|
||||||
|
<< "\" data-page-no=\"" << pageNum
|
||||||
|
<< "\" data-page-url=\"";
|
||||||
|
|
||||||
|
outputURL(f_pages.fs, cur_page_filename);
|
||||||
|
f_pages.fs << "\">";
|
||||||
|
}
|
||||||
|
|
||||||
if(param.process_nontext)
|
if(param.process_nontext)
|
||||||
{
|
{
|
||||||
f_pages.fs << "<img class=\"" << CSS::BACKGROUND_IMAGE_CN
|
(*f_curpage) << "<img class=\"" << CSS::BACKGROUND_IMAGE_CN
|
||||||
<< "\" alt=\"\" src=\"";
|
<< "\" alt=\"\" src=\"";
|
||||||
if(param.embed_image)
|
if(param.embed_image)
|
||||||
{
|
{
|
||||||
@ -202,13 +223,13 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
|||||||
ifstream fin((char*)path, ifstream::binary);
|
ifstream fin((char*)path, ifstream::binary);
|
||||||
if(!fin)
|
if(!fin)
|
||||||
throw string("Cannot read background image ") + (char*)path;
|
throw string("Cannot read background image ") + (char*)path;
|
||||||
f_pages.fs << "data:image/png;base64," << Base64Stream(fin);
|
(*f_curpage) << "data:image/png;base64," << Base64Stream(fin);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f_pages.fs << (char*)str_fmt("bg%x.png", pageNum);
|
(*f_curpage) << (char*)str_fmt("bg%x.png", pageNum);
|
||||||
}
|
}
|
||||||
f_pages.fs << "\"/>";
|
(*f_curpage) << "\"/>";
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_state();
|
reset_state();
|
||||||
@ -216,7 +237,7 @@ void HTMLRenderer::startPage(int pageNum, GfxState *state, XRef * xref)
|
|||||||
|
|
||||||
void HTMLRenderer::endPage() {
|
void HTMLRenderer::endPage() {
|
||||||
// dump all text
|
// dump all text
|
||||||
html_text_page.dump_text(f_pages.fs);
|
html_text_page.dump_text(*f_curpage);
|
||||||
html_text_page.dump_css(f_css.fs);
|
html_text_page.dump_css(f_css.fs);
|
||||||
html_text_page.clear();
|
html_text_page.clear();
|
||||||
|
|
||||||
@ -224,26 +245,31 @@ void HTMLRenderer::endPage() {
|
|||||||
cur_doc->processLinks(this, pageNum);
|
cur_doc->processLinks(this, pageNum);
|
||||||
|
|
||||||
// close box
|
// close box
|
||||||
f_pages.fs << "</div>";
|
(*f_curpage) << "</div>";
|
||||||
|
|
||||||
// dump info for js
|
// dump info for js
|
||||||
// TODO: create a function for this
|
// TODO: create a function for this
|
||||||
// BE CAREFUL WITH ESCAPES
|
// BE CAREFUL WITH ESCAPES
|
||||||
f_pages.fs << "<div class=\"" << CSS::PAGE_DATA_CN << "\" data-data='{";
|
(*f_curpage) << "<div class=\"" << CSS::PAGE_DATA_CN << "\" data-data='{";
|
||||||
|
|
||||||
//default CTM
|
//default CTM
|
||||||
f_pages.fs << "\"ctm\":[";
|
(*f_curpage) << "\"ctm\":[";
|
||||||
for(int i = 0; i < 6; ++i)
|
for(int i = 0; i < 6; ++i)
|
||||||
{
|
{
|
||||||
if(i > 0) f_pages.fs << ",";
|
if(i > 0) (*f_curpage) << ",";
|
||||||
f_pages.fs << round(default_ctm[i]);
|
(*f_curpage) << round(default_ctm[i]);
|
||||||
}
|
}
|
||||||
f_pages.fs << "]";
|
(*f_curpage) << "]";
|
||||||
|
|
||||||
f_pages.fs << "}'></div>";
|
(*f_curpage) << "}'></div>";
|
||||||
|
|
||||||
// close page
|
// close page
|
||||||
f_pages.fs << "</div></div>" << endl;
|
(*f_curpage) << "</div></div>" << endl;
|
||||||
|
|
||||||
|
if(param.split_pages)
|
||||||
|
{
|
||||||
|
f_pages.fs << "</div></div>" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLRenderer::pre_process(PDFDoc * doc)
|
void HTMLRenderer::pre_process(PDFDoc * doc)
|
||||||
@ -324,9 +350,6 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
|||||||
set_stream_flags(f_outline.fs);
|
set_stream_flags(f_outline.fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if split-pages is specified, open & close the file in the process loop
|
|
||||||
// if not, open the file here:
|
|
||||||
if(!param.split_pages)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* we have to keep the html file for pages into a temporary place
|
* we have to keep the html file for pages into a temporary place
|
||||||
@ -343,6 +366,15 @@ void HTMLRenderer::pre_process(PDFDoc * doc)
|
|||||||
throw string("Cannot open ") + (char*)fn + " for writing";
|
throw string("Cannot open ") + (char*)fn + " for writing";
|
||||||
set_stream_flags(f_pages.fs);
|
set_stream_flags(f_pages.fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(param.split_pages)
|
||||||
|
{
|
||||||
|
f_curpage = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
f_curpage = &f_pages.fs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLRenderer::post_process(void)
|
void HTMLRenderer::post_process(void)
|
||||||
@ -436,25 +468,11 @@ void HTMLRenderer::post_process(void)
|
|||||||
}
|
}
|
||||||
else if (line == "$pages")
|
else if (line == "$pages")
|
||||||
{
|
{
|
||||||
if(!param.split_pages)
|
ifstream fin(f_pages.path, ifstream::binary);
|
||||||
{
|
if(!fin)
|
||||||
ifstream fin(f_pages.path, ifstream::binary);
|
throw "Cannot open pages for reading";
|
||||||
if(!fin)
|
output << fin.rdbuf();
|
||||||
throw "Cannot open pages for reading";
|
output.clear(); // output will set fail bit if fin is empty
|
||||||
output << fin.rdbuf();
|
|
||||||
output.clear(); // output will set fail bit if fin is empty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (line == "$page_urls")
|
|
||||||
{
|
|
||||||
for(auto iter = page_filenames.begin(); iter != page_filenames.end(); ++iter)
|
|
||||||
{
|
|
||||||
if(iter != page_filenames.begin())
|
|
||||||
output << ",";
|
|
||||||
output << "'";
|
|
||||||
outputJSON(output, *iter);
|
|
||||||
output << "'";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -195,17 +195,17 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
|||||||
|
|
||||||
if(!dest_str.empty())
|
if(!dest_str.empty())
|
||||||
{
|
{
|
||||||
f_pages.fs << "<a class=\"" << CSS::LINK_CN << "\" href=\"";
|
(*f_curpage) << "<a class=\"" << CSS::LINK_CN << "\" href=\"";
|
||||||
outputURL(f_pages.fs, dest_str);
|
outputURL((*f_curpage), dest_str);
|
||||||
f_pages.fs << "\"";
|
(*f_curpage) << "\"";
|
||||||
|
|
||||||
if(!dest_detail_str.empty())
|
if(!dest_detail_str.empty())
|
||||||
f_pages.fs << " data-dest-detail='" << dest_detail_str << "'";
|
(*f_curpage) << " data-dest-detail='" << dest_detail_str << "'";
|
||||||
|
|
||||||
f_pages.fs << ">";
|
(*f_curpage) << ">";
|
||||||
}
|
}
|
||||||
|
|
||||||
f_pages.fs << "<div class=\"" << CSS::CSS_DRAW_CN << ' ' << CSS::TRANSFORM_MATRIX_CN
|
(*f_curpage) << "<div class=\"" << CSS::CSS_DRAW_CN << ' ' << CSS::TRANSFORM_MATRIX_CN
|
||||||
<< all_manager.transform_matrix.install(default_ctm)
|
<< all_manager.transform_matrix.install(default_ctm)
|
||||||
<< "\" style=\"";
|
<< "\" style=\"";
|
||||||
|
|
||||||
@ -232,31 +232,31 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
|||||||
border_top_bottom_width, border_left_right_width);
|
border_top_bottom_width, border_left_right_width);
|
||||||
|
|
||||||
if(abs(border_top_bottom_width - border_left_right_width) < EPS)
|
if(abs(border_top_bottom_width - border_left_right_width) < EPS)
|
||||||
f_pages.fs << "border-width:" << round(border_top_bottom_width) << "px;";
|
(*f_curpage) << "border-width:" << round(border_top_bottom_width) << "px;";
|
||||||
else
|
else
|
||||||
f_pages.fs << "border-width:" << round(border_top_bottom_width) << "px " << round(border_left_right_width) << "px;";
|
(*f_curpage) << "border-width:" << round(border_top_bottom_width) << "px " << round(border_left_right_width) << "px;";
|
||||||
}
|
}
|
||||||
auto style = border->getStyle();
|
auto style = border->getStyle();
|
||||||
switch(style)
|
switch(style)
|
||||||
{
|
{
|
||||||
case AnnotBorder::borderSolid:
|
case AnnotBorder::borderSolid:
|
||||||
f_pages.fs << "border-style:solid;";
|
(*f_curpage) << "border-style:solid;";
|
||||||
break;
|
break;
|
||||||
case AnnotBorder::borderDashed:
|
case AnnotBorder::borderDashed:
|
||||||
f_pages.fs << "border-style:dashed;";
|
(*f_curpage) << "border-style:dashed;";
|
||||||
break;
|
break;
|
||||||
case AnnotBorder::borderBeveled:
|
case AnnotBorder::borderBeveled:
|
||||||
f_pages.fs << "border-style:outset;";
|
(*f_curpage) << "border-style:outset;";
|
||||||
break;
|
break;
|
||||||
case AnnotBorder::borderInset:
|
case AnnotBorder::borderInset:
|
||||||
f_pages.fs << "border-style:inset;";
|
(*f_curpage) << "border-style:inset;";
|
||||||
break;
|
break;
|
||||||
case AnnotBorder::borderUnderlined:
|
case AnnotBorder::borderUnderlined:
|
||||||
f_pages.fs << "border-style:none;border-bottom-style:solid;";
|
(*f_curpage) << "border-style:none;border-bottom-style:solid;";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
cerr << "Warning:Unknown annotation border style: " << style << endl;
|
cerr << "Warning:Unknown annotation border style: " << style << endl;
|
||||||
f_pages.fs << "border-style:solid;";
|
(*f_curpage) << "border-style:solid;";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -274,36 +274,36 @@ void HTMLRenderer::processLink(AnnotLink * al)
|
|||||||
r = g = b = 0;
|
r = g = b = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
f_pages.fs << "border-color:rgb("
|
(*f_curpage) << "border-color:rgb("
|
||||||
<< dec << (int)dblToByte(r) << "," << (int)dblToByte(g) << "," << (int)dblToByte(b) << hex
|
<< dec << (int)dblToByte(r) << "," << (int)dblToByte(g) << "," << (int)dblToByte(b) << hex
|
||||||
<< ");";
|
<< ");";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f_pages.fs << "border-style:none;";
|
(*f_curpage) << "border-style:none;";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f_pages.fs << "border-style:none;";
|
(*f_curpage) << "border-style:none;";
|
||||||
}
|
}
|
||||||
|
|
||||||
tm_transform(default_ctm, x, y);
|
tm_transform(default_ctm, x, y);
|
||||||
|
|
||||||
f_pages.fs << "position:absolute;"
|
(*f_curpage) << "position:absolute;"
|
||||||
<< "left:" << round(x) << "px;"
|
<< "left:" << round(x) << "px;"
|
||||||
<< "bottom:" << round(y) << "px;"
|
<< "bottom:" << round(y) << "px;"
|
||||||
<< "width:" << round(w) << "px;"
|
<< "width:" << round(w) << "px;"
|
||||||
<< "height:" << round(h) << "px;";
|
<< "height:" << round(h) << "px;";
|
||||||
|
|
||||||
// fix for IE
|
// fix for IE
|
||||||
f_pages.fs << "background-color:rgba(255,255,255,0.000001);";
|
(*f_curpage) << "background-color:rgba(255,255,255,0.000001);";
|
||||||
|
|
||||||
f_pages.fs << "\"></div>";
|
(*f_curpage) << "\"></div>";
|
||||||
|
|
||||||
if(dest_str != "")
|
if(dest_str != "")
|
||||||
{
|
{
|
||||||
f_pages.fs << "</a>";
|
(*f_curpage) << "</a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user