2525use setasign \Fpdi \PdfParser \Type \PdfString ;
2626use setasign \Fpdi \PdfParser \Type \PdfToken ;
2727use setasign \Fpdi \PdfParser \Type \PdfType ;
28+ use setasign \Fpdi \PdfParser \Type \PdfTypeException ;
2829
2930/**
3031 * A PDF parser class
@@ -258,25 +259,25 @@ public function readValue($token = null, $expectedType = null)
258259 switch ($ token ) {
259260 case '( ' :
260261 $ this ->ensureExpectedType ($ token , $ expectedType );
261- return PdfString:: parse ( $ this ->streamReader );
262+ return $ this ->parsePdfString ( );
262263
263264 case '< ' :
264265 if ($ this ->streamReader ->getByte () === '< ' ) {
265266 $ this ->ensureExpectedType ('<< ' , $ expectedType );
266267 $ this ->streamReader ->addOffset (1 );
267- return PdfDictionary:: parse ( $ this ->tokenizer , $ this -> streamReader , $ this );
268+ return $ this ->parsePdfDictionary ( );
268269 }
269270
270271 $ this ->ensureExpectedType ($ token , $ expectedType );
271- return PdfHexString:: parse ( $ this ->streamReader );
272+ return $ this ->parsePdfHexString ( );
272273
273274 case '/ ' :
274275 $ this ->ensureExpectedType ($ token , $ expectedType );
275- return PdfName:: parse ( $ this ->tokenizer , $ this -> streamReader );
276+ return $ this ->parsePdfName ( );
276277
277278 case '[ ' :
278279 $ this ->ensureExpectedType ($ token , $ expectedType );
279- return PdfArray:: parse ( $ this ->tokenizer , $ this );
280+ return $ this ->parsePdfArray ( );
280281
281282 default :
282283 if (\is_numeric ($ token )) {
@@ -291,13 +292,7 @@ public function readValue($token = null, $expectedType = null)
291292 );
292293 }
293294
294- return PdfIndirectObject::parse (
295- (int ) $ token ,
296- (int ) $ token2 ,
297- $ this ,
298- $ this ->tokenizer ,
299- $ this ->streamReader
300- );
295+ return $ this ->parsePdfIndirectObject ((int )$ token , (int )$ token2 );
301296 case 'R ' :
302297 if (
303298 $ expectedType !== null &&
@@ -309,7 +304,7 @@ public function readValue($token = null, $expectedType = null)
309304 );
310305 }
311306
312- return PdfIndirectObjectReference::create ((int ) $ token , (int ) $ token2 );
307+ return PdfIndirectObjectReference::create ((int )$ token , (int )$ token2 );
313308 }
314309
315310 $ this ->tokenizer ->pushStack ($ token3 );
@@ -351,6 +346,65 @@ public function readValue($token = null, $expectedType = null)
351346 }
352347 }
353348
349+ /**
350+ * @return PdfString
351+ */
352+ protected function parsePdfString ()
353+ {
354+ return PdfString::parse ($ this ->streamReader );
355+ }
356+
357+ /**
358+ * @return false|PdfHexString
359+ */
360+ protected function parsePdfHexString ()
361+ {
362+ return PdfHexString::parse ($ this ->streamReader );
363+ }
364+
365+ /**
366+ * @return bool|PdfDictionary
367+ * @throws PdfTypeException
368+ */
369+ protected function parsePdfDictionary ()
370+ {
371+ return PdfDictionary::parse ($ this ->tokenizer , $ this ->streamReader , $ this );
372+ }
373+
374+ /**
375+ * @return PdfName
376+ */
377+ protected function parsePdfName ()
378+ {
379+ return PdfName::parse ($ this ->tokenizer , $ this ->streamReader );
380+ }
381+
382+ /**
383+ * @return false|PdfArray
384+ * @throws PdfTypeException
385+ */
386+ protected function parsePdfArray ()
387+ {
388+ return PdfArray::parse ($ this ->tokenizer , $ this );
389+ }
390+
391+ /**
392+ * @param int $objectNumber
393+ * @param int $generationNumber
394+ * @return false|PdfIndirectObject
395+ * @throws Type\PdfTypeException
396+ */
397+ protected function parsePdfIndirectObject ($ objectNumber , $ generationNumber )
398+ {
399+ return PdfIndirectObject::parse (
400+ $ objectNumber ,
401+ $ generationNumber ,
402+ $ this ,
403+ $ this ->tokenizer ,
404+ $ this ->streamReader
405+ );
406+ }
407+
354408 /**
355409 * Ensures that the token will evaluate to an expected object type (or not).
356410 *
@@ -359,7 +413,7 @@ public function readValue($token = null, $expectedType = null)
359413 * @return bool
360414 * @throws Type\PdfTypeException
361415 */
362- private function ensureExpectedType ($ token , $ expectedType )
416+ protected function ensureExpectedType ($ token , $ expectedType )
363417 {
364418 static $ mapping = [
365419 '( ' => PdfString::class,
0 commit comments