[Pkg-javascript-commits] [pdf.js] 312/414: Keep track of the character to glyph mapping in font_renderer.js, to prevent errors when different characters point to the same glyph (issue 7101)
David Prévot
taffit at moszumanska.debian.org
Tue Jun 28 17:12:34 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 17aaa125df7f08465008b21d994c16684de83e32
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date: Wed Mar 23 13:52:30 2016 +0100
Keep track of the character to glyph mapping in font_renderer.js, to prevent errors when different characters point to the same glyph (issue 7101)
Fixes 7101.
---
src/core/font_renderer.js | 39 +++++++++++++++++++++++----------------
test/pdfs/.gitignore | 1 +
test/pdfs/issue7101.pdf | Bin 0 -> 6832 bytes
test/test_manifest.json | 7 +++++++
4 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js
index 568d30e..729282c 100644
--- a/src/core/font_renderer.js
+++ b/src/core/font_renderer.js
@@ -137,7 +137,7 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
function lookupCmap(ranges, unicode) {
- var code = unicode.charCodeAt(0);
+ var code = unicode.charCodeAt(0), gid = 0;
var l = 0, r = ranges.length - 1;
while (l < r) {
var c = (l + r + 1) >> 1;
@@ -148,10 +148,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
}
}
if (ranges[l].start <= code && code <= ranges[l].end) {
- return (ranges[l].idDelta + (ranges[l].ids ?
- ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
+ gid = (ranges[l].idDelta + (ranges[l].ids ?
+ ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
}
- return 0;
+ return {
+ charCode: code,
+ glyphId: gid,
+ };
}
function compileGlyf(code, cmds, font) {
@@ -451,14 +454,14 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
x = stack.pop();
cmds.push({cmd: 'save'});
cmds.push({cmd: 'translate', args: [x, y]});
- var gid = lookupCmap(font.cmap, String.fromCharCode(
+ var cmap = lookupCmap(font.cmap, String.fromCharCode(
font.glyphNameMap[StandardEncoding[achar]]));
- compileCharString(font.glyphs[gid], cmds, font);
+ compileCharString(font.glyphs[cmap.glyphId], cmds, font);
cmds.push({cmd: 'restore'});
- gid = lookupCmap(font.cmap, String.fromCharCode(
+ cmap = lookupCmap(font.cmap, String.fromCharCode(
font.glyphNameMap[StandardEncoding[bchar]]));
- compileCharString(font.glyphs[gid], cmds, font);
+ compileCharString(font.glyphs[cmap.glyphId], cmds, font);
}
return;
case 18: // hstemhm
@@ -610,14 +613,19 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
function CompiledFont(fontMatrix) {
this.compiledGlyphs = Object.create(null);
+ this.compiledCharCodeToGlyphId = Object.create(null);
this.fontMatrix = fontMatrix;
}
CompiledFont.prototype = {
getPathJs: function (unicode) {
- var gid = lookupCmap(this.cmap, unicode);
- var fn = this.compiledGlyphs[gid];
+ var cmap = lookupCmap(this.cmap, unicode);
+ var fn = this.compiledGlyphs[cmap.glyphId];
if (!fn) {
- this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
+ fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
+ this.compiledGlyphs[cmap.glyphId] = fn;
+ }
+ if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
+ this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
}
return fn;
},
@@ -644,8 +652,9 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
},
hasBuiltPath: function (unicode) {
- var gid = lookupCmap(this.cmap, unicode);
- return gid in this.compiledGlyphs;
+ var cmap = lookupCmap(this.cmap, unicode);
+ return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
+ this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
}
};
@@ -655,8 +664,6 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
this.glyphs = glyphs;
this.cmap = cmap;
-
- this.compiledGlyphs = [];
}
Util.inherit(TrueTypeCompiled, CompiledFont, {
@@ -668,13 +675,13 @@ var FontRendererFactory = (function FontRendererFactoryClosure() {
function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
CompiledFont.call(this, fontMatrix);
+
this.glyphs = cffInfo.glyphs;
this.gsubrs = cffInfo.gsubrs || [];
this.subrs = cffInfo.subrs || [];
this.cmap = cmap;
this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
- this.compiledGlyphs = [];
this.gsubrsBias = (this.gsubrs.length < 1240 ?
107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
this.subrsBias = (this.subrs.length < 1240 ?
diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index b675adf..df3522d 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -21,6 +21,7 @@
!issue6782.pdf
!issue6961.pdf
!issue7020.pdf
+!issue7101.pdf
!issue7115.pdf
!filled-background.pdf
!ArabicCIDTrueType.pdf
diff --git a/test/pdfs/issue7101.pdf b/test/pdfs/issue7101.pdf
new file mode 100644
index 0000000..400ebe5
Binary files /dev/null and b/test/pdfs/issue7101.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 6113fcd..706a1bb 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -1263,6 +1263,13 @@
"rounds": 1,
"type": "eq"
},
+ { "id": "issue7101",
+ "file": "pdfs/issue7101.pdf",
+ "md5": "cc9cabe12ac9ad49e5372ef33d10aeb4",
+ "link": false,
+ "rounds": 1,
+ "type": "eq"
+ },
{ "id": "pr4606",
"file": "pdfs/pr4606.pdf",
"md5": "6574fde2314648600056bd0e229df98c",
--
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