Skip to content

Commit 0414c07

Browse files
committed
Fixing base encoding presence detection; character width scale
1 parent 728f3fc commit 0414c07

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/canvas.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,14 @@ var CanvasGraphics = (function canvasGraphics() {
537537
var charSpacing = current.charSpacing;
538538
var wordSpacing = current.wordSpacing;
539539
var textHScale = current.textHScale;
540+
var fontMatrix = font.fontMatrix || IDENTITY_MATRIX;
541+
var textHScale2 = textHScale * fontMatrix[0];
540542
var glyphsLength = glyphs.length;
541543
if (font.coded) {
542544
ctx.save();
543545
ctx.transform.apply(ctx, current.textMatrix);
544546
ctx.translate(current.x, current.y);
545547

546-
var fontMatrix = font.fontMatrix || IDENTITY_MATRIX;
547548
ctx.scale(1 / textHScale, 1);
548549
for (var i = 0; i < glyphsLength; ++i) {
549550

@@ -564,7 +565,7 @@ var CanvasGraphics = (function canvasGraphics() {
564565
var width = transformed[0] * fontSize + charSpacing;
565566

566567
ctx.translate(width, 0);
567-
current.x += width;
568+
current.x += width * textHScale2;
568569

569570
}
570571
ctx.restore();
@@ -573,7 +574,7 @@ var CanvasGraphics = (function canvasGraphics() {
573574
ctx.transform.apply(ctx, current.textMatrix);
574575
ctx.scale(1, -1);
575576
ctx.translate(current.x, -1 * current.y);
576-
ctx.transform.apply(ctx, font.fontMatrix || IDENTITY_MATRIX);
577+
ctx.transform.apply(ctx, fontMatrix);
577578

578579
ctx.scale(1 / textHScale, 1);
579580

@@ -592,7 +593,7 @@ var CanvasGraphics = (function canvasGraphics() {
592593

593594
// TODO actual characters can be extracted from the glyph.unicode
594595
}
595-
current.x += width;
596+
current.x += width * textHScale2;
596597

597598
ctx.restore();
598599
}
@@ -602,12 +603,13 @@ var CanvasGraphics = (function canvasGraphics() {
602603
var ctx = this.ctx;
603604
var current = this.current;
604605
var fontSize = current.fontSize;
605-
var textHScale = current.textHScale;
606+
var textHScale2 = current.textHScale *
607+
(current.font.fontMatrix || IDENTITY_MATRIX)[0];
606608
var arrLength = arr.length;
607609
for (var i = 0; i < arrLength; ++i) {
608610
var e = arr[i];
609611
if (isNum(e)) {
610-
current.x -= e * 0.001 * fontSize * textHScale;
612+
current.x -= e * 0.001 * fontSize * textHScale2;
611613
} else if (isString(e)) {
612614
this.showText(e);
613615
} else {

src/evaluator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ var PartialEvaluator = (function partialEvaluator() {
498498
var baseName = encoding.get('BaseEncoding');
499499
if (baseName)
500500
baseEncoding = Encodings[baseName.name];
501+
else
502+
hasEncoding = false; // base encoding was not provided
501503

502504
// Load the differences between the base and original
503505
if (encoding.has('Differences')) {

src/fonts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ var Font = (function Font() {
764764
this.hasEncoding = properties.hasEncoding;
765765

766766
this.fontMatrix = properties.fontMatrix;
767+
this.widthMultiplier = 1.0;
767768
if (properties.type == 'Type3')
768769
return;
769770

@@ -826,6 +827,8 @@ var Font = (function Font() {
826827

827828
this.data = data;
828829
this.fontMatrix = properties.fontMatrix;
830+
this.widthMultiplier = !properties.fontMatrix ? 1.0 :
831+
1.0 / properties.fontMatrix[0];
829832
this.encoding = properties.baseEncoding;
830833
this.hasShortCmap = properties.hasShortCmap;
831834
this.loadedName = getUniqueName();
@@ -2131,10 +2134,12 @@ var Font = (function Font() {
21312134
if (typeof unicodeChars === 'number')
21322135
unicodeChars = String.fromCharCode(unicodeChars);
21332136

2137+
width = (isNum(width) ? width : this.defaultWidth) * this.widthMultiplier;
2138+
21342139
return {
21352140
fontChar: String.fromCharCode(unicode),
21362141
unicode: unicodeChars,
2137-
width: isNum(width) ? width : this.defaultWidth,
2142+
width: width,
21382143
codeIRQueue: codeIRQueue
21392144
};
21402145
},

src/glyphlist.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4287,6 +4287,7 @@ var GlyphsUnicode = {
42874287
zretroflexhook: 0x0290,
42884288
zstroke: 0x01B6,
42894289
zuhiragana: 0x305A,
4290-
zukatakana: 0x30BA
4290+
zukatakana: 0x30BA,
4291+
'.notdef': 0x0000
42914292
};
42924293

0 commit comments

Comments
 (0)