Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields
Zend_Pdf_StringParser Class Reference

Public Member Functions

 cleanUp ()
 
 skipWhiteSpace ($skipComment=true)
 
 skipComment ()
 
 readComment ()
 
 readLexeme ()
 
 readElement ($nextLexeme=null)
 
 getObject ($offset, Zend_Pdf_Element_Reference_Context $context)
 
 getLength ()
 
 getString ()
 
 setContext (Zend_Pdf_Element_Reference_Context $context)
 
 __construct ($source, Zend_Pdf_ElementFactory_Interface $factory)
 

Static Public Member Functions

static isWhiteSpace ($chCode)
 
static isDelimiter ($chCode)
 
static parseIntFromStream ($stream, $offset, $size)
 

Data Fields

 $data = ''
 
 $offset = 0
 

Detailed Description

Definition at line 44 of file StringParser.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $source,
Zend_Pdf_ElementFactory_Interface  $factory 
)

Object constructor

Note: PHP duplicates string, which is sent by value, only of it's updated. Thus we don't need to care about overhead

Parameters
string$pdfString
Zend_Pdf_ElementFactory_Interface$factory

Definition at line 726 of file StringParser.php.

727  {
728  $this->data = $source;
729  $this->_objFactory = $factory;
730  }
$source
Definition: source.php:23

Member Function Documentation

◆ cleanUp()

cleanUp ( )

Clean up resources.

Clear current state to remove cyclic object references

Definition at line 87 of file StringParser.php.

88  {
89  $this->_context = null;
90  $this->_elements = array();
91  $this->_objFactory = null;
92  }

◆ getLength()

getLength ( )

Get length of source string

Returns
integer

Definition at line 670 of file StringParser.php.

671  {
672  return strlen($this->data);
673  }

◆ getObject()

getObject (   $offset,
Zend_Pdf_Element_Reference_Context  $context 
)

Read inderect object from a PDF stream

Parameters
integer$offset
Zend_Pdf_Element_Reference_Context$context
Returns
Zend_Pdf_Element_Object

Object is not generated by factory (thus it's not marked as modified object). But factory is assigned to the obect.

It's a stream object

References are automatically dereferenced at this moment.

'stream' keyword must be followed by either cr-lf sequence or lf character only. This restriction gives the possibility to recognize all cases exactly

Definition at line 546 of file StringParser.php.

547  {
548  if ($offset === null ) {
549  return new Zend_Pdf_Element_Null();
550  }
551 
552  // Save current offset to make getObject() reentrant
553  $offsetSave = $this->offset;
554 
555  $this->offset = $offset;
556  $this->_context = $context;
557  $this->_elements = array();
558 
559  $objNum = $this->readLexeme();
560  if (!ctype_digit($objNum)) {
561  #require_once 'Zend/Pdf/Exception.php';
562  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. Object number expected.', $this->offset - strlen($objNum)));
563  }
564 
565  $genNum = $this->readLexeme();
566  if (!ctype_digit($genNum)) {
567  #require_once 'Zend/Pdf/Exception.php';
568  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. Object generation number expected.', $this->offset - strlen($genNum)));
569  }
570 
571  $objKeyword = $this->readLexeme();
572  if ($objKeyword != 'obj') {
573  #require_once 'Zend/Pdf/Exception.php';
574  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. \'obj\' keyword expected.', $this->offset - strlen($objKeyword)));
575  }
576 
577  $objValue = $this->readElement();
578 
579  $nextLexeme = $this->readLexeme();
580 
581  if( $nextLexeme == 'endobj' ) {
586  $obj = new Zend_Pdf_Element_Object($objValue, (int)$objNum, (int)$genNum, $this->_objFactory->resolve());
587 
588  foreach ($this->_elements as $element) {
589  $element->setParentObject($obj);
590  }
591 
592  // Restore offset value
593  $this->offset = $offsetSave;
594 
595  return $obj;
596  }
597 
601  if ($nextLexeme != 'stream') {
602  #require_once 'Zend/Pdf/Exception.php';
603  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. \'endobj\' or \'stream\' keywords expected.', $this->offset - strlen($nextLexeme)));
604  }
605 
606  if (!$objValue instanceof Zend_Pdf_Element_Dictionary) {
607  #require_once 'Zend/Pdf/Exception.php';
608  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. Stream extent must be preceded by stream dictionary.', $this->offset - strlen($nextLexeme)));
609  }
610 
614  $streamLength = $objValue->Length->value;
615 
620  if ($this->data[$this->offset] == "\r" &&
621  $this->data[$this->offset + 1] == "\n" ) {
622  $this->offset += 2;
623  } else if ($this->data[$this->offset] == "\n" ) {
624  $this->offset++;
625  } else {
626  #require_once 'Zend/Pdf/Exception.php';
627  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. \'stream\' must be followed by either cr-lf sequence or lf character only.', $this->offset - strlen($nextLexeme)));
628  }
629 
630  $dataOffset = $this->offset;
631 
632  $this->offset += $streamLength;
633 
634  $nextLexeme = $this->readLexeme();
635  if ($nextLexeme != 'endstream') {
636  #require_once 'Zend/Pdf/Exception.php';
637  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. \'endstream\' keyword expected.', $this->offset - strlen($nextLexeme)));
638  }
639 
640  $nextLexeme = $this->readLexeme();
641  if ($nextLexeme != 'endobj') {
642  #require_once 'Zend/Pdf/Exception.php';
643  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X. \'endobj\' keyword expected.', $this->offset - strlen($nextLexeme)));
644  }
645 
646  $obj = new Zend_Pdf_Element_Object_Stream(substr($this->data,
647  $dataOffset,
648  $streamLength),
649  (int)$objNum,
650  (int)$genNum,
651  $this->_objFactory->resolve(),
652  $objValue);
653 
654  foreach ($this->_elements as $element) {
655  $element->setParentObject($obj);
656  }
657 
658  // Restore offset value
659  $this->offset = $offsetSave;
660 
661  return $obj;
662  }
readElement($nextLexeme=null)
$element
Definition: element.phtml:12

