Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Extracted.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Pdf/Resource/Font.php';
26 
39 {
43  const TYPE_NOT_SUPPORTED = 'Unsupported font type.';
44  const ENCODING_NOT_SUPPORTED = 'Font encoding is not supported';
45  const OPERATION_NOT_SUPPORTED = 'Operation is not supported for extracted fonts';
46 
54  protected $_encoding = null;
55 
64  public function __construct($fontDictionary)
65  {
66  // Extract object factory and resource object from font dirctionary object
67  $this->_objectFactory = $fontDictionary->getFactory();
68  $this->_resource = $fontDictionary;
69 
70  if ($fontDictionary->Encoding !== null) {
71  $this->_encoding = $fontDictionary->Encoding->value;
72  }
73 
74  switch ($fontDictionary->Subtype->value) {
75  case 'Type0':
76  // Composite type 0 font
77  if (count($fontDictionary->DescendantFonts->items) != 1) {
78  // Multiple descendant fonts are not supported
79  #require_once 'Zend/Pdf/Exception.php';
80  throw new Zend_Pdf_Exception(self::TYPE_NOT_SUPPORTED);
81  }
82 
83  $fontDictionaryIterator = $fontDictionary->DescendantFonts->items->getIterator();
84  $fontDictionaryIterator->rewind();
85  $descendantFont = $fontDictionaryIterator->current();
86  $fontDescriptor = $descendantFont->FontDescriptor;
87  break;
88 
89  case 'Type1':
90  if ($fontDictionary->FontDescriptor === null) {
91  // That's one of the standard fonts
92  $standardFont = Zend_Pdf_Font::fontWithName($fontDictionary->BaseFont->value);
93 
94  $this->_fontNames = $standardFont->getFontNames();
95  $this->_isBold = $standardFont->isBold();
96  $this->_isItalic = $standardFont->isItalic();
97  $this->_isMonospace = $standardFont->isMonospace();
98  $this->_underlinePosition = $standardFont->getUnderlinePosition();
99  $this->_underlineThickness = $standardFont->getUnderlineThickness();
100  $this->_strikePosition = $standardFont->getStrikePosition();
101  $this->_strikeThickness = $standardFont->getStrikeThickness();
102  $this->_unitsPerEm = $standardFont->getUnitsPerEm();
103  $this->_ascent = $standardFont->getAscent();
104  $this->_descent = $standardFont->getDescent();
105  $this->_lineGap = $standardFont->getLineGap();
106 
107  return;
108  }
109 
110  $fontDescriptor = $fontDictionary->FontDescriptor;
111  break;
112 
113  case 'TrueType':
114  $fontDescriptor = $fontDictionary->FontDescriptor;
115  break;
116 
117  default:
118  #require_once 'Zend/Pdf/Exception.php';
119  throw new Zend_Pdf_Exception(self::TYPE_NOT_SUPPORTED);
120  }
121 
122  $this->_fontNames[Zend_Pdf_Font::NAME_POSTSCRIPT]['en'] = iconv('UTF-8', 'UTF-16BE', $fontDictionary->BaseFont->value);
123 
124  $this->_isBold = false; // this property is actually not used anywhere
125  $this->_isItalic = ( ($fontDescriptor->Flags->value & (1 << 6)) != 0 ); // Bit-7 is set
126  $this->_isMonospace = ( ($fontDescriptor->Flags->value & (1 << 0)) != 0 ); // Bit-1 is set
127  $this->_underlinePosition = null; // Can't be extracted
128  $this->_underlineThickness = null; // Can't be extracted
129  $this->_strikePosition = null; // Can't be extracted
130  $this->_strikeThickness = null; // Can't be extracted
131  $this->_unitsPerEm = null; // Can't be extracted
132  $this->_ascent = $fontDescriptor->Ascent->value;
133  $this->_descent = $fontDescriptor->Descent->value;
134  $this->_lineGap = null; // Can't be extracted
135  }
136 
148  public function glyphNumbersForCharacters($characterCodes)
149  {
150  #require_once 'Zend/Pdf/Exception.php';
151  throw new Zend_Pdf_Exception(self::OPERATION_NOT_SUPPORTED);
152  }
153 
166  public function glyphNumberForCharacter($characterCode)
167  {
168  #require_once 'Zend/Pdf/Exception.php';
169  throw new Zend_Pdf_Exception(self::OPERATION_NOT_SUPPORTED);
170  }
171 
190  public function getCoveredPercentage($string, $charEncoding = '')
191  {
192  #require_once 'Zend/Pdf/Exception.php';
193  throw new Zend_Pdf_Exception(self::OPERATION_NOT_SUPPORTED);
194  }
195 
208  public function widthsForGlyphs($glyphNumbers)
209  {
210  #require_once 'Zend/Pdf/Exception.php';
211  throw new Zend_Pdf_Exception(self::OPERATION_NOT_SUPPORTED);
212  }
213 
223  public function widthForGlyph($glyphNumber)
224  {
225  #require_once 'Zend/Pdf/Exception.php';
226  throw new Zend_Pdf_Exception(self::OPERATION_NOT_SUPPORTED);
227  }
228 
238  public function encodeString($string, $charEncoding)
239  {
240  if ($this->_encoding == 'Identity-H') {
241  return iconv($charEncoding, 'UTF-16BE', $string);
242  }
243 
244  if ($this->_encoding == 'WinAnsiEncoding') {
245  return iconv($charEncoding, 'CP1252//IGNORE', $string);
246  }
247 
248  #require_once 'Zend/Pdf/Exception.php';
249  throw new Zend_Pdf_Exception(self::ENCODING_NOT_SUPPORTED);
250  }
251 
261  public function decodeString($string, $charEncoding)
262  {
263  if ($this->_encoding == 'Identity-H') {
264  return iconv('UTF-16BE', $charEncoding, $string);
265  }
266 
267  if ($this->_encoding == 'WinAnsiEncoding') {
268  return iconv('CP1252', $charEncoding, $string);
269  }
270 
271  #require_once 'Zend/Pdf/Exception.php';
272  throw new Zend_Pdf_Exception(self::ENCODING_NOT_SUPPORTED);
273  }
274 }
encodeString($string, $charEncoding)
Definition: Extracted.php:238
getCoveredPercentage($string, $charEncoding='')
Definition: Extracted.php:190
__construct($fontDictionary)
Definition: Extracted.php:64
const NAME_POSTSCRIPT
Definition: Font.php:224
glyphNumbersForCharacters($characterCodes)
Definition: Extracted.php:148
decodeString($string, $charEncoding)
Definition: Extracted.php:261
static fontWithName($name, $embeddingOptions=0)
Definition: Font.php:463
glyphNumberForCharacter($characterCode)
Definition: Extracted.php:166