mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-16 12:12:57 -06:00
[MIG] attachment_preview to version 10.0
This commit is contained in:
parent
295a6dc320
commit
a83f972c2a
@ -6,6 +6,7 @@ addons:
|
|||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
- expect-dev # provides unbuffer utility
|
- expect-dev # provides unbuffer utility
|
||||||
|
- python-magic
|
||||||
|
|
||||||
language: python
|
language: python
|
||||||
|
|
||||||
|
@ -1,15 +1,48 @@
|
|||||||
|
===================
|
||||||
Preview attachments
|
Preview attachments
|
||||||
===================
|
===================
|
||||||
|
|
||||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
!! This file is generated by oca-gen-addon-readme !!
|
||||||
|
!! changes will be overwritten. !!
|
||||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||||
|
:target: https://odoo-community.org/page/development-status
|
||||||
|
:alt: Beta
|
||||||
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github
|
||||||
|
:target: https://github.com/OCA/knowledge/tree/10.0/attachment_preview
|
||||||
|
:alt: OCA/knowledge
|
||||||
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||||
|
:target: https://translation.odoo-community.org/projects/knowledge-10-0/knowledge-10-0-attachment_preview
|
||||||
|
:alt: Translate me on Weblate
|
||||||
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/118/10.0
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
|
||||||
|
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||||
|
|
||||||
This addon allows to preview attachments supported by http://viewerjs.org.
|
This addon allows to preview attachments supported by http://viewerjs.org.
|
||||||
|
|
||||||
Currently, that's most Libreoffice files and PDFs.
|
Currently, that's most Libreoffice files and PDFs.
|
||||||
|
|
||||||
|
.. image:: /attachment_preview/static/description/screenshot-split.png
|
||||||
|
:alt: Screenshot of split form view
|
||||||
|
:width: 100%
|
||||||
|
|
||||||
|
**Table of contents**
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
============
|
============
|
||||||
|
|
||||||
For filetype recognition, you'll get the best results by installing
|
For filetype recognition, you'll get the best results by installing
|
||||||
``python-magic``::
|
``python-magic``:
|
||||||
|
|
||||||
sudo apt-get install python-magic
|
sudo apt-get install python-magic
|
||||||
|
|
||||||
@ -17,30 +50,60 @@ Usage
|
|||||||
=====
|
=====
|
||||||
|
|
||||||
The module adds a little print preview icon right of download links for
|
The module adds a little print preview icon right of download links for
|
||||||
attachments or binary fields.
|
attachments or binary fields. When a preview is opened from the attachments
|
||||||
|
menu it's shown next to the form view. From this screen you can navigate
|
||||||
|
through the attachments using the arrow buttons. Using the pop-out button
|
||||||
|
next to the navigational buttons you can open the preview in a separate window.
|
||||||
|
|
||||||
|
.. image:: /attachment_preview/static/description/screenshot-paginator.png
|
||||||
|
:alt: Screenshot navigator
|
||||||
|
|
||||||
|
Bug Tracker
|
||||||
|
===========
|
||||||
|
|
||||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_.
|
||||||
|
In case of trouble, please check there if your issue has already been reported.
|
||||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||||
|
`feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_preview%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
|
Do not contact contributors directly about support or help with technical issues.
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
* Therp BV
|
||||||
|
* Onestein
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Holger Brunn <hbrunn@therp.nl>
|
||||||
|
* Dennis Sluijk <d.sluijk@onestein.nl>
|
||||||
|
|
||||||
|
Other credits
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
Addon icon
|
Addon icon
|
||||||
----------
|
----------
|
||||||
|
|
||||||
* courtesy of http://commons.wikimedia.org/wiki/Crystal_Clear
|
* courtesy of http://commons.wikimedia.org/wiki/Crystal_Clear
|
||||||
|
|
||||||
Contributors
|
Maintainers
|
||||||
------------
|
~~~~~~~~~~~
|
||||||
|
|
||||||
* Holger Brunn <hbrunn@therp.nl>
|
|
||||||
|
|
||||||
Maintainer
|
|
||||||
----------
|
|
||||||
|
|
||||||
.. image:: http://odoo-community.org/logo.png
|
|
||||||
:alt: Odoo Community Association
|
|
||||||
:target: http://odoo-community.org
|
|
||||||
|
|
||||||
This module is maintained by the OCA.
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
|
.. image:: https://odoo-community.org/logo.png
|
||||||
|
:alt: Odoo Community Association
|
||||||
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
To contribute to this module, please visit http://odoo-community.org.
|
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
|
mission is to support the collaborative development of Odoo features and
|
||||||
|
promote its widespread use.
|
||||||
|
|
||||||
|
This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/10.0/attachment_preview>`_ project on GitHub.
|
||||||
|
|
||||||
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||||
|
@ -1,21 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2014 Therp BV (<http://therp.nl>)
|
||||||
##############################################################################
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
#
|
|
||||||
# OpenERP, Open Source Management Solution
|
from . import models
|
||||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
from . import model
|
|
||||||
|
@ -1,46 +1,23 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2014 Therp BV (<http://therp.nl>)
|
||||||
##############################################################################
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
#
|
|
||||||
# OpenERP, Open Source Management Solution
|
|
||||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
{
|
{
|
||||||
"name": "Preview attachments",
|
"name": "Preview attachments",
|
||||||
"version": "8.0.1.1.0",
|
"version": "10.0.1.3.0",
|
||||||
"author": "Therp BV,Odoo Community Association (OCA)",
|
"author": "Therp BV,"
|
||||||
|
"Onestein,"
|
||||||
|
"Odoo Community Association (OCA)",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"complexity": "normal",
|
"summary": 'Preview attachments supported by Viewer.js',
|
||||||
'summary': 'Preview attachments supported by Viewer.js',
|
|
||||||
"category": "Knowledge Management",
|
"category": "Knowledge Management",
|
||||||
"depends": [
|
"depends": [
|
||||||
'web',
|
'web',
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
"view/attachment_preview.xml",
|
"templates/assets.xml",
|
||||||
],
|
],
|
||||||
"qweb": [
|
"qweb": [
|
||||||
'static/src/xml/attachment_preview.xml',
|
'static/src/xml/attachment_preview.xml',
|
||||||
],
|
],
|
||||||
"test": [
|
"installable": True,
|
||||||
],
|
|
||||||
"auto_install": False,
|
|
||||||
'installable': False,
|
|
||||||
"application": False,
|
|
||||||
"external_dependencies": {
|
|
||||||
'python': [],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# OpenERP, Open Source Management Solution
|
|
||||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
from . import ir_attachment
|
|
@ -1,68 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# OpenERP, Open Source Management Solution
|
|
||||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as
|
|
||||||
# published by the Free Software Foundation, either version 3 of the
|
|
||||||
# License, or (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Affero General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
import collections
|
|
||||||
import os.path
|
|
||||||
import mimetypes
|
|
||||||
import base64
|
|
||||||
from openerp.osv.orm import Model
|
|
||||||
|
|
||||||
|
|
||||||
class IrAttachment(Model):
|
|
||||||
_inherit = 'ir.attachment'
|
|
||||||
|
|
||||||
def get_binary_extension(
|
|
||||||
self, cr, uid, model, ids, binary_field, filename_field=None,
|
|
||||||
context=None):
|
|
||||||
result = {}
|
|
||||||
for this in self.pool[model].browse(
|
|
||||||
cr, uid,
|
|
||||||
ids if isinstance(ids, collections.Iterable) else [ids],
|
|
||||||
context=context):
|
|
||||||
if not this.id:
|
|
||||||
result[this.id] = False
|
|
||||||
continue
|
|
||||||
extension = ''
|
|
||||||
if filename_field and this[filename_field]:
|
|
||||||
filename, extension = os.path.splitext(this[filename_field])
|
|
||||||
if not this[binary_field]:
|
|
||||||
result[this.id] = False
|
|
||||||
continue
|
|
||||||
if not extension:
|
|
||||||
try:
|
|
||||||
import magic
|
|
||||||
ms = magic.open(
|
|
||||||
hasattr(magic, 'MAGIC_MIME_TYPE') and
|
|
||||||
magic.MAGIC_MIME_TYPE or magic.MAGIC_MIME)
|
|
||||||
ms.load()
|
|
||||||
mimetype = ms.buffer(
|
|
||||||
base64.b64decode(this[binary_field]))
|
|
||||||
except ImportError:
|
|
||||||
(mimetype, encoding) = mimetypes.guess_type(
|
|
||||||
'data:;base64,' + this[binary_field], strict=False)
|
|
||||||
extension = mimetypes.guess_extension(
|
|
||||||
mimetype.split(';')[0], strict=False)
|
|
||||||
|
|
||||||
result[this.id] = (extension or '').lstrip('.').lower()
|
|
||||||
return result if isinstance(ids, collections.Iterable) else result[ids]
|
|
||||||
|
|
||||||
def get_attachment_extension(self, cr, uid, ids, context=None):
|
|
||||||
return self.get_binary_extension(
|
|
||||||
cr, uid, self._name, ids, 'datas', 'datas_fname', context=context)
|
|
4
attachment_preview/models/__init__.py
Normal file
4
attachment_preview/models/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Copyright 2014 Therp BV (<http://therp.nl>)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from . import ir_attachment
|
77
attachment_preview/models/ir_attachment.py
Normal file
77
attachment_preview/models/ir_attachment.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# Copyright 2014 Therp BV (<http://therp.nl>)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
import collections
|
||||||
|
import logging
|
||||||
|
import mimetypes
|
||||||
|
import os.path
|
||||||
|
import base64
|
||||||
|
|
||||||
|
from odoo import models, api
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class IrAttachment(models.Model):
|
||||||
|
_inherit = 'ir.attachment'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def get_binary_extension(self, model, ids, binary_field,
|
||||||
|
filename_field=None):
|
||||||
|
result = {}
|
||||||
|
ids_to_browse = ids if isinstance(ids, collections.Iterable) else [ids]
|
||||||
|
|
||||||
|
# First pass: load fields in bin_size mode to avoid loading big files
|
||||||
|
# unnecessarily.
|
||||||
|
if filename_field:
|
||||||
|
for this in self.env[model].with_context(
|
||||||
|
bin_size=True).browse(ids_to_browse):
|
||||||
|
extension = ''
|
||||||
|
if this[filename_field]:
|
||||||
|
filename, extension = os.path.splitext(
|
||||||
|
this[filename_field])
|
||||||
|
if this[binary_field] and extension:
|
||||||
|
result[this.id] = extension
|
||||||
|
_logger.debug('Got extension %s from filename %s',
|
||||||
|
extension, this[filename_field])
|
||||||
|
# Second pass for all attachments which have to be loaded fully
|
||||||
|
# to get the extension from the content
|
||||||
|
ids_to_browse = [_id for _id in ids_to_browse if _id not in result]
|
||||||
|
for this in self.env[model].with_context(
|
||||||
|
bin_size=True).browse(ids_to_browse):
|
||||||
|
if not this[binary_field]:
|
||||||
|
result[this.id] = False
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
import magic
|
||||||
|
ms = magic.open(
|
||||||
|
hasattr(magic, 'MAGIC_MIME_TYPE') and
|
||||||
|
magic.MAGIC_MIME_TYPE or magic.MAGIC_MIME)
|
||||||
|
ms.load()
|
||||||
|
if model == self._name and binary_field == 'datas'\
|
||||||
|
and this.store_fname:
|
||||||
|
mimetype = ms.file(
|
||||||
|
this._full_path(this.store_fname))
|
||||||
|
_logger.debug('Magic determined mimetype %s from file %s',
|
||||||
|
mimetype, this.store_fname)
|
||||||
|
else:
|
||||||
|
mimetype = ms.buffer(
|
||||||
|
base64.b64decode(this[binary_field]))
|
||||||
|
_logger.debug('Magic determined mimetype %s from buffer',
|
||||||
|
mimetype)
|
||||||
|
except ImportError:
|
||||||
|
(mimetype, encoding) = mimetypes.guess_type(
|
||||||
|
'data:;base64,' + this[binary_field], strict=False)
|
||||||
|
_logger.debug('Mimetypes guessed type %s from buffer',
|
||||||
|
mimetype)
|
||||||
|
extension = mimetypes.guess_extension(
|
||||||
|
mimetype.split(';')[0], strict=False)
|
||||||
|
result[this.id] = extension
|
||||||
|
for _id in result:
|
||||||
|
result[_id] = (result[_id] or '').lstrip('.').lower()
|
||||||
|
return result if isinstance(ids, collections.Iterable) else result[ids]
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def get_attachment_extension(self, ids):
|
||||||
|
return self.get_binary_extension(
|
||||||
|
self._name, ids, 'datas', 'datas_fname')
|
2
attachment_preview/readme/CONTRIBUTORS.rst
Normal file
2
attachment_preview/readme/CONTRIBUTORS.rst
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
* Holger Brunn <hbrunn@therp.nl>
|
||||||
|
* Dennis Sluijk <d.sluijk@onestein.nl>
|
4
attachment_preview/readme/CREDITS.rst
Normal file
4
attachment_preview/readme/CREDITS.rst
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Addon icon
|
||||||
|
----------
|
||||||
|
|
||||||
|
* courtesy of http://commons.wikimedia.org/wiki/Crystal_Clear
|
7
attachment_preview/readme/DESCRIPTION.rst
Normal file
7
attachment_preview/readme/DESCRIPTION.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
This addon allows to preview attachments supported by http://viewerjs.org.
|
||||||
|
|
||||||
|
Currently, that's most Libreoffice files and PDFs.
|
||||||
|
|
||||||
|
.. image:: /attachment_preview/static/description/screenshot-split.png
|
||||||
|
:alt: Screenshot of split form view
|
||||||
|
:width: 100%
|
4
attachment_preview/readme/INSTALL.rst
Normal file
4
attachment_preview/readme/INSTALL.rst
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
For filetype recognition, you'll get the best results by installing
|
||||||
|
``python-magic``:
|
||||||
|
|
||||||
|
sudo apt-get install python-magic
|
8
attachment_preview/readme/USAGE.rst
Normal file
8
attachment_preview/readme/USAGE.rst
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
The module adds a little print preview icon right of download links for
|
||||||
|
attachments or binary fields. When a preview is opened from the attachments
|
||||||
|
menu it's shown next to the form view. From this screen you can navigate
|
||||||
|
through the attachments using the arrow buttons. Using the pop-out button
|
||||||
|
next to the navigational buttons you can open the preview in a separate window.
|
||||||
|
|
||||||
|
.. image:: /attachment_preview/static/description/screenshot-paginator.png
|
||||||
|
:alt: Screenshot navigator
|
BIN
attachment_preview/static/description/screenshot-paginator.png
Normal file
BIN
attachment_preview/static/description/screenshot-paginator.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
BIN
attachment_preview/static/description/screenshot-split.png
Normal file
BIN
attachment_preview/static/description/screenshot-split.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 159 KiB |
@ -447,20 +447,10 @@ if (typeof PDFJS === 'undefined') {
|
|||||||
|
|
||||||
// Checks if navigator.language is supported
|
// Checks if navigator.language is supported
|
||||||
(function checkNavigatorLanguage() {
|
(function checkNavigatorLanguage() {
|
||||||
if ('language' in navigator &&
|
if ('language' in navigator) {
|
||||||
/^[a-z]+(-[A-Z]+)?$/.test(navigator.language)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
function formatLocale(locale) {
|
PDFJS.locale = navigator.userLanguage || 'en-US';
|
||||||
var split = locale.split(/[-_]/);
|
|
||||||
split[0] = split[0].toLowerCase();
|
|
||||||
if (split.length > 1) {
|
|
||||||
split[1] = split[1].toUpperCase();
|
|
||||||
}
|
|
||||||
return split.join('-');
|
|
||||||
}
|
|
||||||
var language = navigator.language || navigator.userLanguage || 'en-US';
|
|
||||||
PDFJS.locale = formatLocale(language);
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
(function checkRangeRequests() {
|
(function checkRangeRequests() {
|
||||||
@ -479,7 +469,10 @@ if (typeof PDFJS === 'undefined') {
|
|||||||
var regex = /Android\s[0-2][^\d]/;
|
var regex = /Android\s[0-2][^\d]/;
|
||||||
var isOldAndroid = regex.test(navigator.userAgent);
|
var isOldAndroid = regex.test(navigator.userAgent);
|
||||||
|
|
||||||
if (isSafari || isOldAndroid) {
|
// Range requests are broken in Chrome 39 and 40, https://crbug.com/442318
|
||||||
|
var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(navigator.userAgent);
|
||||||
|
|
||||||
|
if (isSafari || isOldAndroid || isChromeWithRangeBug) {
|
||||||
PDFJS.disableRange = true;
|
PDFJS.disableRange = true;
|
||||||
PDFJS.disableStream = true;
|
PDFJS.disableStream = true;
|
||||||
}
|
}
|
||||||
@ -572,3 +565,13 @@ if (typeof PDFJS === 'undefined') {
|
|||||||
PDFJS.maxCanvasPixels = 5242880;
|
PDFJS.maxCanvasPixels = 5242880;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
// Disable fullscreen support for certain problematic configurations.
|
||||||
|
// Support: IE11+ (when embedded).
|
||||||
|
(function checkFullscreenSupport() {
|
||||||
|
var isEmbeddedIE = (navigator.userAgent.indexOf('Trident') >= 0 &&
|
||||||
|
window.parent !== window);
|
||||||
|
if (isEmbeddedIE) {
|
||||||
|
PDFJS.disableFullscreen = true;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
File diff suppressed because one or more lines are too long
@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
|
|||||||
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFJS.version = '1.0.1040';
|
PDFJS.version = '1.1.114';
|
||||||
PDFJS.build = '997096f';
|
PDFJS.build = '3fd44fd';
|
||||||
|
|
||||||
(function pdfjsWrapper() {
|
(function pdfjsWrapper() {
|
||||||
// Use strict in our context only - users might not want it
|
// Use strict in our context only - users might not want it
|
||||||
@ -239,17 +239,10 @@ function warn(msg) {
|
|||||||
// Fatal errors that should trigger the fallback UI and halt execution by
|
// Fatal errors that should trigger the fallback UI and halt execution by
|
||||||
// throwing an exception.
|
// throwing an exception.
|
||||||
function error(msg) {
|
function error(msg) {
|
||||||
// If multiple arguments were passed, pass them all to the log function.
|
if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
|
||||||
if (arguments.length > 1) {
|
|
||||||
var logArguments = ['Error:'];
|
|
||||||
logArguments.push.apply(logArguments, arguments);
|
|
||||||
console.log.apply(console, logArguments);
|
|
||||||
// Join the arguments into a single string for the lines below.
|
|
||||||
msg = [].join.call(arguments, ' ');
|
|
||||||
} else {
|
|
||||||
console.log('Error: ' + msg);
|
console.log('Error: ' + msg);
|
||||||
|
console.log(backtrace());
|
||||||
}
|
}
|
||||||
console.log(backtrace());
|
|
||||||
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
|
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
|
||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
@ -341,6 +334,7 @@ function isValidUrl(url, allowRelative) {
|
|||||||
case 'https':
|
case 'https':
|
||||||
case 'ftp':
|
case 'ftp':
|
||||||
case 'mailto':
|
case 'mailto':
|
||||||
|
case 'tel':
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -355,6 +349,7 @@ function shadow(obj, prop, value) {
|
|||||||
writable: false });
|
writable: false });
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
PDFJS.shadow = shadow;
|
||||||
|
|
||||||
var PasswordResponses = PDFJS.PasswordResponses = {
|
var PasswordResponses = PDFJS.PasswordResponses = {
|
||||||
NEED_PASSWORD: 1,
|
NEED_PASSWORD: 1,
|
||||||
@ -470,6 +465,8 @@ var XRefParseException = (function XRefParseExceptionClosure() {
|
|||||||
|
|
||||||
|
|
||||||
function bytesToString(bytes) {
|
function bytesToString(bytes) {
|
||||||
|
assert(bytes !== null && typeof bytes === 'object' &&
|
||||||
|
bytes.length !== undefined, 'Invalid argument for bytesToString');
|
||||||
var length = bytes.length;
|
var length = bytes.length;
|
||||||
var MAX_ARGUMENT_COUNT = 8192;
|
var MAX_ARGUMENT_COUNT = 8192;
|
||||||
if (length < MAX_ARGUMENT_COUNT) {
|
if (length < MAX_ARGUMENT_COUNT) {
|
||||||
@ -485,6 +482,7 @@ function bytesToString(bytes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stringToBytes(str) {
|
function stringToBytes(str) {
|
||||||
|
assert(typeof str === 'string', 'Invalid argument for stringToBytes');
|
||||||
var length = str.length;
|
var length = str.length;
|
||||||
var bytes = new Uint8Array(length);
|
var bytes = new Uint8Array(length);
|
||||||
for (var i = 0; i < length; ++i) {
|
for (var i = 0; i < length; ++i) {
|
||||||
@ -1002,10 +1000,6 @@ function isString(v) {
|
|||||||
return typeof v === 'string';
|
return typeof v === 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNull(v) {
|
|
||||||
return v === null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isName(v) {
|
function isName(v) {
|
||||||
return v instanceof Name;
|
return v instanceof Name;
|
||||||
}
|
}
|
||||||
@ -1639,7 +1633,7 @@ PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
|
|||||||
*/
|
*/
|
||||||
PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
|
PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* By default fonts are converted to OpenType fonts and loaded via font face
|
* By default fonts are converted to OpenType fonts and loaded via font face
|
||||||
* rules. If disabled, the font will be rendered using a built in font renderer
|
* rules. If disabled, the font will be rendered using a built in font renderer
|
||||||
* that constructs the glyphs with primitive path commands.
|
* that constructs the glyphs with primitive path commands.
|
||||||
@ -1694,6 +1688,9 @@ PDFJS.disableStream = (PDFJS.disableStream === undefined ?
|
|||||||
* Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
|
* Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
|
||||||
* will automatically keep fetching more data even if it isn't needed to display
|
* will automatically keep fetching more data even if it isn't needed to display
|
||||||
* the current page. This default behavior can be disabled.
|
* the current page. This default behavior can be disabled.
|
||||||
|
*
|
||||||
|
* NOTE: It is also necessary to disable streaming, see above,
|
||||||
|
* in order for disabling of pre-fetching to work correctly.
|
||||||
* @var {boolean}
|
* @var {boolean}
|
||||||
*/
|
*/
|
||||||
PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
|
PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
|
||||||
@ -1726,6 +1723,14 @@ PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
|
|||||||
PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
|
PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
|
||||||
true : PDFJS.disableWebGL);
|
true : PDFJS.disableWebGL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disables fullscreen support, and by extension Presentation Mode,
|
||||||
|
* in browsers which support the fullscreen API.
|
||||||
|
* @var {boolean}
|
||||||
|
*/
|
||||||
|
PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
|
||||||
|
false : PDFJS.disableFullscreen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables CSS only zooming.
|
* Enables CSS only zooming.
|
||||||
* @var {boolean}
|
* @var {boolean}
|
||||||
@ -1752,12 +1757,23 @@ PDFJS.verbosity = (PDFJS.verbosity === undefined ?
|
|||||||
PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
|
PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
|
||||||
16777216 : PDFJS.maxCanvasPixels);
|
16777216 : PDFJS.maxCanvasPixels);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens external links in a new window if enabled. The default behavior opens
|
||||||
|
* external links in the PDF.js window.
|
||||||
|
* @var {boolean}
|
||||||
|
*/
|
||||||
|
PDFJS.openExternalLinksInNewWindow = (
|
||||||
|
PDFJS.openExternalLinksInNewWindow === undefined ?
|
||||||
|
false : PDFJS.openExternalLinksInNewWindow);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document initialization / loading parameters object.
|
* Document initialization / loading parameters object.
|
||||||
*
|
*
|
||||||
* @typedef {Object} DocumentInitParameters
|
* @typedef {Object} DocumentInitParameters
|
||||||
* @property {string} url - The URL of the PDF.
|
* @property {string} url - The URL of the PDF.
|
||||||
* @property {TypedArray} data - A typed array with PDF data.
|
* @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
|
||||||
|
* (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
|
||||||
|
* use atob() to convert it to a binary string first.
|
||||||
* @property {Object} httpHeaders - Basic authentication headers.
|
* @property {Object} httpHeaders - Basic authentication headers.
|
||||||
* @property {boolean} withCredentials - Indicates whether or not cross-site
|
* @property {boolean} withCredentials - Indicates whether or not cross-site
|
||||||
* Access-Control requests should be made using credentials such as cookies
|
* Access-Control requests should be made using credentials such as cookies
|
||||||
@ -1766,6 +1782,9 @@ PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
|
|||||||
* @property {TypedArray} initialData - A typed array with the first portion or
|
* @property {TypedArray} initialData - A typed array with the first portion or
|
||||||
* all of the pdf data. Used by the extension since some data is already
|
* all of the pdf data. Used by the extension since some data is already
|
||||||
* loaded before the switch to range requests.
|
* loaded before the switch to range requests.
|
||||||
|
* @property {number} length - The PDF file length. It's used for progress
|
||||||
|
* reports and range requests operations.
|
||||||
|
* @property {PDFDataRangeTransport} range
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1782,68 +1801,226 @@ PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
|
|||||||
* is used, which means it must follow the same origin rules that any XHR does
|
* is used, which means it must follow the same origin rules that any XHR does
|
||||||
* e.g. No cross domain requests without CORS.
|
* e.g. No cross domain requests without CORS.
|
||||||
*
|
*
|
||||||
* @param {string|TypedArray|DocumentInitParameters} source Can be a url to
|
* @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
|
||||||
* where a PDF is located, a typed array (Uint8Array) already populated with
|
* Can be a url to where a PDF is located, a typed array (Uint8Array)
|
||||||
* data or parameter object.
|
* already populated with data or parameter object.
|
||||||
*
|
*
|
||||||
* @param {Object} pdfDataRangeTransport is optional. It is used if you want
|
* @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
|
||||||
* to manually serve range requests for data in the PDF. See viewer.js for
|
* if you want to manually serve range requests for data in the PDF.
|
||||||
* an example of pdfDataRangeTransport's interface.
|
|
||||||
*
|
*
|
||||||
* @param {function} passwordCallback is optional. It is used to request a
|
* @param {function} passwordCallback (deprecated) It is used to request a
|
||||||
* password if wrong or no password was provided. The callback receives two
|
* password if wrong or no password was provided. The callback receives two
|
||||||
* parameters: function that needs to be called with new password and reason
|
* parameters: function that needs to be called with new password and reason
|
||||||
* (see {PasswordResponses}).
|
* (see {PasswordResponses}).
|
||||||
*
|
*
|
||||||
* @param {function} progressCallback is optional. It is used to be able to
|
* @param {function} progressCallback (deprecated) It is used to be able to
|
||||||
* monitor the loading progress of the PDF file (necessary to implement e.g.
|
* monitor the loading progress of the PDF file (necessary to implement e.g.
|
||||||
* a loading bar). The callback receives an {Object} with the properties:
|
* a loading bar). The callback receives an {Object} with the properties:
|
||||||
* {number} loaded and {number} total.
|
* {number} loaded and {number} total.
|
||||||
*
|
*
|
||||||
* @return {Promise} A promise that is resolved with {@link PDFDocumentProxy}
|
* @return {PDFDocumentLoadingTask}
|
||||||
* object.
|
|
||||||
*/
|
*/
|
||||||
PDFJS.getDocument = function getDocument(source,
|
PDFJS.getDocument = function getDocument(src,
|
||||||
pdfDataRangeTransport,
|
pdfDataRangeTransport,
|
||||||
passwordCallback,
|
passwordCallback,
|
||||||
progressCallback) {
|
progressCallback) {
|
||||||
var workerInitializedCapability, workerReadyCapability, transport;
|
var task = new PDFDocumentLoadingTask();
|
||||||
|
|
||||||
if (typeof source === 'string') {
|
// Support of the obsolete arguments (for compatibility with API v1.0)
|
||||||
source = { url: source };
|
if (pdfDataRangeTransport) {
|
||||||
} else if (isArrayBuffer(source)) {
|
if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
|
||||||
source = { data: source };
|
// Not a PDFDataRangeTransport instance, trying to add missing properties.
|
||||||
} else if (typeof source !== 'object') {
|
pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
|
||||||
error('Invalid parameter in getDocument, need either Uint8Array, ' +
|
pdfDataRangeTransport.length = src.length;
|
||||||
'string or a parameter object');
|
pdfDataRangeTransport.initialData = src.initialData;
|
||||||
|
}
|
||||||
|
src = Object.create(src);
|
||||||
|
src.range = pdfDataRangeTransport;
|
||||||
|
}
|
||||||
|
task.onPassword = passwordCallback || null;
|
||||||
|
task.onProgress = progressCallback || null;
|
||||||
|
|
||||||
|
var workerInitializedCapability, transport;
|
||||||
|
var source;
|
||||||
|
if (typeof src === 'string') {
|
||||||
|
source = { url: src };
|
||||||
|
} else if (isArrayBuffer(src)) {
|
||||||
|
source = { data: src };
|
||||||
|
} else if (src instanceof PDFDataRangeTransport) {
|
||||||
|
source = { range: src };
|
||||||
|
} else {
|
||||||
|
if (typeof src !== 'object') {
|
||||||
|
error('Invalid parameter in getDocument, need either Uint8Array, ' +
|
||||||
|
'string or a parameter object');
|
||||||
|
}
|
||||||
|
if (!src.url && !src.data && !src.range) {
|
||||||
|
error('Invalid parameter object: need either .data, .range or .url');
|
||||||
|
}
|
||||||
|
|
||||||
|
source = src;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!source.url && !source.data) {
|
|
||||||
error('Invalid parameter array, need either .data or .url');
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy/use all keys as is except 'url' -- full path is required
|
|
||||||
var params = {};
|
var params = {};
|
||||||
for (var key in source) {
|
for (var key in source) {
|
||||||
if (key === 'url' && typeof window !== 'undefined') {
|
if (key === 'url' && typeof window !== 'undefined') {
|
||||||
|
// The full path is required in the 'url' field.
|
||||||
params[key] = combineUrl(window.location.href, source[key]);
|
params[key] = combineUrl(window.location.href, source[key]);
|
||||||
continue;
|
continue;
|
||||||
|
} else if (key === 'range') {
|
||||||
|
continue;
|
||||||
|
} else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
|
||||||
|
// Converting string or array-like data to Uint8Array.
|
||||||
|
var pdfBytes = source[key];
|
||||||
|
if (typeof pdfBytes === 'string') {
|
||||||
|
params[key] = stringToBytes(pdfBytes);
|
||||||
|
} else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
|
||||||
|
!isNaN(pdfBytes.length)) {
|
||||||
|
params[key] = new Uint8Array(pdfBytes);
|
||||||
|
} else {
|
||||||
|
error('Invalid PDF binary data: either typed array, string or ' +
|
||||||
|
'array-like object is expected in the data property.');
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
params[key] = source[key];
|
params[key] = source[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
workerInitializedCapability = createPromiseCapability();
|
workerInitializedCapability = createPromiseCapability();
|
||||||
workerReadyCapability = createPromiseCapability();
|
transport = new WorkerTransport(workerInitializedCapability, source.range);
|
||||||
transport = new WorkerTransport(workerInitializedCapability,
|
|
||||||
workerReadyCapability, pdfDataRangeTransport,
|
|
||||||
progressCallback);
|
|
||||||
workerInitializedCapability.promise.then(function transportInitialized() {
|
workerInitializedCapability.promise.then(function transportInitialized() {
|
||||||
transport.passwordCallback = passwordCallback;
|
transport.fetchDocument(task, params);
|
||||||
transport.fetchDocument(params);
|
|
||||||
});
|
});
|
||||||
return workerReadyCapability.promise;
|
|
||||||
|
return task;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF document loading operation.
|
||||||
|
* @class
|
||||||
|
*/
|
||||||
|
var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
|
||||||
|
/** @constructs PDFDocumentLoadingTask */
|
||||||
|
function PDFDocumentLoadingTask() {
|
||||||
|
this._capability = createPromiseCapability();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to request a password if wrong or no password was provided.
|
||||||
|
* The callback receives two parameters: function that needs to be called
|
||||||
|
* with new password and reason (see {PasswordResponses}).
|
||||||
|
*/
|
||||||
|
this.onPassword = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to be able to monitor the loading progress of the PDF file
|
||||||
|
* (necessary to implement e.g. a loading bar). The callback receives
|
||||||
|
* an {Object} with the properties: {number} loaded and {number} total.
|
||||||
|
*/
|
||||||
|
this.onProgress = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFDocumentLoadingTask.prototype =
|
||||||
|
/** @lends PDFDocumentLoadingTask.prototype */ {
|
||||||
|
/**
|
||||||
|
* @return {Promise}
|
||||||
|
*/
|
||||||
|
get promise() {
|
||||||
|
return this._capability.promise;
|
||||||
|
},
|
||||||
|
|
||||||
|
// TODO add cancel or abort method
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers callbacks to indicate the document loading completion.
|
||||||
|
*
|
||||||
|
* @param {function} onFulfilled The callback for the loading completion.
|
||||||
|
* @param {function} onRejected The callback for the loading failure.
|
||||||
|
* @return {Promise} A promise that is resolved after the onFulfilled or
|
||||||
|
* onRejected callback.
|
||||||
|
*/
|
||||||
|
then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
|
||||||
|
return this.promise.then.apply(this.promise, arguments);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return PDFDocumentLoadingTask;
|
||||||
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class to support range requests file loading.
|
||||||
|
* @class
|
||||||
|
*/
|
||||||
|
var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
|
||||||
|
/**
|
||||||
|
* @constructs PDFDataRangeTransport
|
||||||
|
* @param {number} length
|
||||||
|
* @param {Uint8Array} initialData
|
||||||
|
*/
|
||||||
|
function PDFDataRangeTransport(length, initialData) {
|
||||||
|
this.length = length;
|
||||||
|
this.initialData = initialData;
|
||||||
|
|
||||||
|
this._rangeListeners = [];
|
||||||
|
this._progressListeners = [];
|
||||||
|
this._progressiveReadListeners = [];
|
||||||
|
this._readyCapability = createPromiseCapability();
|
||||||
|
}
|
||||||
|
PDFDataRangeTransport.prototype =
|
||||||
|
/** @lends PDFDataRangeTransport.prototype */ {
|
||||||
|
addRangeListener:
|
||||||
|
function PDFDataRangeTransport_addRangeListener(listener) {
|
||||||
|
this._rangeListeners.push(listener);
|
||||||
|
},
|
||||||
|
|
||||||
|
addProgressListener:
|
||||||
|
function PDFDataRangeTransport_addProgressListener(listener) {
|
||||||
|
this._progressListeners.push(listener);
|
||||||
|
},
|
||||||
|
|
||||||
|
addProgressiveReadListener:
|
||||||
|
function PDFDataRangeTransport_addProgressiveReadListener(listener) {
|
||||||
|
this._progressiveReadListeners.push(listener);
|
||||||
|
},
|
||||||
|
|
||||||
|
onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
|
||||||
|
var listeners = this._rangeListeners;
|
||||||
|
for (var i = 0, n = listeners.length; i < n; ++i) {
|
||||||
|
listeners[i](begin, chunk);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
|
||||||
|
this._readyCapability.promise.then(function () {
|
||||||
|
var listeners = this._progressListeners;
|
||||||
|
for (var i = 0, n = listeners.length; i < n; ++i) {
|
||||||
|
listeners[i](loaded);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
onDataProgressiveRead:
|
||||||
|
function PDFDataRangeTransport_onDataProgress(chunk) {
|
||||||
|
this._readyCapability.promise.then(function () {
|
||||||
|
var listeners = this._progressiveReadListeners;
|
||||||
|
for (var i = 0, n = listeners.length; i < n; ++i) {
|
||||||
|
listeners[i](chunk);
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
transportReady: function PDFDataRangeTransport_transportReady() {
|
||||||
|
this._readyCapability.resolve();
|
||||||
|
},
|
||||||
|
|
||||||
|
requestDataRange:
|
||||||
|
function PDFDataRangeTransport_requestDataRange(begin, end) {
|
||||||
|
throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return PDFDataRangeTransport;
|
||||||
|
})();
|
||||||
|
|
||||||
|
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used
|
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used
|
||||||
* properties that can be read synchronously.
|
* properties that can be read synchronously.
|
||||||
@ -1959,7 +2136,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
return this.transport.downloadInfoCapability.promise;
|
return this.transport.downloadInfoCapability.promise;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @returns {Promise} A promise this is resolved with current stats about
|
* @return {Promise} A promise this is resolved with current stats about
|
||||||
* document structures (see {@link PDFDocumentStats}).
|
* document structures (see {@link PDFDocumentStats}).
|
||||||
*/
|
*/
|
||||||
getStats: function PDFDocumentProxy_getStats() {
|
getStats: function PDFDocumentProxy_getStats() {
|
||||||
@ -2023,7 +2200,7 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
|
|||||||
* (default value is 'display').
|
* (default value is 'display').
|
||||||
* @property {Object} imageLayer - (optional) An object that has beginLayout,
|
* @property {Object} imageLayer - (optional) An object that has beginLayout,
|
||||||
* endLayout and appendImage functions.
|
* endLayout and appendImage functions.
|
||||||
* @property {function} continueCallback - (optional) A function that will be
|
* @property {function} continueCallback - (deprecated) A function that will be
|
||||||
* called each time the rendering is paused. To continue
|
* called each time the rendering is paused. To continue
|
||||||
* rendering call the function that is the first argument
|
* rendering call the function that is the first argument
|
||||||
* to the callback.
|
* to the callback.
|
||||||
@ -2156,7 +2333,12 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
intentState.renderTasks = [];
|
intentState.renderTasks = [];
|
||||||
}
|
}
|
||||||
intentState.renderTasks.push(internalRenderTask);
|
intentState.renderTasks.push(internalRenderTask);
|
||||||
var renderTask = new RenderTask(internalRenderTask);
|
var renderTask = internalRenderTask.task;
|
||||||
|
|
||||||
|
// Obsolete parameter support
|
||||||
|
if (params.continueCallback) {
|
||||||
|
renderTask.onContinue = params.continueCallback;
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
intentState.displayReadyCapability.promise.then(
|
intentState.displayReadyCapability.promise.then(
|
||||||
@ -2321,19 +2503,16 @@ var PDFPageProxy = (function PDFPageProxyClosure() {
|
|||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
var WorkerTransport = (function WorkerTransportClosure() {
|
var WorkerTransport = (function WorkerTransportClosure() {
|
||||||
function WorkerTransport(workerInitializedCapability, workerReadyCapability,
|
function WorkerTransport(workerInitializedCapability, pdfDataRangeTransport) {
|
||||||
pdfDataRangeTransport, progressCallback) {
|
|
||||||
this.pdfDataRangeTransport = pdfDataRangeTransport;
|
this.pdfDataRangeTransport = pdfDataRangeTransport;
|
||||||
|
|
||||||
this.workerInitializedCapability = workerInitializedCapability;
|
this.workerInitializedCapability = workerInitializedCapability;
|
||||||
this.workerReadyCapability = workerReadyCapability;
|
|
||||||
this.progressCallback = progressCallback;
|
|
||||||
this.commonObjs = new PDFObjects();
|
this.commonObjs = new PDFObjects();
|
||||||
|
|
||||||
|
this.loadingTask = null;
|
||||||
|
|
||||||
this.pageCache = [];
|
this.pageCache = [];
|
||||||
this.pagePromises = [];
|
this.pagePromises = [];
|
||||||
this.downloadInfoCapability = createPromiseCapability();
|
this.downloadInfoCapability = createPromiseCapability();
|
||||||
this.passwordCallback = null;
|
|
||||||
|
|
||||||
// If worker support isn't disabled explicit and the browser has worker
|
// If worker support isn't disabled explicit and the browser has worker
|
||||||
// support, create a new web worker and test if it/the browser fullfills
|
// support, create a new web worker and test if it/the browser fullfills
|
||||||
@ -2482,48 +2661,50 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
this.numPages = data.pdfInfo.numPages;
|
this.numPages = data.pdfInfo.numPages;
|
||||||
var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
|
var pdfDocument = new PDFDocumentProxy(pdfInfo, this);
|
||||||
this.pdfDocument = pdfDocument;
|
this.pdfDocument = pdfDocument;
|
||||||
this.workerReadyCapability.resolve(pdfDocument);
|
this.loadingTask._capability.resolve(pdfDocument);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('NeedPassword',
|
messageHandler.on('NeedPassword',
|
||||||
function transportNeedPassword(exception) {
|
function transportNeedPassword(exception) {
|
||||||
if (this.passwordCallback) {
|
var loadingTask = this.loadingTask;
|
||||||
return this.passwordCallback(updatePassword,
|
if (loadingTask.onPassword) {
|
||||||
PasswordResponses.NEED_PASSWORD);
|
return loadingTask.onPassword(updatePassword,
|
||||||
|
PasswordResponses.NEED_PASSWORD);
|
||||||
}
|
}
|
||||||
this.workerReadyCapability.reject(
|
loadingTask._capability.reject(
|
||||||
new PasswordException(exception.message, exception.code));
|
new PasswordException(exception.message, exception.code));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('IncorrectPassword',
|
messageHandler.on('IncorrectPassword',
|
||||||
function transportIncorrectPassword(exception) {
|
function transportIncorrectPassword(exception) {
|
||||||
if (this.passwordCallback) {
|
var loadingTask = this.loadingTask;
|
||||||
return this.passwordCallback(updatePassword,
|
if (loadingTask.onPassword) {
|
||||||
PasswordResponses.INCORRECT_PASSWORD);
|
return loadingTask.onPassword(updatePassword,
|
||||||
|
PasswordResponses.INCORRECT_PASSWORD);
|
||||||
}
|
}
|
||||||
this.workerReadyCapability.reject(
|
loadingTask._capability.reject(
|
||||||
new PasswordException(exception.message, exception.code));
|
new PasswordException(exception.message, exception.code));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
|
messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
|
||||||
this.workerReadyCapability.reject(
|
this.loadingTask._capability.reject(
|
||||||
new InvalidPDFException(exception.message));
|
new InvalidPDFException(exception.message));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
|
messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
|
||||||
this.workerReadyCapability.reject(
|
this.loadingTask._capability.reject(
|
||||||
new MissingPDFException(exception.message));
|
new MissingPDFException(exception.message));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('UnexpectedResponse',
|
messageHandler.on('UnexpectedResponse',
|
||||||
function transportUnexpectedResponse(exception) {
|
function transportUnexpectedResponse(exception) {
|
||||||
this.workerReadyCapability.reject(
|
this.loadingTask._capability.reject(
|
||||||
new UnexpectedResponseException(exception.message, exception.status));
|
new UnexpectedResponseException(exception.message, exception.status));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('UnknownError',
|
messageHandler.on('UnknownError',
|
||||||
function transportUnknownError(exception) {
|
function transportUnknownError(exception) {
|
||||||
this.workerReadyCapability.reject(
|
this.loadingTask._capability.reject(
|
||||||
new UnknownErrorException(exception.message, exception.details));
|
new UnknownErrorException(exception.message, exception.details));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
@ -2618,8 +2799,9 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('DocProgress', function transportDocProgress(data) {
|
messageHandler.on('DocProgress', function transportDocProgress(data) {
|
||||||
if (this.progressCallback) {
|
var loadingTask = this.loadingTask;
|
||||||
this.progressCallback({
|
if (loadingTask.onProgress) {
|
||||||
|
loadingTask.onProgress({
|
||||||
loaded: data.loaded,
|
loaded: data.loaded,
|
||||||
total: data.total
|
total: data.total
|
||||||
});
|
});
|
||||||
@ -2679,10 +2861,16 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchDocument: function WorkerTransport_fetchDocument(source) {
|
fetchDocument: function WorkerTransport_fetchDocument(loadingTask, source) {
|
||||||
|
this.loadingTask = loadingTask;
|
||||||
|
|
||||||
source.disableAutoFetch = PDFJS.disableAutoFetch;
|
source.disableAutoFetch = PDFJS.disableAutoFetch;
|
||||||
source.disableStream = PDFJS.disableStream;
|
source.disableStream = PDFJS.disableStream;
|
||||||
source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
|
source.chunkedViewerLoading = !!this.pdfDataRangeTransport;
|
||||||
|
if (this.pdfDataRangeTransport) {
|
||||||
|
source.length = this.pdfDataRangeTransport.length;
|
||||||
|
source.initialData = this.pdfDataRangeTransport.initialData;
|
||||||
|
}
|
||||||
this.messageHandler.send('GetDocRequest', {
|
this.messageHandler.send('GetDocRequest', {
|
||||||
source: source,
|
source: source,
|
||||||
disableRange: PDFJS.disableRange,
|
disableRange: PDFJS.disableRange,
|
||||||
@ -2893,26 +3081,37 @@ var PDFObjects = (function PDFObjectsClosure() {
|
|||||||
*/
|
*/
|
||||||
var RenderTask = (function RenderTaskClosure() {
|
var RenderTask = (function RenderTaskClosure() {
|
||||||
function RenderTask(internalRenderTask) {
|
function RenderTask(internalRenderTask) {
|
||||||
this.internalRenderTask = internalRenderTask;
|
this._internalRenderTask = internalRenderTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promise for rendering task completion.
|
* Callback for incremental rendering -- a function that will be called
|
||||||
* @type {Promise}
|
* each time the rendering is paused. To continue rendering call the
|
||||||
|
* function that is the first argument to the callback.
|
||||||
|
* @type {function}
|
||||||
*/
|
*/
|
||||||
this.promise = this.internalRenderTask.capability.promise;
|
this.onContinue = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderTask.prototype = /** @lends RenderTask.prototype */ {
|
RenderTask.prototype = /** @lends RenderTask.prototype */ {
|
||||||
|
/**
|
||||||
|
* Promise for rendering task completion.
|
||||||
|
* @return {Promise}
|
||||||
|
*/
|
||||||
|
get promise() {
|
||||||
|
return this._internalRenderTask.capability.promise;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels the rendering task. If the task is currently rendering it will
|
* Cancels the rendering task. If the task is currently rendering it will
|
||||||
* not be cancelled until graphics pauses with a timeout. The promise that
|
* not be cancelled until graphics pauses with a timeout. The promise that
|
||||||
* this object extends will resolved when cancelled.
|
* this object extends will resolved when cancelled.
|
||||||
*/
|
*/
|
||||||
cancel: function RenderTask_cancel() {
|
cancel: function RenderTask_cancel() {
|
||||||
this.internalRenderTask.cancel();
|
this._internalRenderTask.cancel();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers callback to indicate the rendering task completion.
|
* Registers callbacks to indicate the rendering task completion.
|
||||||
*
|
*
|
||||||
* @param {function} onFulfilled The callback for the rendering completion.
|
* @param {function} onFulfilled The callback for the rendering completion.
|
||||||
* @param {function} onRejected The callback for the rendering failure.
|
* @param {function} onRejected The callback for the rendering failure.
|
||||||
@ -2920,7 +3119,7 @@ var RenderTask = (function RenderTaskClosure() {
|
|||||||
* onRejected callback.
|
* onRejected callback.
|
||||||
*/
|
*/
|
||||||
then: function RenderTask_then(onFulfilled, onRejected) {
|
then: function RenderTask_then(onFulfilled, onRejected) {
|
||||||
return this.promise.then(onFulfilled, onRejected);
|
return this.promise.then.apply(this.promise, arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2947,6 +3146,7 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||||||
this.graphicsReady = false;
|
this.graphicsReady = false;
|
||||||
this.cancelled = false;
|
this.cancelled = false;
|
||||||
this.capability = createPromiseCapability();
|
this.capability = createPromiseCapability();
|
||||||
|
this.task = new RenderTask(this);
|
||||||
// caching this-bound methods
|
// caching this-bound methods
|
||||||
this._continueBound = this._continue.bind(this);
|
this._continueBound = this._continue.bind(this);
|
||||||
this._scheduleNextBound = this._scheduleNext.bind(this);
|
this._scheduleNextBound = this._scheduleNext.bind(this);
|
||||||
@ -3009,8 +3209,8 @@ var InternalRenderTask = (function InternalRenderTaskClosure() {
|
|||||||
if (this.cancelled) {
|
if (this.cancelled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.params.continueCallback) {
|
if (this.task.onContinue) {
|
||||||
this.params.continueCallback(this._scheduleNextBound);
|
this.task.onContinue.call(this.task, this._scheduleNextBound);
|
||||||
} else {
|
} else {
|
||||||
this._scheduleNext();
|
this._scheduleNext();
|
||||||
}
|
}
|
||||||
@ -3149,11 +3349,8 @@ function createScratchCanvas(width, height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addContextCurrentTransform(ctx) {
|
function addContextCurrentTransform(ctx) {
|
||||||
// If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
|
// If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
|
||||||
if (!ctx.mozCurrentTransform) {
|
if (!ctx.mozCurrentTransform) {
|
||||||
// Store the original context
|
|
||||||
ctx._scaleX = ctx._scaleX || 1.0;
|
|
||||||
ctx._scaleY = ctx._scaleY || 1.0;
|
|
||||||
ctx._originalSave = ctx.save;
|
ctx._originalSave = ctx.save;
|
||||||
ctx._originalRestore = ctx.restore;
|
ctx._originalRestore = ctx.restore;
|
||||||
ctx._originalRotate = ctx.rotate;
|
ctx._originalRotate = ctx.rotate;
|
||||||
@ -3162,7 +3359,7 @@ function addContextCurrentTransform(ctx) {
|
|||||||
ctx._originalTransform = ctx.transform;
|
ctx._originalTransform = ctx.transform;
|
||||||
ctx._originalSetTransform = ctx.setTransform;
|
ctx._originalSetTransform = ctx.setTransform;
|
||||||
|
|
||||||
ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
|
ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
|
||||||
ctx._transformStack = [];
|
ctx._transformStack = [];
|
||||||
|
|
||||||
Object.defineProperty(ctx, 'mozCurrentTransform', {
|
Object.defineProperty(ctx, 'mozCurrentTransform', {
|
||||||
@ -3538,6 +3735,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.smaskCounter = 0;
|
this.smaskCounter = 0;
|
||||||
this.tempSMask = null;
|
this.tempSMask = null;
|
||||||
if (canvasCtx) {
|
if (canvasCtx) {
|
||||||
|
// NOTE: if mozCurrentTransform is polyfilled, then the current state of
|
||||||
|
// the transformation must already be set in canvasCtx._transformMatrix.
|
||||||
addContextCurrentTransform(canvasCtx);
|
addContextCurrentTransform(canvasCtx);
|
||||||
}
|
}
|
||||||
this.cachedGetSinglePixelWidth = null;
|
this.cachedGetSinglePixelWidth = null;
|
||||||
@ -5254,7 +5453,6 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var WebGLUtils = (function WebGLUtilsClosure() {
|
var WebGLUtils = (function WebGLUtilsClosure() {
|
||||||
function loadShader(gl, code, shaderType) {
|
function loadShader(gl, code, shaderType) {
|
||||||
var shader = gl.createShader(shaderType);
|
var shader = gl.createShader(shaderType);
|
||||||
@ -6165,7 +6363,8 @@ var FontLoader = {
|
|||||||
|
|
||||||
nativeFontFaces: [],
|
nativeFontFaces: [],
|
||||||
|
|
||||||
isFontLoadingAPISupported: !isWorker && !!document.fonts,
|
isFontLoadingAPISupported: (!isWorker && typeof document !== 'undefined' &&
|
||||||
|
!!document.fonts),
|
||||||
|
|
||||||
addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
|
addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
|
||||||
this.nativeFontFaces.push(nativeFontFace);
|
this.nativeFontFaces.push(nativeFontFace);
|
||||||
@ -6634,6 +6833,9 @@ var AnnotationUtils = (function AnnotationUtilsClosure() {
|
|||||||
|
|
||||||
var link = document.createElement('a');
|
var link = document.createElement('a');
|
||||||
link.href = link.title = item.url || '';
|
link.href = link.title = item.url || '';
|
||||||
|
if (item.url && PDFJS.openExternalLinksInNewWindow) {
|
||||||
|
link.target = '_blank';
|
||||||
|
}
|
||||||
|
|
||||||
container.appendChild(link);
|
container.appendChild(link);
|
||||||
|
|
||||||
@ -7159,6 +7361,9 @@ var SVGGraphics = (function SVGGraphicsClosure() {
|
|||||||
case OPS.setWordSpacing:
|
case OPS.setWordSpacing:
|
||||||
this.setWordSpacing(args[0]);
|
this.setWordSpacing(args[0]);
|
||||||
break;
|
break;
|
||||||
|
case OPS.setHScale:
|
||||||
|
this.setHScale(args[0]);
|
||||||
|
break;
|
||||||
case OPS.setTextMatrix:
|
case OPS.setTextMatrix:
|
||||||
this.setTextMatrix(args[0], args[1], args[2],
|
this.setTextMatrix(args[0], args[1], args[2],
|
||||||
args[3], args[4], args[5]);
|
args[3], args[4], args[5]);
|
||||||
|
431
attachment_preview/static/lib/ViewerJS/pdf.worker.js
vendored
431
attachment_preview/static/lib/ViewerJS/pdf.worker.js
vendored
@ -22,8 +22,8 @@ if (typeof PDFJS === 'undefined') {
|
|||||||
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
(typeof window !== 'undefined' ? window : this).PDFJS = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFJS.version = '1.0.1040';
|
PDFJS.version = '1.1.114';
|
||||||
PDFJS.build = '997096f';
|
PDFJS.build = '3fd44fd';
|
||||||
|
|
||||||
(function pdfjsWrapper() {
|
(function pdfjsWrapper() {
|
||||||
// Use strict in our context only - users might not want it
|
// Use strict in our context only - users might not want it
|
||||||
@ -239,17 +239,10 @@ function warn(msg) {
|
|||||||
// Fatal errors that should trigger the fallback UI and halt execution by
|
// Fatal errors that should trigger the fallback UI and halt execution by
|
||||||
// throwing an exception.
|
// throwing an exception.
|
||||||
function error(msg) {
|
function error(msg) {
|
||||||
// If multiple arguments were passed, pass them all to the log function.
|
if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
|
||||||
if (arguments.length > 1) {
|
|
||||||
var logArguments = ['Error:'];
|
|
||||||
logArguments.push.apply(logArguments, arguments);
|
|
||||||
console.log.apply(console, logArguments);
|
|
||||||
// Join the arguments into a single string for the lines below.
|
|
||||||
msg = [].join.call(arguments, ' ');
|
|
||||||
} else {
|
|
||||||
console.log('Error: ' + msg);
|
console.log('Error: ' + msg);
|
||||||
|
console.log(backtrace());
|
||||||
}
|
}
|
||||||
console.log(backtrace());
|
|
||||||
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
|
UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
|
||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
@ -341,6 +334,7 @@ function isValidUrl(url, allowRelative) {
|
|||||||
case 'https':
|
case 'https':
|
||||||
case 'ftp':
|
case 'ftp':
|
||||||
case 'mailto':
|
case 'mailto':
|
||||||
|
case 'tel':
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -355,6 +349,7 @@ function shadow(obj, prop, value) {
|
|||||||
writable: false });
|
writable: false });
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
PDFJS.shadow = shadow;
|
||||||
|
|
||||||
var PasswordResponses = PDFJS.PasswordResponses = {
|
var PasswordResponses = PDFJS.PasswordResponses = {
|
||||||
NEED_PASSWORD: 1,
|
NEED_PASSWORD: 1,
|
||||||
@ -470,6 +465,8 @@ var XRefParseException = (function XRefParseExceptionClosure() {
|
|||||||
|
|
||||||
|
|
||||||
function bytesToString(bytes) {
|
function bytesToString(bytes) {
|
||||||
|
assert(bytes !== null && typeof bytes === 'object' &&
|
||||||
|
bytes.length !== undefined, 'Invalid argument for bytesToString');
|
||||||
var length = bytes.length;
|
var length = bytes.length;
|
||||||
var MAX_ARGUMENT_COUNT = 8192;
|
var MAX_ARGUMENT_COUNT = 8192;
|
||||||
if (length < MAX_ARGUMENT_COUNT) {
|
if (length < MAX_ARGUMENT_COUNT) {
|
||||||
@ -485,6 +482,7 @@ function bytesToString(bytes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function stringToBytes(str) {
|
function stringToBytes(str) {
|
||||||
|
assert(typeof str === 'string', 'Invalid argument for stringToBytes');
|
||||||
var length = str.length;
|
var length = str.length;
|
||||||
var bytes = new Uint8Array(length);
|
var bytes = new Uint8Array(length);
|
||||||
for (var i = 0; i < length; ++i) {
|
for (var i = 0; i < length; ++i) {
|
||||||
@ -1002,10 +1000,6 @@ function isString(v) {
|
|||||||
return typeof v === 'string';
|
return typeof v === 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNull(v) {
|
|
||||||
return v === null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isName(v) {
|
function isName(v) {
|
||||||
return v instanceof Name;
|
return v instanceof Name;
|
||||||
}
|
}
|
||||||
@ -1874,7 +1868,6 @@ var NetworkManager = (function NetworkManagerClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var ChunkedStream = (function ChunkedStreamClosure() {
|
var ChunkedStream = (function ChunkedStreamClosure() {
|
||||||
function ChunkedStream(length, chunkSize, manager) {
|
function ChunkedStream(length, chunkSize, manager) {
|
||||||
this.bytes = new Uint8Array(length);
|
this.bytes = new Uint8Array(length);
|
||||||
@ -2026,6 +2019,9 @@ var ChunkedStream = (function ChunkedStreamClosure() {
|
|||||||
getUint16: function ChunkedStream_getUint16() {
|
getUint16: function ChunkedStream_getUint16() {
|
||||||
var b0 = this.getByte();
|
var b0 = this.getByte();
|
||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
|
if (b0 === -1 || b1 === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return (b0 << 8) + b1;
|
return (b0 << 8) + b1;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -2415,7 +2411,6 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// The maximum number of bytes fetched per range request
|
// The maximum number of bytes fetched per range request
|
||||||
var RANGE_CHUNK_SIZE = 65536;
|
var RANGE_CHUNK_SIZE = 65536;
|
||||||
|
|
||||||
@ -2621,7 +2616,6 @@ var NetworkPdfManager = (function NetworkPdfManagerClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var Page = (function PageClosure() {
|
var Page = (function PageClosure() {
|
||||||
|
|
||||||
var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
|
||||||
@ -3131,7 +3125,6 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var Name = (function NameClosure() {
|
var Name = (function NameClosure() {
|
||||||
function Name(name) {
|
function Name(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -3301,6 +3294,10 @@ var Dict = (function DictClosure() {
|
|||||||
return all;
|
return all;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getKeys: function Dict_getKeys() {
|
||||||
|
return Object.keys(this.map);
|
||||||
|
},
|
||||||
|
|
||||||
set: function Dict_set(key, value) {
|
set: function Dict_set(key, value) {
|
||||||
this.map[key] = value;
|
this.map[key] = value;
|
||||||
},
|
},
|
||||||
@ -3706,6 +3703,7 @@ var Catalog = (function CatalogClosure() {
|
|||||||
var nodesToVisit = [this.catDict.getRaw('Pages')];
|
var nodesToVisit = [this.catDict.getRaw('Pages')];
|
||||||
var currentPageIndex = 0;
|
var currentPageIndex = 0;
|
||||||
var xref = this.xref;
|
var xref = this.xref;
|
||||||
|
var checkAllKids = false;
|
||||||
|
|
||||||
function next() {
|
function next() {
|
||||||
while (nodesToVisit.length) {
|
while (nodesToVisit.length) {
|
||||||
@ -3713,7 +3711,7 @@ var Catalog = (function CatalogClosure() {
|
|||||||
|
|
||||||
if (isRef(currentNode)) {
|
if (isRef(currentNode)) {
|
||||||
xref.fetchAsync(currentNode).then(function (obj) {
|
xref.fetchAsync(currentNode).then(function (obj) {
|
||||||
if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
|
if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
|
||||||
if (pageIndex === currentPageIndex) {
|
if (pageIndex === currentPageIndex) {
|
||||||
capability.resolve([obj, currentNode]);
|
capability.resolve([obj, currentNode]);
|
||||||
} else {
|
} else {
|
||||||
@ -3728,12 +3726,17 @@ var Catalog = (function CatalogClosure() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// must be a child page dictionary
|
// Must be a child page dictionary.
|
||||||
assert(
|
assert(
|
||||||
isDict(currentNode),
|
isDict(currentNode),
|
||||||
'page dictionary kid reference points to wrong type of object'
|
'page dictionary kid reference points to wrong type of object'
|
||||||
);
|
);
|
||||||
var count = currentNode.get('Count');
|
var count = currentNode.get('Count');
|
||||||
|
// If the current node doesn't have any children, avoid getting stuck
|
||||||
|
// in an empty node further down in the tree (see issue5644.pdf).
|
||||||
|
if (count === 0) {
|
||||||
|
checkAllKids = true;
|
||||||
|
}
|
||||||
// Skip nodes where the page can't be.
|
// Skip nodes where the page can't be.
|
||||||
if (currentPageIndex + count <= pageIndex) {
|
if (currentPageIndex + count <= pageIndex) {
|
||||||
currentPageIndex += count;
|
currentPageIndex += count;
|
||||||
@ -3742,7 +3745,7 @@ var Catalog = (function CatalogClosure() {
|
|||||||
|
|
||||||
var kids = currentNode.get('Kids');
|
var kids = currentNode.get('Kids');
|
||||||
assert(isArray(kids), 'page dictionary kids object is not an array');
|
assert(isArray(kids), 'page dictionary kids object is not an array');
|
||||||
if (count === kids.length) {
|
if (!checkAllKids && count === kids.length) {
|
||||||
// Nodes that don't have the page have been skipped and this is the
|
// Nodes that don't have the page have been skipped and this is the
|
||||||
// bottom of the tree which means the page requested must be a
|
// bottom of the tree which means the page requested must be a
|
||||||
// descendant of this pages node. Ideally we would just resolve the
|
// descendant of this pages node. Ideally we would just resolve the
|
||||||
@ -4908,7 +4911,6 @@ var ExpertSubsetCharset = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var DEFAULT_ICON_SIZE = 22; // px
|
var DEFAULT_ICON_SIZE = 22; // px
|
||||||
var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
|
var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
|
||||||
|
|
||||||
@ -5374,7 +5376,7 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
|
|||||||
data.annotationType = AnnotationType.LINK;
|
data.annotationType = AnnotationType.LINK;
|
||||||
|
|
||||||
var action = dict.get('A');
|
var action = dict.get('A');
|
||||||
if (action) {
|
if (action && isDict(action)) {
|
||||||
var linkType = action.get('S').name;
|
var linkType = action.get('S').name;
|
||||||
if (linkType === 'URI') {
|
if (linkType === 'URI') {
|
||||||
var url = action.get('URI');
|
var url = action.get('URI');
|
||||||
@ -6802,10 +6804,10 @@ var ColorSpace = (function ColorSpaceClosure() {
|
|||||||
case 'CMYK':
|
case 'CMYK':
|
||||||
return 'DeviceCmykCS';
|
return 'DeviceCmykCS';
|
||||||
case 'CalGray':
|
case 'CalGray':
|
||||||
params = cs[1].getAll();
|
params = xref.fetchIfRef(cs[1]).getAll();
|
||||||
return ['CalGrayCS', params];
|
return ['CalGrayCS', params];
|
||||||
case 'CalRGB':
|
case 'CalRGB':
|
||||||
params = cs[1].getAll();
|
params = xref.fetchIfRef(cs[1]).getAll();
|
||||||
return ['CalRGBCS', params];
|
return ['CalRGBCS', params];
|
||||||
case 'ICCBased':
|
case 'ICCBased':
|
||||||
var stream = xref.fetchIfRef(cs[1]);
|
var stream = xref.fetchIfRef(cs[1]);
|
||||||
@ -9721,7 +9723,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
|
|||||||
this.cf = dict.get('CF');
|
this.cf = dict.get('CF');
|
||||||
this.stmf = dict.get('StmF') || identityName;
|
this.stmf = dict.get('StmF') || identityName;
|
||||||
this.strf = dict.get('StrF') || identityName;
|
this.strf = dict.get('StrF') || identityName;
|
||||||
this.eff = dict.get('EFF') || this.strf;
|
this.eff = dict.get('EFF') || this.stmf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -9796,6 +9798,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
|
|||||||
return CipherTransformFactory;
|
return CipherTransformFactory;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
var PatternType = {
|
var PatternType = {
|
||||||
FUNCTION_BASED: 1,
|
FUNCTION_BASED: 1,
|
||||||
AXIAL: 2,
|
AXIAL: 2,
|
||||||
@ -11446,7 +11449,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
styles: Object.create(null)
|
styles: Object.create(null)
|
||||||
};
|
};
|
||||||
var bidiTexts = textContent.items;
|
var bidiTexts = textContent.items;
|
||||||
var SPACE_FACTOR = 0.35;
|
var SPACE_FACTOR = 0.3;
|
||||||
var MULTI_SPACE_FACTOR = 1.5;
|
var MULTI_SPACE_FACTOR = 1.5;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
@ -11885,11 +11888,18 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var cmap, cmapObj = toUnicode;
|
var cmap, cmapObj = toUnicode;
|
||||||
if (isName(cmapObj)) {
|
if (isName(cmapObj)) {
|
||||||
cmap = CMapFactory.create(cmapObj,
|
cmap = CMapFactory.create(cmapObj,
|
||||||
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
|
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
|
||||||
return new ToUnicodeMap(cmap);
|
if (cmap instanceof IdentityCMap) {
|
||||||
|
return new IdentityToUnicodeMap(0, 0xFFFF);
|
||||||
|
}
|
||||||
|
return new ToUnicodeMap(cmap.getMap());
|
||||||
} else if (isStream(cmapObj)) {
|
} else if (isStream(cmapObj)) {
|
||||||
cmap = CMapFactory.create(cmapObj,
|
cmap = CMapFactory.create(cmapObj,
|
||||||
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
|
{ url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
|
||||||
|
if (cmap instanceof IdentityCMap) {
|
||||||
|
return new IdentityToUnicodeMap(0, 0xFFFF);
|
||||||
|
}
|
||||||
|
cmap = cmap.getMap();
|
||||||
// Convert UTF-16BE
|
// Convert UTF-16BE
|
||||||
// NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
|
// NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
|
||||||
// to iterate over all keys.
|
// to iterate over all keys.
|
||||||
@ -12117,6 +12127,21 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
hash.update(encoding.name);
|
hash.update(encoding.name);
|
||||||
} else if (isRef(encoding)) {
|
} else if (isRef(encoding)) {
|
||||||
hash.update(encoding.num + '_' + encoding.gen);
|
hash.update(encoding.num + '_' + encoding.gen);
|
||||||
|
} else if (isDict(encoding)) {
|
||||||
|
var keys = encoding.getKeys();
|
||||||
|
for (var i = 0, ii = keys.length; i < ii; i++) {
|
||||||
|
var entry = encoding.getRaw(keys[i]);
|
||||||
|
if (isName(entry)) {
|
||||||
|
hash.update(entry.name);
|
||||||
|
} else if (isRef(entry)) {
|
||||||
|
hash.update(entry.num + '_' + entry.gen);
|
||||||
|
} else if (isArray(entry)) { // 'Differences' entry.
|
||||||
|
// Ideally we should check the contents of the array, but to avoid
|
||||||
|
// parsing it here and then again in |extractDataStructures|,
|
||||||
|
// we only use the array length for now (fixes bug1157493.pdf).
|
||||||
|
hash.update(entry.length.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
|
var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
|
||||||
@ -13384,6 +13409,7 @@ var CMap = (function CMapClosure() {
|
|||||||
// - bf chars are variable-length byte sequences, stored as strings, with
|
// - bf chars are variable-length byte sequences, stored as strings, with
|
||||||
// one byte per character.
|
// one byte per character.
|
||||||
this._map = [];
|
this._map = [];
|
||||||
|
this.name = '';
|
||||||
this.vertical = false;
|
this.vertical = false;
|
||||||
this.useCMap = null;
|
this.useCMap = null;
|
||||||
this.builtInCMap = builtInCMap;
|
this.builtInCMap = builtInCMap;
|
||||||
@ -13483,13 +13509,28 @@ var CMap = (function CMapClosure() {
|
|||||||
}
|
}
|
||||||
out.charcode = 0;
|
out.charcode = 0;
|
||||||
out.length = 1;
|
out.length = 1;
|
||||||
|
},
|
||||||
|
|
||||||
|
get isIdentityCMap() {
|
||||||
|
if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this._map.length !== 0x10000) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < 0x10000; i++) {
|
||||||
|
if (this._map[i] !== i) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return CMap;
|
return CMap;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// A special case of CMap, where the _map array implicitly has a length of
|
// A special case of CMap, where the _map array implicitly has a length of
|
||||||
// 65535 and each element is equal to its index.
|
// 65536 and each element is equal to its index.
|
||||||
var IdentityCMap = (function IdentityCMapClosure() {
|
var IdentityCMap = (function IdentityCMapClosure() {
|
||||||
function IdentityCMap(vertical, n) {
|
function IdentityCMap(vertical, n) {
|
||||||
CMap.call(this);
|
CMap.call(this);
|
||||||
@ -13544,7 +13585,11 @@ var IdentityCMap = (function IdentityCMapClosure() {
|
|||||||
return map;
|
return map;
|
||||||
},
|
},
|
||||||
|
|
||||||
readCharCode: CMap.prototype.readCharCode
|
readCharCode: CMap.prototype.readCharCode,
|
||||||
|
|
||||||
|
get isIdentityCMap() {
|
||||||
|
error('should not access .isIdentityCMap');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return IdentityCMap;
|
return IdentityCMap;
|
||||||
@ -14009,6 +14054,13 @@ var CMapFactory = (function CMapFactoryClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseCMapName(cMap, lexer) {
|
||||||
|
var obj = lexer.getObj();
|
||||||
|
if (isName(obj) && isString(obj.name)) {
|
||||||
|
cMap.name = obj.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
|
function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
|
||||||
var previous;
|
var previous;
|
||||||
var embededUseCMap;
|
var embededUseCMap;
|
||||||
@ -14019,6 +14071,8 @@ var CMapFactory = (function CMapFactoryClosure() {
|
|||||||
} else if (isName(obj)) {
|
} else if (isName(obj)) {
|
||||||
if (obj.name === 'WMode') {
|
if (obj.name === 'WMode') {
|
||||||
parseWMode(cMap, lexer);
|
parseWMode(cMap, lexer);
|
||||||
|
} else if (obj.name === 'CMapName') {
|
||||||
|
parseCMapName(cMap, lexer);
|
||||||
}
|
}
|
||||||
previous = obj;
|
previous = obj;
|
||||||
} else if (isCmd(obj)) {
|
} else if (isCmd(obj)) {
|
||||||
@ -14128,6 +14182,9 @@ var CMapFactory = (function CMapFactoryClosure() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
warn('Invalid CMap data. ' + e);
|
warn('Invalid CMap data. ' + e);
|
||||||
}
|
}
|
||||||
|
if (cMap.isIdentityCMap) {
|
||||||
|
return createBuiltInCMap(cMap.name, builtInCMapParams);
|
||||||
|
}
|
||||||
return cMap;
|
return cMap;
|
||||||
}
|
}
|
||||||
error('Encoding required.');
|
error('Encoding required.');
|
||||||
@ -14637,7 +14694,7 @@ var SpecialPUASymbols = {
|
|||||||
'63731': 0x23A9, // braceleftbt (0xF8F3)
|
'63731': 0x23A9, // braceleftbt (0xF8F3)
|
||||||
'63740': 0x23AB, // bracerighttp (0xF8FC)
|
'63740': 0x23AB, // bracerighttp (0xF8FC)
|
||||||
'63741': 0x23AC, // bracerightmid (0xF8FD)
|
'63741': 0x23AC, // bracerightmid (0xF8FD)
|
||||||
'63742': 0x23AD, // bracerightmid (0xF8FE)
|
'63742': 0x23AD, // bracerightbt (0xF8FE)
|
||||||
'63726': 0x23A1, // bracketlefttp (0xF8EE)
|
'63726': 0x23A1, // bracketlefttp (0xF8EE)
|
||||||
'63727': 0x23A2, // bracketleftex (0xF8EF)
|
'63727': 0x23A2, // bracketleftex (0xF8EF)
|
||||||
'63728': 0x23A3, // bracketleftbt (0xF8F0)
|
'63728': 0x23A3, // bracketleftbt (0xF8F0)
|
||||||
@ -16317,6 +16374,10 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
has: function(i) {
|
||||||
|
return this._map[i] !== undefined;
|
||||||
|
},
|
||||||
|
|
||||||
get: function(i) {
|
get: function(i) {
|
||||||
return this._map[i];
|
return this._map[i];
|
||||||
},
|
},
|
||||||
@ -16337,7 +16398,7 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
|
|||||||
|
|
||||||
IdentityToUnicodeMap.prototype = {
|
IdentityToUnicodeMap.prototype = {
|
||||||
get length() {
|
get length() {
|
||||||
error('should not access .length');
|
return (this.lastChar + 1) - this.firstChar;
|
||||||
},
|
},
|
||||||
|
|
||||||
forEach: function (callback) {
|
forEach: function (callback) {
|
||||||
@ -16346,6 +16407,10 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
has: function (i) {
|
||||||
|
return this.firstChar <= i && i <= this.lastChar;
|
||||||
|
},
|
||||||
|
|
||||||
get: function (i) {
|
get: function (i) {
|
||||||
if (this.firstChar <= i && i <= this.lastChar) {
|
if (this.firstChar <= i && i <= this.lastChar) {
|
||||||
return String.fromCharCode(i);
|
return String.fromCharCode(i);
|
||||||
@ -16577,7 +16642,7 @@ var Font = (function FontClosure() {
|
|||||||
// to be used with the canvas.font.
|
// to be used with the canvas.font.
|
||||||
var fontName = name.replace(/[,_]/g, '-');
|
var fontName = name.replace(/[,_]/g, '-');
|
||||||
var isStandardFont = !!stdFontMap[fontName] ||
|
var isStandardFont = !!stdFontMap[fontName] ||
|
||||||
(nonStdFontMap[fontName] && !!stdFontMap[nonStdFontMap[fontName]]);
|
!!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
|
||||||
fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
|
fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
|
||||||
|
|
||||||
this.bold = (fontName.search(/bold/gi) !== -1);
|
this.bold = (fontName.search(/bold/gi) !== -1);
|
||||||
@ -16678,11 +16743,13 @@ var Font = (function FontClosure() {
|
|||||||
if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
|
if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
|
||||||
type = 'CIDFontType0';
|
type = 'CIDFontType0';
|
||||||
}
|
}
|
||||||
// XXX: Temporarily change the type for open type so we trigger a warning.
|
|
||||||
// This should be removed when we add support for open type.
|
|
||||||
if (subtype === 'OpenType') {
|
if (subtype === 'OpenType') {
|
||||||
type = 'OpenType';
|
type = 'OpenType';
|
||||||
}
|
}
|
||||||
|
// Some CIDFontType0C fonts by mistake claim CIDFontType0.
|
||||||
|
if (type === 'CIDFontType0') {
|
||||||
|
subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
|
||||||
|
}
|
||||||
|
|
||||||
var data;
|
var data;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -16763,6 +16830,52 @@ var Font = (function FontClosure() {
|
|||||||
return readUint32(header, 0) === 0x00010000;
|
return readUint32(header, 0) === 0x00010000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isType1File(file) {
|
||||||
|
var header = file.peekBytes(2);
|
||||||
|
// All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
|
||||||
|
if (header[0] === 0x25 && header[1] === 0x21) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// ... obviously some fonts violate that part of the specification,
|
||||||
|
// please refer to the comment in |Type1Font| below.
|
||||||
|
if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for |adjustMapping|.
|
||||||
|
* @return {boolean}
|
||||||
|
*/
|
||||||
|
function isProblematicUnicodeLocation(code) {
|
||||||
|
if (code <= 0x1F) { // Control chars
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (code >= 0x80 && code <= 0x9F) { // Control chars
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ((code >= 0x2000 && code <= 0x200F) || // General punctuation chars
|
||||||
|
(code >= 0x2028 && code <= 0x202F) ||
|
||||||
|
(code >= 0x2060 && code <= 0x206F)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials Unicode block
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (code) {
|
||||||
|
case 0x7F: // Control char
|
||||||
|
case 0xA0: // Non breaking space
|
||||||
|
case 0xAD: // Soft hyphen
|
||||||
|
case 0x0E33: // Thai character SARA AM
|
||||||
|
case 0x2011: // Non breaking hyphen
|
||||||
|
case 0x205F: // Medium mathematical space
|
||||||
|
case 0x25CC: // Dotted circle (combining mark)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rebuilds the char code to glyph ID map by trying to replace the char codes
|
* Rebuilds the char code to glyph ID map by trying to replace the char codes
|
||||||
* with their unicode value. It also moves char codes that are in known
|
* with their unicode value. It also moves char codes that are in known
|
||||||
@ -16778,7 +16891,6 @@ var Font = (function FontClosure() {
|
|||||||
var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
|
var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
|
||||||
var isIdentityUnicode =
|
var isIdentityUnicode =
|
||||||
properties.toUnicode instanceof IdentityToUnicodeMap;
|
properties.toUnicode instanceof IdentityToUnicodeMap;
|
||||||
var isCidFontType2 = (properties.type === 'CIDFontType2');
|
|
||||||
var newMap = Object.create(null);
|
var newMap = Object.create(null);
|
||||||
var toFontChar = [];
|
var toFontChar = [];
|
||||||
var usedFontCharCodes = [];
|
var usedFontCharCodes = [];
|
||||||
@ -16789,17 +16901,11 @@ var Font = (function FontClosure() {
|
|||||||
var fontCharCode = originalCharCode;
|
var fontCharCode = originalCharCode;
|
||||||
// First try to map the value to a unicode position if a non identity map
|
// First try to map the value to a unicode position if a non identity map
|
||||||
// was created.
|
// was created.
|
||||||
if (!isIdentityUnicode) {
|
if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
|
||||||
if (toUnicode.get(originalCharCode) !== undefined) {
|
var unicode = toUnicode.get(fontCharCode);
|
||||||
var unicode = toUnicode.get(fontCharCode);
|
// TODO: Try to map ligatures to the correct spot.
|
||||||
// TODO: Try to map ligatures to the correct spot.
|
if (unicode.length === 1) {
|
||||||
if (unicode.length === 1) {
|
fontCharCode = unicode.charCodeAt(0);
|
||||||
fontCharCode = unicode.charCodeAt(0);
|
|
||||||
}
|
|
||||||
} else if (isCidFontType2) {
|
|
||||||
// For CIDFontType2, move characters not present in toUnicode
|
|
||||||
// to the private use area (fixes bug 1028735 and issue 4881).
|
|
||||||
fontCharCode = nextAvailableFontCharCode;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Try to move control characters, special characters and already mapped
|
// Try to move control characters, special characters and already mapped
|
||||||
@ -16809,13 +16915,7 @@ var Font = (function FontClosure() {
|
|||||||
// characters probably aren't in the correct position (fixes an issue
|
// characters probably aren't in the correct position (fixes an issue
|
||||||
// with firefox and thuluthfont).
|
// with firefox and thuluthfont).
|
||||||
if ((usedFontCharCodes[fontCharCode] !== undefined ||
|
if ((usedFontCharCodes[fontCharCode] !== undefined ||
|
||||||
fontCharCode <= 0x1f || // Control chars
|
isProblematicUnicodeLocation(fontCharCode) ||
|
||||||
fontCharCode === 0x7F || // Control char
|
|
||||||
fontCharCode === 0xAD || // Soft hyphen
|
|
||||||
fontCharCode === 0xA0 || // Non breaking space
|
|
||||||
(fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
|
|
||||||
// Prevent drawing characters in the specials unicode block.
|
|
||||||
(fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
|
|
||||||
(isSymbolic && isIdentityUnicode)) &&
|
(isSymbolic && isIdentityUnicode)) &&
|
||||||
nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
|
nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
|
||||||
// Loop to try and find a free spot in the private use area.
|
// Loop to try and find a free spot in the private use area.
|
||||||
@ -17289,13 +17389,20 @@ var Font = (function FontClosure() {
|
|||||||
var offset = font.getInt32() >>> 0;
|
var offset = font.getInt32() >>> 0;
|
||||||
var useTable = false;
|
var useTable = false;
|
||||||
|
|
||||||
if (platformId === 1 && encodingId === 0) {
|
if (platformId === 0 && encodingId === 0) {
|
||||||
useTable = true;
|
useTable = true;
|
||||||
// Continue the loop since there still may be a higher priority
|
// Continue the loop since there still may be a higher priority
|
||||||
// table.
|
// table.
|
||||||
} else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
|
} else if (platformId === 1 && encodingId === 0) {
|
||||||
useTable = true;
|
useTable = true;
|
||||||
canBreak = true;
|
// Continue the loop since there still may be a higher priority
|
||||||
|
// table.
|
||||||
|
} else if (platformId === 3 && encodingId === 1 &&
|
||||||
|
(!isSymbolicFont || !potentialTable)) {
|
||||||
|
useTable = true;
|
||||||
|
if (!isSymbolicFont) {
|
||||||
|
canBreak = true;
|
||||||
|
}
|
||||||
} else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
|
} else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
|
||||||
useTable = true;
|
useTable = true;
|
||||||
canBreak = true;
|
canBreak = true;
|
||||||
@ -17640,6 +17747,7 @@ var Font = (function FontClosure() {
|
|||||||
var newGlyfData = new Uint8Array(oldGlyfDataLength);
|
var newGlyfData = new Uint8Array(oldGlyfDataLength);
|
||||||
var startOffset = itemDecode(locaData, 0);
|
var startOffset = itemDecode(locaData, 0);
|
||||||
var writeOffset = 0;
|
var writeOffset = 0;
|
||||||
|
var missingGlyphData = {};
|
||||||
itemEncode(locaData, 0, writeOffset);
|
itemEncode(locaData, 0, writeOffset);
|
||||||
var i, j;
|
var i, j;
|
||||||
for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
|
for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
|
||||||
@ -17657,6 +17765,10 @@ var Font = (function FontClosure() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (startOffset === endOffset) {
|
||||||
|
missingGlyphData[i] = true;
|
||||||
|
}
|
||||||
|
|
||||||
var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
|
var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
|
||||||
newGlyfData, writeOffset, hintsValid);
|
newGlyfData, writeOffset, hintsValid);
|
||||||
writeOffset += newLength;
|
writeOffset += newLength;
|
||||||
@ -17673,7 +17785,7 @@ var Font = (function FontClosure() {
|
|||||||
itemEncode(locaData, j, simpleGlyph.length);
|
itemEncode(locaData, j, simpleGlyph.length);
|
||||||
}
|
}
|
||||||
glyf.data = simpleGlyph;
|
glyf.data = simpleGlyph;
|
||||||
return;
|
return missingGlyphData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dupFirstEntry) {
|
if (dupFirstEntry) {
|
||||||
@ -17690,6 +17802,7 @@ var Font = (function FontClosure() {
|
|||||||
} else {
|
} else {
|
||||||
glyf.data = newGlyfData.subarray(0, writeOffset);
|
glyf.data = newGlyfData.subarray(0, writeOffset);
|
||||||
}
|
}
|
||||||
|
return missingGlyphData;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readPostScriptTable(post, properties, maxpNumGlyphs) {
|
function readPostScriptTable(post, properties, maxpNumGlyphs) {
|
||||||
@ -18080,7 +18193,8 @@ var Font = (function FontClosure() {
|
|||||||
var isTrueType = !tables['CFF '];
|
var isTrueType = !tables['CFF '];
|
||||||
if (!isTrueType) {
|
if (!isTrueType) {
|
||||||
// OpenType font
|
// OpenType font
|
||||||
if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
|
if (header.version === 'OTTO' ||
|
||||||
|
!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
|
||||||
// no major tables: throwing everything at CFFFont
|
// no major tables: throwing everything at CFFFont
|
||||||
cffFile = new Stream(tables['CFF '].data);
|
cffFile = new Stream(tables['CFF '].data);
|
||||||
cff = new CFFFont(cffFile, properties);
|
cff = new CFFFont(cffFile, properties);
|
||||||
@ -18149,11 +18263,13 @@ var Font = (function FontClosure() {
|
|||||||
|
|
||||||
sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
|
sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
|
||||||
|
|
||||||
|
var missingGlyphs = {};
|
||||||
if (isTrueType) {
|
if (isTrueType) {
|
||||||
var isGlyphLocationsLong = int16(tables.head.data[50],
|
var isGlyphLocationsLong = int16(tables.head.data[50],
|
||||||
tables.head.data[51]);
|
tables.head.data[51]);
|
||||||
sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
|
missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
|
||||||
isGlyphLocationsLong, hintsValid, dupFirstEntry);
|
numGlyphs, isGlyphLocationsLong,
|
||||||
|
hintsValid, dupFirstEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tables.hhea) {
|
if (!tables.hhea) {
|
||||||
@ -18175,19 +18291,33 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var charCodeToGlyphId = [], charCode;
|
var charCodeToGlyphId = [], charCode, toUnicode = properties.toUnicode;
|
||||||
|
|
||||||
|
function hasGlyph(glyphId, charCode) {
|
||||||
|
if (!missingGlyphs[glyphId]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (charCode >= 0 && toUnicode.has(charCode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.type === 'CIDFontType2') {
|
if (properties.type === 'CIDFontType2') {
|
||||||
var cidToGidMap = properties.cidToGidMap || [];
|
var cidToGidMap = properties.cidToGidMap || [];
|
||||||
var cidToGidMapLength = cidToGidMap.length;
|
var isCidToGidMapEmpty = cidToGidMap.length === 0;
|
||||||
|
|
||||||
properties.cMap.forEach(function(charCode, cid) {
|
properties.cMap.forEach(function(charCode, cid) {
|
||||||
assert(cid <= 0xffff, 'Max size of CID is 65,535');
|
assert(cid <= 0xffff, 'Max size of CID is 65,535');
|
||||||
var glyphId = -1;
|
var glyphId = -1;
|
||||||
if (cidToGidMapLength === 0) {
|
if (isCidToGidMapEmpty) {
|
||||||
glyphId = charCode;
|
glyphId = charCode;
|
||||||
} else if (cidToGidMap[cid] !== undefined) {
|
} else if (cidToGidMap[cid] !== undefined) {
|
||||||
glyphId = cidToGidMap[cid];
|
glyphId = cidToGidMap[cid];
|
||||||
}
|
}
|
||||||
if (glyphId >= 0 && glyphId < numGlyphs) {
|
|
||||||
|
if (glyphId >= 0 && glyphId < numGlyphs &&
|
||||||
|
hasGlyph(glyphId, charCode)) {
|
||||||
charCodeToGlyphId[charCode] = glyphId;
|
charCodeToGlyphId[charCode] = glyphId;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -18247,7 +18377,8 @@ var Font = (function FontClosure() {
|
|||||||
|
|
||||||
var found = false;
|
var found = false;
|
||||||
for (i = 0; i < cmapMappingsLength; ++i) {
|
for (i = 0; i < cmapMappingsLength; ++i) {
|
||||||
if (cmapMappings[i].charCode === unicodeOrCharCode) {
|
if (cmapMappings[i].charCode === unicodeOrCharCode &&
|
||||||
|
hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode)) {
|
||||||
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
@ -18257,11 +18388,17 @@ var Font = (function FontClosure() {
|
|||||||
// Try to map using the post table. There are currently no known
|
// Try to map using the post table. There are currently no known
|
||||||
// pdfs that this fixes.
|
// pdfs that this fixes.
|
||||||
var glyphId = properties.glyphNames.indexOf(glyphName);
|
var glyphId = properties.glyphNames.indexOf(glyphName);
|
||||||
if (glyphId > 0) {
|
if (glyphId > 0 && hasGlyph(glyphId, -1)) {
|
||||||
charCodeToGlyphId[charCode] = glyphId;
|
charCodeToGlyphId[charCode] = glyphId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
|
||||||
|
// Default Unicode semantics, use the charcodes as is.
|
||||||
|
for (i = 0; i < cmapMappingsLength; ++i) {
|
||||||
|
charCodeToGlyphId[cmapMappings[i].charCode] =
|
||||||
|
cmapMappings[i].glyphId;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// For (3, 0) cmap tables:
|
// For (3, 0) cmap tables:
|
||||||
// The charcode key being stored in charCodeToGlyphId is the lower
|
// The charcode key being stored in charCodeToGlyphId is the lower
|
||||||
@ -22026,7 +22163,6 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var GlyphsUnicode = {
|
var GlyphsUnicode = {
|
||||||
A: 0x0041,
|
A: 0x0041,
|
||||||
AE: 0x00C6,
|
AE: 0x00C6,
|
||||||
@ -30033,7 +30169,6 @@ var Metrics = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var EOF = {};
|
var EOF = {};
|
||||||
|
|
||||||
function isEOF(v) {
|
function isEOF(v) {
|
||||||
@ -30176,6 +30311,102 @@ var Parser = (function ParserClosure() {
|
|||||||
}
|
}
|
||||||
return ((stream.pos - 4) - startPos);
|
return ((stream.pos - 4) - startPos);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Find the EOI (end-of-image) marker 0xFFD9 of the stream.
|
||||||
|
* @returns {number} The inline stream length.
|
||||||
|
*/
|
||||||
|
findDCTDecodeInlineStreamEnd:
|
||||||
|
function Parser_findDCTDecodeInlineStreamEnd(stream) {
|
||||||
|
var startPos = stream.pos, foundEOI = false, b, markerLength, length;
|
||||||
|
while ((b = stream.getByte()) !== -1) {
|
||||||
|
if (b !== 0xFF) { // Not a valid marker.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
switch (stream.getByte()) {
|
||||||
|
case 0x00: // Byte stuffing.
|
||||||
|
// 0xFF00 appears to be a very common byte sequence in JPEG images.
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xFF: // Fill byte.
|
||||||
|
// Avoid skipping a valid marker, resetting the stream position.
|
||||||
|
stream.skip(-1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xD9: // EOI
|
||||||
|
foundEOI = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0xC0: // SOF0
|
||||||
|
case 0xC1: // SOF1
|
||||||
|
case 0xC2: // SOF2
|
||||||
|
case 0xC3: // SOF3
|
||||||
|
|
||||||
|
case 0xC5: // SOF5
|
||||||
|
case 0xC6: // SOF6
|
||||||
|
case 0xC7: // SOF7
|
||||||
|
|
||||||
|
case 0xC9: // SOF9
|
||||||
|
case 0xCA: // SOF10
|
||||||
|
case 0xCB: // SOF11
|
||||||
|
|
||||||
|
case 0xCD: // SOF13
|
||||||
|
case 0xCE: // SOF14
|
||||||
|
case 0xCF: // SOF15
|
||||||
|
|
||||||
|
case 0xC4: // DHT
|
||||||
|
case 0xCC: // DAC
|
||||||
|
|
||||||
|
case 0xDA: // SOS
|
||||||
|
case 0xDB: // DQT
|
||||||
|
case 0xDC: // DNL
|
||||||
|
case 0xDD: // DRI
|
||||||
|
case 0xDE: // DHP
|
||||||
|
case 0xDF: // EXP
|
||||||
|
|
||||||
|
case 0xE0: // APP0
|
||||||
|
case 0xE1: // APP1
|
||||||
|
case 0xE2: // APP2
|
||||||
|
case 0xE3: // APP3
|
||||||
|
case 0xE4: // APP4
|
||||||
|
case 0xE5: // APP5
|
||||||
|
case 0xE6: // APP6
|
||||||
|
case 0xE7: // APP7
|
||||||
|
case 0xE8: // APP8
|
||||||
|
case 0xE9: // APP9
|
||||||
|
case 0xEA: // APP10
|
||||||
|
case 0xEB: // APP11
|
||||||
|
case 0xEC: // APP12
|
||||||
|
case 0xED: // APP13
|
||||||
|
case 0xEE: // APP14
|
||||||
|
case 0xEF: // APP15
|
||||||
|
|
||||||
|
case 0xFE: // COM
|
||||||
|
// The marker should be followed by the length of the segment.
|
||||||
|
markerLength = stream.getUint16();
|
||||||
|
if (markerLength > 2) {
|
||||||
|
// |markerLength| contains the byte length of the marker segment,
|
||||||
|
// including its own length (2 bytes) and excluding the marker.
|
||||||
|
stream.skip(markerLength - 2); // Jump to the next marker.
|
||||||
|
} else {
|
||||||
|
// The marker length is invalid, resetting the stream position.
|
||||||
|
stream.skip(-2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (foundEOI) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
length = stream.pos - startPos;
|
||||||
|
if (b === -1) {
|
||||||
|
warn('Inline DCTDecode image stream: ' +
|
||||||
|
'EOI marker not found, searching for /EI/ instead.');
|
||||||
|
stream.skip(-length); // Reset the stream position.
|
||||||
|
return this.findDefaultInlineStreamEnd(stream);
|
||||||
|
}
|
||||||
|
this.inlineStreamSkipEI(stream);
|
||||||
|
return length;
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
|
* Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
|
||||||
* @returns {number} The inline stream length.
|
* @returns {number} The inline stream length.
|
||||||
@ -30267,7 +30498,9 @@ var Parser = (function ParserClosure() {
|
|||||||
|
|
||||||
// Parse image stream.
|
// Parse image stream.
|
||||||
var startPos = stream.pos, length, i, ii;
|
var startPos = stream.pos, length, i, ii;
|
||||||
if (filterName === 'ASCII85Decide' || filterName === 'A85') {
|
if (filterName === 'DCTDecode' || filterName === 'DCT') {
|
||||||
|
length = this.findDCTDecodeInlineStreamEnd(stream);
|
||||||
|
} else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
|
||||||
length = this.findASCII85DecodeInlineStreamEnd(stream);
|
length = this.findASCII85DecodeInlineStreamEnd(stream);
|
||||||
} else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
|
} else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
|
||||||
length = this.findASCIIHexDecodeInlineStreamEnd(stream);
|
length = this.findASCIIHexDecodeInlineStreamEnd(stream);
|
||||||
@ -31194,6 +31427,9 @@ var Stream = (function StreamClosure() {
|
|||||||
getUint16: function Stream_getUint16() {
|
getUint16: function Stream_getUint16() {
|
||||||
var b0 = this.getByte();
|
var b0 = this.getByte();
|
||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
|
if (b0 === -1 || b1 === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return (b0 << 8) + b1;
|
return (b0 << 8) + b1;
|
||||||
},
|
},
|
||||||
getInt32: function Stream_getInt32() {
|
getInt32: function Stream_getInt32() {
|
||||||
@ -31321,6 +31557,9 @@ var DecodeStream = (function DecodeStreamClosure() {
|
|||||||
getUint16: function DecodeStream_getUint16() {
|
getUint16: function DecodeStream_getUint16() {
|
||||||
var b0 = this.getByte();
|
var b0 = this.getByte();
|
||||||
var b1 = this.getByte();
|
var b1 = this.getByte();
|
||||||
|
if (b0 === -1 || b1 === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return (b0 << 8) + b1;
|
return (b0 << 8) + b1;
|
||||||
},
|
},
|
||||||
getInt32: function DecodeStream_getInt32() {
|
getInt32: function DecodeStream_getInt32() {
|
||||||
@ -31433,25 +31672,25 @@ var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
var FlateStream = (function FlateStreamClosure() {
|
var FlateStream = (function FlateStreamClosure() {
|
||||||
var codeLenCodeMap = new Uint32Array([
|
var codeLenCodeMap = new Int32Array([
|
||||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var lengthDecode = new Uint32Array([
|
var lengthDecode = new Int32Array([
|
||||||
0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
|
0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
|
||||||
0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
|
0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
|
||||||
0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
|
0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
|
||||||
0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
|
0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var distDecode = new Uint32Array([
|
var distDecode = new Int32Array([
|
||||||
0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
|
0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
|
||||||
0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
|
0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
|
||||||
0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
|
0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
|
||||||
0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
|
0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var fixedLitCodeTab = [new Uint32Array([
|
var fixedLitCodeTab = [new Int32Array([
|
||||||
0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
|
0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
|
||||||
0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
|
0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
|
||||||
0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
|
0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
|
||||||
@ -31518,7 +31757,7 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
|
0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
|
||||||
]), 9];
|
]), 9];
|
||||||
|
|
||||||
var fixedDistCodeTab = [new Uint32Array([
|
var fixedDistCodeTab = [new Int32Array([
|
||||||
0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
|
0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
|
||||||
0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
|
0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
|
||||||
0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
|
0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
|
||||||
@ -31615,7 +31854,7 @@ var FlateStream = (function FlateStreamClosure() {
|
|||||||
|
|
||||||
// build the table
|
// build the table
|
||||||
var size = 1 << maxLen;
|
var size = 1 << maxLen;
|
||||||
var codes = new Uint32Array(size);
|
var codes = new Int32Array(size);
|
||||||
for (var len = 1, code = 0, skip = 2;
|
for (var len = 1, code = 0, skip = 2;
|
||||||
len <= maxLen;
|
len <= maxLen;
|
||||||
++len, code <<= 1, skip <<= 1) {
|
++len, code <<= 1, skip <<= 1) {
|
||||||
@ -33185,6 +33424,10 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
|
|
||||||
var gotEOL = false;
|
var gotEOL = false;
|
||||||
|
|
||||||
|
if (this.byteAlign) {
|
||||||
|
this.inputBits &= ~7;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.eoblock && this.row === this.rows - 1) {
|
if (!this.eoblock && this.row === this.rows - 1) {
|
||||||
this.eof = true;
|
this.eof = true;
|
||||||
} else {
|
} else {
|
||||||
@ -33208,10 +33451,6 @@ var CCITTFaxStream = (function CCITTFaxStreamClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.byteAlign && !gotEOL) {
|
|
||||||
this.inputBits &= ~7;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.eof && this.encoding > 0) {
|
if (!this.eof && this.encoding > 0) {
|
||||||
this.nextLine2D = !this.lookBits(1);
|
this.nextLine2D = !this.lookBits(1);
|
||||||
this.eatBits(1);
|
this.eatBits(1);
|
||||||
@ -34891,9 +35130,9 @@ var JpegImage = (function jpegImage() {
|
|||||||
if (fileMarker === 0xFFEE) {
|
if (fileMarker === 0xFFEE) {
|
||||||
if (appData[0] === 0x41 && appData[1] === 0x64 &&
|
if (appData[0] === 0x41 && appData[1] === 0x64 &&
|
||||||
appData[2] === 0x6F && appData[3] === 0x62 &&
|
appData[2] === 0x6F && appData[3] === 0x62 &&
|
||||||
appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
|
appData[4] === 0x65) { // 'Adobe'
|
||||||
adobe = {
|
adobe = {
|
||||||
version: appData[6],
|
version: (appData[5] << 8) | appData[6],
|
||||||
flags0: (appData[7] << 8) | appData[8],
|
flags0: (appData[7] << 8) | appData[8],
|
||||||
flags1: (appData[9] << 8) | appData[10],
|
flags1: (appData[9] << 8) | appData[10],
|
||||||
transformCode: appData[11]
|
transformCode: appData[11]
|
||||||
@ -35014,6 +35253,13 @@ var JpegImage = (function jpegImage() {
|
|||||||
successiveApproximation >> 4, successiveApproximation & 15);
|
successiveApproximation >> 4, successiveApproximation & 15);
|
||||||
offset += processed;
|
offset += processed;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0xFFFF: // Fill bytes
|
||||||
|
if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
|
||||||
|
offset--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (data[offset - 3] === 0xFF &&
|
if (data[offset - 3] === 0xFF &&
|
||||||
data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
|
data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
|
||||||
@ -35420,11 +35666,6 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
context.QCC = [];
|
context.QCC = [];
|
||||||
context.COC = [];
|
context.COC = [];
|
||||||
break;
|
break;
|
||||||
case 0xFF55: // Tile-part lengths, main header (TLM)
|
|
||||||
var Ltlm = readUint16(data, position); // Marker segment length
|
|
||||||
// Skip tile length markers
|
|
||||||
position += Ltlm;
|
|
||||||
break;
|
|
||||||
case 0xFF5C: // Quantization default (QCD)
|
case 0xFF5C: // Quantization default (QCD)
|
||||||
length = readUint16(data, position);
|
length = readUint16(data, position);
|
||||||
var qcd = {};
|
var qcd = {};
|
||||||
@ -35614,6 +35855,9 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
length = tile.dataEnd - position;
|
length = tile.dataEnd - position;
|
||||||
parseTilePackets(context, data, position, length);
|
parseTilePackets(context, data, position, length);
|
||||||
break;
|
break;
|
||||||
|
case 0xFF55: // Tile-part lengths, main header (TLM)
|
||||||
|
case 0xFF57: // Packet length, main header (PLM)
|
||||||
|
case 0xFF58: // Packet length, tile-part header (PLT)
|
||||||
case 0xFF64: // Comment (COM)
|
case 0xFF64: // Comment (COM)
|
||||||
length = readUint16(data, position);
|
length = readUint16(data, position);
|
||||||
// skipping content
|
// skipping content
|
||||||
@ -37450,7 +37694,6 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var Jbig2Image = (function Jbig2ImageClosure() {
|
var Jbig2Image = (function Jbig2ImageClosure() {
|
||||||
// Utility data structures
|
// Utility data structures
|
||||||
function ContextCache() {}
|
function ContextCache() {}
|
||||||
@ -37611,10 +37854,9 @@ var Jbig2Image = (function Jbig2ImageClosure() {
|
|||||||
|
|
||||||
// At each pixel: Clear contextLabel pixels that are shifted
|
// At each pixel: Clear contextLabel pixels that are shifted
|
||||||
// out of the context, then add new ones.
|
// out of the context, then add new ones.
|
||||||
// If j + n is out of range at the right image border, then
|
|
||||||
// the undefined value of bitmap[i - 2][j + n] is shifted to 0
|
|
||||||
contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
|
contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
|
||||||
(row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
|
(j + 3 < width ? row2[j + 3] << 11 : 0) |
|
||||||
|
(j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38928,7 +39170,6 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
|
|||||||
return bidi;
|
return bidi;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
var /**@const{!string}*/pdfjs_version = "v1.0.1040";
|
var /**@const{!string}*/pdfjs_version = "v1.1.114";
|
||||||
|
@ -13,14 +13,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals CustomStyle, scrollIntoView, PDFJS */
|
/* globals CustomStyle, PDFJS */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var FIND_SCROLL_OFFSET_TOP = -50;
|
|
||||||
var FIND_SCROLL_OFFSET_LEFT = -400;
|
|
||||||
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
var MAX_TEXT_DIVS_TO_RENDER = 100000;
|
||||||
var RENDER_DELAY = 200; // ms
|
|
||||||
|
|
||||||
var NonWhitespaceRegexp = /\S/;
|
var NonWhitespaceRegexp = /\S/;
|
||||||
|
|
||||||
@ -33,9 +30,6 @@ function isAllWhitespace(str) {
|
|||||||
* @property {HTMLDivElement} textLayerDiv - The text layer container.
|
* @property {HTMLDivElement} textLayerDiv - The text layer container.
|
||||||
* @property {number} pageIndex - The page index.
|
* @property {number} pageIndex - The page index.
|
||||||
* @property {PageViewport} viewport - The viewport of the text layer.
|
* @property {PageViewport} viewport - The viewport of the text layer.
|
||||||
* @property {ILastScrollSource} lastScrollSource - The object that records when
|
|
||||||
* last time scroll happened.
|
|
||||||
* @property {boolean} isViewerInPresentationMode
|
|
||||||
* @property {PDFFindController} findController
|
* @property {PDFFindController} findController
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -49,18 +43,27 @@ function isAllWhitespace(str) {
|
|||||||
var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
||||||
function TextLayerBuilder(options) {
|
function TextLayerBuilder(options) {
|
||||||
this.textLayerDiv = options.textLayerDiv;
|
this.textLayerDiv = options.textLayerDiv;
|
||||||
this.layoutDone = false;
|
this.renderingDone = false;
|
||||||
this.divContentDone = false;
|
this.divContentDone = false;
|
||||||
this.pageIdx = options.pageIndex;
|
this.pageIdx = options.pageIndex;
|
||||||
|
this.pageNumber = this.pageIdx + 1;
|
||||||
this.matches = [];
|
this.matches = [];
|
||||||
this.lastScrollSource = options.lastScrollSource || null;
|
|
||||||
this.viewport = options.viewport;
|
this.viewport = options.viewport;
|
||||||
this.isViewerInPresentationMode = options.isViewerInPresentationMode;
|
|
||||||
this.textDivs = [];
|
this.textDivs = [];
|
||||||
this.findController = options.findController || null;
|
this.findController = options.findController || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextLayerBuilder.prototype = {
|
TextLayerBuilder.prototype = {
|
||||||
|
_finishRendering: function TextLayerBuilder_finishRendering() {
|
||||||
|
this.renderingDone = true;
|
||||||
|
|
||||||
|
var event = document.createEvent('CustomEvent');
|
||||||
|
event.initCustomEvent('textlayerrendered', true, true, {
|
||||||
|
pageNumber: this.pageNumber
|
||||||
|
});
|
||||||
|
this.textLayerDiv.dispatchEvent(event);
|
||||||
|
},
|
||||||
|
|
||||||
renderLayer: function TextLayerBuilder_renderLayer() {
|
renderLayer: function TextLayerBuilder_renderLayer() {
|
||||||
var textLayerFrag = document.createDocumentFragment();
|
var textLayerFrag = document.createDocumentFragment();
|
||||||
var textDivs = this.textDivs;
|
var textDivs = this.textDivs;
|
||||||
@ -71,6 +74,7 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
// No point in rendering many divs as it would make the browser
|
// No point in rendering many divs as it would make the browser
|
||||||
// unusable even after the divs are rendered.
|
// unusable even after the divs are rendered.
|
||||||
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
|
||||||
|
this._finishRendering();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,27 +118,33 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.textLayerDiv.appendChild(textLayerFrag);
|
this.textLayerDiv.appendChild(textLayerFrag);
|
||||||
this.renderingDone = true;
|
this._finishRendering();
|
||||||
this.updateMatches();
|
this.updateMatches();
|
||||||
},
|
},
|
||||||
|
|
||||||
setupRenderLayoutTimer:
|
/**
|
||||||
function TextLayerBuilder_setupRenderLayoutTimer() {
|
* Renders the text layer.
|
||||||
// Schedule renderLayout() if the user has been scrolling,
|
* @param {number} timeout (optional) if specified, the rendering waits
|
||||||
// otherwise run it right away.
|
* for specified amount of ms.
|
||||||
var self = this;
|
*/
|
||||||
var lastScroll = (this.lastScrollSource === null ?
|
render: function TextLayerBuilder_render(timeout) {
|
||||||
0 : this.lastScrollSource.lastScroll);
|
if (!this.divContentDone || this.renderingDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Date.now() - lastScroll > RENDER_DELAY) { // Render right away
|
if (this.renderTimer) {
|
||||||
|
clearTimeout(this.renderTimer);
|
||||||
|
this.renderTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timeout) { // Render right away
|
||||||
this.renderLayer();
|
this.renderLayer();
|
||||||
} else { // Schedule
|
} else { // Schedule
|
||||||
if (this.renderTimer) {
|
var self = this;
|
||||||
clearTimeout(this.renderTimer);
|
|
||||||
}
|
|
||||||
this.renderTimer = setTimeout(function() {
|
this.renderTimer = setTimeout(function() {
|
||||||
self.setupRenderLayoutTimer();
|
self.renderLayer();
|
||||||
}, RENDER_DELAY);
|
self.renderTimer = null;
|
||||||
|
}, timeout);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -204,7 +214,6 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
this.appendText(textItems[i], textContent.styles);
|
this.appendText(textItems[i], textContent.styles);
|
||||||
}
|
}
|
||||||
this.divContentDone = true;
|
this.divContentDone = true;
|
||||||
this.setupRenderLayoutTimer();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
convertMatches: function TextLayerBuilder_convertMatches(matches) {
|
convertMatches: function TextLayerBuilder_convertMatches(matches) {
|
||||||
@ -266,8 +275,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
var bidiTexts = this.textContent.items;
|
var bidiTexts = this.textContent.items;
|
||||||
var textDivs = this.textDivs;
|
var textDivs = this.textDivs;
|
||||||
var prevEnd = null;
|
var prevEnd = null;
|
||||||
|
var pageIdx = this.pageIdx;
|
||||||
var isSelectedPage = (this.findController === null ?
|
var isSelectedPage = (this.findController === null ?
|
||||||
false : (this.pageIdx === this.findController.selected.pageIdx));
|
false : (pageIdx === this.findController.selected.pageIdx));
|
||||||
var selectedMatchIdx = (this.findController === null ?
|
var selectedMatchIdx = (this.findController === null ?
|
||||||
-1 : this.findController.selected.matchIdx);
|
-1 : this.findController.selected.matchIdx);
|
||||||
var highlightAll = (this.findController === null ?
|
var highlightAll = (this.findController === null ?
|
||||||
@ -313,10 +323,9 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
var isSelected = (isSelectedPage && i === selectedMatchIdx);
|
var isSelected = (isSelectedPage && i === selectedMatchIdx);
|
||||||
var highlightSuffix = (isSelected ? ' selected' : '');
|
var highlightSuffix = (isSelected ? ' selected' : '');
|
||||||
|
|
||||||
if (isSelected && !this.isViewerInPresentationMode) {
|
if (this.findController) {
|
||||||
scrollIntoView(textDivs[begin.divIdx],
|
this.findController.updateMatchPosition(pageIdx, i, textDivs,
|
||||||
{ top: FIND_SCROLL_OFFSET_TOP,
|
begin.divIdx, end.divIdx);
|
||||||
left: FIND_SCROLL_OFFSET_LEFT });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match inside new div.
|
// Match inside new div.
|
||||||
@ -387,3 +396,24 @@ var TextLayerBuilder = (function TextLayerBuilderClosure() {
|
|||||||
};
|
};
|
||||||
return TextLayerBuilder;
|
return TextLayerBuilder;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @implements IPDFTextLayerFactory
|
||||||
|
*/
|
||||||
|
function DefaultTextLayerFactory() {}
|
||||||
|
DefaultTextLayerFactory.prototype = {
|
||||||
|
/**
|
||||||
|
* @param {HTMLDivElement} textLayerDiv
|
||||||
|
* @param {number} pageIndex
|
||||||
|
* @param {PageViewport} viewport
|
||||||
|
* @returns {TextLayerBuilder}
|
||||||
|
*/
|
||||||
|
createTextLayerBuilder: function (textLayerDiv, pageIndex, viewport) {
|
||||||
|
return new TextLayerBuilder({
|
||||||
|
textLayerDiv: textLayerDiv,
|
||||||
|
pageIndex: pageIndex,
|
||||||
|
viewport: viewport
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -22,7 +22,6 @@ var UNKNOWN_SCALE = 0;
|
|||||||
var MAX_AUTO_SCALE = 1.25;
|
var MAX_AUTO_SCALE = 1.25;
|
||||||
var SCROLLBAR_PADDING = 40;
|
var SCROLLBAR_PADDING = 40;
|
||||||
var VERTICAL_PADDING = 5;
|
var VERTICAL_PADDING = 5;
|
||||||
var DEFAULT_CACHE_SIZE = 10;
|
|
||||||
|
|
||||||
// optimised CSS custom property getter/setter
|
// optimised CSS custom property getter/setter
|
||||||
var CustomStyle = (function CustomStyleClosure() {
|
var CustomStyle = (function CustomStyleClosure() {
|
||||||
@ -161,13 +160,10 @@ function watchScroll(viewAreaElement, callback) {
|
|||||||
|
|
||||||
var currentY = viewAreaElement.scrollTop;
|
var currentY = viewAreaElement.scrollTop;
|
||||||
var lastY = state.lastY;
|
var lastY = state.lastY;
|
||||||
if (currentY > lastY) {
|
if (currentY !== lastY) {
|
||||||
state.down = true;
|
state.down = currentY > lastY;
|
||||||
} else if (currentY < lastY) {
|
|
||||||
state.down = false;
|
|
||||||
}
|
}
|
||||||
state.lastY = currentY;
|
state.lastY = currentY;
|
||||||
// else do nothing and use previous value
|
|
||||||
callback(state);
|
callback(state);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -183,6 +179,38 @@ function watchScroll(viewAreaElement, callback) {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use binary search to find the index of the first item in a given array which
|
||||||
|
* passes a given condition. The items are expected to be sorted in the sense
|
||||||
|
* that if the condition is true for one item in the array, then it is also true
|
||||||
|
* for all following items.
|
||||||
|
*
|
||||||
|
* @returns {Number} Index of the first array element to pass the test,
|
||||||
|
* or |items.length| if no such element exists.
|
||||||
|
*/
|
||||||
|
function binarySearchFirstItem(items, condition) {
|
||||||
|
var minIndex = 0;
|
||||||
|
var maxIndex = items.length - 1;
|
||||||
|
|
||||||
|
if (items.length === 0 || !condition(items[maxIndex])) {
|
||||||
|
return items.length;
|
||||||
|
}
|
||||||
|
if (condition(items[minIndex])) {
|
||||||
|
return minIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (minIndex < maxIndex) {
|
||||||
|
var currentIndex = (minIndex + maxIndex) >> 1;
|
||||||
|
var currentItem = items[currentIndex];
|
||||||
|
if (condition(currentItem)) {
|
||||||
|
maxIndex = currentIndex;
|
||||||
|
} else {
|
||||||
|
minIndex = currentIndex + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minIndex; /* === maxIndex */
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic helper to find out what elements are visible within a scroll pane.
|
* Generic helper to find out what elements are visible within a scroll pane.
|
||||||
*/
|
*/
|
||||||
@ -190,30 +218,45 @@ function getVisibleElements(scrollEl, views, sortByVisibility) {
|
|||||||
var top = scrollEl.scrollTop, bottom = top + scrollEl.clientHeight;
|
var top = scrollEl.scrollTop, bottom = top + scrollEl.clientHeight;
|
||||||
var left = scrollEl.scrollLeft, right = left + scrollEl.clientWidth;
|
var left = scrollEl.scrollLeft, right = left + scrollEl.clientWidth;
|
||||||
|
|
||||||
var visible = [], view;
|
function isElementBottomBelowViewTop(view) {
|
||||||
|
var element = view.div;
|
||||||
|
var elementBottom =
|
||||||
|
element.offsetTop + element.clientTop + element.clientHeight;
|
||||||
|
return elementBottom > top;
|
||||||
|
}
|
||||||
|
|
||||||
|
var visible = [], view, element;
|
||||||
var currentHeight, viewHeight, hiddenHeight, percentHeight;
|
var currentHeight, viewHeight, hiddenHeight, percentHeight;
|
||||||
var currentWidth, viewWidth;
|
var currentWidth, viewWidth;
|
||||||
for (var i = 0, ii = views.length; i < ii; ++i) {
|
var firstVisibleElementInd = (views.length === 0) ? 0 :
|
||||||
|
binarySearchFirstItem(views, isElementBottomBelowViewTop);
|
||||||
|
|
||||||
|
for (var i = firstVisibleElementInd, ii = views.length; i < ii; i++) {
|
||||||
view = views[i];
|
view = views[i];
|
||||||
currentHeight = view.el.offsetTop + view.el.clientTop;
|
element = view.div;
|
||||||
viewHeight = view.el.clientHeight;
|
currentHeight = element.offsetTop + element.clientTop;
|
||||||
if ((currentHeight + viewHeight) < top) {
|
viewHeight = element.clientHeight;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (currentHeight > bottom) {
|
if (currentHeight > bottom) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
currentWidth = view.el.offsetLeft + view.el.clientLeft;
|
|
||||||
viewWidth = view.el.clientWidth;
|
currentWidth = element.offsetLeft + element.clientLeft;
|
||||||
if ((currentWidth + viewWidth) < left || currentWidth > right) {
|
viewWidth = element.clientWidth;
|
||||||
|
if (currentWidth + viewWidth < left || currentWidth > right) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
hiddenHeight = Math.max(0, top - currentHeight) +
|
hiddenHeight = Math.max(0, top - currentHeight) +
|
||||||
Math.max(0, currentHeight + viewHeight - bottom);
|
Math.max(0, currentHeight + viewHeight - bottom);
|
||||||
percentHeight = ((viewHeight - hiddenHeight) * 100 / viewHeight) | 0;
|
percentHeight = ((viewHeight - hiddenHeight) * 100 / viewHeight) | 0;
|
||||||
|
|
||||||
visible.push({ id: view.id, x: currentWidth, y: currentHeight,
|
visible.push({
|
||||||
view: view, percent: percentHeight });
|
id: view.id,
|
||||||
|
x: currentWidth,
|
||||||
|
y: currentHeight,
|
||||||
|
view: view,
|
||||||
|
percent: percentHeight
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var first = visible[0];
|
var first = visible[0];
|
||||||
@ -349,23 +392,3 @@ var ProgressBar = (function ProgressBarClosure() {
|
|||||||
|
|
||||||
return ProgressBar;
|
return ProgressBar;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
var Cache = function cacheCache(size) {
|
|
||||||
var data = [];
|
|
||||||
this.push = function cachePush(view) {
|
|
||||||
var i = data.indexOf(view);
|
|
||||||
if (i >= 0) {
|
|
||||||
data.splice(i, 1);
|
|
||||||
}
|
|
||||||
data.push(view);
|
|
||||||
if (data.length > size) {
|
|
||||||
data.shift().destroy();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.resize = function (newSize) {
|
|
||||||
size = newSize;
|
|
||||||
while (data.length > size) {
|
|
||||||
data.shift().destroy();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,26 +0,0 @@
|
|||||||
.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-preview
|
|
||||||
{
|
|
||||||
position: absolute;
|
|
||||||
right: 18px;
|
|
||||||
top: 0px;
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.openerp .oe_sidebar .oe_dropdown_menu li:hover .oe-sidebar-attachment-preview
|
|
||||||
{
|
|
||||||
display: inherit;
|
|
||||||
}
|
|
||||||
.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-preview:hover
|
|
||||||
{
|
|
||||||
text-decoration: none;
|
|
||||||
color: white;
|
|
||||||
background: #8786b7;
|
|
||||||
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
|
|
||||||
-moz-border-radius: 2px;
|
|
||||||
-webkit-border-radius: 2px;
|
|
||||||
border-radius: 2px;
|
|
||||||
}
|
|
||||||
.openerp .oe-binary-preview
|
|
||||||
{
|
|
||||||
cursor: pointer;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
@ -1,242 +1,337 @@
|
|||||||
//-*- coding: utf-8 -*-
|
///* Copyright 2014 Therp BV (<http://therp.nl>)
|
||||||
//############################################################################
|
// * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||||
//
|
|
||||||
// OpenERP, Open Source Management Solution
|
|
||||||
// This module copyright (C) 2014 Therp BV (<http://therp.nl>).
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
//############################################################################
|
|
||||||
|
|
||||||
openerp.attachment_preview = function(instance)
|
odoo.define('attachment_preview', function(require) {
|
||||||
{
|
'use strict';
|
||||||
var _t = instance.web._t;
|
|
||||||
openerp.attachment_preview.show_preview = function(
|
var core = require('web.core');
|
||||||
attachment_id, attachment_url, attachment_extension,
|
var _t = core._t;
|
||||||
attachment_title)
|
var qweb = core.qweb;
|
||||||
{
|
var Sidebar = require('web.Sidebar');
|
||||||
var url = (window.location.origin || '') +
|
var FieldBinaryFile = core.form_widget_registry.get('binary');
|
||||||
'/attachment_preview/static/lib/ViewerJS/index.html#' +
|
var FormView = require('web.FormView');
|
||||||
attachment_url.replace(window.location.origin, '') +
|
var Widget = require('web.Widget');
|
||||||
'&title=' + encodeURIComponent(attachment_title) +
|
var Model = require('web.Model');
|
||||||
'&ext=.' + encodeURIComponent(attachment_extension);
|
|
||||||
window.open(url);
|
var AttachmentPreviewMixin = {
|
||||||
};
|
canPreview: function(extension) {
|
||||||
openerp.attachment_preview.can_preview = function(extension)
|
return $.inArray(
|
||||||
{
|
extension,
|
||||||
return jQuery.inArray(
|
[
|
||||||
extension,
|
'odt', 'odp', 'ods', 'fodt', 'pdf', 'ott', 'fodp', 'otp',
|
||||||
[
|
'fods', 'ots'
|
||||||
'odt', 'odp', 'ods', 'fodt', 'pdf', 'ott', 'fodp', 'otp',
|
]) > -1;
|
||||||
'fods', 'ots'
|
|
||||||
]) > -1;
|
|
||||||
};
|
|
||||||
instance.web.Sidebar.include(
|
|
||||||
{
|
|
||||||
on_attachments_loaded: function(attachments)
|
|
||||||
{
|
|
||||||
var result = this._super.apply(this, arguments);
|
|
||||||
this.$el.find('.oe-sidebar-attachment-preview')
|
|
||||||
.click(this.on_attachment_preview);
|
|
||||||
this.update_preview_buttons();
|
|
||||||
return result;
|
|
||||||
},
|
},
|
||||||
on_attachment_preview: function(e)
|
|
||||||
{
|
getUrl: function(attachment_id, attachment_url, attachment_extension, attachment_title) {
|
||||||
e.preventDefault();
|
var url = (window.location.origin || '') +
|
||||||
e.stopPropagation();
|
'/attachment_preview/static/lib/ViewerJS/index.html' +
|
||||||
|
'?type=' + encodeURIComponent(attachment_extension) +
|
||||||
|
'&title=' + encodeURIComponent(attachment_title) +
|
||||||
|
'#' +
|
||||||
|
attachment_url.replace(window.location.origin, '');
|
||||||
|
return url;
|
||||||
|
},
|
||||||
|
|
||||||
|
showPreview: function(attachment_id, attachment_url, attachment_extension, attachment_title, split_screen) {
|
||||||
|
var url = this.getUrl(attachment_id, attachment_url, attachment_extension, attachment_title);
|
||||||
|
if (split_screen) {
|
||||||
|
this.trigger_up('onAttachmentPreview', {url: url});
|
||||||
|
} else {
|
||||||
|
window.open(url);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Sidebar.include(AttachmentPreviewMixin);
|
||||||
|
Sidebar.include({
|
||||||
|
events: _.extend({}, Sidebar.prototype.events, {
|
||||||
|
'click .o_sidebar_preview_attachment': '_onPreviewAttachment'
|
||||||
|
}),
|
||||||
|
|
||||||
|
previewableAttachments: null,
|
||||||
|
|
||||||
|
redraw: function () {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
this.getPreviewableAttachments().done(function(atts) {
|
||||||
|
this.previewableAttachments = atts;
|
||||||
|
this.updatePreviewButtons(atts);
|
||||||
|
this.trigger_up('setPreviewableAttachments', {attachments: atts});
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
_onPreviewAttachment: function(event) {
|
||||||
|
event.preventDefault();
|
||||||
var self = this,
|
var self = this,
|
||||||
$target = jQuery(e.currentTarget),
|
$target = $(event.currentTarget),
|
||||||
attachment_id = parseInt($target.attr('data-id')),
|
split_screen = $target.attr('data-target') != 'new',
|
||||||
|
attachment_id = parseInt($target.attr('data-id'), 10),
|
||||||
attachment_url = $target.attr('data-url'),
|
attachment_url = $target.attr('data-url'),
|
||||||
attachment_extension = $target.attr('data-extension'),
|
attachment_extension = $target.attr('data-extension'),
|
||||||
attachment_title = $target.attr('data-original-title');
|
attachment_title = $target.attr('data-original-title');
|
||||||
if(attachment_extension)
|
|
||||||
{
|
if(attachment_extension) {
|
||||||
openerp.attachment_preview.show_preview(
|
this.showPreview(attachment_id, attachment_url, attachment_extension, attachment_title, split_screen);
|
||||||
attachment_id, attachment_url, attachment_extension,
|
} else {
|
||||||
attachment_title);
|
new Model('ir.attachment').call('get_attachment_extension', [
|
||||||
}
|
attachment_id
|
||||||
else
|
], {}).then(function(extension) {
|
||||||
{
|
self.showPreview(attachment_id, attachment_url, extension, null, split_screen);
|
||||||
(new instance.web.Model('ir.attachment')).call(
|
|
||||||
'get_attachment_extension', [attachment_id], {})
|
|
||||||
.then(function(extension)
|
|
||||||
{
|
|
||||||
openerp.attachment_preview.show_preview(
|
|
||||||
attachment_id, attachment_url, extension);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
update_preview_buttons: function()
|
|
||||||
{
|
getPreviewableAttachments: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return (new instance.web.Model('ir.attachment')).call(
|
var deferred = $.Deferred();
|
||||||
'get_attachment_extension',
|
|
||||||
[
|
var $items = this.$el.find('.o_sidebar_preview_attachment');
|
||||||
this.$el.find('.oe-sidebar-attachment-preview')
|
var attachments = _.object($items.map(function() {
|
||||||
.map(function()
|
return parseInt($(this).attr('data-id'), 10);
|
||||||
{
|
}), $items.map(function () {
|
||||||
return parseInt(jQuery(this).attr('data-id'));
|
return {
|
||||||
})
|
url: $(this).attr('data-url'),
|
||||||
.get()
|
extension: $(this).attr('data-extension'),
|
||||||
],
|
title: $(this).attr('data-original-title'),
|
||||||
{})
|
};
|
||||||
.then(function(extensions)
|
}));
|
||||||
{
|
|
||||||
_(extensions).each(function(extension, id)
|
new Model('ir.attachment').call('get_attachment_extension', [
|
||||||
{
|
_.map(_.keys(attachments), function(id) {
|
||||||
var $element = jQuery(
|
return parseInt(id, 10);
|
||||||
'a.oe-sidebar-attachment-preview[data-id="'
|
})
|
||||||
+ id + '"]');
|
], {}).then(function (extensions) {
|
||||||
if(openerp.attachment_preview.can_preview(extension))
|
var reviewableAttachments = _.map(_.keys(_.pick(extensions, function(extension, id) {
|
||||||
{
|
return self.canPreview(extension);
|
||||||
$element.attr('data-extension', extension);
|
})), function (id) {
|
||||||
}
|
return {
|
||||||
else
|
id: id,
|
||||||
{
|
url: attachments[id]['url'],
|
||||||
$element.remove();
|
extension: extensions[id],
|
||||||
}
|
title: attachments[id]['title'],
|
||||||
});
|
previewUrl: self.getUrl(
|
||||||
|
id,
|
||||||
|
attachments[id]['url'],
|
||||||
|
extensions[id],
|
||||||
|
id + ' - ' + attachments[id]['title']
|
||||||
|
)
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
deferred.resolve(reviewableAttachments);
|
||||||
});
|
}, function() {
|
||||||
instance.web.ListView.include(
|
deferred.reject();
|
||||||
{
|
});
|
||||||
reload_content: function()
|
|
||||||
{
|
return deferred.promise();
|
||||||
var deferred = this._super.apply(this, arguments),
|
},
|
||||||
self = this;
|
|
||||||
deferred.then(function()
|
updatePreviewButtons: function(previewableAttachments) {
|
||||||
{
|
this.$el.find('.o_sidebar_preview_attachment').each(function() {
|
||||||
var $elements = self.$el.find('.oe-binary-preview');
|
var $this = $(this);
|
||||||
if(!$elements.length)
|
var id = $this.attr('data-id');
|
||||||
{
|
var att = _.findWhere(previewableAttachments, {id: id});
|
||||||
return;
|
if (att) {
|
||||||
}
|
$this.attr('data-extension', att.extension);
|
||||||
$elements.click(function(e)
|
} else {
|
||||||
{
|
$this.remove();
|
||||||
e.stopPropagation();
|
}
|
||||||
var $target = jQuery(e.currentTarget),
|
|
||||||
attachment_id = parseInt($target.attr('data-id')),
|
|
||||||
attachment_extension = $target.attr('data-extension');
|
|
||||||
openerp.attachment_preview.show_preview(
|
|
||||||
attachment_id,
|
|
||||||
$target.siblings('a').attr('href'),
|
|
||||||
attachment_extension,
|
|
||||||
$target.attr('alt'));
|
|
||||||
});
|
|
||||||
return (new instance.web.Model('ir.attachment')).call(
|
|
||||||
'get_binary_extension',
|
|
||||||
[
|
|
||||||
$elements.attr('data-model'),
|
|
||||||
$elements
|
|
||||||
.map(function()
|
|
||||||
{
|
|
||||||
return parseInt(jQuery(this).attr('data-id'));
|
|
||||||
})
|
|
||||||
.get(),
|
|
||||||
$elements.attr('data-field'),
|
|
||||||
$elements.attr('data-filename'),
|
|
||||||
],
|
|
||||||
{})
|
|
||||||
.then(function(extensions)
|
|
||||||
{
|
|
||||||
_(extensions).each(function(extension, id)
|
|
||||||
{
|
|
||||||
var $element = $elements.filter(
|
|
||||||
'[data-id="' + id + '"]');
|
|
||||||
if(openerp.attachment_preview.can_preview(extension))
|
|
||||||
{
|
|
||||||
$element.attr('data-extension', extension);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$element.remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return deferred;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instance.web.list.Binary.include(
|
|
||||||
{
|
|
||||||
_format: function (row_data, options)
|
|
||||||
{
|
|
||||||
var link = this._super.apply(this, arguments);
|
|
||||||
link += _.template(
|
|
||||||
'<img class="oe-binary-preview" title="<%-preview_text%>" alt="<%-preview_text%>" data-id="<%-preview_id%>" data-model="<%-preview_model%>" data-field="<%-preview_field%>" data-filename="<%-preview_filename%>" src="/web/static/src/img/icons/gtk-print-preview.png" />',
|
|
||||||
{
|
|
||||||
preview_id: options.id,
|
|
||||||
preview_text: _.str.sprintf(_t('Preview %s'), this.string),
|
|
||||||
preview_model: options.model,
|
|
||||||
preview_field: this.id,
|
|
||||||
preview_filename: this.filename || '',
|
|
||||||
});
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instance.web.form.FieldBinaryFile.include(
|
|
||||||
{
|
|
||||||
render_value: function()
|
|
||||||
{
|
|
||||||
this._super.apply(this, arguments);
|
|
||||||
if(this.get("effective_readonly") && this.get('value'))
|
|
||||||
{
|
|
||||||
var self = this;
|
|
||||||
(new instance.web.Model('ir.attachment')).call(
|
|
||||||
'get_binary_extension', [
|
|
||||||
this.view.dataset.model,
|
|
||||||
this.view.datarecord.id ? [this.view.datarecord.id] : [],
|
|
||||||
this.name,
|
|
||||||
this.node.attrs.filename,
|
|
||||||
],
|
|
||||||
{})
|
|
||||||
.then(function(extensions)
|
|
||||||
{
|
|
||||||
_(extensions).each(function(extension)
|
|
||||||
{
|
|
||||||
var $element = self.$el.find('.oe-binary-preview');
|
|
||||||
if(openerp.attachment_preview.can_preview(extension))
|
|
||||||
{
|
|
||||||
$element.click(function()
|
|
||||||
{
|
|
||||||
openerp.attachment_preview.show_preview(
|
|
||||||
null,
|
|
||||||
_.str.sprintf(
|
|
||||||
'/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d',
|
|
||||||
instance.session.session_id,
|
|
||||||
self.view.dataset.model,
|
|
||||||
self.name,
|
|
||||||
self.view.datarecord.id),
|
|
||||||
extension,
|
|
||||||
_.str.sprintf(_t('Preview %s'), self.field.string));
|
|
||||||
});
|
|
||||||
$element.attr('title', _.str.sprintf(_t('Preview %s'), self.field.string));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$element.remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.$el.find('.oe-binary-preview').remove();
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
FieldBinaryFile.include(AttachmentPreviewMixin);
|
||||||
|
FieldBinaryFile.include({
|
||||||
|
events: _.extend({}, FieldBinaryFile.prototype.events, {
|
||||||
|
'click .fa-search': '_onPreview'
|
||||||
|
}),
|
||||||
|
|
||||||
|
_renderReadonly: function () {
|
||||||
|
var self = this;
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
this._getBinaryExtension().done(function(extension) {
|
||||||
|
if(self.canPreview(extension)) {
|
||||||
|
self._renderPreviewButton(extension);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_renderPreviewButton: function(extension) {
|
||||||
|
this.$previewBtn = $("<span/>");
|
||||||
|
this.$previewBtn.addClass('fa fa-search');
|
||||||
|
this.$previewBtn.attr('title', _.str.sprintf(_t('Preview %s'), this.field.string));
|
||||||
|
this.$previewBtn.attr('data-extension', extension);
|
||||||
|
this.$el.find('.fa-download').after(this.$previewBtn);
|
||||||
|
},
|
||||||
|
|
||||||
|
_getBinaryExtension: function () {
|
||||||
|
return new Model('ir.attachment').call('get_binary_extension', [
|
||||||
|
this.model,
|
||||||
|
this.recordData.id,
|
||||||
|
this.name,
|
||||||
|
this.attrs.filename
|
||||||
|
], {});
|
||||||
|
},
|
||||||
|
|
||||||
|
_onPreview: function(event) {
|
||||||
|
this.showPreview(
|
||||||
|
null,
|
||||||
|
_.str.sprintf(
|
||||||
|
'/web/content?model=%s&field=%s&id=%d',
|
||||||
|
this.model,
|
||||||
|
this.name,
|
||||||
|
this.recordData.id
|
||||||
|
),
|
||||||
|
$(event.currentTarget).attr('data-extension'),
|
||||||
|
_.str.sprintf(_t('Preview %s'), this.field.string),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var AttachmentPreviewWidget = Widget.extend({
|
||||||
|
template: 'attachment_preview.AttachmentPreviewWidget',
|
||||||
|
activeIndex: 0,
|
||||||
|
attachments: null,
|
||||||
|
|
||||||
|
events: {
|
||||||
|
'click .attachment_preview_close': '_onCloseClick',
|
||||||
|
'click .attachment_preview_previous': '_onPreviousClick',
|
||||||
|
'click .attachment_preview_next': '_onNextClick',
|
||||||
|
'click .attachment_preview_popout': '_onPopoutClick',
|
||||||
|
},
|
||||||
|
|
||||||
|
start: function () {
|
||||||
|
var res = this._super.apply(this, arguments);
|
||||||
|
this.$overlay = this.$el.find('.attachment_preview_overlay');
|
||||||
|
this.$iframe = this.$el.find('.attachment_preview_iframe');
|
||||||
|
this.$current = this.$el.find('.attachment_preview_current');
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
|
_onCloseClick: function () {
|
||||||
|
this.hide();
|
||||||
|
},
|
||||||
|
|
||||||
|
_onPreviousClick: function () {
|
||||||
|
this.previous();
|
||||||
|
},
|
||||||
|
|
||||||
|
_onNextClick: function () {
|
||||||
|
this.next();
|
||||||
|
},
|
||||||
|
|
||||||
|
_onPopoutClick: function () {
|
||||||
|
if (!this.attachments[this.activeIndex]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.open(this.attachments[this.activeIndex].previewUrl);
|
||||||
|
},
|
||||||
|
|
||||||
|
next: function() {
|
||||||
|
var index = this.activeIndex + 1;
|
||||||
|
if (index >= this.attachments.length) {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
this.activeIndex = index;
|
||||||
|
this.updatePaginator();
|
||||||
|
this.loadPreview();
|
||||||
|
},
|
||||||
|
|
||||||
|
previous: function() {
|
||||||
|
var index = this.activeIndex - 1;
|
||||||
|
if (index < 0) {
|
||||||
|
index = this.attachments.length - 1;
|
||||||
|
}
|
||||||
|
this.activeIndex = index;
|
||||||
|
this.updatePaginator();
|
||||||
|
this.loadPreview();
|
||||||
|
},
|
||||||
|
|
||||||
|
show: function () {
|
||||||
|
this.$el.removeClass('hidden');
|
||||||
|
this.trigger('shown');
|
||||||
|
},
|
||||||
|
|
||||||
|
hide: function () {
|
||||||
|
this.$el.addClass('hidden');
|
||||||
|
this.trigger('hidden');
|
||||||
|
},
|
||||||
|
|
||||||
|
updatePaginator: function() {
|
||||||
|
var value = _.str.sprintf('%s / %s', this.activeIndex + 1, this.attachments.length);
|
||||||
|
this.$current.html(value);
|
||||||
|
},
|
||||||
|
|
||||||
|
loadPreview: function() {
|
||||||
|
if (this.attachments.length == 0) {
|
||||||
|
this.$iframe.attr('src', 'about:blank');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var att = this.attachments[this.activeIndex];
|
||||||
|
this.$iframe.attr('src', att.previewUrl);
|
||||||
|
},
|
||||||
|
|
||||||
|
setAttachments: function(attachments) {
|
||||||
|
this.attachments = attachments;
|
||||||
|
this.activeIndex = 0;
|
||||||
|
this.updatePaginator();
|
||||||
|
this.loadPreview();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
FormView.include({
|
||||||
|
custom_events: _.extend({}, FormView.prototype.custom_events, {
|
||||||
|
onAttachmentPreview: '_onAttachmentPreview',
|
||||||
|
setPreviewableAttachments: '_setPreviewableAttachments'
|
||||||
|
}),
|
||||||
|
|
||||||
|
attachmentPreviewWidget: null,
|
||||||
|
|
||||||
|
init: function() {
|
||||||
|
var res = this._super.apply(this, arguments);
|
||||||
|
this.attachmentPreviewWidget = new AttachmentPreviewWidget(this);
|
||||||
|
this.attachmentPreviewWidget.on('hidden', this, this._attachmentPreviewWidgetHidden);
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
|
start: function () {
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
this.attachmentPreviewWidget.insertAfter(this.$el);
|
||||||
|
},
|
||||||
|
|
||||||
|
_attachmentPreviewWidgetHidden: function() {
|
||||||
|
this.$el.removeClass('attachment_preview');
|
||||||
|
},
|
||||||
|
|
||||||
|
showAttachmentPreviewWidget: function () {
|
||||||
|
this.$el.addClass('attachment_preview');
|
||||||
|
this.attachmentPreviewWidget.setAttachments(
|
||||||
|
this.sidebar.previewableAttachments
|
||||||
|
);
|
||||||
|
this.attachmentPreviewWidget.show();
|
||||||
|
},
|
||||||
|
|
||||||
|
on_detach_callback: function () {
|
||||||
|
this.attachmentPreviewWidget.hide();
|
||||||
|
return this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
_onAttachmentPreview: function (event) {
|
||||||
|
this.showAttachmentPreviewWidget();
|
||||||
|
},
|
||||||
|
|
||||||
|
_setPreviewableAttachments: function (event) {
|
||||||
|
this.attachmentPreviewWidget.setAttachments(
|
||||||
|
event.data.attachments
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
AttachmentPreviewMixin: AttachmentPreviewMixin,
|
||||||
|
AttachmentPreviewWidget: AttachmentPreviewWidget
|
||||||
|
};
|
||||||
|
});
|
||||||
|
@ -1,33 +1,14 @@
|
|||||||
//-*- coding: utf-8 -*-
|
/* Copyright 2014 Therp BV (<http://therp.nl>)
|
||||||
//############################################################################
|
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||||
//
|
|
||||||
// OpenERP, Open Source Management Solution
|
|
||||||
// This module copyright (C) 2014 Therp BV (<http://therp.nl>).
|
|
||||||
//
|
|
||||||
// This program is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU Affero General Public License as
|
|
||||||
// published by the Free Software Foundation, either version 3 of the
|
|
||||||
// License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This program is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU Affero General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
//############################################################################
|
|
||||||
|
|
||||||
// This file contains tweaks for viewerjs itself and is not meant to be run in
|
// This file contains tweaks for viewerjs itself and is not meant to be run in
|
||||||
// OpenERP's context
|
// OpenERP's context
|
||||||
var original_Viewer = Viewer;
|
(function(original_Viewer) {
|
||||||
Viewer = function(plugin, parameters)
|
window.Viewer = function(plugin, parameters) {
|
||||||
{
|
if(!plugin) {
|
||||||
var matches = (/&title=([^&]+)&/).exec(window.location.hash);
|
// eslint-disable-next-line no-alert
|
||||||
if(matches && matches.length > 1)
|
alert('Unsupported file type');
|
||||||
{
|
}
|
||||||
parameters.title = decodeURIComponent(matches[1]);
|
return original_Viewer(plugin, parameters);
|
||||||
}
|
};
|
||||||
return original_Viewer(plugin, parameters);
|
}(window.Viewer));
|
||||||
}
|
|
||||||
|
55
attachment_preview/static/src/less/attachment_preview.less
Normal file
55
attachment_preview/static/src/less/attachment_preview.less
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
.o_cp_sidebar {
|
||||||
|
li .o_sidebar_preview_attachment {
|
||||||
|
position: absolute;
|
||||||
|
top: 5px;
|
||||||
|
right: 26px;
|
||||||
|
|
||||||
|
&.o_sidebar_preview_attachment_new_tab {
|
||||||
|
right: 43px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.open .dropdown-menu > li > a {
|
||||||
|
padding-right: 60px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_form_uri .fa-search {
|
||||||
|
padding-left: 5px;
|
||||||
|
padding-right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Preview widget */
|
||||||
|
|
||||||
|
.o_form_view.attachment_preview {
|
||||||
|
width: 60%;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.o_form_view + .attachment_preview_widget {
|
||||||
|
width: 40%;
|
||||||
|
height: 100%;
|
||||||
|
float: right;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
> .attachment_preview_iframe {
|
||||||
|
width: 100%;
|
||||||
|
height: calc(~"100% - 30px");
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.attachment_preview_buttons {
|
||||||
|
padding: 4px;
|
||||||
|
float: left;
|
||||||
|
width: 100%;
|
||||||
|
background-color: #FFF;
|
||||||
|
border-left: 1px solid @gray-light;
|
||||||
|
|
||||||
|
button {
|
||||||
|
min-width: 25px;
|
||||||
|
min-height: 25px;
|
||||||
|
padding-top: 2px;
|
||||||
|
padding-bottom: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,35 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<templates>
|
<templates>
|
||||||
<t t-extend="Sidebar">
|
<t t-extend="Sidebar">
|
||||||
<t t-jquery="a.oe_sidebar_delete_item" t-operation="before">
|
<t t-jquery="span.o_sidebar_delete_attachment" t-operation="before">
|
||||||
<a t-if="section.name == 'files' and !item.callback and item.url" href="#" class="oe-sidebar-attachment-preview" t-att-data-id="item.id" t-att-data-url="item.url" t-attf-title="Preview #{item.name}">
|
<span t-if="section.name == 'files' and widget.options.editable and !item.callback and item.url"
|
||||||
<img t-att-src='_s + "/web/static/src/img/icons/gtk-print-preview.png"' width="12" height="12" border="0"/>
|
class="fa fa-search o_sidebar_preview_attachment"
|
||||||
</a>
|
t-att-data-id="item.id"
|
||||||
|
t-att-data-url="item.url"
|
||||||
|
t-attf-title="Preview #{item.name}"/>
|
||||||
|
|
||||||
|
<span t-if="section.name == 'files' and widget.options.editable and !item.callback and item.url"
|
||||||
|
class="fa fa-external-link o_sidebar_preview_attachment o_sidebar_preview_attachment_new_tab"
|
||||||
|
data-target="new"
|
||||||
|
t-att-data-id="item.id"
|
||||||
|
t-att-data-url="item.url"
|
||||||
|
t-attf-title="Open preview #{item.name} in a new tab"/>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
<t t-extend="FieldBinaryFile">
|
|
||||||
<t t-jquery="a.oe_form_uri" t-operation="after">
|
<t t-name="attachment_preview.AttachmentPreviewWidget">
|
||||||
<img class="oe-binary-preview" t-att-src='_s + "/web/static/src/img/icons/gtk-print-preview.png"'/>
|
<div class="attachment_preview_widget hidden">
|
||||||
</t>
|
<div class="attachment_preview_buttons">
|
||||||
|
<div class="button-group pull-left">
|
||||||
|
<button class="btn btn-sm btn-default attachment_preview_previous"><i class="fa fa-chevron-left"/></button>
|
||||||
|
<button class="btn btn-sm btn-default disabled attachment_preview_current">1 / 5</button>
|
||||||
|
<button class="btn btn-sm btn-default attachment_preview_next"><i class="fa fa-chevron-right"/></button>
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-sm btn-default pull-left ml8 attachment_preview_popout"><i class="fa fa-external-link"/></button>
|
||||||
|
|
||||||
|
<button class="btn btn-sm btn-default pull-right attachment_preview_close"><i class="fa fa-times"/></button>
|
||||||
|
</div>
|
||||||
|
<iframe class="attachment_preview_iframe"></iframe>
|
||||||
|
</div>
|
||||||
</t>
|
</t>
|
||||||
</templates>
|
</templates>
|
||||||
|
9
attachment_preview/templates/assets.xml
Normal file
9
attachment_preview/templates/assets.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<odoo>
|
||||||
|
<template id="assets_backend" name="attachment_preview assets" inherit_id="web.assets_backend">
|
||||||
|
<xpath expr="." position="inside">
|
||||||
|
<script type="text/javascript" src="/attachment_preview/static/src/js/attachment_preview.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/less" href="/attachment_preview/static/src/less/attachment_preview.less" />
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
</odoo>
|
4
attachment_preview/tests/__init__.py
Normal file
4
attachment_preview/tests/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Copyright 2018 Onestein
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from . import test_attachment_preview
|
57
attachment_preview/tests/test_attachment_preview.py
Normal file
57
attachment_preview/tests/test_attachment_preview.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Copyright 2018 Onestein
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
import base64
|
||||||
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
|
class TestAttachmentPreview(TransactionCase):
|
||||||
|
def test_get_extension(self):
|
||||||
|
attachment = self.env['ir.attachment'].create({
|
||||||
|
'datas': base64.b64encode(b'from this, to that.'),
|
||||||
|
'name': 'doc.txt',
|
||||||
|
'datas_fname': 'doc.txt'
|
||||||
|
})
|
||||||
|
attachment2 = self.env['ir.attachment'].create({
|
||||||
|
'datas': base64.b64encode(b'Png'),
|
||||||
|
'name': 'image.png',
|
||||||
|
'datas_fname': 'image.png'
|
||||||
|
})
|
||||||
|
res = self.env['ir.attachment'].get_attachment_extension(
|
||||||
|
attachment.id
|
||||||
|
)
|
||||||
|
self.assertEqual(res, 'txt')
|
||||||
|
|
||||||
|
res = self.env['ir.attachment'].get_attachment_extension(
|
||||||
|
[attachment.id, attachment2.id]
|
||||||
|
)
|
||||||
|
self.assertEqual(res[attachment.id], 'txt')
|
||||||
|
self.assertEqual(res[attachment2.id], 'png')
|
||||||
|
|
||||||
|
res2 = self.env['ir.attachment'].get_binary_extension(
|
||||||
|
'ir.attachment',
|
||||||
|
attachment.id,
|
||||||
|
'datas'
|
||||||
|
)
|
||||||
|
self.assertTrue(res2)
|
||||||
|
|
||||||
|
modules = self.env['ir.module.module'].search([])
|
||||||
|
module = modules.filtered(
|
||||||
|
lambda m: m.icon_image
|
||||||
|
)[0]
|
||||||
|
res3 = self.env['ir.attachment'].get_binary_extension(
|
||||||
|
'ir.module.module',
|
||||||
|
module.id,
|
||||||
|
'icon_image'
|
||||||
|
)
|
||||||
|
self.assertTrue(res3)
|
||||||
|
|
||||||
|
att1 = self.env['ir.attachment'].create({
|
||||||
|
'name': 'Test Attachment Preview'
|
||||||
|
})
|
||||||
|
res4 = self.env['ir.attachment'].get_binary_extension(
|
||||||
|
'ir.attachment',
|
||||||
|
att1.id,
|
||||||
|
'datas'
|
||||||
|
)
|
||||||
|
self.assertFalse(res4)
|
@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<openerp>
|
|
||||||
<data>
|
|
||||||
<template id="assets_backend" name="attachment_preview assets" inherit_id="web.assets_backend">
|
|
||||||
<xpath expr="." position="inside">
|
|
||||||
<script type="text/javascript" src="/attachment_preview/static/src/js/attachment_preview.js"></script>
|
|
||||||
<link rel="stylesheet" type="text/css" href="/attachment_preview/static/src/css/attachment_preview.css" />
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
</data>
|
|
||||||
</openerp>
|
|
Loading…
Reference in New Issue
Block a user