Permalink
Browse files

Merge pull request #861 from notmasteryet/issue-840

(#840) fix font stretching and overlapping characters encoding
  • Loading branch information...
2 parents b958fd4 + 05c1f68 commit c0291e9fa3dbfd0a710729d34a06aaf18bd00158 @vingtetun vingtetun committed Dec 2, 2011
Showing with 21 additions and 6 deletions.
  1. +2 −2 src/canvas.js
  2. +12 −4 src/fonts.js
  3. +1 −0 test/pdfs/.gitignore
  4. BIN test/pdfs/issue840.pdf
  5. +6 −0 test/test_manifest.json
View
4 src/canvas.js
@@ -575,7 +575,7 @@ var CanvasGraphics = (function canvasGraphics() {
ctx.scale(1, -1);
ctx.translate(current.x, -1 * current.y);
ctx.transform.apply(ctx, fontMatrix);
- ctx.scale(1 / textHScale, 1);
+ ctx.scale(textHScale, 1);
},
getTextGeometry: function canvasGetTextGeometry() {
var geometry = {};
@@ -651,7 +651,7 @@ var CanvasGraphics = (function canvasGraphics() {
ctx.transform.apply(ctx, current.textMatrix);
ctx.translate(current.x, current.y);
- ctx.scale(1 / textHScale, 1);
+ ctx.scale(textHScale, 1);
for (var i = 0; i < glyphsLength; ++i) {
var glyph = glyphs[i];
View
16 src/fonts.js
@@ -1705,10 +1705,18 @@ var Font = (function Font() {
var cidToGidMap = properties.cidToGidMap || [];
var gidToCidMap = [0];
- for (var j = cidToGidMap.length - 1; j >= 0; j--) {
- var gid = cidToGidMap[j];
- if (gid)
- gidToCidMap[gid] = j;
+ if (cidToGidMap.length > 0) {
+ for (var j = cidToGidMap.length - 1; j >= 0; j--) {
+ var gid = cidToGidMap[j];
+ if (gid)
+ gidToCidMap[gid] = j;
+ }
+ // filling the gaps using CID above the CIDs currently used in font
+ var nextCid = cidToGidMap.length;
+ for (var i = 1; i < numGlyphs; i++) {
+ if (!gidToCidMap[i])
+ gidToCidMap[i] = nextCid++;
+ }
}
var glyphs = [], ids = [];
View
1 test/pdfs/.gitignore
@@ -16,3 +16,4 @@
!alphatrans.pdf
!devicen.pdf
!cmykjpeg.pdf
+!issue840.pdf
View
BIN test/pdfs/issue840.pdf
Binary file not shown.
View
6 test/test_manifest.json
@@ -290,5 +290,11 @@
"link": true,
"rounds": 1,
"type": "eq"
+ },
+ { "id": "issue840",
+ "file": "pdfs/issue840.pdf",
+ "md5": "20d88011dd7e3c4fb5274979094dab93",
+ "rounds": 1,
+ "type": "eq"
}
]

0 comments on commit c0291e9

Please sign in to comment.