source-class-Com.Tecnick.Pdf.Font.Font

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * Font.php
  4:  *
  5:  * @since       2011-05-23
  6:  * @category    Library
  7:  * @package     PdfFont
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-pdf-font
 12:  *
 13:  * This file is part of tc-lib-pdf-font software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Pdf\Font;
 17: 
 18: use \Com\Tecnick\Pdf\Font\Exception as FontException;
 19: 
 20: /**
 21:  * Com\Tecnick\Pdf\Font\Font
 22:  *
 23:  * @since       2011-05-23
 24:  * @category    Library
 25:  * @package     PdfFont
 26:  * @author      Nicola Asuni <info@tecnick.com>
 27:  * @copyright   2011-2015 Nicola Asuni - Tecnick.com LTD
 28:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 29:  * @link        https://github.com/tecnickcom/tc-lib-pdf-font
 30:  */
 31: class Font extends \Com\Tecnick\Pdf\Font\Load
 32: {
 33:     /**
 34:      * Font data
 35:      *
 36:      * @var array
 37:      */
 38:     protected $data = array(
 39:         'n'           => 0,              // PDF object number
 40:         'i'           => 0,              // font number
 41:         'key'         => '',             // font key
 42:         'ifile'       => '',             // JSON font file
 43:         'family'      => '',             // font family name
 44:         'unicode'     => true,           // unicode mode
 45:         'pdfa'        => false,          // PDF/A mode
 46:         'style'       => '',             // font style string
 47:         'fakestyle'   => false,          // emulated style
 48:         'mode'        => array(
 49:             'bold'        => false,
 50:             'italic'      => false,
 51:             'underline'   => false,
 52:             'linethrough' => false,
 53:             'overline'    => false
 54:         ),
 55:         'type'        => '',
 56:         'name'        => '',
 57:         'desc'        => array(),
 58:         'up'          => -100,
 59:         'ut'          => 50,
 60:         'cw'          => array(),
 61:         'cbbox'       => array(),
 62:         'dw'          => 0,
 63:         'enc'         => '',
 64:         'cidinfo'     => array(
 65:             'Registry'    => 'Adobe',
 66:             'Ordering'    => 'Identity',
 67:             'Supplement'  => 0,
 68:             'uni2cid'     => array()
 69:         ),
 70:         'file'        => '',             // original font file
 71:         'dir'         => '',             // font directory
 72:         'ctg'         => '',             // font CTG file
 73:         'diff'        => '',             // encoding differences
 74:         'diff_n'      => 0,              // object ID of the difference object
 75:         'subset'      => false,          // True if the font is subset
 76:         'subsetchars' => array(),        // subset characters
 77:     );
 78: 
 79:     /**
 80:      * Load an imported font
 81:      *
 82:      * The definition file (and the font file itself when embedding) must be present either in the current directory
 83:      * or in the one indicated by K_PATH_FONTS if the constant is defined.
 84:      *
 85:      * @param string $font   Font family.
 86:      *                       If it is a standard family name, it will override the corresponding font.
 87:      * @param string $style  Font style.
 88:      *                       Possible values are (case insensitive):
 89:      *                          regular (default)
 90:      *                          B: bold
 91:      *                          I: italic
 92:      *                          U: underline
 93:      *                          D: strikeout (linethrough)
 94:      *                          O: overline
 95:      * @param string $ifile  The font definition file (or empty for autodetect).
 96:      *                       By default, the name is built from the family and style, in lower case with no spaces.
 97:      * @param bool   $subset If true embedd only a subset of the font
 98:      *                       (stores only the information related to the used characters);
 99:      *                       If false embedd full font;
100:      *                       This option is valid only for TrueTypeUnicode fonts and it is disabled for PDF/A.
101:      *                       If you want to enable users to modify the document, set this parameter to false.
102:      *                       If you subset the font, the person who receives your PDF would need to have
103:      *                       your same font in order to make changes to your PDF.
104:      *                       The file size of the PDF would also be smaller because you are embedding only a subset.
105:      * @param bool $unicode  True if we are in Unicode mode, False otherwhise.
106:      * @param bool $pdfa     True if we are in PDF/A mode.
107:      *
108:      * @throws FontException in case of error
109:      */
110:     public function __construct($font, $style = '', $ifile = '', $subset = false, $unicode = true, $pdfa = false)
111:     {
112:         if (empty($font)) {
113:             throw new FontException('empty font family name');
114:         }
115:         $this->data['ifile'] = $ifile;
116:         $this->data['family'] = $font;
117:         $this->data['unicode'] = (bool) $unicode;
118:         $this->data['pdfa'] = (bool) $pdfa;
119:         $this->data['subset'] = $subset;
120:         $this->data['subsetchars'] = array_fill(0, 255, true);
121:         
122:         // generate the font key and set styles
123:         $this->setStyle($style);
124:     }
125: 
126:     /**
127:      * Get the font key
128:      *
129:      * @return string
130:      */
131:     public function getFontkey()
132:     {
133:         return $this->data['key'];
134:     }
135: 
136:     /**
137:      * Get the font data
138:      *
139:      * @return string
140:      */
141:     public function getFontData()
142:     {
143:         return $this->data;
144:     }
145: 
146:     /**
147:      * Set style and normalize the font name
148:      *
149:      * @param string $style Style
150:      */
151:     protected function setStyle($style)
152:     {
153:         $style = strtoupper($style);
154:         if (substr($this->data['family'], -1) == 'I') {
155:             $style .= 'I';
156:             $this->data['family'] = substr($this->data['family'], 0, -1);
157:         }
158:         if (substr($this->data['family'], -1) == 'B') {
159:             $style .= 'B';
160:             $this->data['family'] = substr($this->data['family'], 0, -1);
161:         }
162:         // normalize family name
163:         $this->data['family'] = strtolower($this->data['family']);
164:         if ((!$this->data['unicode']) && ($this->data['family'] == 'arial')) {
165:             $this->data['family'] = 'helvetica';
166:         }
167:         if (($this->data['family'] == 'symbol') || ($this->data['family'] == 'zapfdingbats')) {
168:             $style = '';
169:         }
170:         if ($this->data['pdfa'] && (isset(Core::$font[$this->data['family']]))) {
171:             // core fonts must be embedded in PDF/A
172:             $this->data['family'] = 'pdfa'.$this->data['family'];
173:         }
174:         $this->setStyleMode($style);
175:     }
176: 
177:     /**
178:      * Set style mode properties
179:      *
180:      * @param string $style Style
181:      *
182:      * @return string Style
183:      */
184:     protected function setStyleMode($style)
185:     {
186:         $suffix = '';
187:         if (strpos($style, 'B') !== false) {
188:             $this->data['mode']['bold'] = true;
189:             $suffix .= 'B';
190:         }
191:         if (strpos($style, 'I') !== false) {
192:             $this->data['mode']['italic'] = true;
193:             $suffix .= 'I';
194:         }
195:         $this->data['style'] = $suffix;
196:         if (strpos($style, 'U') !== false) {
197:             $this->data['mode']['underline'] = true;
198:             $this->data['style'] .= 'U';
199:         }
200:         if (strpos($style, 'D') !== false) {
201:             $this->data['mode']['linethrough'] = true;
202:             $this->data['style'] .= 'D';
203:         }
204:         if (strpos($style, 'O') !== false) {
205:             $this->data['mode']['overline'] = true;
206:             $this->data['style'] .= 'O';
207:         }
208:         $this->data['key'] = $this->data['family'].$suffix;
209:     }
210: }
211: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy