1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 04:50:09 +00:00

remove old implementation of smooth rescaling

This commit is contained in:
Lu Wang 2013-11-05 12:36:29 +08:00
parent 75908842f5
commit 7c5470ac4d

View File

@ -39,10 +39,10 @@
/* The namespace */ /* The namespace */
(function(pdf2htmlEX){ (function(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@',
@ -67,14 +67,12 @@
'loading_indicator_cls' : 'loading-indicator', 'loading_indicator_cls' : 'loading-indicator',
// How many page shall we preload that are below the last visible page // How many page shall we preload that are below the last visible page
'preload_pages' : 3, 'preload_pages' : 3,
// Smooth zoom is enabled when the number of pages shown is less than the threshold
// Otherwise page content is hidden and redrawn after a delay (function schedule_render).
// 0: disable smooth zoom optimizations (less CPU usage but flickering on zoom)
'smooth_zoom_threshold' : 4,
// how many ms should we wait before actually rendering the pages and after a scroll event // how many ms should we wait before actually rendering the pages and after a scroll event
'render_timeout' : 100, 'render_timeout' : 100,
// zoom ratio step for each zoom in/out event // zoom ratio step for each zoom in/out event
'scale_step' : 0.9, 'scale_step' : 0.9,
// register global key handler
'register_key_handler' : true,
'__dummy__' : 'no comma' '__dummy__' : 'no comma'
}; };
@ -143,30 +141,23 @@
}, },
show : function(){ show : function(){
if (this.loaded) { if (this.loaded) {
if(Math.abs(this.set_r - this.cur_r) > EPS) {
this.cur_r = this.set_r;
this.$b.css('transform', 'scale('+this.cur_r.toFixed(3)+')');
}
if (! this.shown) { if (! this.shown) {
this.$b.addClass('opened'); this.$b.addClass('opened');
this.shown = true; this.shown = true;
} }
} }
}, },
/** rescale : function(ratio) {
* @param {boolean=} force_show Force showing the page for smooth rescaling
*/
rescale : function(ratio, force_show) {
if(ratio == 0) { if(ratio == 0) {
this.set_r = this.default_r; this.set_r = this.default_r;
} else { } else {
this.set_r = ratio; this.set_r = ratio;
} }
if (force_show) if(Math.abs(this.set_r - this.cur_r) > EPS) {
this.show(); // Refresh content this.cur_r = this.set_r;
else this.$b.css('transform', 'scale('+this.cur_r.toFixed(3)+')');
this.hide(); // Wait for redraw }
this.$p.height(this.h * this.set_r); this.$p.height(this.h * this.set_r);
this.$p.width(this.w * this.set_r); this.$p.width(this.w * this.set_r);
@ -244,7 +235,8 @@
var _ = this; var _ = this;
this.$container.scroll(function(){ _.schedule_render(); }); this.$container.scroll(function(){ _.schedule_render(); });
//this.register_key_handler(); if(this.config['register_key_handler'])
this.register_key_handler();
// 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);
@ -396,13 +388,15 @@
$(window).on('keydown', function keydown(e) { $(window).on('keydown', function keydown(e) {
var handled = false; var handled = false;
/*
var cmd = (e.ctrlKey ? 1 : 0) var cmd = (e.ctrlKey ? 1 : 0)
| (e.altKey ? 2 : 0) | (e.altKey ? 2 : 0)
| (e.shiftKey ? 4 : 0) | (e.shiftKey ? 4 : 0)
| (e.metaKey ? 8 : 0) | (e.metaKey ? 8 : 0)
; ;
var with_ctrl = (cmd == 9); */
var with_alt = (cmd == 2); var with_ctrl = e.ctrlKey || e.metaKey;
var with_alt = e.altKey;
switch (e.keyCode) { switch (e.keyCode) {
case 61: // FF/Mac '=' case 61: // FF/Mac '='
case 107: // FF '+' and '=' case 107: // FF '+' and '='
@ -466,6 +460,7 @@
get_next_page : function() { return undefined; }, get_next_page : function() { return undefined; },
get_prev_page : function() { return undefined; }, get_prev_page : function() { return undefined; },
// TODO: offsetX/Y is by default the center of container
rescale : function (ratio, is_relative, offsetX, offsetY) { rescale : function (ratio, is_relative, offsetX, offsetY) {
if (! offsetX) if (! offsetX)
offsetX = 0; offsetX = 0;
@ -480,36 +475,19 @@
var old_scale = this.scale; var old_scale = this.scale;
var pl = this.pages; var pl = this.pages;
var prerendering_enabled = false;
if (this.config['smooth_zoom_threshold'] > 0) {
// Immediate rendering optimizations enabled to improve reactiveness while zooming
// Find out which pages are visible
var min_visible, max_visible;
// TODO: page index
min_visible = max_visible = this.page_map[active_page.n];
while (pl[min_visible] && pl[min_visible].is_visible()) { --min_visible; }
++ min_visible;
while (pl[max_visible] && pl[max_visible].is_visible()) { ++max_visible; }
-- max_visible;
// If less then the threshold, enable prerendering on selected pages
if (max_visible - min_visible + 1 < this.config['smooth_zoom_threshold'])
prerendering_enabled = true;
}
// Set new scale // Set new scale
if (is_relative) if (ratio == 0) {
this.scale = 1;
is_relative = false;
}
else if (is_relative)
this.scale *= ratio; this.scale *= ratio;
else else
this.scale = ratio; this.scale = ratio;
// Rescale pages // Rescale pages
for(var i = 0, l = pl.length; i < l; ++i) { for(var i = 0, l = pl.length; i < l; ++i)
if (prerendering_enabled && i >= min_visible && i <= max_visible) pl[i].rescale(this.scale);
pl[i].rescale(this.scale, true); // Force immediate refresh
else
pl[i].rescale(this.scale); // Delayed refresh
}
// Correct container scroll to keep view aligned while zooming // Correct container scroll to keep view aligned while zooming
var correction_top = active_page.$p[0].getBoundingClientRect().top - prev_offset.top; var correction_top = active_page.$p[0].getBoundingClientRect().top - prev_offset.top;
@ -522,7 +500,7 @@
// Scroll the container accordingly to keep alignment to the initial reference // Scroll the container accordingly to keep alignment to the initial reference
this.$container.scrollLeft( this.$container.scrollLeft() + correction_left + offsetX ); this.$container.scrollLeft( this.$container.scrollLeft() + correction_left + offsetX );
// Delayed rendering for pages not already shown // some pages' visibility may be toggled, wait for next render()
this.schedule_render(); this.schedule_render();
}, },