1
1
<?php
2
+
3
+ namespace Librecode \TcpdiParser ;
4
+
2
5
//============================================================+
3
6
// File name : tcpdi_parser.php
4
7
// Version : 1.1
@@ -483,7 +486,7 @@ protected function decodeXrefStream($startxref, $xref=array()) {
483
486
$ v = $ sarr [$ key ];
484
487
if (($ key == '/Type ' ) AND ($ v [0 ] == PDF_TYPE_TOKEN AND ($ v [1 ] == 'XRef ' ))) {
485
488
$ valid_crs = true ;
486
- } elseif (($ key == '/Index ' ) AND ($ v [0 ] == PDF_TYPE_ARRAY AND count ($ v [1 ] >= 2 ))) {
489
+ } elseif (($ key == '/Index ' ) AND ($ v [0 ] == PDF_TYPE_ARRAY AND ( count ($ v [1 ]) >= 2 ))) {
487
490
// first object number in the subsection
488
491
$ index_first = intval ($ v [1 ][0 ][1 ]);
489
492
// number of entries in the subsection
@@ -709,20 +712,19 @@ protected function getRawObject($offset=0, $data=null) {
709
712
$ objtype = '' ; // object type to be returned
710
713
$ objval = '' ; // object value to be returned
711
714
// skip initial white space chars: \x00 null (NUL), \x09 horizontal tab (HT), \x0A line feed (LF), \x0C form feed (FF), \x0D carriage return (CR), \x20 space (SP)
712
- while (strspn ($ data{ $ offset} , "\x00\x09\x0a\x0c\x0d\x20" ) == 1 ) {
715
+ while (strspn ($ data[ $ offset] , "\x00\x09\x0a\x0c\x0d\x20" )) {
713
716
$ offset ++;
714
717
}
715
718
// get first char
716
- $ char = $ data{ $ offset} ;
719
+ $ char = $ data[ $ offset] ;
717
720
// get object type
718
721
switch ($ char ) {
719
722
case '% ' : { // \x25 PERCENT SIGN
720
723
// skip comment and search for next token
721
724
$ next = strcspn ($ data , "\r\n" , $ offset );
722
725
if ($ next > 0 ) {
723
726
$ offset += $ next ;
724
- list ($ obj , $ unused ) = $ this ->getRawObject ($ offset , $ data );
725
- return $ obj ;
727
+ return $ this ->getRawObject ($ offset , $ data );
726
728
}
727
729
break ;
728
730
}
@@ -744,10 +746,10 @@ protected function getRawObject($offset=0, $data=null) {
744
746
if ($ char == '( ' ) {
745
747
$ open_bracket = 1 ;
746
748
while ($ open_bracket > 0 ) {
747
- if (!isset ($ data{ $ strpos} )) {
749
+ if (!isset ($ data[ $ strpos] )) {
748
750
break ;
749
751
}
750
- $ ch = $ data{ $ strpos} ;
752
+ $ ch = $ data[ $ strpos] ;
751
753
switch ($ ch ) {
752
754
case '\\' : { // REVERSE SOLIDUS (5Ch) (Backslash)
753
755
// skip next character
@@ -792,7 +794,7 @@ protected function getRawObject($offset=0, $data=null) {
792
794
}
793
795
case '< ' : // \x3C LESS-THAN SIGN
794
796
case '> ' : { // \x3E GREATER-THAN SIGN
795
- if (isset ($ data{ ($ offset + 1 )} ) AND ($ data{ ($ offset + 1 )} == $ char )) {
797
+ if (isset ($ data[ ($ offset + 1 )] ) AND ($ data[ ($ offset + 1 )] == $ char )) {
796
798
// dictionary object
797
799
$ objtype = PDF_TYPE_DICTIONARY ;
798
800
if ($ char == '< ' ) {
@@ -809,13 +811,16 @@ protected function getRawObject($offset=0, $data=null) {
809
811
if (($ char == '< ' ) AND (preg_match ('/^([0-9A-Fa-f ]+)[>]/iU ' , substr ($ data , $ offset ), $ matches ) == 1 )) {
810
812
$ objval = $ matches [1 ];
811
813
$ offset += strlen ($ matches [0 ]);
812
- unset($ matches );
814
+ } else if (($ char == '< ' ) AND ($ endpos = strpos ($ this ->pdfdata , '> ' , $ offset )) !== FALSE ) {
815
+ $ objval = substr ($ data , $ offset ,$ endpos -$ offset );
816
+ $ offset = $ endpos + 1 ;
813
817
}
818
+ unset($ matches );
814
819
}
815
820
break ;
816
821
}
817
822
default : {
818
- $ frag = $ data{ $ offset} . @$ data{ $ offset +1 } . @$ data{ $ offset +2 } . @$ data{ $ offset +3 } ;
823
+ $ frag = $ data[ $ offset] . @$ data[ $ offset +1 ] . @$ data[ $ offset +2 ] . @$ data[ $ offset +3 ] ;
819
824
switch ($ frag ) {
820
825
case 'endo ' :
821
826
// indirect object
@@ -888,20 +893,25 @@ private function getDictValue($offset, &$data) {
888
893
$ objval = array ();
889
894
890
895
// Extract dict from data.
891
- $ i =1 ;
896
+ $ i =2 ;
892
897
$ dict = '' ;
893
898
$ offset += 2 ;
894
899
do {
895
- if ($ data{ $ offset} == '> ' && $ data{ $ offset +1 } == '> ' ) {
896
- $ i-- ;
900
+ if ($ data[ $ offset] == '> ' && $ data[ $ offset +1 ] == '> ' ) {
901
+ $ i -= 2 ;
897
902
$ dict .= '>> ' ;
898
903
$ offset += 2 ;
899
- } else if ($ data{ $ offset} == '< ' && $ data{ $ offset +1 } == '< ' ) {
900
- $ i++ ;
904
+ } else if ($ data[ $ offset] == '< ' && $ data[ $ offset +1 ] == '< ' ) {
905
+ $ i += 2 ;
901
906
$ dict .= '<< ' ;
902
907
$ offset += 2 ;
903
908
} else {
904
- $ dict .= $ data {$ offset };
909
+ if ($ data [$ offset ] == '< ' ) {
910
+ $ i ++;
911
+ } else if ($ data [$ offset ] == '> ' ) {
912
+ $ i --;
913
+ }
914
+ $ dict .= $ data [$ offset ];
905
915
$ offset ++;
906
916
}
907
917
} while ($ i >0 );
@@ -1441,7 +1451,7 @@ private function _getPageRotation($obj) { // $obj = /Page
1441
1451
*/
1442
1452
public function Error ($ msg ) {
1443
1453
// exit program and print error
1444
- die ("<strong>TCPDI_PARSER ERROR [ {$ this ->uniqueid }]: </strong> " .$ msg );
1454
+ throw new Exception ("<strong>TCPDI_PARSER ERROR [ {$ this ->uniqueid }]: </strong> " .$ msg );
1445
1455
}
1446
1456
1447
1457
} // END OF TCPDF_PARSER CLASS
0 commit comments