[Pkg-javascript-commits] [pdf.js] 01/119: Create a IdentityToUnicodeMap in evaluator.js when toUnicode contains IdentityH/IdentityV

David Prévot taffit at moszumanska.debian.org
Wed May 13 21:27:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit f19a1db414b381052922c604f6da34e977b20f27
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Mon Feb 9 10:05:55 2015 +0100

    Create a IdentityToUnicodeMap in evaluator.js when toUnicode contains IdentityH/IdentityV
    
    Currently if a font contains a `toUnicode` entry, we always create a new `ToUnicodeMap` in evaluator.js. This is done even for `IdentityV/IdentityH`, despite to possibility to use the much more compact `IdentityToUnicodeMap` representation.
    This patch refactors the `IdentityH/IdentityV` cases, to:
     - Avoid calling `IdentityCMap.getMap`, since this prevents allocating and iterating through an array with 65536 elements.
    
     - Ensure that the handling of `toUnicode` is actually correct in fonts.js.
    We rely on `toUnicode instanceof IdentityToUnicodeMap` in a few places, and currently this does not work correctly for `IdentityH/IdentityV`.
---
 src/core/evaluator.js | 15 +++++++++------
 src/core/fonts.js     |  2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index 267c276..9df3e76 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -14,15 +14,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals assert, ColorSpace, DecodeStream, Dict, Encodings,
+/* globals assert, CMapFactory, ColorSpace, DecodeStream, Dict, Encodings,
            error, ErrorFont, Font, FONT_IDENTITY_MATRIX, fontCharsToUnicode,
            FontFlags, ImageKind, info, isArray, isCmd, isDict, isEOF, isName,
-           isNum, isStream, isString, JpegStream, Lexer, Metrics,
+           isNum, isStream, isString, JpegStream, Lexer, Metrics, IdentityCMap,
            MurmurHash3_64, Name, Parser, Pattern, PDFImage, PDFJS, serifFonts,
            stdFontMap, symbolsFonts, getTilingPatternIR, warn, Util, Promise,
-           RefSetCache, isRef, TextRenderingMode, ToUnicodeMap, CMapFactory,
+           RefSetCache, isRef, TextRenderingMode, IdentityToUnicodeMap,
            OPS, UNSUPPORTED_FEATURES, UnsupportedManager, NormalizedUnicodes,
-           IDENTITY_MATRIX, reverseIfRtl, createPromiseCapability,
+           IDENTITY_MATRIX, reverseIfRtl, createPromiseCapability, ToUnicodeMap,
            getFontType */
 
 'use strict';
@@ -1332,8 +1332,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       var cmap, cmapObj = toUnicode;
       if (isName(cmapObj)) {
         cmap = CMapFactory.create(cmapObj,
-          { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
-        return new ToUnicodeMap(cmap);
+          { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
+        if (cmap instanceof IdentityCMap) {
+          return new IdentityToUnicodeMap(0, 0xFFFF);
+        }
+        return new ToUnicodeMap(cmap.getMap());
       } else if (isStream(cmapObj)) {
         cmap = CMapFactory.create(cmapObj,
           { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
diff --git a/src/core/fonts.js b/src/core/fonts.js
index 9542db8..ff383c3 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -2223,7 +2223,7 @@ var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
 
   IdentityToUnicodeMap.prototype = {
     get length() {
-      error('should not access .length');
+      return (this.lastChar + 1) - this.firstChar;
     },
 
     forEach: function (callback) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list