Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TrimmedTable.php
Go to the documentation of this file.
1 <?php
24 #require_once 'Zend/Pdf/Cmap.php';
25 
26 
40 {
41  /**** Instance Variables ****/
42 
43 
48  protected $_startCode = 0;
49 
54  protected $_endCode = 0;
55 
60  protected $_glyphIndexArray = array();
61 
62 
63 
64  /**** Public Interface ****/
65 
66 
67  /* Concrete Class Implementation */
68 
80  public function glyphNumbersForCharacters($characterCodes)
81  {
82  $glyphNumbers = array();
83  foreach ($characterCodes as $key => $characterCode) {
84 
85  if (($characterCode < $this->_startCode) || ($characterCode > $this->_endCode)) {
86  $glyphNumbers[$key] = Zend_Pdf_Cmap::MISSING_CHARACTER_GLYPH;
87  continue;
88  }
89 
90  $glyphIndex = $characterCode - $this->_startCode;
91  $glyphNumbers[$key] = $this->_glyphIndexArray[$glyphIndex];
92 
93  }
94  return $glyphNumbers;
95  }
96 
109  public function glyphNumberForCharacter($characterCode)
110  {
111  if (($characterCode < $this->_startCode) || ($characterCode > $this->_endCode)) {
113  }
114  $glyphIndex = $characterCode - $this->_startCode;
115  return $this->_glyphIndexArray[$glyphIndex];
116  }
117 
124  public function getCoveredCharacters()
125  {
126  $characterCodes = array();
127  for ($code = $this->_startCode; $code <= $this->_endCode; $code++) {
128  $characterCodes[] = $code;
129  }
130  return $characterCodes;
131  }
132 
133 
145  public function getCoveredCharactersGlyphs()
146  {
147  $glyphNumbers = array();
148  for ($code = $this->_startCode; $code <= $this->_endCode; $code++) {
149  $glyphNumbers[$code] = $this->_glyphIndexArray[$code - $this->_startCode];
150  }
151 
152  return $glyphNumbers;
153  }
154 
155 
156  /* Object Lifecycle */
157 
167  public function __construct($cmapData)
168  {
169  /* Sanity check: The table should be at least 9 bytes in size.
170  */
171  $actualLength = strlen($cmapData);
172  if ($actualLength < 9) {
173  #require_once 'Zend/Pdf/Exception.php';
174  throw new Zend_Pdf_Exception('Insufficient table data',
176  }
177 
178  /* Sanity check: Make sure this is right data for this table type.
179  */
180  $type = $this->_extractUInt2($cmapData, 0);
182  #require_once 'Zend/Pdf/Exception.php';
183  throw new Zend_Pdf_Exception('Wrong cmap table type',
185  }
186 
187  $length = $this->_extractUInt2($cmapData, 2);
188  if ($length != $actualLength) {
189  #require_once 'Zend/Pdf/Exception.php';
190  throw new Zend_Pdf_Exception("Table length ($length) does not match actual length ($actualLength)",
192  }
193 
194  /* Mapping tables should be language-independent. The font may not work
195  * as expected if they are not. Unfortunately, many font files in the
196  * wild incorrectly record a language ID in this field, so we can't
197  * call this a failure.
198  */
199  $language = $this->_extractUInt2($cmapData, 4);
200  if ($language != 0) {
201  // Record a warning here somehow?
202  }
203 
204  $this->_startCode = $this->_extractUInt2($cmapData, 6);
205 
206  $entryCount = $this->_extractUInt2($cmapData, 8);
207  $expectedCount = ($length - 10) >> 1;
208  if ($entryCount != $expectedCount) {
209  #require_once 'Zend/Pdf/Exception.php';
210  throw new Zend_Pdf_Exception("Entry count is wrong; expected: $expectedCount; actual: $entryCount",
212  }
213 
214  $this->_endCode = $this->_startCode + $entryCount - 1;
215 
216  $offset = 10;
217  for ($i = 0; $i < $entryCount; $i++, $offset += 2) {
218  $this->_glyphIndexArray[] = $this->_extractUInt2($cmapData, $offset);
219  }
220 
221  /* Sanity check: After reading all of the data, we should be at the end
222  * of the table.
223  */
224  if ($offset != $length) {
225  #require_once 'Zend/Pdf/Exception.php';
226  throw new Zend_Pdf_Exception("Ending offset ($offset) does not match length ($length)",
228  }
229  }
230 
231 }
glyphNumberForCharacter($characterCode)
const CMAP_WRONG_TABLE_LENGTH
Definition: Exception.php:275
const CMAP_FINAL_OFFSET_NOT_LENGTH
Definition: Exception.php:287
const CMAP_WRONG_ENTRY_COUNT
Definition: Exception.php:292
const CMAP_TABLE_DATA_TOO_SMALL
Definition: Exception.php:265
const TYPE_TRIMMED_TABLE
Definition: Cmap.php:78
$type
Definition: item.phtml:13
glyphNumbersForCharacters($characterCodes)
const CMAP_WRONG_TABLE_TYPE
Definition: Exception.php:270
const MISSING_CHARACTER_GLYPH
Definition: Cmap.php:112
_extractUInt2(&$data, $index)
Definition: Cmap.php:297
$i
Definition: gallery.phtml:31
$code
Definition: info.phtml:12