1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-10-05 19:41: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 \
--warning_level VERBOSE \
--process_jquery_primitives \
--output_wrapper "(function(){%output%})();" \
--js "$INPUT" \
--js_output_file "$OUTPUT" && \
echo 'Done.') || \

View File

@ -27,26 +27,27 @@
'use strict';
(function(pdf2htmlEX, document){
/**
var pdf2htmlEX = window['pdf2htmlEX'] = window['pdf2htmlEX'] || {};
/**
* @const
* @struct
*/
var CSS_CLASS_NAMES = {
var CSS_CLASS_NAMES = {
page_frame : '@CSS_PAGE_FRAME_CN@',
page_content_box : '@CSS_PAGE_CONTENT_BOX_CN@',
page_data : '@CSS_PAGE_DATA_CN@',
background_image : '@CSS_BACKGROUND_IMAGE_CN@',
link : '@CSS_LINK_CN@',
__dummy__ : 'no comma'
};
};
/**
/**
* configurations of Viewer
* @const
* @dict
*/
var DEFAULT_CONFIG = {
var DEFAULT_CONFIG = {
// id of the element to put the pages in
'container_id' : 'page-container',
// id of the element for sidebar (to open and close)
@ -65,14 +66,14 @@
'register_key_handler' : true,
'__dummy__' : 'no comma'
};
};
/** @const */
var EPS = 1e-6;
/** @const */
var EPS = 1e-6;
/************************************/
/* utility function */
function invert(ctm) {
/************************************/
/* utility function */
function invert(ctm) {
var det = ctm[0] * ctm[3] - ctm[1] * ctm[2];
return [ ctm[3] / det
,-ctm[1] / det
@ -81,34 +82,34 @@
,(ctm[2] * ctm[5] - ctm[3] * ctm[4]) / det
,(ctm[1] * ctm[4] - ctm[0] * ctm[5]) / det
];
};
function transform(ctm, pos) {
};
function transform(ctm, pos) {
return [ctm[0] * pos[0] + ctm[2] * pos[1] + ctm[4]
,ctm[1] * pos[0] + ctm[3] * pos[1] + ctm[5]];
};
};
/**
/**
* @param{Element} ele
*/
function get_page_number(ele) {
function get_page_number(ele) {
return parseInt(ele.getAttribute('data-page-no'), 16);
};
};
/**
/**
* @param{NodeList} eles
*/
function disable_dragstart(eles) {
function disable_dragstart(eles) {
for(var i = 0, l = eles.length; i < l; ++i) {
eles[i].addEventListener('dragstart', function() {
return false;
}, false);
}
};
};
/**
/**
* @param{...Object} var_args
*/
function clone_and_extend_objs(var_args) {
function clone_and_extend_objs(var_args) {
var result_obj = {};
for(var i = 0, l = arguments.length; i < l; ++i) {
var cur_obj = arguments[i];
@ -119,13 +120,13 @@
}
}
return result_obj;
};
};
/**
/**
* @constructor
* @param{Element} page The element for the page
*/
function Page(page) {
function Page(page) {
if(!page) return;
this.loaded = false;
@ -159,8 +160,8 @@
this.loaded = true;
}
};
Page.prototype = {
};
Page.prototype = {
/* hide & show are for contents, the page frame is still there */
hide : function(){
if(this.loaded && this.shown) {
@ -228,13 +229,13 @@
width : function () {
return this.p.clientWidth;
}
};
};
/**
/**
* export pdf2htmlEX.Viewer
* @constructor
*/
function Viewer(config) {
function Viewer(config) {
this.config = clone_and_extend_objs(DEFAULT_CONFIG, config);
this.pages_loading = [];
this.init_before_loading_content();
@ -243,9 +244,9 @@
document.addEventListener('DOMContentLoaded', function(){
_.init_after_loading_content();
}, false);
};
};
Viewer.prototype = {
Viewer.prototype = {
scale : 1,
init_before_loading_content : function() {
@ -568,6 +569,20 @@
* TODO consider scale on offsetX/Y
*/
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)
offsetX = 0;
if (! offsetY)
@ -579,22 +594,11 @@
var active_page_ele = active_page.p;
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
var pl = this.pages;
for(var i = 0, l = pl.length; i < l; ++i)
pl[i].rescale(this.scale);
pl[i].rescale(new_scale);
var container = this.container;
// Correct container scroll to keep view aligned while zooming
@ -604,7 +608,7 @@
// Take the center of the view as a reference
var prev_center_x = container.clientWidth / 2 - prev_offset[0];
// 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
container.scrollLeft += correction_left + offsetX;
@ -686,13 +690,17 @@
var target_page = this.pages[target_page_idx];
var pos = [0,0];
var zoom = this.scale;
var upside_down = true;
// TODO: zoom
// TODO: fitb*
// TODO: BBox
switch(detail[1]) {
case 'XYZ':
pos = [(detail[2] == null) ? cur_pos[0] : detail[2]
,(detail[3] == null) ? cur_pos[1] : detail[3]];
zoom = detail[4];
if((zoom == null) || (zoom == 0))
zoom = this.scale;
ok = true;
break;
case 'Fit':
@ -722,8 +730,13 @@
}
if(ok) {
this.rescale(zoom, false);
var _ = this;
/* page should of type Page */
/**
* page should of type Page
* @param{Page} page
*/
var transform_and_scroll = function(page) {
pos = transform(page.ctm, pos);
if(upside_down) {
@ -767,7 +780,6 @@
},
__last_member__ : 'no comma' /*,*/
};
};
pdf2htmlEX['Viewer'] = Viewer;
})((window['pdf2htmlEX'] = window['pdf2htmlEX'] || {}), document);
pdf2htmlEX['Viewer'] = Viewer;