◆ getString()

getString ( )

Get source string

Returns
string

Definition at line 680 of file StringParser.php.

681  {
682  return $this->data;
683  }

◆ isDelimiter()

static isDelimiter (   $chCode)
static

Character with code $chCode is a delimiter character

Parameters
integer$chCode
Returns
boolean

Definition at line 122 of file StringParser.php.

123  {
124  if ($chCode == 0x28 || // '('
125  $chCode == 0x29 || // ')'
126  $chCode == 0x3C || // '<'
127  $chCode == 0x3E || // '>'
128  $chCode == 0x5B || // '['
129  $chCode == 0x5D || // ']'
130  $chCode == 0x7B || // '{'
131  $chCode == 0x7D || // '}'
132  $chCode == 0x2F || // '/'
133  $chCode == 0x25 // '%'
134  ) {
135  return true;
136  } else {
137  return false;
138  }
139  }

◆ isWhiteSpace()

static isWhiteSpace (   $chCode)
static

Character with code $chCode is white space

Parameters
integer$chCode
Returns
boolean

Definition at line 100 of file StringParser.php.

101  {
102  if ($chCode == 0x00 || // null character
103  $chCode == 0x09 || // Tab
104  $chCode == 0x0A || // Line feed
105  $chCode == 0x0C || // Form Feed
106  $chCode == 0x0D || // Carriage return
107  $chCode == 0x20 // Space
108  ) {
109  return true;
110  } else {
111  return false;
112  }
113  }

◆ parseIntFromStream()

static parseIntFromStream (   $stream,
  $offset,
  $size 
)
static

Parse integer value from a binary stream

Parameters
string$stream
integer$offset
integer$size
Returns
integer

Definition at line 694 of file StringParser.php.

695  {
696  $value = 0;
697  for ($count = 0; $count < $size; $count++) {
698  $value *= 256;
699  $value += ord($stream[$offset + $count]);
700  }
701 
702  return $value;
703  }
$count
Definition: recent.phtml:13
$value
Definition: gender.phtml:16

◆ readComment()

readComment ( )

Read comment line

Returns
string

Check if it's a comment line

Definition at line 202 of file StringParser.php.

203  {
204  $this->skipWhiteSpace(false);
205 
207  if ($this->data[$this->offset] != '%') {
208  return '';
209  }
210 
211  for ($start = $this->offset;
212  $this->offset < strlen($this->data);
213  $this->offset++) {
214  if (ord($this->data[$this->offset]) == 0x0A || // Line feed
215  ord($this->data[$this->offset]) == 0x0d // Carriage return
216  ) {
217  break;
218  }
219  }
220 
221  return substr($this->data, $start, $this->offset-$start);
222  }
$start
Definition: listing.phtml:18
skipWhiteSpace($skipComment=true)

◆ readElement()

readElement (   $nextLexeme = null)

Read elemental object from a PDF stream

Returns
Zend_Pdf_Element
Exceptions
Zend_Pdf_Exception

Note: readElement() method is a public method and could be invoked from other classes. If readElement() is used not by Zend_Pdf_StringParser::getObject() method, then we should not care about _elements member management.

Definition at line 287 of file StringParser.php.

