Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Pdf_FileParser Class Reference
Inheritance diagram for Zend_Pdf_FileParser:
Zend_Pdf_FileParser_Font Zend_Pdf_FileParser_Image Zend_Pdf_FileParser_Font_OpenType Zend_Pdf_FileParser_Image_Png Zend_Pdf_FileParser_Font_OpenType_TrueType

Public Member Functions

 screen ()
 
 parse ()
 
 __construct (Zend_Pdf_FileParserDataSource $dataSource)
 
 __destruct ()
 
 isScreened ()
 
 isParsed ()
 
 getDataSource ()
 
 moveToOffset ($offset)
 
 getOffset ()
 
 getSize ()
 
 readBytes ($byteCount)
 
 skipBytes ($byteCount)
 
 readInt ($size, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
 
 readUInt ($size, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
 
 isBitSet ($bit, $bitField)
 
 readFixed ($mantissaBits, $fractionBits, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
 
 readStringUTF16 ($byteCount, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN, $characterSet='')
 
 readStringMacRoman ($byteCount, $characterSet='')
 
 readStringPascal ($characterSet='', $lengthBytes=1)
 

Data Fields

const BYTE_ORDER_LITTLE_ENDIAN = 0
 
const BYTE_ORDER_BIG_ENDIAN = 1
 

Protected Attributes

 $_isScreened = false
 
 $_isParsed = false
 
 $_dataSource = null
 

Detailed Description

Definition at line 39 of file FileParser.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( Zend_Pdf_FileParserDataSource  $dataSource)

Object constructor.

Verifies that the data source has been properly initialized.

Parameters
Zend_Pdf_FileParserDataSource$dataSource
Exceptions
Zend_Pdf_Exception

Definition at line 113 of file FileParser.php.

114  {
115  if ($dataSource->getSize() == 0) {
116  #require_once 'Zend/Pdf/Exception.php';
117  throw new Zend_Pdf_Exception('The data source has not been properly initialized',
119  }
120  $this->_dataSource = $dataSource;
121  }

◆ __destruct()

__destruct ( )

Object destructor.

Discards the data source object.

Definition at line 128 of file FileParser.php.

129  {
130  $this->_dataSource = null;
131  }

Member Function Documentation

◆ getDataSource()

getDataSource ( )

Returns the data source object representing the file being parsed.

Returns
Zend_Pdf_FileParserDataSource

Definition at line 161 of file FileParser.php.

162  {
163  return $this->_dataSource;
164  }

◆ getOffset()

getOffset ( )

Definition at line 180 of file FileParser.php.

180  {
181  return $this->_dataSource->getOffset();
182  }

◆ getSize()

getSize ( )

Definition at line 184 of file FileParser.php.

184  {
185  return $this->_dataSource->getSize();
186  }

◆ isBitSet()

isBitSet (   $bit,
  $bitField 
)

Returns true if the specified bit is set in the integer bitfield.

Parameters
integer$bitBit number to test (i.e. - 0-31)
integer$bitField
Returns
boolean

Definition at line 339 of file FileParser.php.

340  {
341  $bitMask = 1 << $bit;
342  $isSet = (($bitField & $bitMask) == $bitMask);
343  return $isSet;
344  }

◆ isParsed()

isParsed ( )

Returns true if the file has been successfully parsed.

Returns
boolean

Definition at line 151 of file FileParser.php.

152  {
153  return $this->_isParsed;
154  }

◆ isScreened()

isScreened ( )

Returns true if the file has passed a cursory validation check.

Returns
boolean

Definition at line 141 of file FileParser.php.

142  {
143  return $this->_isScreened;
144  }

◆ moveToOffset()

moveToOffset (   $offset)

Convenience wrapper for the data source object's moveToOffset() method.

Parameters
integer$offsetDestination byte offset.
Exceptions
Zend_Pdf_Exception

Definition at line 175 of file FileParser.php.

176  {
177  $this->_dataSource->moveToOffset($offset);
178  }

◆ parse()

parse ( )
abstract

Reads and parses the complete binary file.

Must set $this->_isParsed to true if successful.

Exceptions
Zend_Pdf_Exception

◆ readBytes()

readBytes (   $byteCount)

Convenience wrapper for the data source object's readBytes() method.

Parameters
integer$byteCountNumber of bytes to read.
Returns
string
Exceptions
Zend_Pdf_Exception

Definition at line 195 of file FileParser.php.

196  {
197  return $this->_dataSource->readBytes($byteCount);
198  }

◆ readFixed()

readFixed (   $mantissaBits,
  $fractionBits,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN 
)

Reads the signed fixed-point number from the binary file at the current byte offset.

Common fixed-point sizes are 2.14 and 16.16.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters
integer$mantissaBitsNumber of bits in the mantissa
integer$fractionBitsNumber of bits in the fraction
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
Returns
float
Exceptions
Zend_Pdf_Exception

Definition at line 363 of file FileParser.php.

365  {
366  $bitsToRead = $mantissaBits + $fractionBits;
367  if (($bitsToRead % 8) !== 0) {
368  #require_once 'Zend/Pdf/Exception.php';
369  throw new Zend_Pdf_Exception('Fixed-point numbers are whole bytes',
371  }
372  $number = $this->readInt(($bitsToRead >> 3), $byteOrder) / (1 << $fractionBits);
373  return $number;
374  }
readInt($size, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
Definition: FileParser.php:228
$number
Definition: details.phtml:22
const BAD_FIXED_POINT_SIZE
Definition: Exception.php:201

◆ readInt()

readInt (   $size,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN 
)

Reads the signed integer value from the binary file at the current byte offset.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters
integer$sizeSize of integer in bytes: 1-4
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
Returns
integer
Exceptions
Zend_Pdf_Exception

Definition at line 228 of file FileParser.php.

229  {
230  if (($size < 1) || ($size > 4)) {
231  #require_once 'Zend/Pdf/Exception.php';
232  throw new Zend_Pdf_Exception("Invalid signed integer size: $size",
234  }
235  $bytes = $this->_dataSource->readBytes($size);
236  /* unpack() will not work for this method because it always works in
237  * the host byte order for signed integers. It also does not allow for
238  * variable integer sizes.
239  */
240  if ($byteOrder == Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) {
241  $number = ord($bytes[0]);
242  if (($number & 0x80) == 0x80) {
243  /* This number is negative. Extract the positive equivalent.
244  */
245  $number = (~ $number) & 0xff;
246  for ($i = 1; $i < $size; $i++) {
247  $number = ($number << 8) | ((~ ord($bytes[$i])) & 0xff);
248  }
249  /* Now turn this back into a negative number by taking the
250  * two's complement (we didn't add one above so won't
251  * subtract it below). This works reliably on both 32- and
252  * 64-bit systems.
253  */
254  $number = ~$number;
255  } else {
256  for ($i = 1; $i < $size; $i++) {
257  $number = ($number << 8) | ord($bytes[$i]);
258  }
259  }
260  } else if ($byteOrder == Zend_Pdf_FileParser::BYTE_ORDER_LITTLE_ENDIAN) {
261  $number = ord($bytes[$size - 1]);
262  if (($number & 0x80) == 0x80) {
263  /* Negative number. See discussion above.
264  */
265  $number = 0;
266  for ($i = --$size; $i >= 0; $i--) {
267  $number |= ((~ ord($bytes[$i])) & 0xff) << ($i * 8);
268  }
269  $number = ~$number;
270  } else {
271  $number = 0;
272  for ($i = --$size; $i >= 0; $i--) {
273  $number |= ord($bytes[$i]) << ($i * 8);
274  }
275  }
276  } else {
277  #require_once 'Zend/Pdf/Exception.php';
278  throw new Zend_Pdf_Exception("Invalid byte order: $byteOrder",
280  }
281  return $number;
282  }
$number
Definition: details.phtml:22
const INVALID_INTEGER_SIZE
Definition: Exception.php:196
const BYTE_ORDER_BIG_ENDIAN
Definition: FileParser.php:51
const INVALID_BYTE_ORDER
Definition: Exception.php:191
const BYTE_ORDER_LITTLE_ENDIAN
Definition: FileParser.php:46
$i
Definition: gallery.phtml:31

◆ readStringMacRoman()

readStringMacRoman (   $byteCount,
  $characterSet = '' 
)

Reads the Mac Roman-encoded string from the binary file at the current byte offset.

You must supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters
integer$byteCountNumber of bytes (characters) to return.
string$characterSet(optional) Desired resulting character set. You may use any character set supported by iconv(). If omitted, uses 'current locale'.
Returns
string
Exceptions
Zend_Pdf_Exception

Definition at line 442 of file FileParser.php.

443  {
444  if ($byteCount == 0) {
445  return '';
446  }
447  $bytes = $this->_dataSource->readBytes($byteCount);
448  if ($characterSet == 'MacRoman') {
449  return $bytes;
450  }
451  return iconv('MacRoman', $characterSet, $bytes);
452  }

◆ readStringPascal()

readStringPascal (   $characterSet = '',
  $lengthBytes = 1 
)

Reads the Pascal string from the binary file at the current byte offset.

The length of the Pascal string is determined by reading the length bytes which preceed the character data. You must supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Parameters
string$characterSet(optional) Desired resulting character set. You may use any character set supported by iconv(). If omitted, uses 'current locale'.
integer$lengthBytes(optional) Number of bytes that make up the length. Default is 1.
Returns
string
Exceptions
Zend_Pdf_Exception

Definition at line 472 of file FileParser.php.

473  {
474  $byteCount = $this->readUInt($lengthBytes);
475  if ($byteCount == 0) {
476  return '';
477  }
478  $bytes = $this->_dataSource->readBytes($byteCount);
479  if ($characterSet == 'ASCII') {
480  return $bytes;
481  }
482  return iconv('ASCII', $characterSet, $bytes);
483  }
readUInt($size, $byteOrder=Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN)
Definition: FileParser.php:303

◆ readStringUTF16()

readStringUTF16 (   $byteCount,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN,
  $characterSet = '' 
)

Reads the Unicode UTF-16-encoded string from the binary file at the current byte offset.

The byte order of the UTF-16 string must be specified. You must also supply the desired resulting character set.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

Todo:

Consider changing $byteCount to a character count. They are not always equivalent (in the case of surrogates).

Make $byteOrder optional if there is a byte-order mark (BOM) in the string being extracted.

Parameters
integer$byteCountNumber of bytes (characters * 2) to return.
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
string$characterSet(optional) Desired resulting character set. You may use any character set supported by iconv(). If omitted, uses 'current locale'.
Returns
string
Exceptions
Zend_Pdf_Exception

Definition at line 401 of file FileParser.php.

404  {
405  if ($byteCount == 0) {
406  return '';
407  }
408  $bytes = $this->_dataSource->readBytes($byteCount);
409  if ($byteOrder == Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) {
410  if ($characterSet == 'UTF-16BE') {
411  return $bytes;
412  }
413  return iconv('UTF-16BE', $characterSet, $bytes);
414  } else if ($byteOrder == Zend_Pdf_FileParser::BYTE_ORDER_LITTLE_ENDIAN) {
415  if ($characterSet == 'UTF-16LE') {
416  return $bytes;
417  }
418  return iconv('UTF-16LE', $characterSet, $bytes);
419  } else {
420  #require_once 'Zend/Pdf/Exception.php';
421  throw new Zend_Pdf_Exception("Invalid byte order: $byteOrder",
423  }
424  }
const BYTE_ORDER_BIG_ENDIAN
Definition: FileParser.php:51
const INVALID_BYTE_ORDER
Definition: Exception.php:191
const BYTE_ORDER_LITTLE_ENDIAN
Definition: FileParser.php:46

◆ readUInt()

readUInt (   $size,
  $byteOrder = Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN 
)

Reads the unsigned integer value from the binary file at the current byte offset.

Advances the offset by the number of bytes read. Throws an exception if an error occurs.

NOTE: If you ask for a 4-byte unsigned integer on a 32-bit machine, the resulting value WILL BE SIGNED because PHP uses signed integers internally for everything. To guarantee portability, be sure to use bitwise operators operators on large unsigned integers!

Parameters
integer$sizeSize of integer in bytes: 1-4
integer$byteOrder(optional) Big- or little-endian byte order. Use the BYTE_ORDER_ constants defined in Zend_Pdf_FileParser. If omitted, uses big-endian.
Returns
integer
Exceptions
Zend_Pdf_Exception

Definition at line 303 of file FileParser.php.

304  {
305  if (($size < 1) || ($size > 4)) {
306  #require_once 'Zend/Pdf/Exception.php';
307  throw new Zend_Pdf_Exception("Invalid unsigned integer size: $size",
309  }
310  $bytes = $this->_dataSource->readBytes($size);
311  /* unpack() is a bit heavyweight for this simple conversion. Just
312  * work the bytes directly.
313  */
314  if ($byteOrder == Zend_Pdf_FileParser::BYTE_ORDER_BIG_ENDIAN) {
315  $number = ord($bytes[0]);
316  for ($i = 1; $i < $size; $i++) {
317  $number = ($number << 8) | ord($bytes[$i]);
318  }
319  } else if ($byteOrder == Zend_Pdf_FileParser::BYTE_ORDER_LITTLE_ENDIAN) {
320  $number = 0;
321  for ($i = --$size; $i >= 0; $i--) {
322  $number |= ord($bytes[$i]) << ($i * 8);
323  }
324  } else {
325  #require_once 'Zend/Pdf/Exception.php';
326  throw new Zend_Pdf_Exception("Invalid byte order: $byteOrder",
328  }
329  return $number;
330  }
$number
Definition: details.phtml:22
const INVALID_INTEGER_SIZE
Definition: Exception.php:196
const BYTE_ORDER_BIG_ENDIAN
Definition: FileParser.php:51
const INVALID_BYTE_ORDER
Definition: Exception.php:191
const BYTE_ORDER_LITTLE_ENDIAN
Definition: FileParser.php:46
$i
Definition: gallery.phtml:31

◆ screen()

screen ( )
abstract

Performs a cursory check to verify that the binary file is in the expected format. Intended to quickly weed out obviously bogus files.

Must set $this->_isScreened to true if successful.

Exceptions
Zend_Pdf_Exception

◆ skipBytes()

skipBytes (   $byteCount)

Convenience wrapper for the data source object's skipBytes() method.

Parameters
integer$byteCountNumber of bytes to skip.
Exceptions
Zend_Pdf_Exception

Definition at line 206 of file FileParser.php.

207  {
208  $this->_dataSource->skipBytes($byteCount);
209  }

Field Documentation

◆ $_dataSource

$_dataSource = null
protected

Definition at line 74 of file FileParser.php.

◆ $_isParsed

$_isParsed = false
protected

Definition at line 68 of file FileParser.php.

◆ $_isScreened

$_isScreened = false
protected

Definition at line 62 of file FileParser.php.

◆ BYTE_ORDER_BIG_ENDIAN

const BYTE_ORDER_BIG_ENDIAN = 1

Big-endian byte order (0x01 0x02 0x03 0x04).

Definition at line 51 of file FileParser.php.

◆ BYTE_ORDER_LITTLE_ENDIAN

const BYTE_ORDER_LITTLE_ENDIAN = 0

Little-endian byte order (0x04 0x03 0x02 0x01).

Definition at line 46 of file FileParser.php.


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