@@ -159,7 +159,7 @@ var CanvasExtraState = (function CanvasExtraStateClosure() {
159
159
this .fontSize = 0 ;
160
160
this .fontSizeScale = 1 ;
161
161
this .textMatrix = IDENTITY_MATRIX ;
162
- this .fontMatrix = IDENTITY_MATRIX ;
162
+ this .fontMatrix = FONT_IDENTITY_MATRIX ;
163
163
this .leading = 0 ;
164
164
// Current point (in user coordinates)
165
165
this .x = 0 ;
@@ -768,11 +768,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
768
768
if (!fontObj )
769
769
error ('Can\'t find font for ' + fontRefName );
770
770
771
- // Slice-clone matrix so we can manipulate it without affecting original
772
- if (fontObj .fontMatrix )
773
- current .fontMatrix = fontObj .fontMatrix .slice (0 );
774
- else
775
- current .fontMatrix = IDENTITY_MATRIX .slice (0 );
771
+ current .fontMatrix = fontObj .fontMatrix ? fontObj .fontMatrix :
772
+ FONT_IDENTITY_MATRIX ;
776
773
777
774
// A valid matrix needs all main diagonal elements to be non-zero
778
775
// This also ensures we bypass FF bugzilla bug #719844.
@@ -783,11 +780,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
783
780
784
781
// The spec for Tf (setFont) says that 'size' specifies the font 'scale',
785
782
// and in some docs this can be negative (inverted x-y axes).
786
- // We implement this condition with fontMatrix.
787
783
if (size < 0 ) {
788
784
size = -size ;
789
- current .fontMatrix [0 ] *= -1 ;
790
- current .fontMatrix [3 ] *= -1 ;
785
+ current .fontDirection = -1 ;
786
+ } else {
787
+ current .fontDirection = 1 ;
791
788
}
792
789
793
790
this .current .font = fontObj ;
@@ -840,14 +837,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
840
837
applyTextTransforms : function CanvasGraphics_applyTextTransforms () {
841
838
var ctx = this .ctx ;
842
839
var current = this .current ;
843
- var textHScale = current .textHScale ;
844
- var fontMatrix = current .fontMatrix || IDENTITY_MATRIX ;
845
-
846
840
ctx .transform .apply (ctx , current .textMatrix );
847
- ctx .scale (1 , -1 );
848
- ctx .translate (current .x , -current .y - current .textRise );
849
- ctx .transform .apply (ctx , fontMatrix );
850
- ctx .scale (textHScale , 1 );
841
+ ctx .translate (current .x , current .y + current .textRise );
842
+ if (current .fontDirection > 0 ) {
843
+ ctx .scale (current .textHScale , -1 );
844
+ } else {
845
+ ctx .scale (-current .textHScale , 1 );
846
+ }
851
847
},
852
848
createTextGeometry : function CanvasGraphics_createTextGeometry () {
853
849
var geometry = {};
@@ -878,9 +874,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
878
874
var fontSizeScale = current .fontSizeScale ;
879
875
var charSpacing = current .charSpacing ;
880
876
var wordSpacing = current .wordSpacing ;
881
- var textHScale = current .textHScale ;
882
- var fontMatrix = current .fontMatrix || IDENTITY_MATRIX ;
883
- var textHScale2 = textHScale * fontMatrix [0 ];
877
+ var textHScale = current .textHScale * current .fontDirection ;
878
+ var fontMatrix = current .fontMatrix || FONT_IDENTITY_MATRIX ;
884
879
var glyphsLength = glyphs .length ;
885
880
var textLayer = this .textLayer ;
886
881
var geom ;
@@ -919,8 +914,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
919
914
this .restore ();
920
915
921
916
var transformed = Util .applyTransform ([glyph .width , 0 ], fontMatrix );
922
- var width = transformed [0 ] * fontSize +
923
- Util . sign ( current . fontMatrix [ 0 ]) * charSpacing ;
917
+ var width = ( transformed [0 ] * fontSize + charSpacing ) *
918
+ current . fontDirection ;
924
919
925
920
ctx .translate (width , 0 );
926
921
current .x += width * textHScale ;
@@ -934,8 +929,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
934
929
935
930
var lineWidth = current .lineWidth ;
936
931
var a1 = current .textMatrix [0 ], b1 = current .textMatrix [1 ];
937
- var a2 = fontMatrix [0 ], b2 = fontMatrix [1 ];
938
- var scale = Math .sqrt ((a1 * a1 + b1 * b1 ) * (a2 * a2 + b2 * b2 ));
932
+ var scale = Math .sqrt (a1 * a1 + b1 * b1 );
939
933
if (scale == 0 || lineWidth == 0 )
940
934
lineWidth = this .getSinglePixelWidth ();
941
935
else
@@ -956,13 +950,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
956
950
var glyph = glyphs [i ];
957
951
if (glyph === null ) {
958
952
// word break
959
- x += Util . sign ( current .fontMatrix [ 0 ]) * wordSpacing ;
953
+ x += current .fontDirection * wordSpacing ;
960
954
continue ;
961
955
}
962
956
963
957
var character = glyph .fontChar ;
964
- var charWidth = glyph .width * fontSize * 0.001 +
965
- Util . sign ( current . fontMatrix [ 0 ]) * charSpacing ;
958
+ var charWidth = glyph .width * fontSize * current . fontMatrix [ 0 ] +
959
+ charSpacing * current . fontDirection ;
966
960
967
961
if (!glyph .disabled ) {
968
962
var scaledX = x / fontSizeScale ;
@@ -995,7 +989,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
995
989
996
990
canvasWidth += charWidth ;
997
991
}
998
- current .x += x * textHScale2 ;
992
+ current .x += x * textHScale ;
999
993
ctx .restore ();
1000
994
}
1001
995
@@ -1011,9 +1005,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
1011
1005
var current = this .current ;
1012
1006
var font = current .font ;
1013
1007
var fontSize = current .fontSize ;
1014
- var textHScale = current .textHScale ;
1015
- if (! font . coded )
1016
- textHScale *= ( current .fontMatrix || IDENTITY_MATRIX )[ 0 ] ;
1008
+ var textHScale = current .textHScale * ( current . fontMatrix && ! font . coded ?
1009
+ current . fontMatrix [ 0 ] : FONT_IDENTITY_MATRIX [ 0 ]) *
1010
+ current .fontDirection ;
1017
1011
var arrLength = arr .length ;
1018
1012
var textLayer = this .textLayer ;
1019
1013
var geom ;
@@ -1022,22 +1016,15 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
1022
1016
1023
1017
if (textSelection ) {
1024
1018
ctx .save ();
1025
- // Type3 fonts - each glyph is a "mini-PDF" (see also showText)
1026
- if (font .coded ) {
1027
- ctx .transform .apply (ctx , current .textMatrix );
1028
- ctx .scale (1 , -1 );
1029
- ctx .translate (current .x , -1 * current .y );
1030
- ctx .scale (textHScale , 1 );
1031
- } else
1032
- this .applyTextTransforms ();
1019
+ this .applyTextTransforms ();
1033
1020
geom = this .createTextGeometry ();
1034
1021
ctx .restore ();
1035
1022
}
1036
1023
1037
1024
for (var i = 0 ; i < arrLength ; ++i ) {
1038
1025
var e = arr [i ];
1039
1026
if (isNum (e )) {
1040
- var spacingLength = -e * 0.001 * fontSize * textHScale ;
1027
+ var spacingLength = -e * fontSize * textHScale ;
1041
1028
current .x += spacingLength ;
1042
1029
1043
1030
if (textSelection )
0 commit comments