Skip to content

Commit c0291e9

Browse files
committed
Merge pull request mozilla#861 from notmasteryet/issue-840
(mozilla#840) fix font stretching and overlapping characters encoding
2 parents b958fd4 + 05c1f68 commit c0291e9

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

src/canvas.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ var CanvasGraphics = (function canvasGraphics() {
575575
ctx.scale(1, -1);
576576
ctx.translate(current.x, -1 * current.y);
577577
ctx.transform.apply(ctx, fontMatrix);
578-
ctx.scale(1 / textHScale, 1);
578+
ctx.scale(textHScale, 1);
579579
},
580580
getTextGeometry: function canvasGetTextGeometry() {
581581
var geometry = {};
@@ -651,7 +651,7 @@ var CanvasGraphics = (function canvasGraphics() {
651651
ctx.transform.apply(ctx, current.textMatrix);
652652
ctx.translate(current.x, current.y);
653653

654-
ctx.scale(1 / textHScale, 1);
654+
ctx.scale(textHScale, 1);
655655
for (var i = 0; i < glyphsLength; ++i) {
656656

657657
var glyph = glyphs[i];

src/fonts.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,10 +1705,18 @@ var Font = (function Font() {
17051705

17061706
var cidToGidMap = properties.cidToGidMap || [];
17071707
var gidToCidMap = [0];
1708-
for (var j = cidToGidMap.length - 1; j >= 0; j--) {
1709-
var gid = cidToGidMap[j];
1710-
if (gid)
1711-
gidToCidMap[gid] = j;
1708+
if (cidToGidMap.length > 0) {
1709+
for (var j = cidToGidMap.length - 1; j >= 0; j--) {
1710+
var gid = cidToGidMap[j];
1711+
if (gid)
1712+
gidToCidMap[gid] = j;
1713+
}
1714+
// filling the gaps using CID above the CIDs currently used in font
1715+
var nextCid = cidToGidMap.length;
1716+
for (var i = 1; i < numGlyphs; i++) {
1717+
if (!gidToCidMap[i])
1718+
gidToCidMap[i] = nextCid++;
1719+
}
17121720
}
17131721

17141722
var glyphs = [], ids = [];

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
!alphatrans.pdf
1717
!devicen.pdf
1818
!cmykjpeg.pdf
19+
!issue840.pdf

test/pdfs/issue840.pdf

149 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,11 @@
290290
"link": true,
291291
"rounds": 1,
292292
"type": "eq"
293+
},
294+
{ "id": "issue840",
295+
"file": "pdfs/issue840.pdf",
296+
"md5": "20d88011dd7e3c4fb5274979094dab93",
297+
"rounds": 1,
298+
"type": "eq"
293299
}
294300
]

0 commit comments

Comments
 (0)