@@ -2538,7 +2538,7 @@ class PartialEvaluator {
25382538
25392539 const preprocessor = new EvaluatorPreprocessor ( stream , xref , stateManager ) ;
25402540
2541- let textState ;
2541+ let textState , currentTextState ;
25422542
25432543 function pushWhitespace ( {
25442544 width = 0 ,
@@ -2800,7 +2800,9 @@ class PartialEvaluator {
28002800
28012801 // When the total height of the current chunk is negative
28022802 // then we're writing from bottom to top.
2803- const textOrientation = Math . sign ( textContentItem . height ) ;
2803+ const textOrientation = Math . sign (
2804+ textContentItem . height || textContentItem . totalHeight
2805+ ) ;
28042806 if ( advanceY < textOrientation * textContentItem . negativeSpaceMax ) {
28052807 if (
28062808 Math . abs ( advanceX ) >
@@ -2864,7 +2866,9 @@ class PartialEvaluator {
28642866
28652867 // When the total width of the current chunk is negative
28662868 // then we're writing from right to left.
2867- const textOrientation = Math . sign ( textContentItem . width ) ;
2869+ const textOrientation = Math . sign (
2870+ textContentItem . width || textContentItem . totalWidth
2871+ ) ;
28682872 if ( advanceX < textOrientation * textContentItem . negativeSpaceMax ) {
28692873 if (
28702874 Math . abs ( advanceY ) >
@@ -2922,6 +2926,15 @@ class PartialEvaluator {
29222926 }
29232927
29242928 function buildTextContentItem ( { chars, extraSpacing } ) {
2929+ if (
2930+ currentTextState !== textState &&
2931+ ( currentTextState . fontName !== textState . fontName ||
2932+ currentTextState . fontSize !== textState . fontSize )
2933+ ) {
2934+ flushTextContentItem ( ) ;
2935+ currentTextState = textState . clone ( ) ;
2936+ }
2937+
29252938 const font = textState . font ;
29262939 if ( ! chars ) {
29272940 // Just move according to the space we have.
@@ -3177,8 +3190,8 @@ class PartialEvaluator {
31773190 break ;
31783191 }
31793192
3180- const previousState = textState ;
31813193 textState = stateManager . state ;
3194+ currentTextState ||= textState . clone ( ) ;
31823195 const fn = operation . fn ;
31833196 args = operation . args ;
31843197
@@ -3195,7 +3208,6 @@ class PartialEvaluator {
31953208 break ;
31963209 }
31973210
3198- flushTextContentItem ( ) ;
31993211 textState . fontName = fontNameArg ;
32003212 textState . fontSize = fontSizeArg ;
32013213 next ( handleSetFont ( fontNameArg , null ) ) ;
@@ -3552,14 +3564,10 @@ class PartialEvaluator {
35523564 }
35533565 break ;
35543566 case OPS . restore :
3555- if (
3556- previousState &&
3557- ( previousState . font !== textState . font ||
3558- previousState . fontSize !== textState . fontSize ||
3559- previousState . fontName !== textState . fontName )
3560- ) {
3561- flushTextContentItem ( ) ;
3562- }
3567+ stateManager . restore ( ) ;
3568+ break ;
3569+ case OPS . save :
3570+ stateManager . save ( ) ;
35633571 break ;
35643572 } // switch
35653573 if ( textContent . items . length >= ( sink ?. desiredSize ?? 1 ) ) {
@@ -5083,7 +5091,7 @@ class TextState {
50835091 }
50845092
50855093 clone ( ) {
5086- const clone = Object . create ( this ) ;
5094+ const clone = Object . assign ( Object . create ( this ) , this ) ;
50875095 clone . textMatrix = this . textMatrix . slice ( ) ;
50885096 clone . textLineMatrix = this . textLineMatrix . slice ( ) ;
50895097 clone . fontMatrix = this . fontMatrix . slice ( ) ;
0 commit comments