288  {
289  if ($nextLexeme === null) {
290  $nextLexeme = $this->readLexeme();
291  }
292 
298  switch ($nextLexeme) {
299  case '(':
300  return ($this->_elements[] = $this->_readString());
301 
302  case '<':
303  return ($this->_elements[] = $this->_readBinaryString());
304 
305  case '/':
306  return ($this->_elements[] = new Zend_Pdf_Element_Name(
308  ));
309 
310  case '[':
311  return ($this->_elements[] = $this->_readArray());
312 
313  case '<<':
314  return ($this->_elements[] = $this->_readDictionary());
315 
316  case ')':
317  // fall through to next case
318  case '>':
319  // fall through to next case
320  case ']':
321  // fall through to next case
322  case '>>':
323  // fall through to next case
324  case '{':
325  // fall through to next case
326  case '}':
327  #require_once 'Zend/Pdf/Exception.php';
328  throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Offset - 0x%X.',
329  $this->offset));
330 
331  default:
332  if (strcasecmp($nextLexeme, 'true') == 0) {
333  return ($this->_elements[] = new Zend_Pdf_Element_Boolean(true));
334  } else if (strcasecmp($nextLexeme, 'false') == 0) {
335  return ($this->_elements[] = new Zend_Pdf_Element_Boolean(false));
336  } else if (strcasecmp($nextLexeme, 'null') == 0) {
337  return ($this->_elements[] = new Zend_Pdf_Element_Null());
338  }
339 
340  $ref = $this->_readReference($nextLexeme);
341  if ($ref !== null) {
342  return ($this->_elements[] = $ref);
343  }
344 
345  return ($this->_elements[] = $this->_readNumeric($nextLexeme));
346  }
347  }
static unescape($inStr)
Definition: Name.php:134

◆ readLexeme()

readLexeme ( )

Returns next lexeme from a pdf stream

Returns
string

Definition at line 230 of file StringParser.php.

231  {
232  // $this->skipWhiteSpace();
233  while (true) {
234  $this->offset += strspn($this->data, "\x00\t\n\f\r ", $this->offset);
235 
236  if ($this->offset < strlen($this->data) && $this->data[$this->offset] == '%') {
237  $this->offset += strcspn($this->data, "\r\n", $this->offset);
238  } else {
239  break;
240  }
241  }
242 
243  if ($this->offset >= strlen($this->data)) {
244  return '';
245  }
246 
247  if ( /* self::isDelimiter( ord($this->data[$start]) ) */
248  strpos('()<>[]{}/%', $this->data[$this->offset]) !== false ) {
249 
250  switch (substr($this->data, $this->offset, 2)) {
251  case '<<':
252  $this->offset += 2;
253  return '<<';
254  break;
255 
256  case '>>':
257  $this->offset += 2;
258  return '>>';
259  break;
260 
261  default:
262  return $this->data[$this->offset++];
263  break;
264  }
265  } else {
267  $compare = '';
268  if( version_compare( phpversion(), '5.2.5' ) >= 0) {
269  $compare = "()<>[]{}/%\x00\t\n\f\r ";
270  } else {
271  $compare = "()<>[]{}/%\x00\t\n\r ";
272  }
273 
274  $this->offset += strcspn($this->data, $compare, $this->offset);
275 
276  return substr($this->data, $start, $this->offset - $start);
277  }
278  }
$start
Definition: listing.phtml:18

◆ setContext()

setContext ( Zend_Pdf_Element_Reference_Context  $context)

Set current context

Parameters
Zend_Pdf_Element_Reference_Context$context

Definition at line 712 of file StringParser.php.

713  {
714  $this->_context = $context;
715  }

◆ skipComment()

skipComment ( )

Skip comment

Definition at line 182 of file StringParser.php.

183  {
184  while ($this->offset < strlen($this->data))
185  {
186  if (ord($this->data[$this->offset]) != 0x0A || // Line feed
187  ord($this->data[$this->offset]) != 0x0d // Carriage return
188  ) {
189  $this->offset++;
190  } else {
191  return;
192  }
193  }
194  }

◆ skipWhiteSpace()

skipWhiteSpace (   $skipComment = true)

Skip white space

Parameters
boolean$skipComment

Original (non-optimized) implementation.

Definition at line 147 of file StringParser.php.

148  {
149  if ($skipComment) {
150  while (true) {
151  $this->offset += strspn($this->data, "\x00\t\n\f\r ", $this->offset);
152 
153  if ($this->offset < strlen($this->data) && $this->data[$this->offset] == '%') {
154  // Skip comment
155  $this->offset += strcspn($this->data, "\r\n", $this->offset);
156  } else {
157  // Non white space character not equal to '%' is found
158  return;
159  }
160  }
161  } else {
162  $this->offset += strspn($this->data, "\x00\t\n\f\r ", $this->offset);
163  }
164 
165 // /** Original (non-optimized) implementation. */
166 //
167 // while ($this->offset < strlen($this->data)) {
168 // if (strpos("\x00\t\n\f\r ", $this->data[$this->offset]) !== false) {
169 // $this->offset++;
170 // } else if (ord($this->data[$this->offset]) == 0x25 && $skipComment) { // '%'
171 // $this->skipComment();
172 // } else {
173 // return;
174 // }
175 // }
176  }

Field Documentation

◆ $data

$data = ''

Definition at line 51 of file StringParser.php.

◆ $offset

$offset = 0

Definition at line 58 of file StringParser.php.


The documentation for this class was generated from the following file: