merge experimental range request support, fixes #1356

This commit is contained in:
j 2013-03-03 08:22:46 +00:00
parent 6236a296be
commit 74511f85d6
10 changed files with 1682 additions and 701 deletions

View file

@ -20,16 +20,21 @@ limitations under the License.
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title></title> <title></title>
<link rel="stylesheet" href="/static/pdf.js/viewer.css"/> <link rel="stylesheet" href="/static/pdf.js/viewer.css"/>
<script type="text/javascript" src="/static/oxjs/build/Ox.js"></script> <script type="text/javascript" src="/static/oxjs/build/Ox.js"></script>
<script type="text/javascript" src="/static/oxjs/source/Ox.UI/js/Core/Message.js"></script> <script type="text/javascript" src="/static/oxjs/source/Ox.UI/js/Core/Message.js"></script>
<script type="text/javascript" src="/static/pdf.js/compatibility.js"></script> <script type="text/javascript" src="/static/pdf.js/compatibility.js"></script>
<!-- This snippet is used in production, see Makefile --> <!-- This snippet is used in production, see Makefile -->
<link rel="resource" type="application/l10n" href="/static/pdf.js/locale/locale.properties"/> <link rel="resource" type="application/l10n" href="/static/pdf.js/locale/locale.properties"/>
<script type="text/javascript" src="/static/pdf.js/l10n.js"></script> <script type="text/javascript" src="/static/pdf.js/l10n.js"></script>
<script type="text/javascript" src="/static/pdf.js/pdf.js"></script> <script type="text/javascript" src="/static/pdf.js/pdf.js"></script>
<script type="text/javascript" src="/static/pdf.js/debugger.js"></script> <script type="text/javascript" src="/static/pdf.js/debugger.js"></script>
<script type="text/javascript"> <script type="text/javascript">
var DEFAULT_URL = '{{url}}', var DEFAULT_URL = '{{url}}',
@ -37,8 +42,10 @@ limitations under the License.
editable = {{editable|safe}}; editable = {{editable|safe}};
</script> </script>
<script type="text/javascript" src="/static/pdf.js/embeds.js"></script> <script type="text/javascript" src="/static/pdf.js/embeds.js"></script>
<script type="text/javascript" src="/static/pdf.js/viewer.js"></script> <script type="text/javascript" src="/static/pdf.js/viewer.js"></script>
<link rel="stylesheet" type="text/css" href="/static/pdf.js/css/videopdf.css"/> <link rel="stylesheet" type="text/css" href="/static/pdf.js/css/videopdf.css"/>
</head> </head>
<body> <body>
@ -132,11 +139,11 @@ limitations under the License.
<div class="outerCenter"> <div class="outerCenter">
<div class="innerCenter" id="toolbarViewerMiddle"> <div class="innerCenter" id="toolbarViewerMiddle">
<div class="splitToolbarButton"> <div class="splitToolbarButton">
<button class="toolbarButton zoomOut" id="zoom_out" title="Zoom Out" tabindex="8" data-l10n-id="zoom_out"> <button class="toolbarButton zoomOut" title="Zoom Out" tabindex="8" data-l10n-id="zoom_out">
<span data-l10n-id="zoom_out_label">Zoom Out</span> <span data-l10n-id="zoom_out_label">Zoom Out</span>
</button> </button>
<div class="splitToolbarButtonSeparator"></div> <div class="splitToolbarButtonSeparator"></div>
<button class="toolbarButton zoomIn" id="zoom_in" title="Zoom In" tabindex="9" data-l10n-id="zoom_in"> <button class="toolbarButton zoomIn" title="Zoom In" tabindex="9" data-l10n-id="zoom_in">
<span data-l10n-id="zoom_in_label">Zoom In</span> <span data-l10n-id="zoom_in_label">Zoom In</span>
</button> </button>
</div> </div>
@ -205,3 +212,4 @@ limitations under the License.
<div id="printContainer"></div> <div id="printContainer"></div>
</body> </body>
</html> </html>

View file

@ -1,124 +0,0 @@
# Copyright 2012 Mozilla Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Main toolbar buttons (tooltips and alt text for images)
previous.title=Página anterior
previous_label=Anterior
next.title=Página siguiente
next_label=Siguiente
# LOCALIZATION NOTE (page_label, page_of):
# These strings are concatenated to form the "Page: X of Y" string.
# Do not translate "{{pageCount}}", it will be substituted with a number
# representing the total number of pages.
page_label=Página:
page_of=of {{pageCount}}
zoom_out.title=Reducir
zoom_out_label=Reducir
zoom_in.title=Aumentar
zoom_in_label=Aumentar
zoom.title=Tamaño
print.title=Imprimir
print_label=Imprimir
presentation_mode.title=Cambiar al modo de presentación
presentation_mode_label=Modo de presentación
open_file.title=Abrir archivo
open_file_label=Abrir
download.title=Descargar
download_label=Descargar
bookmark.title=Vista actual (copiar o abrir en una nueva ventana)
bookmark_label=Vista actual
# Tooltips and alt text for side panel toolbar buttons
# (the _label strings are alt text for the buttons, the .title strings are
# tooltips)
toggle_sidebar.title=Activar barra lateral
toggle_sidebar_label=Activar barra lateral
outline.title=Mostrar el esquema del documento
outline_label=Esquema del documento
thumbs.title=Mostrar miniaturas
thumbs_label=Miniaturas
findbar.title=Buscar en el documento
findbar_label=Buscar
# Document outline messages
no_outline=No hay esquema disponible
# Thumbnails panel item (tooltip and alt text for images)
# LOCALIZATION NOTE (thumb_page_title): "{{page}}" will be replaced by the page
# number.
thumb_page_title=Página {{page}}
# LOCALIZATION NOTE (thumb_page_canvas): "{{page}}" will be replaced by the page
# number.
thumb_page_canvas=Miniatura o página {{page}}
# Context menu
first_page.label=Ir a la primera página
last_page.label=Ir a la última página
page_rotate_cw.label=Girar hacia la derecha
page_rotate_ccw.label=Girar hacia la izquierda
# Find panel button title and messages
find_label=Buscar:
find_previous.title=Ir a la anterior frase encontrada
find_previous_label=Anterior
find_next.title=Ir a la siguiente frase encontrada
find_next_label=Siguiente
find_highlight=Marcar todo
find_match_case_label=Coincidir con mayúsculas y minúsculas
find_reached_top=Inicio del documento, se continúa desde el final
find_reached_bottom=Final del documento, se continúa desde el inicio
find_not_found=No se encontró la frase
# Error panel labels
error_more_info=Más información
error_less_info=Menos información
error_close=Cerrar
# LOCALIZATION NOTE (error_version_info): "{{version}}" and "{{build}}" will be
# replaced by the PDF.JS version and build ID.
error_version_info=PDF.js v{{version}} (compilación: {{build}})
# LOCALIZATION NOTE (error_message): "{{message}}" will be replaced by an
# english string describing the error.
error_message=Mensaje: {{message}}
# LOCALIZATION NOTE (error_stack): "{{stack}}" will be replaced with a stack
# trace.
error_stack=Pila: {{stack}}
# LOCALIZATION NOTE (error_file): "{{file}}" will be replaced with a filename
error_file=Archivo: {{file}}
# LOCALIZATION NOTE (error_line): "{{line}}" will be replaced with a line number
error_line=Línea: {{line}}
rendering_error=Ocurrió un error al interpretar la página.
# Predefined zoom values
page_scale_width=Ancho de página
page_scale_fit=Ajustar a la página
page_scale_auto=Ampliación automática
page_scale_actual=Tamaño real
# Loading indicator messages
loading_error_indicator=Error
loading_error=Ocurrió un error al cargar el PDF.
invalid_file_error=Archivo PDF inválido o corrupto.
missing_file_error=Archivo PDF faltante.
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
# "{{type}}" will be replaced with an annotation type from a list defined in
# the PDF spec (32000-1:2008 Table 169 Annotation types).
# Some common types are e.g.: "Check", "Text", "Comment", "Note"
text_annotation_type=[Anotación {{type}}]
request_password=El archivo PDF está protegido por contraseña:
printing_not_supported=Advertencia: la impresión no está completamente soportada en este navegador.
web_fonts_disabled=Las tipografías web están deshabilitadas: no es posible utilizar tipografías PDF incrustadas.

View file

@ -111,7 +111,6 @@ page_scale_actual=実際のサイズ
loading_error_indicator=エラー loading_error_indicator=エラー
loading_error=PDFの読み込み中にエラーが発生しました loading_error=PDFの読み込み中にエラーが発生しました
invalid_file_error=無効または破損したPDFファイル invalid_file_error=無効または破損したPDFファイル
missing_file_error=PDF ファイルが見つかりません。
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip. # LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
# "{{type}}" will be replaced with an annotation type from a list defined in # "{{type}}" will be replaced with an annotation type from a list defined in

View file

@ -19,9 +19,6 @@
[es] [es]
@import url(es/viewer.properties) @import url(es/viewer.properties)
[es-MX]
@import url(es-MX/viewer.properties)
[fi] [fi]
@import url(fi/viewer.properties) @import url(fi/viewer.properties)

View file

@ -38,14 +38,14 @@ open_file.title=Bestand openen
open_file_label=Openen open_file_label=Openen
download.title=Downloaden download.title=Downloaden
download_label=Downloaden download_label=Downloaden
bookmark.title=Huidige weergave (kopiëren of openen in nieuw venster) bookmark.title=Huidige weergave (kopiëren of openen in nieuw venster)
bookmark_label=Huidige weergave bookmark_label=Huidige weergave
# Tooltips and alt text for side panel toolbar buttons # Tooltips and alt text for side panel toolbar buttons
# (the _label strings are alt text for the buttons, the .title strings are # (the _label strings are alt text for the buttons, the .title strings are
# tooltips) # tooltips)
toggle_sidebar.title=Zijbalk tonen/verbergen toggle_slider.title=Zijbalk tonen/verbergen
toggle_sidebar_label=Zijbalk tonen/verbergen toggle_slider_label=Zijbalk tonen/verbergen
outline.title=Documentstructuur tonen outline.title=Documentstructuur tonen
outline_label=Documentstructuur outline_label=Documentstructuur
thumbs.title=Miniaturen tonen thumbs.title=Miniaturen tonen
@ -78,17 +78,17 @@ find_next.title=Het volgende voorkomen van de tekst zoeken
find_next_label=Volgende find_next_label=Volgende
find_highlight=Alles markeren find_highlight=Alles markeren
find_match_case_label=Hoofdlettergevoelig find_match_case_label=Hoofdlettergevoelig
find_reached_top=Bovenkant van de pagina bereikt, doorgegaan vanaf de onderkant find_wrapped_to_bottom=Onderkant van de pagina bereikt, doorgegaan vanaf de onderkant
find_reached_bottom=Onderkant van de pagina bereikt, doorgegaan vanaf de bovenkant find_wrapped_to_top=Onderkant van de pagina bereikt, doorgegaan vanaf de bovenkant
find_not_found=Tekst niet gevonden find_not_found=Tekst niet gevonden
# Error panel labels # Error panel labels
error_more_info=Meer informatie error_more_info=Meer informatie
error_less_info=Minder informatie error_less_info=Minder informatie
error_close=Sluiten error_close=Sluiten
# LOCALIZATION NOTE (error_version_info): "{{version}}" and "{{build}}" will be # LOCALIZATION NOTE (error_build): "{{build}}" will be replaced by the PDF.JS
# replaced by the PDF.JS version and build ID. # build ID.
error_version_info=PDF.js versie {{version}} (build {{build}}) error_build=PDF.JS-build: {{build}}
# LOCALIZATION NOTE (error_message): "{{message}}" will be replaced by an # LOCALIZATION NOTE (error_message): "{{message}}" will be replaced by an
# english string describing the error. # english string describing the error.
error_message=Bericht: {{message}} error_message=Bericht: {{message}}
@ -110,8 +110,6 @@ page_scale_actual=Werkelijke grootte
# Loading indicator messages # Loading indicator messages
loading_error_indicator=Fout loading_error_indicator=Fout
loading_error=Er is een fout opgetreden bij het laden van de PDF. loading_error=Er is een fout opgetreden bij het laden van de PDF.
invalid_file_error=Ongeldig of corrupt PDF-bestand.
missing_file_error=Ontbrekend PDF-bestand.
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip. # LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
# "{{type}}" will be replaced with an annotation type from a list defined in # "{{type}}" will be replaced with an annotation type from a list defined in
@ -121,4 +119,3 @@ text_annotation_type=[{{type}}-aantekening]
request_password=Dit PDF-bestand is beveiligd met een wachtwoord: request_password=Dit PDF-bestand is beveiligd met een wachtwoord:
printing_not_supported=Waarschuwing: afdrukken wordt niet volledig ondersteund door deze browser. printing_not_supported=Waarschuwing: afdrukken wordt niet volledig ondersteund door deze browser.
web_fonts_disabled=Weblettertypen zijn uitgeschakeld: kan geen ingebakken PDF-lettertypen gebruiken.

View file

@ -32,8 +32,8 @@ zoom_in_label=Zooma in
zoom.title=Zooma zoom.title=Zooma
print.title=Skriv ut print.title=Skriv ut
print_label=Skriv ut print_label=Skriv ut
presentation_mode.title=Presentationsläge presentation_mode.title=Växla till presentationsläge
presentation_mode_label=Presentationsläge presentation_mode_label=Presentatationsläge
open_file.title=Öppna fil open_file.title=Öppna fil
open_file_label=Öppna open_file_label=Öppna
download.title=Ladda ner download.title=Ladda ner
@ -44,17 +44,17 @@ bookmark_label=Aktuell vy
# Tooltips and alt text for side panel toolbar buttons # Tooltips and alt text for side panel toolbar buttons
# (the _label strings are alt text for the buttons, the .title strings are # (the _label strings are alt text for the buttons, the .title strings are
# tooltips) # tooltips)
toggle_sidebar.title=Visa/Dölj sidopanel toggle_slider.title=Visa/Dölj panel
toggle_sidebar_label=Visa/Dölj sidopanel toggle_slider_label=Visa/Dölj panel
outline.title=Visa bokmärken outline.title=Visa dokumentdisposition
outline_label=Bokmärken outline_label=Dokumentdisposition
thumbs.title=Visa sidminiatyrer thumbs.title=Visa miniatyrer
thumbs_label=Sidminiatyrer thumbs_label=Miniatyrer
findbar.title=Sök i dokumentet findbar.title=Sök i dokumentet
findbar_label=Sök findbar_label=Sök
# Document outline messages # Document outline messages
no_outline=Inga bokmärken tillgängliga no_outline=Ingen dokumentdisposition tillgänglig
# Thumbnails panel item (tooltip and alt text for images) # Thumbnails panel item (tooltip and alt text for images)
# LOCALIZATION NOTE (thumb_page_title): "{{page}}" will be replaced by the page # LOCALIZATION NOTE (thumb_page_title): "{{page}}" will be replaced by the page
@ -77,18 +77,18 @@ find_previous_label=Föregående
find_next.title=Hitta nästa förekomst av frasen find_next.title=Hitta nästa förekomst av frasen
find_next_label=Nästa find_next_label=Nästa
find_highlight=Markera alla find_highlight=Markera alla
find_match_case_label=Matcha VERSALER/gemener find_match_case_label=Matcha versaler/gemener
find_reached_top=Kommit till början av dokumentet, börjat om find_wrapped_to_bottom=Nådde toppen av sidan, fortsätter från slutet
find_reached_bottom=Kommit till slutet av dokumentet, börjat om find_wrapped_to_top=Nådde slutet av sidan, fortsätter från toppen
find_not_found=Frasen hittades inte find_not_found=Frasen hittades inte
# Error panel labels # Error panel labels
error_more_info=Mer information error_more_info=Mer information
error_less_info=Mindre information error_less_info=Mindre information
error_close=Stäng error_close=Stäng
# LOCALIZATION NOTE (error_version_info): "{{version}}" and "{{build}}" will be # LOCALIZATION NOTE (error_build): "{{build}}" will be replaced by the PDF.JS
# replaced by the PDF.JS version and build ID. # build ID.
error_version_info=PDF.js v{{version}} (bygge: {{build}}) error_build=PDF.JS Bygge: {{build}}
# LOCALIZATION NOTE (error_message): "{{message}}" will be replaced by an # LOCALIZATION NOTE (error_message): "{{message}}" will be replaced by an
# english string describing the error. # english string describing the error.
error_message=Meddelande: {{message}} error_message=Meddelande: {{message}}
@ -103,22 +103,20 @@ rendering_error=Ett fel inträffade när sidan renderades.
# Predefined zoom values # Predefined zoom values
page_scale_width=Sidbredd page_scale_width=Sidbredd
page_scale_fit=Helsida page_scale_fit=Passa sida
page_scale_auto=Automatisk zoom page_scale_auto=Automatisk Zoom
page_scale_actual=Faktisk storlek page_scale_actual=Faktisk storlek
# Loading indicator messages # Loading indicator messages
loading_error_indicator=Fel loading_error_indicator=Fel
loading_error=Ett fel inträffade när PDF-filen laddades. loading_error=Ett fel inträffade när PDFen skulle laddas.
invalid_file_error=Ogiltig eller korrupt PDF-fil. invalid_file_error=Ogiltig eller korrupt PDF-fil.
missing_file_error=PDF-filen saknas.
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip. # LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
# "{{type}}" will be replaced with an annotation type from a list defined in # "{{type}}" will be replaced with an annotation type from a list defined in
# the PDF spec (32000-1:2008 Table 169 Annotation types). # the PDF spec (32000-1:2008 Table 169 Annotation types).
# Some common types are e.g.: "Check", "Text", "Comment", "Note" # Some common types are e.g.: "Check", "Text", "Comment", "Note"
text_annotation_type=[{{type}}-anteckning] text_annotation_type=[{{type}} Annotering]
request_password=PDF-filen är lösenordsskyddad: request_password=PDFen är skyddad av lösenord:
printing_not_supported=Varning: Utskrifter stöds inte fullt ut av denna webbläsare. printing_not_supported=Varning: Utskrifter stöds inte fullt ut av denna webbläsare.
web_fonts_disabled=Webbtypsnitt är inaktiverade: Typsnitt inkluderade i PDF-filer kan ej användas.

View file

@ -44,8 +44,8 @@ bookmark_label=当前视图
# Tooltips and alt text for side panel toolbar buttons # Tooltips and alt text for side panel toolbar buttons
# (the _label strings are alt text for the buttons, the .title strings are # (the _label strings are alt text for the buttons, the .title strings are
# tooltips) # tooltips)
toggle_sidebar.title=切换侧栏 toggle_slider.title=切换侧栏
toggle_sidebar_label=切换侧栏 toggle_slider_label=切换侧栏
outline.title=显示文档大纲 outline.title=显示文档大纲
outline_label=文档大纲 outline_label=文档大纲
thumbs.title=显示缩略图 thumbs.title=显示缩略图
@ -111,7 +111,6 @@ page_scale_actual=实际大小
loading_error_indicator=错误 loading_error_indicator=错误
loading_error=加载 PDF 文件时出错。 loading_error=加载 PDF 文件时出错。
invalid_file_error=PDF 文件无效或已损坏。 invalid_file_error=PDF 文件无效或已损坏。
missing_file_error=缺失 PDF 文件。
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip. # LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
# "{{type}}" will be replaced with an annotation type from a list defined in # "{{type}}" will be replaced with an annotation type from a list defined in

File diff suppressed because it is too large Load diff

View file

@ -1165,7 +1165,6 @@ canvas {
bottom: 0; bottom: 0;
color: #000; color: #000;
font-family: sans-serif; font-family: sans-serif;
overflow: hidden;
} }
.imageLayer { .imageLayer {
position: absolute; position: absolute;

View file

@ -890,16 +890,28 @@ var PDFView = {
PDFView.loadingBar = new ProgressBar('#loadingBar', {}); PDFView.loadingBar = new ProgressBar('#loadingBar', {});
} }
window.addEventListener('message', function window_message(e) { function windowMessage(e) {
var args = e.data; var args = e.data;
if (typeof args !== 'object' || !('pdfjsLoadAction' in args)) if (typeof args !== 'object' || !('pdfjsLoadAction' in args))
return; return;
switch (args.pdfjsLoadAction) { switch (args.pdfjsLoadAction) {
case 'supportsChunkedLoading':
window.removeEventListener('message', windowMessage);
PDFView.open({
url: args.pdfUrl,
chunkedChromeLoading: true,
totalLength: args.totalLength,
loadedBegin: args.loadedBegin,
loadedChunk: args.loadedChunk
}, 0);
break;
case 'progress': case 'progress':
PDFView.progress(args.loaded / args.total); PDFView.progress(args.loaded / args.total);
break; break;
case 'complete': case 'complete':
// TODO(mack): remove the listener when file loading is complete
// window.removeEventListener('message', windowMessage);
if (!args.data) { if (!args.data) {
PDFView.error(mozL10n.get('loading_error', null, PDFView.error(mozL10n.get('loading_error', null,
'An error occurred while loading the PDF.'), e); 'An error occurred while loading the PDF.'), e);
@ -908,7 +920,8 @@ var PDFView = {
PDFView.open(args.data, 0); PDFView.open(args.data, 0);
break; break;
} }
}); }
window.addEventListener('message', windowMessage);
FirefoxCom.requestSync('initPassiveLoading', null); FirefoxCom.requestSync('initPassiveLoading', null);
}, },
@ -934,6 +947,10 @@ var PDFView = {
parameters.url = url; parameters.url = url;
} else if (url && 'byteLength' in url) { // ArrayBuffer } else if (url && 'byteLength' in url) { // ArrayBuffer
parameters.data = url; parameters.data = url;
} else {
this.setTitleUsingUrl(url.url);
parameters = url;
parameters.password = password;
} }
if (!PDFView.loadingBar) { if (!PDFView.loadingBar) {
@ -1175,6 +1192,7 @@ var PDFView = {
container.removeChild(container.lastChild); container.removeChild(container.lastChild);
var pagesCount = pdfDocument.numPages; var pagesCount = pdfDocument.numPages;
var id = pdfDocument.fingerprint; var id = pdfDocument.fingerprint;
document.getElementById('numPages').textContent = document.getElementById('numPages').textContent =
mozL10n.get('page_of', {pageCount: pagesCount}, 'of {{pageCount}}'); mozL10n.get('page_of', {pageCount: pagesCount}, 'of {{pageCount}}');
@ -1189,29 +1207,74 @@ var PDFView = {
var pages = this.pages = []; var pages = this.pages = [];
this.pageText = []; this.pageText = [];
this.startedTextExtraction = false; this.startedTextExtraction = false;
var pagesRefMap = {}; var pagesRefMap = this.pagesRefMap = {};
var thumbnails = this.thumbnails = []; var thumbnails = this.thumbnails = [];
var pagePromises = []; var pagePromises = [];
for (var i = 1; i <= pagesCount; i++)
pagePromises.push(pdfDocument.getPage(i));
var self = this;
var pagesPromise = PDFJS.Promise.all(pagePromises);
pagesPromise.then(function(promisedPages) {
for (var i = 1; i <= pagesCount; i++) {
var page = promisedPages[i - 1];
var pageView = new PageView(container, page, i, scale,
page.stats, self.navigateTo.bind(self));
var thumbnailView = new ThumbnailView(thumbsView, page, i);
bindOnAfterDraw(pageView, thumbnailView);
pages.push(pageView); var firstPageLoaded = true;
thumbnails.push(thumbnailView);
var pageRef = page.ref; var self = this;
pagesRefMap[pageRef.num + ' ' + pageRef.gen + ' R'] = i; for (var pageIdx = 0; pageIdx < pagesCount; ++pageIdx) {
var pageNum = pageIdx + 1;
var pagePromise = pdfDocument.getPage(pageNum);
pagePromise.then(function(page) {
if (firstPageLoaded) {
var pagesFrag = document.createDocumentFragment();
// TODO(mack): clone
var defaultView = page.view;
for (var pageIdx = 0; pageIdx < pagesCount; ++pageIdx) {
var pageNum = pageIdx + 1;
var pageView = new PageView(container, pageNum, scale,
self.navigateTo.bind(self), defaultView);
pages[pageIdx] = pageView;
pagesFrag.appendChild(pageView.element);
}
container.appendChild(pagesFrag);
var storedHash = null;
if (store.get('exists', false)) {
var page_ = store.get('page', '1');
var zoom = store.get('zoom', PDFView.currentScale);
var left = store.get('scrollLeft', '0');
var top = store.get('scrollTop', '0');
storedHash =
'page=' + page_ + '&zoom=' + zoom + ',' + left +',' + top;
} }
self.pagesRefMap = pagesRefMap; self.setInitialView(storedHash, scale);
firstPageLoaded = false;
}
var pageIdx = page.pageInfo.pageIndex;
var pageNum = pageIdx + 1;
var pageView = pages[pageIdx];
pageView.setPdfPage(page);
pageView.setStats(page.stats);
var thumbnailView = new ThumbnailView(thumbsView, page, pageNum);
bindOnAfterDraw(pageView, thumbnailView);
pages[pageIdx] = pageView;
thumbnails[pageIdx] = thumbnailView;
var pageRef = page.ref;
pagesRefMap[pageRef.num + ' ' + pageRef.gen + ' R'] = pageNum;
var visiblePages = self.visiblePages;
var firstNum = visiblePages.first.id;
var lastNum = visiblePages.last.id;
if (pageNum >= firstNum && pageNum <= lastNum) {
// TODO(mack): This logic could probably be better, as it's probably
// going in here more often than necessary
self.renderHighestPriority();
//updateViewarea();
}
}); });
pagePromises.push(pagePromise);
}
var pagesPromise = PDFJS.Promise.all(pagePromises);
var destinationsPromise = pdfDocument.getDestinations(); var destinationsPromise = pdfDocument.getDestinations();
destinationsPromise.then(function(destinations) { destinationsPromise.then(function(destinations) {
@ -1225,20 +1288,6 @@ var PDFView = {
pdfDocument.getOutline().then(function(outline) { pdfDocument.getOutline().then(function(outline) {
self.outline = new DocumentOutlineView(outline); self.outline = new DocumentOutlineView(outline);
}); });
var storedHash = null;
if (store.get('exists', false)) {
var page = store.get('page', '1');
var zoom = store.get('zoom', PDFView.currentScale);
var left = store.get('scrollLeft', '0');
var top = store.get('scrollTop', '0');
if(document.location.hash) {
page = document.location.hash.substring(1);
}
storedHash = 'page=' + page + '&zoom=' + zoom + ',' + left + ',' + top;
}
self.setInitialView(storedHash, scale);
}); });
pdfDocument.getMetadata().then(function(data) { pdfDocument.getMetadata().then(function(data) {
@ -1296,8 +1345,8 @@ var PDFView = {
renderHighestPriority: function pdfViewRenderHighestPriority() { renderHighestPriority: function pdfViewRenderHighestPriority() {
// Pages have a higher priority than thumbnails, so check them first. // Pages have a higher priority than thumbnails, so check them first.
var visiblePages = this.getVisiblePages(); this.visiblePages = this.getVisiblePages();
var pageView = this.getHighestPriority(visiblePages, this.pages, var pageView = this.getHighestPriority(this.visiblePages, this.pages,
this.pageViewScroll.down); this.pageViewScroll.down);
if (pageView) { if (pageView) {
this.renderView(pageView, 'page'); this.renderView(pageView, 'page');
@ -1330,7 +1379,7 @@ var PDFView = {
} }
for (var i = 0; i < numVisible; ++i) { for (var i = 0; i < numVisible; ++i) {
var view = visibleViews[i].view; var view = visibleViews[i].view;
if (!this.isViewFinished(view)) if (!this.isViewRenderable(view))
return view; return view;
} }
@ -1338,19 +1387,22 @@ var PDFView = {
if (scrolledDown) { if (scrolledDown) {
var nextPageIndex = visible.last.id; var nextPageIndex = visible.last.id;
// ID's start at 1 so no need to add 1. // ID's start at 1 so no need to add 1.
if (views[nextPageIndex] && !this.isViewFinished(views[nextPageIndex])) if (views[nextPageIndex] && !this.isViewRenderable(views[nextPageIndex]))
return views[nextPageIndex]; return views[nextPageIndex];
} else { } else {
var previousPageIndex = visible.first.id - 2; var previousPageIndex = visible.first.id - 2;
if (views[previousPageIndex] && if (views[previousPageIndex] &&
!this.isViewFinished(views[previousPageIndex])) !this.isViewRenderable(views[previousPageIndex]))
return views[previousPageIndex]; return views[previousPageIndex];
} }
// Everything that needs to be rendered has been. // Everything that needs to be rendered has been.
return false; return false;
}, },
isViewFinished: function pdfViewNeedsRendering(view) { isViewRenderable: function pdfViewNeedsRendering(view) {
if (view instanceof PageView && !view.pdfPage) {
return false;
}
return view.renderingState === RenderingStates.FINISHED; return view.renderingState === RenderingStates.FINISHED;
}, },
@ -1711,14 +1763,30 @@ var PDFView = {
} }
}; };
var PageView = function pageView(container, pdfPage, id, scale, var PageView = function pageView(container, id, scale,
stats, navigateTo) { navigateTo, defaultView) {
this.id = id; this.id = id;
this.pdfPage = pdfPage; //this.pdfPage = pdfPage;
this.rotation = 0; this.rotation = 0;
this.scale = scale || 1.0; this.scale = scale || 1.0;
this.viewport = this.pdfPage.getViewport(this.scale, this.pdfPage.rotate); //this.viewport = this.pdfPage.getViewport(this.scale, this.pdfPage.rotate);
this.defaultView = defaultView;
this.getViewport = function pageViewGetViewport() {
var view;
var totalRotation;
if (this.pdfPage) {
totalRotation = (this.rotation + this.pdfPage.rotate) % 360;
view = this.pdfPage.view;
} else {
totalRotation = this.rotation;
view = this.defaultView;
}
return new PDFJS.PageViewport(view, this.scale, totalRotation, 0, 0);
};
this.viewport = this.getViewport();
this.renderingState = RenderingStates.INITIAL; this.renderingState = RenderingStates.INITIAL;
this.resume = null; this.resume = null;
@ -1730,13 +1798,34 @@ var PageView = function pageView(container, pdfPage, id, scale,
anchor.name = '' + this.id; anchor.name = '' + this.id;
var div = this.el = document.createElement('div'); var div = this.el = document.createElement('div');
//var div = this.el = element;
div.id = 'pageContainer' + this.id; div.id = 'pageContainer' + this.id;
div.className = 'page'; div.className = 'page';
div.style.width = Math.floor(this.viewport.width) + 'px'; div.style.width = Math.floor(this.viewport.width) + 'px';
div.style.height = Math.floor(this.viewport.height) + 'px'; div.style.height = Math.floor(this.viewport.height) + 'px';
container.appendChild(anchor); this.container = container;
container.appendChild(div); //this.container.appendChild(anchor);
//this.container.appendChild(div);
var docFrag = document.createDocumentFragment();
docFrag.appendChild(anchor);
docFrag.appendChild(div);
Object.defineProperty(this, 'element', {
get: function PlaceholderPageView_getElement() {
return docFrag;
},
enumerable: true
});
this.setPdfPage = function pageViewSetPdfPage(pdfPage) {
this.pdfPage = pdfPage;
};
this.setStats = function pageViewSetStats(stats) {
this.stats = stats;
};
this.destroy = function pageViewDestroy() { this.destroy = function pageViewDestroy() {
this.update(); this.update();
@ -1752,9 +1841,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
} }
this.scale = scale || this.scale; this.scale = scale || this.scale;
var viewport = this.getViewport();
var totalRotation = (this.rotation + this.pdfPage.rotate) % 360;
var viewport = this.pdfPage.getViewport(this.scale, totalRotation);
this.viewport = viewport; this.viewport = viewport;
div.style.width = Math.floor(viewport.width) + 'px'; div.style.width = Math.floor(viewport.width) + 'px';
@ -1960,6 +2047,12 @@ var PageView = function pageView(container, pdfPage, id, scale,
}; };
this.draw = function pageviewDraw(callback) { this.draw = function pageviewDraw(callback) {
if (!this.pdfPage) {
console.log('Cannot draw without page');
return;
}
var pdfPage = this.pdfPage;
if (this.renderingState !== RenderingStates.INITIAL) { if (this.renderingState !== RenderingStates.INITIAL) {
console.error('Must be in new state before drawing'); console.error('Must be in new state before drawing');
} }
@ -2017,6 +2110,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
ctx.scale(outputScale.sx, outputScale.sy); ctx.scale(outputScale.sx, outputScale.sy);
} }
// Rendering area // Rendering area
var self = this; var self = this;
@ -2093,6 +2187,12 @@ var PageView = function pageView(container, pdfPage, id, scale,
this.beforePrint = function pageViewBeforePrint() { this.beforePrint = function pageViewBeforePrint() {
var pdfPage = this.pdfPage; var pdfPage = this.pdfPage;
if (!pdfPage) {
console.log('Pdf page has not been rendered and thus cannot be printed');
return;
}
var viewport = pdfPage.getViewport(1); var viewport = pdfPage.getViewport(1);
// Use the same hack we use for high dpi displays for printing to get better // Use the same hack we use for high dpi displays for printing to get better
// output until bug 811002 is fixed in FF. // output until bug 811002 is fixed in FF.
@ -2143,6 +2243,10 @@ var PageView = function pageView(container, pdfPage, id, scale,
}; };
this.updateStats = function pageViewUpdateStats() { this.updateStats = function pageViewUpdateStats() {
if (!this.stats) {
console.log('No stats available');
}
if (PDFJS.pdfBug && Stats.enabled) { if (PDFJS.pdfBug && Stats.enabled) {
var stats = this.stats; var stats = this.stats;
Stats.add(this.id, stats); Stats.add(this.id, stats);
@ -3043,9 +3147,6 @@ window.addEventListener('scalechange', function scalechange(evt) {
customScaleOption.selected = true; customScaleOption.selected = true;
} }
document.getElementById('zoom_out').disabled = (evt.scale === MIN_SCALE);
document.getElementById('zoom_in').disabled = (evt.scale === MAX_SCALE);
updateViewarea(); updateViewarea();
}, true); }, true);
@ -3056,7 +3157,10 @@ window.addEventListener('pagechange', function pagechange(evt) {
var selected = document.querySelector('.thumbnail.selected'); var selected = document.querySelector('.thumbnail.selected');
if (selected) if (selected)
selected.classList.remove('selected'); selected.classList.remove('selected');
var thumbnail = document.getElementById('thumbnailContainer' + page); var thumbnail = document.getElementById('thumbnailContainer' + page);
// FIXME(mack): remove checking if thumbnail is null hack
if (thumbnail) {
thumbnail.classList.add('selected'); thumbnail.classList.add('selected');
var visibleThumbs = PDFView.getVisibleThumbs(); var visibleThumbs = PDFView.getVisibleThumbs();
var numVisibleThumbs = visibleThumbs.views.length; var numVisibleThumbs = visibleThumbs.views.length;
@ -3069,6 +3173,7 @@ window.addEventListener('pagechange', function pagechange(evt) {
if (page <= first || page >= last) if (page <= first || page >= last)
scrollIntoView(thumbnail); scrollIntoView(thumbnail);
} }
}
} }
document.getElementById('previous').disabled = (page <= 1); document.getElementById('previous').disabled = (page <= 1);
@ -3195,12 +3300,6 @@ window.addEventListener('keydown', function keydown(evt) {
PDFView.page--; PDFView.page--;
handled = true; handled = true;
break; break;
case 27: // esc key
if (!PDFView.supportsIntegratedFind && PDFFindBar.opened) {
PDFFindBar.close();
handled = true;
}
break;
case 40: // down arrow case 40: // down arrow
case 34: // pg down case 34: // pg down
case 32: // spacebar case 32: // spacebar