@@ -1036,7 +1036,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
10361036 showText : function CanvasGraphics_showText (glyphs , skipTextSelection ) {
10371037 var ctx = this .ctx ;
10381038 var current = this .current ;
1039- var font = current .font ;
1039+ var font = current .font || {} ;
10401040 var fontSize = current .fontSize ;
10411041 var fontSizeScale = current .fontSizeScale ;
10421042 var charSpacing = current .charSpacing ;
@@ -1095,19 +1095,20 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
10951095 this .processingType3 = null ;
10961096 } else {
10971097 ctx .save ();
1098- var tx = 0 ;
10991098
11001099//MQZ Dec.04.2013 handles leading word spacing
1100+ var tx = 0 ;
11011101 if (wordSpacing !== 0 ) {
1102- var firstGlyph = _ . find ( glyphs , function ( g ) { return _. isObject ( g );}) ;
1102+ var firstGlyph = glyphs . filter ( g => g && ( 'fontChar' in g || 'unicode' in g ))[ 0 ] ;
11031103 if (firstGlyph && (firstGlyph .fontChar === ' ' || firstGlyph .unicode === ' ' )) {
1104- if (_ .find (glyphs , function (g ) { return _.isObject (g ) && g .unicode !== ' ' ;})) {
1105- current .x += wordSpacing * fontSize * textHScale ;
1106- }
1104+ tx = wordSpacing * fontSize * textHScale ;
11071105 }
11081106 }
11091107
1108+ current .x += tx
11101109 this .applyTextTransforms ();
1110+ current .x -= tx
1111+ // MQZ-GYJ Apr.20.2017 handles leading word spacing over
11111112
11121113 var lineWidth = current .lineWidth ;
11131114 var a1 = current .textMatrix [0 ], b1 = current .textMatrix [1 ];
@@ -1286,7 +1287,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
12861287 }
12871288 }
12881289 else {
1289- if (-e >= spaceWidth ) {
1290+ //MQZ-GYJ. Apr.20.2017 split word when spacing is a positive number but very big
1291+ if (Math .abs (e ) >= spaceWidth ) {
12901292 if (vertical ) {
12911293 current .y += spacingLength ;
12921294 } else {
@@ -1533,6 +1535,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
15331535 var depth = this .current .paintFormXObjectDepth ;
15341536 do {
15351537 this .restore ();
1538+ this .current .paintFormXObjectDepth --;
15361539 // some pdf don't close all restores inside object
15371540 // closing those for them
15381541 } while (this .current .paintFormXObjectDepth >= depth );
@@ -1616,6 +1619,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
16161619 },
16171620
16181621 endGroup : function CanvasGraphics_endGroup (group ) {
1622+ //MQZ. make sure endGroup is always invoked after beginGroup
1623+ if (this .groupLevel == 0 )
1624+ this .beginGroup (group );
1625+
16191626 this .groupLevel --;
16201627 var groupCtx = this .ctx ;
16211628 this .ctx = this .groupStack .pop ();
0 commit comments