@@ -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 ;
@@ -716,11 +716,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
716
716
if (!fontObj )
717
717
error ('Can\'t find font for ' + fontRefName );
718
718
719
- // Slice-clone matrix so we can manipulate it without affecting original
720
- if (fontObj .fontMatrix )
721
- current .fontMatrix = fontObj .fontMatrix .slice (0 );
722
- else
723
- current .fontMatrix = IDENTITY_MATRIX .slice (0 );
719
+ current .fontMatrix = fontObj .fontMatrix ? fontObj .fontMatrix :
720
+ FONT_IDENTITY_MATRIX ;
724
721
725
722
// A valid matrix needs all main diagonal elements to be non-zero
726
723
// This also ensures we bypass FF bugzilla bug #719844.
@@ -731,11 +728,11 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
731
728
732
729
// The spec for Tf (setFont) says that 'size' specifies the font 'scale',
733
730
// and in some docs this can be negative (inverted x-y axes).
734
- // We implement this condition with fontMatrix.
735
731
if (size < 0 ) {
736
732
size = -size ;
737
- current .fontMatrix [0 ] *= -1 ;
738
- current .fontMatrix [3 ] *= -1 ;
733
+ current .fontDirection = -1 ;
734
+ } else {
735
+ current .fontDirection = 1 ;
739
736
}
740
737
741
738
this .current .font = fontObj ;
@@ -788,14 +785,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
788
785
applyTextTransforms : function CanvasGraphics_applyTextTransforms () {
789
786
var ctx = this .ctx ;
790
787
var current = this .current ;
791
- var textHScale = current .textHScale ;
792
- var fontMatrix = current .fontMatrix || IDENTITY_MATRIX ;
793
-
794
788
ctx .transform .apply (ctx , current .textMatrix );
795
- ctx .scale (1 , -1 );
796
- ctx .translate (current .x , -current .y - current .textRise );
797
- ctx .transform .apply (ctx , fontMatrix );
798
- ctx .scale (textHScale , 1 );
789
+ ctx .translate (current .x , current .y + current .textRise );
790
+ if (current .fontDirection > 0 ) {
791
+ ctx .scale (current .textHScale , -1 );
792
+ } else {
793
+ ctx .scale (-current .textHScale , 1 );
794
+ }
799
795
},
800
796
createTextGeometry : function CanvasGraphics_createTextGeometry () {
801
797
var geometry = {};
@@ -826,9 +822,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
826
822
var fontSizeScale = current .fontSizeScale ;
827
823
var charSpacing = current .charSpacing ;
828
824
var wordSpacing = current .wordSpacing ;
829
- var textHScale = current .textHScale ;
830
- var fontMatrix = current .fontMatrix || IDENTITY_MATRIX ;
831
- var textHScale2 = textHScale * fontMatrix [0 ];
825
+ var textHScale = current .textHScale * current .fontDirection ;
826
+ var fontMatrix = current .fontMatrix || FONT_IDENTITY_MATRIX ;
832
827
var glyphsLength = glyphs .length ;
833
828
var textLayer = this .textLayer ;
834
829
var geom ;
@@ -867,8 +862,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
867
862
this .restore ();
868
863
869
864
var transformed = Util .applyTransform ([glyph .width , 0 ], fontMatrix );
870
- var width = transformed [0 ] * fontSize +
871
- Util . sign ( current . fontMatrix [ 0 ]) * charSpacing ;
865
+ var width = ( transformed [0 ] * fontSize + charSpacing ) *
866
+ current . fontDirection ;
872
867
873
868
ctx .translate (width , 0 );
874
869
current .x += width * textHScale ;
@@ -882,8 +877,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
882
877
883
878
var lineWidth = current .lineWidth ;
884
879
var a1 = current .textMatrix [0 ], b1 = current .textMatrix [1 ];
885
- var a2 = fontMatrix [0 ], b2 = fontMatrix [1 ];
886
- var scale = Math .sqrt ((a1 * a1 + b1 * b1 ) * (a2 * a2 + b2 * b2 ));
880
+ var scale = Math .sqrt (a1 * a1 + b1 * b1 );
887
881
if (scale == 0 || lineWidth == 0 )
888
882
lineWidth = this .getSinglePixelWidth ();
889
883
else
@@ -904,13 +898,13 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
904
898
var glyph = glyphs [i ];
905
899
if (glyph === null ) {
906
900
// word break
907
- x += Util . sign ( current .fontMatrix [ 0 ]) * wordSpacing ;
901
+ x += current .fontDirection * wordSpacing ;
908
902
continue ;
909
903
}
910
904
911
905
var character = glyph .fontChar ;
912
- var charWidth = glyph .width * fontSize * 0.001 +
913
- Util . sign ( current . fontMatrix [ 0 ]) * charSpacing ;
906
+ var charWidth = glyph .width * fontSize * current . fontMatrix [ 0 ] +
907
+ charSpacing * current . fontDirection ;
914
908
915
909
if (!glyph .disabled ) {
916
910
var scaledX = x / fontSizeScale ;
@@ -943,7 +937,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
943
937
944
938
canvasWidth += charWidth ;
945
939
}
946
- current .x += x * textHScale2 ;
940
+ current .x += x * textHScale ;
947
941
ctx .restore ();
948
942
}
949
943
@@ -959,9 +953,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
959
953
var current = this .current ;
960
954
var font = current .font ;
961
955
var fontSize = current .fontSize ;
962
- var textHScale = current .textHScale ;
963
- if (! font . coded )
964
- textHScale *= ( current .fontMatrix || IDENTITY_MATRIX )[ 0 ] ;
956
+ var textHScale = current .textHScale * ( current . fontMatrix && ! font . coded ?
957
+ current . fontMatrix [ 0 ] : FONT_IDENTITY_MATRIX [ 0 ]) *
958
+ current .fontDirection ;
965
959
var arrLength = arr .length ;
966
960
var textLayer = this .textLayer ;
967
961
var geom ;
@@ -970,22 +964,15 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
970
964
971
965
if (textSelection ) {
972
966
ctx .save ();
973
- // Type3 fonts - each glyph is a "mini-PDF" (see also showText)
974
- if (font .coded ) {
975
- ctx .transform .apply (ctx , current .textMatrix );
976
- ctx .scale (1 , -1 );
977
- ctx .translate (current .x , -1 * current .y );
978
- ctx .scale (textHScale , 1 );
979
- } else
980
- this .applyTextTransforms ();
967
+ this .applyTextTransforms ();
981
968
geom = this .createTextGeometry ();
982
969
ctx .restore ();
983
970
}
984
971
985
972
for (var i = 0 ; i < arrLength ; ++i ) {
986
973
var e = arr [i ];
987
974
if (isNum (e )) {
988
- var spacingLength = -e * 0.001 * fontSize * textHScale ;
975
+ var spacingLength = -e * fontSize * textHScale ;
989
976
current .x += spacingLength ;
990
977
991
978
if (textSelection )
0 commit comments