66
77class HtmlFormatter
88{
9- protected $ output = '' ;
109 protected $ encoding ;
1110 protected $ defaultFont ;
1211 protected $ fromhtml = false ;
12+ protected $ openedTags = [];
13+ protected $ output = '' ;
14+ protected $ previousState ;
15+ protected $ rtfEncoding ;
16+ protected $ state ;
17+ protected $ states = [];
1318
1419 /**
1520 * Object constructor.
@@ -65,8 +70,8 @@ public function format(Document $document)
6570 $ this ->processGroup ($ document ->root );
6671
6772 // Instead of removing opened tags, we close them
68- $ this ->output .= $ this ->openedTags ['span ' ] ? '</span> ' : '' ;
69- $ this ->output .= $ this ->openedTags ['p ' ] ? '</p> ' : '' ;
73+ $ this ->output .= $ this ->openedTags ['span ' ] ? '</span> ' : '' ; // @phpstan-ignore-line
74+ $ this ->output .= $ this ->openedTags ['p ' ] ? '</p> ' : '' ; // @phpstan-ignore-line
7075
7176 // Remove extra empty paragraph at the end
7277 // TODO: Find the real reason it's there and fix it
@@ -490,7 +495,7 @@ protected function write($txt)
490495 return ;
491496 }
492497
493- if ($ this ->openedTags ['p ' ] === null ) {
498+ if (! isset ( $ this ->openedTags ['p ' ]) ) {
494499 // Create the first paragraph
495500 $ this ->openTag ('p ' );
496501 }
@@ -499,9 +504,7 @@ protected function write($txt)
499504 // 1st case: style change occured
500505 // 2nd case: there is no change in style but the already created 'span'
501506 // element is somehow closed (ex. because of an end of paragraph)
502- if (!$ this ->state ->equals ($ this ->previousState )
503- || ($ this ->state ->equals ($ this ->previousState ) && !$ this ->openedTags ['span ' ])
504- ) {
507+ if (!$ this ->state ->equals ($ this ->previousState ) || empty ($ this ->openedTags ['span ' ])) {
505508 // If applicable close previously opened 'span' tag
506509 $ this ->closeTag ('span ' );
507510
@@ -535,7 +538,7 @@ protected function closeTag($tag)
535538 return ;
536539 }
537540
538- if ($ this ->openedTags [$ tag ]) {
541+ if (! empty ( $ this ->openedTags [$ tag ]) ) {
539542 // Check for empty html elements
540543 if (substr ($ this ->output , -strlen ("< {$ tag }> " )) == "< {$ tag }> " ) {
541544 switch ($ tag ) {
@@ -649,6 +652,8 @@ protected function getEncodingFromCharset($charset)
649652 if (isset ($ map [$ charset ])) {
650653 return $ map [$ charset ];
651654 }
655+
656+ return null ;
652657 }
653658
654659 /**
@@ -702,12 +707,14 @@ protected function getEncodingFromCodepage($cpg)
702707 if (isset ($ map [$ cpg ])) {
703708 return $ map [$ cpg ];
704709 }
710+
711+ return null ;
705712 }
706713
707714 protected function ordUtf8 ($ chr )
708715 {
709716 $ ord0 = ord ($ chr );
710- if ($ ord0 >= 0 && $ ord0 <= 127 ) {
717+ if ($ ord0 <= 127 ) {
711718 return $ ord0 ;
712719 }
713720
0 commit comments