1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-08-25 04:47:40 +00:00

support zoom in links

This commit is contained in:
Lu Wang 2013-11-08 16:45:32 +08:00
parent 8d2b6d0308
commit 80e6df6c2b
2 changed files with 703 additions and 690 deletions

View File

@ -18,6 +18,7 @@ OUTPUT="$BASEDIR/$OUTPUT_FN"
--compilation_level ADVANCED_OPTIMIZATIONS \ --compilation_level ADVANCED_OPTIMIZATIONS \
--warning_level VERBOSE \ --warning_level VERBOSE \
--process_jquery_primitives \ --process_jquery_primitives \
--output_wrapper "(function(){%output%})();" \
--js "$INPUT" \ --js "$INPUT" \
--js_output_file "$OUTPUT" && \ --js_output_file "$OUTPUT" && \
echo 'Done.') || \ echo 'Done.') || \

View File

@ -27,7 +27,8 @@
'use strict'; 'use strict';
(function(pdf2htmlEX, document){ var pdf2htmlEX = window['pdf2htmlEX'] = window['pdf2htmlEX'] || {};
/** /**
* @const * @const
* @struct * @struct
@ -568,6 +569,20 @@
* TODO consider scale on offsetX/Y * TODO consider scale on offsetX/Y
*/ */
rescale : function (ratio, is_relative, offsetX, offsetY) { rescale : function (ratio, is_relative, offsetX, offsetY) {
var old_scale = this.scale;
var new_scale = 1.0;
// Set new scale
if (ratio == 0) {
new_scale = 1;
is_relative = false;
}
else if (is_relative)
new_scale *= ratio;
else
new_scale = ratio;
this.scale = new_scale;
if (! offsetX) if (! offsetX)
offsetX = 0; offsetX = 0;
if (! offsetY) if (! offsetY)
@ -579,22 +594,11 @@
var active_page_ele = active_page.p; var active_page_ele = active_page.p;
var prev_offset = [ active_page_ele.offsetLeft, active_page_ele.offsetTop ]; var prev_offset = [ active_page_ele.offsetLeft, active_page_ele.offsetTop ];
var old_scale = this.scale;
var pl = this.pages;
// Set new scale
if (ratio == 0) {
this.scale = 1;
is_relative = false;
}
else if (is_relative)
this.scale *= ratio;
else
this.scale = ratio;
// Rescale pages // Rescale pages
var pl = this.pages;
for(var i = 0, l = pl.length; i < l; ++i) for(var i = 0, l = pl.length; i < l; ++i)
pl[i].rescale(this.scale); pl[i].rescale(new_scale);
var container = this.container; var container = this.container;
// Correct container scroll to keep view aligned while zooming // Correct container scroll to keep view aligned while zooming
@ -604,7 +608,7 @@
// Take the center of the view as a reference // Take the center of the view as a reference
var prev_center_x = container.clientWidth / 2 - prev_offset[0]; var prev_center_x = container.clientWidth / 2 - prev_offset[0];
// Calculate the difference respect the center of the view after the zooming // Calculate the difference respect the center of the view after the zooming
var correction_left = prev_center_x * (this.scale/old_scale - 1) + active_page_ele.offsetLeft - prev_offset[0]; var correction_left = prev_center_x * (new_scale/old_scale - 1) + active_page_ele.offsetLeft - prev_offset[0];
// Scroll the container accordingly to keep alignment to the initial reference // Scroll the container accordingly to keep alignment to the initial reference
container.scrollLeft += correction_left + offsetX; container.scrollLeft += correction_left + offsetX;
@ -686,13 +690,17 @@
var target_page = this.pages[target_page_idx]; var target_page = this.pages[target_page_idx];
var pos = [0,0]; var pos = [0,0];
var zoom = this.scale;
var upside_down = true; var upside_down = true;
// TODO: zoom // TODO: fitb*
// TODO: BBox // TODO: BBox
switch(detail[1]) { switch(detail[1]) {
case 'XYZ': case 'XYZ':
pos = [(detail[2] == null) ? cur_pos[0] : detail[2] pos = [(detail[2] == null) ? cur_pos[0] : detail[2]
,(detail[3] == null) ? cur_pos[1] : detail[3]]; ,(detail[3] == null) ? cur_pos[1] : detail[3]];
zoom = detail[4];
if((zoom == null) || (zoom == 0))
zoom = this.scale;
ok = true; ok = true;
break; break;
case 'Fit': case 'Fit':
@ -722,8 +730,13 @@
} }
if(ok) { if(ok) {
this.rescale(zoom, false);
var _ = this; var _ = this;
/* page should of type Page */ /**
* page should of type Page
* @param{Page} page
*/
var transform_and_scroll = function(page) { var transform_and_scroll = function(page) {
pos = transform(page.ctm, pos); pos = transform(page.ctm, pos);
if(upside_down) { if(upside_down) {
@ -770,4 +783,3 @@
}; };
pdf2htmlEX['Viewer'] = Viewer; pdf2htmlEX['Viewer'] = Viewer;
})((window['pdf2htmlEX'] = window['pdf2htmlEX'] || {}), document);