mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-10-11 21:46:13 +00:00
support zoom in links
This commit is contained in:
parent
8d2b6d0308
commit
80e6df6c2b
@ -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.') || \
|
||||||
|
@ -27,26 +27,27 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(function(pdf2htmlEX, document){
|
var pdf2htmlEX = window['pdf2htmlEX'] = window['pdf2htmlEX'] || {};
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* @const
|
* @const
|
||||||
* @struct
|
* @struct
|
||||||
*/
|
*/
|
||||||
var CSS_CLASS_NAMES = {
|
var CSS_CLASS_NAMES = {
|
||||||
page_frame : '@CSS_PAGE_FRAME_CN@',
|
page_frame : '@CSS_PAGE_FRAME_CN@',
|
||||||
page_content_box : '@CSS_PAGE_CONTENT_BOX_CN@',
|
page_content_box : '@CSS_PAGE_CONTENT_BOX_CN@',
|
||||||
page_data : '@CSS_PAGE_DATA_CN@',
|
page_data : '@CSS_PAGE_DATA_CN@',
|
||||||
background_image : '@CSS_BACKGROUND_IMAGE_CN@',
|
background_image : '@CSS_BACKGROUND_IMAGE_CN@',
|
||||||
link : '@CSS_LINK_CN@',
|
link : '@CSS_LINK_CN@',
|
||||||
__dummy__ : 'no comma'
|
__dummy__ : 'no comma'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* configurations of Viewer
|
* configurations of Viewer
|
||||||
* @const
|
* @const
|
||||||
* @dict
|
* @dict
|
||||||
*/
|
*/
|
||||||
var DEFAULT_CONFIG = {
|
var DEFAULT_CONFIG = {
|
||||||
// id of the element to put the pages in
|
// id of the element to put the pages in
|
||||||
'container_id' : 'page-container',
|
'container_id' : 'page-container',
|
||||||
// id of the element for sidebar (to open and close)
|
// id of the element for sidebar (to open and close)
|
||||||
@ -65,14 +66,14 @@
|
|||||||
'register_key_handler' : true,
|
'register_key_handler' : true,
|
||||||
|
|
||||||
'__dummy__' : 'no comma'
|
'__dummy__' : 'no comma'
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @const */
|
/** @const */
|
||||||
var EPS = 1e-6;
|
var EPS = 1e-6;
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
/* utility function */
|
/* utility function */
|
||||||
function invert(ctm) {
|
function invert(ctm) {
|
||||||
var det = ctm[0] * ctm[3] - ctm[1] * ctm[2];
|
var det = ctm[0] * ctm[3] - ctm[1] * ctm[2];
|
||||||
return [ ctm[3] / det
|
return [ ctm[3] / det
|
||||||
,-ctm[1] / det
|
,-ctm[1] / det
|
||||||
@ -81,34 +82,34 @@
|
|||||||
,(ctm[2] * ctm[5] - ctm[3] * ctm[4]) / det
|
,(ctm[2] * ctm[5] - ctm[3] * ctm[4]) / det
|
||||||
,(ctm[1] * ctm[4] - ctm[0] * ctm[5]) / 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]
|
return [ctm[0] * pos[0] + ctm[2] * pos[1] + ctm[4]
|
||||||
,ctm[1] * pos[0] + ctm[3] * pos[1] + ctm[5]];
|
,ctm[1] * pos[0] + ctm[3] * pos[1] + ctm[5]];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param{Element} ele
|
* @param{Element} ele
|
||||||
*/
|
*/
|
||||||
function get_page_number(ele) {
|
function get_page_number(ele) {
|
||||||
return parseInt(ele.getAttribute('data-page-no'), 16);
|
return parseInt(ele.getAttribute('data-page-no'), 16);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param{NodeList} eles
|
* @param{NodeList} eles
|
||||||
*/
|
*/
|
||||||
function disable_dragstart(eles) {
|
function disable_dragstart(eles) {
|
||||||
for(var i = 0, l = eles.length; i < l; ++i) {
|
for(var i = 0, l = eles.length; i < l; ++i) {
|
||||||
eles[i].addEventListener('dragstart', function() {
|
eles[i].addEventListener('dragstart', function() {
|
||||||
return false;
|
return false;
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param{...Object} var_args
|
* @param{...Object} var_args
|
||||||
*/
|
*/
|
||||||
function clone_and_extend_objs(var_args) {
|
function clone_and_extend_objs(var_args) {
|
||||||
var result_obj = {};
|
var result_obj = {};
|
||||||
for(var i = 0, l = arguments.length; i < l; ++i) {
|
for(var i = 0, l = arguments.length; i < l; ++i) {
|
||||||
var cur_obj = arguments[i];
|
var cur_obj = arguments[i];
|
||||||
@ -119,13 +120,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result_obj;
|
return result_obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param{Element} page The element for the page
|
* @param{Element} page The element for the page
|
||||||
*/
|
*/
|
||||||
function Page(page) {
|
function Page(page) {
|
||||||
if(!page) return;
|
if(!page) return;
|
||||||
|
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
@ -159,8 +160,8 @@
|
|||||||
|
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Page.prototype = {
|
Page.prototype = {
|
||||||
/* hide & show are for contents, the page frame is still there */
|
/* hide & show are for contents, the page frame is still there */
|
||||||
hide : function(){
|
hide : function(){
|
||||||
if(this.loaded && this.shown) {
|
if(this.loaded && this.shown) {
|
||||||
@ -228,13 +229,13 @@
|
|||||||
width : function () {
|
width : function () {
|
||||||
return this.p.clientWidth;
|
return this.p.clientWidth;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* export pdf2htmlEX.Viewer
|
* export pdf2htmlEX.Viewer
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function Viewer(config) {
|
function Viewer(config) {
|
||||||
this.config = clone_and_extend_objs(DEFAULT_CONFIG, config);
|
this.config = clone_and_extend_objs(DEFAULT_CONFIG, config);
|
||||||
this.pages_loading = [];
|
this.pages_loading = [];
|
||||||
this.init_before_loading_content();
|
this.init_before_loading_content();
|
||||||
@ -243,9 +244,9 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function(){
|
document.addEventListener('DOMContentLoaded', function(){
|
||||||
_.init_after_loading_content();
|
_.init_after_loading_content();
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
Viewer.prototype = {
|
Viewer.prototype = {
|
||||||
scale : 1,
|
scale : 1,
|
||||||
|
|
||||||
init_before_loading_content : function() {
|
init_before_loading_content : function() {
|
||||||
@ -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) {
|
||||||
@ -767,7 +780,6 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
__last_member__ : 'no comma' /*,*/
|
__last_member__ : 'no comma' /*,*/
|
||||||
};
|
};
|
||||||
|
|
||||||
pdf2htmlEX['Viewer'] = Viewer;
|
pdf2htmlEX['Viewer'] = Viewer;
|
||||||
})((window['pdf2htmlEX'] = window['pdf2htmlEX'] || {}), document);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user