[Pkg-javascript-commits] [pdf.js] 249/414: Only draw glyphs on canvas if they are in the font or the font file is missing.

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:27 UTC 2016


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

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

commit ff87f3fb86e3b50d3d952842cb0d57d991fe994e
Author: Brendan Dahl <brendan.dahl at gmail.com>
Date:   Wed Feb 24 10:48:02 2016 -0800

    Only draw glyphs on canvas if they are in the font or the font file is missing.
---
 src/core/fonts.js               |  16 +++++++++++-----
 src/display/canvas.js           |  22 +++++++++++++---------
 test/pdfs/.gitignore            |   1 +
 test/pdfs/issue6721_reduced.pdf | Bin 0 -> 103344 bytes
 test/test_manifest.json         |   9 +++++++++
 5 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index 0c511f8..9272004 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -191,7 +191,7 @@ function getFontType(type, subtype) {
 
 var Glyph = (function GlyphClosure() {
   function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
-                 isSpace) {
+                 isSpace, isInFont) {
     this.fontChar = fontChar;
     this.unicode = unicode;
     this.accent = accent;
@@ -199,17 +199,20 @@ var Glyph = (function GlyphClosure() {
     this.vmetric = vmetric;
     this.operatorListId = operatorListId;
     this.isSpace = isSpace;
+    this.isInFont = isInFont;
   }
 
   Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
-                                             vmetric, operatorListId, isSpace) {
+                                             vmetric, operatorListId, isSpace,
+                                             isInFont) {
     return this.fontChar === fontChar &&
            this.unicode === unicode &&
            this.accent === accent &&
            this.width === width &&
            this.vmetric === vmetric &&
            this.operatorListId === operatorListId &&
-           this.isSpace === isSpace;
+           this.isSpace === isSpace &&
+           this.isInFont === isInFont;
   };
 
   return Glyph;
@@ -468,6 +471,7 @@ var Font = (function FontClosure() {
     this.loadedName = properties.loadedName;
     this.isType3Font = properties.isType3Font;
     this.sizes = [];
+    this.missingFile = false;
 
     this.glyphCache = Object.create(null);
 
@@ -2807,6 +2811,7 @@ var Font = (function FontClosure() {
         unicode = String.fromCharCode(unicode);
       }
 
+      var isInFont = charcode in this.toFontChar;
       // First try the toFontChar map, if it's not there then try falling
       // back to the char code.
       fontCharCode = this.toFontChar[charcode] || charcode;
@@ -2821,6 +2826,7 @@ var Font = (function FontClosure() {
 
       var accent = null;
       if (this.seacMap && this.seacMap[charcode]) {
+        isInFont = true;
         var seac = this.seacMap[charcode];
         fontCharCode = seac.baseFontCharCode;
         accent = {
@@ -2834,9 +2840,9 @@ var Font = (function FontClosure() {
       var glyph = this.glyphCache[charcode];
       if (!glyph ||
           !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
-                                 operatorListId, isSpace)) {
+                                 operatorListId, isSpace, isInFont)) {
         glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
-                          operatorListId, isSpace);
+                          operatorListId, isSpace, isInFont);
         this.glyphCache[charcode] = glyph;
       }
       return glyph;
diff --git a/src/display/canvas.js b/src/display/canvas.js
index 2e8c766..bd9f68e 100644
--- a/src/display/canvas.js
+++ b/src/display/canvas.js
@@ -1501,15 +1501,19 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
           }
         }
 
-        if (simpleFillText && !accent) {
-          // common case
-          ctx.fillText(character, scaledX, scaledY);
-        } else {
-          this.paintChar(character, scaledX, scaledY);
-          if (accent) {
-            scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
-            scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
-            this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
+        // Only attempt to draw the glyph if it is actually in the embedded font
+        // file or if there isn't a font file so the fallback font is shown.
+        if (glyph.isInFont || font.missingFile) {
+          if (simpleFillText && !accent) {
+            // common case
+            ctx.fillText(character, scaledX, scaledY);
+          } else {
+            this.paintChar(character, scaledX, scaledY);
+            if (accent) {
+              scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
+              scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
+              this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
+            }
           }
         }
 
diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index 911781e..6872698 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -166,6 +166,7 @@
 !issue5010.pdf
 !issue4934.pdf
 !issue4650.pdf
+!issue6721_reduced.pdf
 !issue3025.pdf
 !issue2099-1.pdf
 !issue3371.pdf
diff --git a/test/pdfs/issue6721_reduced.pdf b/test/pdfs/issue6721_reduced.pdf
new file mode 100644
index 0000000..1ce3cb7
Binary files /dev/null and b/test/pdfs/issue6721_reduced.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 1bbc7f0..3f73f9e 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -543,6 +543,15 @@
        "lastPage": 1,
        "type": "eq"
     },
+    {  "id": "issue6721_reduced",
+       "file": "pdfs/issue6721_reduced.pdf",
+       "md5": "719aa66d8081a15e3ba6032ed4279237",
+       "rounds": 1,
+       "link": false,
+       "firstPage": 1,
+       "lastPage": 1,
+       "type": "eq"
+    },
     {  "id": "issue5010",
        "file": "pdfs/issue5010.pdf",
        "md5": "419f4b13403a0871c463ec69d96e342c",

-- 
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