1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-12-22 13:00:08 +00:00
This commit is contained in:
Lu Wang 2013-11-16 19:31:52 +08:00
parent a60570f81c
commit 6e61ee5d19

View File

@ -188,7 +188,7 @@ Page.prototype = {
* @param{number} ratio * @param{number} ratio
*/ */
rescale : function(ratio) { rescale : function(ratio) {
if (ratio == 0) { if (ratio === 0) {
// reset scale // reset scale
this.cur_scale = this.original_scale; this.cur_scale = this.original_scale;
} else { } else {
@ -211,7 +211,7 @@ Page.prototype = {
/* /*
* return the coordinate of the top-left corner of container * return the coordinate of the top-left corner of container
* in our coordinate system * in our coordinate system
* assuming that p.parentNode == p.offsetParent * assuming that p.parentNode === p.offsetParent
*/ */
view_position : function () { view_position : function () {
var p = this.page; var p = this.page;
@ -228,7 +228,6 @@ Page.prototype = {
}; };
/** /**
* export pdf2htmlEX.Viewer
* @constructor * @constructor
* @param{Object=} config * @param{Object=} config
*/ */
@ -265,7 +264,7 @@ Viewer.prototype = {
var nodes = this.outline.childNodes; var nodes = this.outline.childNodes;
for (var i = 0, l = nodes.length; i < l; ++i) { for (var i = 0, l = nodes.length; i < l; ++i) {
var cur_node = nodes[i]; var cur_node = nodes[i];
if (cur_node.nodeName == 'UL') { if (cur_node.nodeName === 'UL') {
empty = false; empty = false;
break; break;
} }
@ -315,7 +314,7 @@ Viewer.prototype = {
var nodes = this.container.childNodes; var nodes = this.container.childNodes;
for (var i = 0, l = nodes.length; i < l; ++i) { for (var i = 0, l = nodes.length; i < l; ++i) {
var cur_node = nodes[i]; var cur_node = nodes[i];
if ((cur_node.nodeType == Node.ELEMENT_NODE) if ((cur_node.nodeType === Node.ELEMENT_NODE)
&& cur_node.classList.contains(CSS_CLASS_NAMES.page_frame)) { && cur_node.classList.contains(CSS_CLASS_NAMES.page_frame)) {
var p = new Page(cur_node); var p = new Page(cur_node);
new_pages.push(p); new_pages.push(p);
@ -331,7 +330,7 @@ Viewer.prototype = {
* @param{number=} pages_to_preload * @param{number=} pages_to_preload
* @param{function(Page)=} callback * @param{function(Page)=} callback
* *
* TODO: remove callback * TODO: remove callback -> promise ?
*/ */
load_page : function(idx, pages_to_preload, callback) { load_page : function(idx, pages_to_preload, callback) {
var pages = this.pages; var pages = this.pages;
@ -363,7 +362,7 @@ Viewer.prototype = {
xhr.open('GET', url, true); xhr.open('GET', url, true);
xhr.onreadystatechange = function(){ xhr.onreadystatechange = function(){
if (xhr.readyState != 4) return; if (xhr.readyState != 4) return;
if (xhr.status == 200) { if (xhr.status === 200) {
// find the page element in the data // find the page element in the data
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = xhr.responseText; div.innerHTML = xhr.responseText;
@ -372,7 +371,7 @@ Viewer.prototype = {
var nodes = div.childNodes; var nodes = div.childNodes;
for (var i = 0, l = nodes.length; i < l; ++i) { for (var i = 0, l = nodes.length; i < l; ++i) {
var cur_node = nodes[i]; var cur_node = nodes[i];
if ((cur_node.nodeType == Node.ELEMENT_NODE) if ((cur_node.nodeType === Node.ELEMENT_NODE)
&& cur_node.classList.contains(CSS_CLASS_NAMES.page_frame)) { && cur_node.classList.contains(CSS_CLASS_NAMES.page_frame)) {
new_page = cur_node; new_page = cur_node;
break; break;
@ -473,7 +472,7 @@ Viewer.prototype = {
if (!cur_page_fully_visible) { if (!cur_page_fully_visible) {
// check the visible fraction of the page // check the visible fraction of the page
var page_visible_ratio = (Math.min(container_max_y, page_max_y) - Math.max(container_min_y, page_min_y)) / page_height; var page_visible_ratio = (Math.min(container_max_y, page_max_y) - Math.max(container_min_y, page_min_y)) / page_height;
if ((i == cur_page_idx) && (Math.abs(page_visible_ratio - 1.0) <= EPS)) { if ((i === cur_page_idx) && (Math.abs(page_visible_ratio - 1.0) <= EPS)) {
cur_page_fully_visible = true; cur_page_fully_visible = true;
} else if (page_visible_ratio > max_visible_ratio) { } else if (page_visible_ratio > max_visible_ratio) {
max_visible_ratio = page_visible_ratio; max_visible_ratio = page_visible_ratio;
@ -610,7 +609,7 @@ Viewer.prototype = {
var old_scale = this.scale; var old_scale = this.scale;
var new_scale = old_scale; var new_scale = old_scale;
// set new scale // set new scale
if (ratio == 0) { if (ratio === 0) {
new_scale = 1; new_scale = 1;
is_relative = false; is_relative = false;
} else if (is_relative) } else if (is_relative)
@ -671,7 +670,7 @@ Viewer.prototype = {
get_containing_page : function(ele) { get_containing_page : function(ele) {
/* get the page obj containing obj */ /* get the page obj containing obj */
while(ele) { while(ele) {
if ((ele.nodeType == Node.ELEMENT_NODE) if ((ele.nodeType === Node.ELEMENT_NODE)
&& ele.classList.contains(CSS_CLASS_NAMES.page_frame)) { && ele.classList.contains(CSS_CLASS_NAMES.page_frame)) {
/* /*
* Get original page number and map it to index of pages * Get original page number and map it to index of pages
@ -717,9 +716,18 @@ Viewer.prototype = {
var target_page_idx = page_map[target_page_no]; var target_page_idx = page_map[target_page_no];
var target_page = this.pages[target_page_idx]; var target_page = this.pages[target_page_idx];
for (var i = 2, l = detail.length; i < l; ++i) {
var d = detail[i];
if(!((d === null) || (typeof d === 'number')))
return;
}
while(detail.length < 6)
detail.push(null);
// cur_page might be undefined, e.g. from Outline // cur_page might be undefined, e.g. from Outline
var cur_page = src_page || this.pages[this.cur_page_idx]; var cur_page = src_page || this.pages[this.cur_page_idx];
// TODO: view_position is now in scaled coordination system, but we need in unscaled system
var cur_pos = cur_page.view_position(); var cur_pos = cur_page.view_position();
//get the coordinates in default user system //get the coordinates in default user system
cur_pos = transform(cur_page.ictm, [cur_pos[0], cur_page.height()-cur_pos[1]]); cur_pos = transform(cur_page.ictm, [cur_pos[0], cur_page.height()-cur_pos[1]]);
@ -732,10 +740,10 @@ Viewer.prototype = {
// 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]; zoom = detail[4];
if ((zoom == null) || (zoom == 0)) if ((zoom === null) || (zoom === 0))
zoom = this.scale; zoom = this.scale;
ok = true; ok = true;
break; break;
@ -746,16 +754,17 @@ Viewer.prototype = {
break; break;
case 'FitH': case 'FitH':
case 'FitBH': case 'FitBH':
pos = [0, (detail[2] == null) ? cur_pos[1] : detail[2]]; pos = [0, (detail[2] === null) ? cur_pos[1] : detail[2]];
ok = true; ok = true;
break; break;
case 'FitV': case 'FitV':
case 'FitBV': case 'FitBV':
pos = [(detail[2] == null) ? cur_pos[0] : detail[2], 0]; pos = [(detail[2] === null) ? cur_pos[0] : detail[2], 0];
ok = true; ok = true;
break; break;
case 'FitR': case 'FitR':
/* locate the top-left corner of the rectangle */ /* locate the top-left corner of the rectangle */
// TODO
pos = [detail[2], detail[5]]; pos = [detail[2], detail[5]];
upside_down = false; upside_down = false;
ok = true; ok = true;
@ -814,4 +823,5 @@ Viewer.prototype = {
} }
}; };
// export pdf2htmlEX.Viewer
pdf2htmlEX['Viewer'] = Viewer; pdf2htmlEX['Viewer'] = Viewer;