File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1030,6 +1030,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
1030
1030
continue ;
1031
1031
}
1032
1032
1033
+ var restoreNeeded = false ;
1033
1034
var character = glyph .fontChar ;
1034
1035
var vmetric = glyph .vmetric || defaultVMetrics ;
1035
1036
if (vertical ) {
@@ -1055,6 +1056,22 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
1055
1056
scaledAccentX = scaledX + accent .offset .x / fontSizeScale ;
1056
1057
scaledAccentY = scaledY - accent .offset .y / fontSizeScale ;
1057
1058
}
1059
+
1060
+ if (font .remeasure && width > 0 ) {
1061
+ // some standard fonts may not have the exact width, trying to
1062
+ // rescale per character
1063
+ var measuredWidth = ctx .measureText (character ).width * 1000 /
1064
+ current .fontSize * current .fontSizeScale ;
1065
+ var characterScaleX = width / measuredWidth ;
1066
+ restoreNeeded = true ;
1067
+ ctx .save ();
1068
+ ctx .scale (characterScaleX , 1 );
1069
+ scaledX /= characterScaleX ;
1070
+ if (accent ) {
1071
+ scaledAccentX /= characterScaleX ;
1072
+ }
1073
+ }
1074
+
1058
1075
switch (textRenderingMode ) {
1059
1076
default : // other unsupported rendering modes
1060
1077
case TextRenderingMode .FILL :
@@ -1096,6 +1113,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
1096
1113
x += charWidth ;
1097
1114
1098
1115
canvasWidth += charWidth ;
1116
+
1117
+ if (restoreNeeded ) {
1118
+ ctx .restore ();
1119
+ }
1099
1120
}
1100
1121
if (vertical ) {
1101
1122
current .y -= x * textHScale ;
Original file line number Diff line number Diff line change @@ -2443,6 +2443,9 @@ var Font = (function FontClosure() {
2443
2443
// name ArialBlack for example will be replaced by Helvetica.
2444
2444
this .black = (name .search (/Black /g ) != -1 );
2445
2445
2446
+ // if at least one width is present, remeasure all chars when exists
2447
+ this .remeasure = Object .keys (this .widths ).length > 0 ;
2448
+
2446
2449
this .encoding = properties .baseEncoding ;
2447
2450
this .noUnicodeAdaptation = true ;
2448
2451
this .loadedName = fontName .split ('-' )[0 ];
@@ -4656,6 +4659,7 @@ var Font = (function FontClosure() {
4656
4659
}
4657
4660
fontCharCode = this .toFontChar [charcode ] || charcode ;
4658
4661
break ;
4662
+ case 'MMType1' : // XXX at the moment only "standard" fonts are supported
4659
4663
case 'Type1' :
4660
4664
var glyphName = this .differences [charcode ] || this .encoding [charcode ];
4661
4665
if (!isNum (width ))
You can’t perform that action at this time.
0 commit comments