Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Pdf_Resource_Font_Simple Class Reference
Inheritance diagram for Zend_Pdf_Resource_Font_Simple:
Zend_Pdf_Resource_Font Zend_Pdf_Resource Zend_Pdf_Resource_Font_Simple_Parsed Zend_Pdf_Resource_Font_Simple_Standard Zend_Pdf_Resource_Font_Simple_Parsed_TrueType Zend_Pdf_Resource_Font_Simple_Standard_Courier Zend_Pdf_Resource_Font_Simple_Standard_CourierBold Zend_Pdf_Resource_Font_Simple_Standard_CourierBoldOblique Zend_Pdf_Resource_Font_Simple_Standard_CourierOblique Zend_Pdf_Resource_Font_Simple_Standard_Helvetica Zend_Pdf_Resource_Font_Simple_Standard_HelveticaBold Zend_Pdf_Resource_Font_Simple_Standard_HelveticaBoldOblique Zend_Pdf_Resource_Font_Simple_Standard_HelveticaOblique Zend_Pdf_Resource_Font_Simple_Standard_Symbol Zend_Pdf_Resource_Font_Simple_Standard_TimesBold Zend_Pdf_Resource_Font_Simple_Standard_TimesBoldItalic Zend_Pdf_Resource_Font_Simple_Standard_TimesItalic Zend_Pdf_Resource_Font_Simple_Standard_TimesRoman Zend_Pdf_Resource_Font_Simple_Standard_ZapfDingbats

Public Member Functions

 __construct ()
 
 glyphNumbersForCharacters ($characterCodes)
 
 glyphNumberForCharacter ($characterCode)
 
 getCoveredPercentage ($string, $charEncoding='')
 
 widthsForGlyphs ($glyphNumbers)
 
 widthForGlyph ($glyphNumber)
 
 encodeString ($string, $charEncoding)
 
 decodeString ($string, $charEncoding)
 
- Public Member Functions inherited from Zend_Pdf_Resource_Font
 __construct ()
 
 __toString ()
 
 getFontType ()
 
 getFontName ($nameType, $language, $characterSet=null)
 
 getFontNames ()
 
 isBold ()
 
 isItalic ()
 
 isMonospace ()
 
 getUnderlinePosition ()
 
 getUnderlineThickness ()
 
 getStrikePosition ()
 
 getStrikeThickness ()
 
 getUnitsPerEm ()
 
 getAscent ()
 
 getDescent ()
 
 getLineGap ()
 
 getLineHeight ()
 
 glyphNumbersForCharacters ($characterCodes)
 
 glyphNumberForCharacter ($characterCode)
 
 getCoveredPercentage ($string, $charEncoding='')
 
 widthsForGlyphs ($glyphNumbers)
 
 widthForGlyph ($glyphNumber)
 
 encodeString ($string, $charEncoding)
 
 decodeString ($string, $charEncoding)
 
 toEmSpace ($value)
 
- Public Member Functions inherited from Zend_Pdf_Resource
 __construct ($resource)
 
 __clone ()
 
 cloneResource ($factory, &$processed)
 
 getResource ()
 
 getFactory ()
 

Protected Attributes

 $_cmap = null
 
 $_glyphWidths = null
 
 $_missingGlyphWidth = 0
 
- Protected Attributes inherited from Zend_Pdf_Resource_Font
 $_fontType = Zend_Pdf_Font::TYPE_UNKNOWN
 
 $_fontNames = array()
 
 $_isBold = false
 
 $_isItalic = false
 
 $_isMonospace = false
 
 $_underlinePosition = 0
 
 $_underlineThickness = 0
 
 $_strikePosition = 0
 
 $_strikeThickness = 0
 
 $_unitsPerEm = 0
 
 $_ascent = 0
 
 $_descent = 0
 
 $_lineGap = 0
 
- Protected Attributes inherited from Zend_Pdf_Resource
 $_objectFactory
 
 $_resource
 

Detailed Description

Definition at line 62 of file Simple.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( )

Object constructor

Todo:
It's easy to add other encodings support now (Standard-Encoding, MacRomanEncoding, PDFDocEncoding, MacExpertEncoding, Symbol, and ZapfDingbats). Steps for the implementation:
  • completely describe all PDF single byte encodings in the documentation
  • implement non-WinAnsi encodings processing into encodeString()/decodeString() methods

These encodings will be automatically supported for standard builtin PDF fonts as well as for external fonts.

Definition at line 105 of file Simple.php.

106  {
107  parent::__construct();
108 
120  $this->_resource->Encoding = new Zend_Pdf_Element_Name('WinAnsiEncoding');
121  }

Member Function Documentation

◆ decodeString()

decodeString (   $string,
  $charEncoding 
)

Convert string from the font encoding.

The method is used to convert strings retrieved from existing content streams

Parameters
string$string
string$charEncodingCharacter encoding of resulting text.
Returns
string

Definition at line 279 of file Simple.php.

280  {
281  return iconv('CP1252', $charEncoding, $string);
282  }

◆ encodeString()

encodeString (   $string,
  $charEncoding 
)

Convert string to the font encoding.

The method is used to prepare string for text drawing operators

Parameters
string$string
string$charEncodingCharacter encoding of source text.
Returns
string

Definition at line 261 of file Simple.php.

262  {
263  if (PHP_OS == 'AIX') {
264  return $string; // returning here b/c AIX doesnt know what CP1252 is
265  }
266 
267  return iconv($charEncoding, 'CP1252//IGNORE', $string);
268  }

◆ getCoveredPercentage()

getCoveredPercentage (   $string,
  $charEncoding = '' 
)

Returns a number between 0 and 1 inclusive that indicates the percentage of characters in the string which are covered by glyphs in this font.

Since no one font will contain glyphs for the entire Unicode character range, this method can be used to help locate a suitable font when the actual contents of the string are not known.

Note that some fonts lie about the characters they support. Additionally, fonts don't usually contain glyphs for control characters such as tabs and line breaks, so it is rare that you will get back a full 1.0 score. The resulting value should be considered informational only.

Parameters
string$string
string$charEncoding(optional) Character encoding of source text. If omitted, uses 'current locale'.
Returns
float
Todo:
Properly handle characters encoded as surrogate pairs.

Definition at line 174 of file Simple.php.

175  {
176  /* Convert the string to UTF-16BE encoding so we can match the string's
177  * character codes to those found in the cmap.
178  */
179  if ($charEncoding != 'UTF-16BE') {
180  if (PHP_OS != 'AIX') { // AIX doesnt know what UTF-16BE is
181  $string = iconv($charEncoding, 'UTF-16BE', $string);
182  }
183  }
184 
185  $charCount = (PHP_OS != 'AIX') ? iconv_strlen($string, 'UTF-16BE') : strlen($string);
186  if ($charCount == 0) {
187  return 0;
188  }
189 
190  /* Fetch the covered character code list from the font's cmap.
191  */
192  $coveredCharacters = $this->_cmap->getCoveredCharacters();
193 
194  /* Calculate the score by doing a lookup for each character.
195  */
196  $score = 0;
197  $maxIndex = strlen($string);
198  for ($i = 0; $i < $maxIndex; $i++) {
202  $charCode = (ord($string[$i]) << 8) | ord($string[++$i]);
203  /* This could probably be optimized a bit with a binary search...
204  */
205  if (in_array($charCode, $coveredCharacters)) {
206  $score++;
207  }
208  }
209  return $score / $charCount;
210  }
$i
Definition: gallery.phtml:31

◆ glyphNumberForCharacter()

glyphNumberForCharacter (   $characterCode)

Returns the glyph number corresponding to the Unicode character.

If a particular character doesn't exist in this font, the special 'missing character glyph' will be substituted.

See also glyphNumbersForCharacters() which is optimized for bulk operations.

Parameters
integer$characterCodeUnicode character code (code point).
Returns
integer Glyph number.

Definition at line 151 of file Simple.php.

152  {
153  return $this->_cmap->glyphNumberForCharacter($characterCode);
154  }

◆ glyphNumbersForCharacters()

glyphNumbersForCharacters (   $characterCodes)

Returns an array of glyph numbers corresponding to the Unicode characters.

If a particular character doesn't exist in this font, the special 'missing character glyph' will be substituted.

See also glyphNumberForCharacter().

Parameters
array$characterCodesArray of Unicode character codes (code points).
Returns
array Array of glyph numbers.

Definition at line 134 of file Simple.php.

135  {
136  return $this->_cmap->glyphNumbersForCharacters($characterCodes);
137  }

◆ widthForGlyph()

widthForGlyph (   $glyphNumber)

Returns the width of the glyph.

Like widthsForGlyphs() but used for one glyph at a time.

Parameters
integer$glyphNumber
Returns
integer

Definition at line 244 of file Simple.php.

245  {
246  if (!isset($this->_glyphWidths[$glyphNumber])) {
248  }
249  return $this->_glyphWidths[$glyphNumber];
250  }

◆ widthsForGlyphs()

widthsForGlyphs (   $glyphNumbers)

Returns the widths of the glyphs.

The widths are expressed in the font's glyph space. You are responsible for converting to user space as necessary. See unitsPerEm().

See also widthForGlyph().

Parameters
array&$glyphNumbersArray of glyph numbers.
Returns
array Array of glyph widths (integers).

Definition at line 223 of file Simple.php.

224  {
225  $widths = array();
226  foreach ($glyphNumbers as $key => $glyphNumber) {
227  if (!isset($this->_glyphWidths[$glyphNumber])) {
228  $widths[$key] = $this->_missingGlyphWidth;
229  } else {
230  $widths[$key] = $this->_glyphWidths[$glyphNumber];
231  }
232  }
233  return $widths;
234  }

Field Documentation

◆ $_cmap

$_cmap = null
protected

Definition at line 68 of file Simple.php.

◆ $_glyphWidths

$_glyphWidths = null
protected

Definition at line 80 of file Simple.php.

◆ $_missingGlyphWidth

$_missingGlyphWidth = 0
protected

Definition at line 93 of file Simple.php.


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