PageRenderTime 65ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/libs/devblocks/libs/ZendFramework/Zend/Pdf/Font.php

https://github.com/sluther/portsensor
PHP | 743 lines | 196 code | 152 blank | 395 comment | 11 complexity | 49f79fee43dc428a1d1a833ca64b3b2a MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @package Zend_Pdf
  16. * @subpackage Fonts
  17. * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /** Zend_Pdf_FileParserDataSource */
  21. require_once 'Zend/Pdf/FileParserDataSource.php';
  22. /** Zend_Pdf_FileParserDataSource_File */
  23. require_once 'Zend/Pdf/FileParserDataSource/File.php';
  24. /** Zend_Pdf_FileParserDataSource_String */
  25. require_once 'Zend/Pdf/FileParserDataSource/String.php';
  26. /** Zend_Pdf_FileParser_Font_OpenType_TrueType */
  27. require_once 'Zend/Pdf/FileParser/Font/OpenType/TrueType.php';
  28. /** Zend_Pdf_Resource_Font_OpenType_TrueType */
  29. require_once 'Zend/Pdf/Resource/Font/OpenType/TrueType.php';
  30. /** Zend_Pdf_Resource_Font_Standard_Courier */
  31. require_once 'Zend/Pdf/Resource/Font/Standard/Courier.php';
  32. /** Zend_Pdf_Resource_Font_Standard_CourierBold */
  33. require_once 'Zend/Pdf/Resource/Font/Standard/CourierBold.php';
  34. /** Zend_Pdf_Resource_Font_Standard_CourierBoldOblique */
  35. require_once 'Zend/Pdf/Resource/Font/Standard/CourierBoldOblique.php';
  36. /** Zend_Pdf_Resource_Font_Standard_CourierOblique */
  37. require_once 'Zend/Pdf/Resource/Font/Standard/CourierOblique.php';
  38. /** Zend_Pdf_Resource_Font_Standard_Helvetica */
  39. require_once 'Zend/Pdf/Resource/Font/Standard/Helvetica.php';
  40. /** Zend_Pdf_Resource_Font_Standard_HelveticaBold */
  41. require_once 'Zend/Pdf/Resource/Font/Standard/HelveticaBold.php';
  42. /** Zend_Pdf_Resource_Font_Standard_HelveticaBoldOblique */
  43. require_once 'Zend/Pdf/Resource/Font/Standard/HelveticaBoldOblique.php';
  44. /** Zend_Pdf_Resource_Font_Standard_HelveticaOblique */
  45. require_once 'Zend/Pdf/Resource/Font/Standard/HelveticaOblique.php';
  46. /** Zend_Pdf_Resource_Font_Standard_Symbol */
  47. require_once 'Zend/Pdf/Resource/Font/Standard/Symbol.php';
  48. /** Zend_Pdf_Resource_Font_Standard_TimesBold */
  49. require_once 'Zend/Pdf/Resource/Font/Standard/TimesBold.php';
  50. /** Zend_Pdf_Resource_Font_Standard_TimesBoldItalic */
  51. require_once 'Zend/Pdf/Resource/Font/Standard/TimesBoldItalic.php';
  52. /** Zend_Pdf_Resource_Font_Standard_TimesItalic */
  53. require_once 'Zend/Pdf/Resource/Font/Standard/TimesItalic.php';
  54. /** Zend_Pdf_Resource_Font_Standard_TimesRoman */
  55. require_once 'Zend/Pdf/Resource/Font/Standard/TimesRoman.php';
  56. /** Zend_Pdf_Resource_Font_Standard_ZapfDingbats */
  57. require_once 'Zend/Pdf/Resource/Font/Standard/ZapfDingbats.php';
  58. /**
  59. * Abstract factory class which vends {@link Zend_Pdf_Resource_Font} objects.
  60. *
  61. * Font objects themselves are normally instantiated through the factory methods
  62. * {@link fontWithName()} or {@link fontWithPath()}.
  63. *
  64. * This class is also the home for font-related constants because the name of
  65. * the true base class ({@link Zend_Pdf_Resource_Font}) is not intuitive for the
  66. * end user.
  67. *
  68. * @package Zend_Pdf
  69. * @subpackage Fonts
  70. * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
  71. * @license http://framework.zend.com/license/new-bsd New BSD License
  72. */
  73. abstract class Zend_Pdf_Font
  74. {
  75. /**** Class Constants ****/
  76. /* Font Types */
  77. /**
  78. * Unknown font type.
  79. */
  80. const TYPE_UNKNOWN = 0;
  81. /**
  82. * One of the standard 14 PDF fonts.
  83. */
  84. const TYPE_STANDARD = 1;
  85. /**
  86. * A PostScript Type 1 font.
  87. */
  88. const TYPE_TYPE_1 = 2;
  89. /**
  90. * A TrueType font or an OpenType font containing TrueType outlines.
  91. */
  92. const TYPE_TRUETYPE = 3;
  93. /* Names of the Standard 14 PDF Fonts */
  94. /**
  95. * Name of the standard PDF font Courier.
  96. */
  97. const FONT_COURIER = 'Courier';
  98. /**
  99. * Name of the bold style of the standard PDF font Courier.
  100. */
  101. const FONT_COURIER_BOLD = 'Courier-Bold';
  102. /**
  103. * Name of the italic style of the standard PDF font Courier.
  104. */
  105. const FONT_COURIER_OBLIQUE = 'Courier-Oblique';
  106. /**
  107. * Convenience constant for a common misspelling of
  108. * {@link FONT_COURIER_OBLIQUE}.
  109. */
  110. const FONT_COURIER_ITALIC = 'Courier-Oblique';
  111. /**
  112. * Name of the bold and italic style of the standard PDF font Courier.
  113. */
  114. const FONT_COURIER_BOLD_OBLIQUE = 'Courier-BoldOblique';
  115. /**
  116. * Convenience constant for a common misspelling of
  117. * {@link FONT_COURIER_BOLD_OBLIQUE}.
  118. */
  119. const FONT_COURIER_BOLD_ITALIC = 'Courier-BoldOblique';
  120. /**
  121. * Name of the standard PDF font Helvetica.
  122. */
  123. const FONT_HELVETICA = 'Helvetica';
  124. /**
  125. * Name of the bold style of the standard PDF font Helvetica.
  126. */
  127. const FONT_HELVETICA_BOLD = 'Helvetica-Bold';
  128. /**
  129. * Name of the italic style of the standard PDF font Helvetica.
  130. */
  131. const FONT_HELVETICA_OBLIQUE = 'Helvetica-Oblique';
  132. /**
  133. * Convenience constant for a common misspelling of
  134. * {@link FONT_HELVETICA_OBLIQUE}.
  135. */
  136. const FONT_HELVETICA_ITALIC = 'Helvetica-Oblique';
  137. /**
  138. * Name of the bold and italic style of the standard PDF font Helvetica.
  139. */
  140. const FONT_HELVETICA_BOLD_OBLIQUE = 'Helvetica-BoldOblique';
  141. /**
  142. * Convenience constant for a common misspelling of
  143. * {@link FONT_HELVETICA_BOLD_OBLIQUE}.
  144. */
  145. const FONT_HELVETICA_BOLD_ITALIC = 'Helvetica-BoldOblique';
  146. /**
  147. * Name of the standard PDF font Symbol.
  148. */
  149. const FONT_SYMBOL = 'Symbol';
  150. /**
  151. * Name of the standard PDF font Times.
  152. */
  153. const FONT_TIMES_ROMAN = 'Times-Roman';
  154. /**
  155. * Convenience constant for a common misspelling of
  156. * {@link FONT_TIMES_ROMAN}.
  157. */
  158. const FONT_TIMES = 'Times-Roman';
  159. /**
  160. * Name of the bold style of the standard PDF font Times.
  161. */
  162. const FONT_TIMES_BOLD = 'Times-Bold';
  163. /**
  164. * Name of the italic style of the standard PDF font Times.
  165. */
  166. const FONT_TIMES_ITALIC = 'Times-Italic';
  167. /**
  168. * Name of the bold and italic style of the standard PDF font Times.
  169. */
  170. const FONT_TIMES_BOLD_ITALIC = 'Times-BoldItalic';
  171. /**
  172. * Name of the standard PDF font Zapf Dingbats.
  173. */
  174. const FONT_ZAPFDINGBATS = 'ZapfDingbats';
  175. /* Font Name String Types */
  176. /**
  177. * Full copyright notice for the font.
  178. */
  179. const NAME_COPYRIGHT = 0;
  180. /**
  181. * Font family name. Used to group similar styles of fonts together.
  182. */
  183. const NAME_FAMILY = 1;
  184. /**
  185. * Font style within the font family. Examples: Regular, Italic, Bold, etc.
  186. */
  187. const NAME_STYLE = 2;
  188. /**
  189. * Unique font identifier.
  190. */
  191. const NAME_ID = 3;
  192. /**
  193. * Full font name. Usually a combination of the {@link NAME_FAMILY} and
  194. * {@link NAME_STYLE} strings.
  195. */
  196. const NAME_FULL = 4;
  197. /**
  198. * Version number of the font.
  199. */
  200. const NAME_VERSION = 5;
  201. /**
  202. * PostScript name for the font. This is the name used to identify fonts
  203. * internally and within the PDF file.
  204. */
  205. const NAME_POSTSCRIPT = 6;
  206. /**
  207. * Font trademark notice. This is distinct from the {@link NAME_COPYRIGHT}.
  208. */
  209. const NAME_TRADEMARK = 7;
  210. /**
  211. * Name of the font manufacturer.
  212. */
  213. const NAME_MANUFACTURER = 8;
  214. /**
  215. * Name of the designer of the font.
  216. */
  217. const NAME_DESIGNER = 9;
  218. /**
  219. * Description of the font. May contain revision information, usage
  220. * recommendations, features, etc.
  221. */
  222. const NAME_DESCRIPTION = 10;
  223. /**
  224. * URL of the font vendor. Some fonts may contain a unique serial number
  225. * embedded in this URL, which is used for licensing.
  226. */
  227. const NAME_VENDOR_URL = 11;
  228. /**
  229. * URL of the font designer ({@link NAME_DESIGNER}).
  230. */
  231. const NAME_DESIGNER_URL = 12;
  232. /**
  233. * Plain language licensing terms for the font.
  234. */
  235. const NAME_LICENSE = 13;
  236. /**
  237. * URL of more detailed licensing information for the font.
  238. */
  239. const NAME_LICENSE_URL = 14;
  240. /**
  241. * Preferred font family. Used by some fonts to work around a Microsoft
  242. * Windows limitation where only four fonts styles can share the same
  243. * {@link NAME_FAMILY} value.
  244. */
  245. const NAME_PREFERRED_FAMILY = 16;
  246. /**
  247. * Preferred font style. A more descriptive string than {@link NAME_STYLE}.
  248. */
  249. const NAME_PREFERRED_STYLE = 17;
  250. /**
  251. * Suggested text to use as a representative sample of the font.
  252. */
  253. const NAME_SAMPLE_TEXT = 19;
  254. /**
  255. * PostScript CID findfont name.
  256. */
  257. const NAME_CID_NAME = 20;
  258. /* Font Weights */
  259. /**
  260. * Thin font weight.
  261. */
  262. const WEIGHT_THIN = 100;
  263. /**
  264. * Extra-light (Ultra-light) font weight.
  265. */
  266. const WEIGHT_EXTRA_LIGHT = 200;
  267. /**
  268. * Light font weight.
  269. */
  270. const WEIGHT_LIGHT = 300;
  271. /**
  272. * Normal (Regular) font weight.
  273. */
  274. const WEIGHT_NORMAL = 400;
  275. /**
  276. * Medium font weight.
  277. */
  278. const WEIGHT_MEDIUM = 500;
  279. /**
  280. * Semi-bold (Demi-bold) font weight.
  281. */
  282. const WEIGHT_SEMI_BOLD = 600;
  283. /**
  284. * Bold font weight.
  285. */
  286. const WEIGHT_BOLD = 700;
  287. /**
  288. * Extra-bold (Ultra-bold) font weight.
  289. */
  290. const WEIGHT_EXTRA_BOLD = 800;
  291. /**
  292. * Black (Heavy) font weight.
  293. */
  294. const WEIGHT_BLACK = 900;
  295. /* Font Widths */
  296. /**
  297. * Ultra-condensed font width. Typically 50% of normal.
  298. */
  299. const WIDTH_ULTRA_CONDENSED = 1;
  300. /**
  301. * Extra-condensed font width. Typically 62.5% of normal.
  302. */
  303. const WIDTH_EXTRA_CONDENSED = 2;
  304. /**
  305. * Condensed font width. Typically 75% of normal.
  306. */
  307. const WIDTH_CONDENSED = 3;
  308. /**
  309. * Semi-condensed font width. Typically 87.5% of normal.
  310. */
  311. const WIDTH_SEMI_CONDENSED = 4;
  312. /**
  313. * Normal (Medium) font width.
  314. */
  315. const WIDTH_NORMAL = 5;
  316. /**
  317. * Semi-expanded font width. Typically 112.5% of normal.
  318. */
  319. const WIDTH_SEMI_EXPANDED = 6;
  320. /**
  321. * Expanded font width. Typically 125% of normal.
  322. */
  323. const WIDTH_EXPANDED = 7;
  324. /**
  325. * Extra-expanded font width. Typically 150% of normal.
  326. */
  327. const WIDTH_EXTRA_EXPANDED = 8;
  328. /**
  329. * Ultra-expanded font width. Typically 200% of normal.
  330. */
  331. const WIDTH_ULTRA_EXPANDED = 9;
  332. /* Font Embedding Options */
  333. /**
  334. * Do not embed the font in the PDF document.
  335. */
  336. const EMBED_DONT_EMBED = 0x01;
  337. /**
  338. * Embed, but do not subset the font in the PDF document.
  339. */
  340. const EMBED_DONT_SUBSET = 0x02;
  341. /**
  342. * Embed, but do not compress the font in the PDF document.
  343. */
  344. const EMBED_DONT_COMPRESS = 0x04;
  345. /**
  346. * Suppress the exception normally thrown if the font cannot be embedded
  347. * due to its copyright bits being set.
  348. */
  349. const EMBED_SUPPRESS_EMBED_EXCEPTION = 0x08;
  350. /**** Class Variables ****/
  351. /**
  352. * Array whose keys are the unique PostScript names of instantiated fonts.
  353. * The values are the font objects themselves.
  354. * @var array
  355. */
  356. private static $_fontNames = array();
  357. /**
  358. * Array whose keys are the md5 hash of the full paths on disk for parsed
  359. * fonts. The values are the font objects themselves.
  360. * @var array
  361. */
  362. private static $_fontFilePaths = array();
  363. /**** Public Interface ****/
  364. /* Factory Methods */
  365. /**
  366. * Returns a {@link Zend_Pdf_Resource_Font} object by full name.
  367. *
  368. * This is the preferred method to obtain one of the standard 14 PDF fonts.
  369. *
  370. * The result of this method is cached, preventing unnecessary duplication
  371. * of font objects. Repetitive calls for a font with the same name will
  372. * return the same object.
  373. *
  374. * The $embeddingOptions parameter allows you to set certain flags related
  375. * to font embedding. You may combine options by OR-ing them together. See
  376. * the EMBED_ constants defined in {@link Zend_Pdf_Font} for the list of
  377. * available options and their descriptions. Note that this value is only
  378. * used when creating a font for the first time. If a font with the same
  379. * name already exists, you will get that object and the options you specify
  380. * here will be ignored. This is because fonts are only embedded within the
  381. * PDF file once.
  382. *
  383. * If the font name supplied does not match the name of a previously
  384. * instantiated object and it is not one of the 14 standard PDF fonts, an
  385. * exception will be thrown.
  386. *
  387. * @param string $name Full PostScript name of font.
  388. * @param integer $embeddingOptions (optional) Options for font embedding.
  389. * @return Zend_Pdf_Resource_Font
  390. * @throws Zend_Pdf_Exception
  391. */
  392. public static function fontWithName($name, $embeddingOptions = 0)
  393. {
  394. /* First check the cache. Don't duplicate font objects.
  395. */
  396. if (isset(Zend_Pdf_Font::$_fontNames[$name])) {
  397. return Zend_Pdf_Font::$_fontNames[$name];
  398. }
  399. /**
  400. * @todo It would be cool to be able to have a mapping of font names to
  401. * file paths in a configuration file for frequently used custom
  402. * fonts. This would allow a user to use custom fonts without having
  403. * to hard-code file paths all over the place. Table this idea until
  404. * {@link Zend_Config} is ready.
  405. */
  406. /* Not an existing font and no mapping in the config file. Check to see
  407. * if this is one of the standard 14 PDF fonts.
  408. */
  409. switch ($name) {
  410. case Zend_Pdf_Font::FONT_COURIER:
  411. $font = new Zend_Pdf_Resource_Font_Standard_Courier();
  412. break;
  413. case Zend_Pdf_Font::FONT_COURIER_BOLD:
  414. $font = new Zend_Pdf_Resource_Font_Standard_CourierBold();
  415. break;
  416. case Zend_Pdf_Font::FONT_COURIER_OBLIQUE:
  417. $font = new Zend_Pdf_Resource_Font_Standard_CourierOblique();
  418. break;
  419. case Zend_Pdf_Font::FONT_COURIER_BOLD_OBLIQUE:
  420. $font = new Zend_Pdf_Resource_Font_Standard_CourierBoldOblique();
  421. break;
  422. case Zend_Pdf_Font::FONT_HELVETICA:
  423. $font = new Zend_Pdf_Resource_Font_Standard_Helvetica();
  424. break;
  425. case Zend_Pdf_Font::FONT_HELVETICA_BOLD:
  426. $font = new Zend_Pdf_Resource_Font_Standard_HelveticaBold();
  427. break;
  428. case Zend_Pdf_Font::FONT_HELVETICA_OBLIQUE:
  429. $font = new Zend_Pdf_Resource_Font_Standard_HelveticaOblique();
  430. break;
  431. case Zend_Pdf_Font::FONT_HELVETICA_BOLD_OBLIQUE:
  432. $font = new Zend_Pdf_Resource_Font_Standard_HelveticaBoldOblique();
  433. break;
  434. case Zend_Pdf_Font::FONT_SYMBOL:
  435. $font = new Zend_Pdf_Resource_Font_Standard_Symbol();
  436. break;
  437. case Zend_Pdf_Font::FONT_TIMES_ROMAN:
  438. $font = new Zend_Pdf_Resource_Font_Standard_TimesRoman();
  439. break;
  440. case Zend_Pdf_Font::FONT_TIMES_BOLD:
  441. $font = new Zend_Pdf_Resource_Font_Standard_TimesBold();
  442. break;
  443. case Zend_Pdf_Font::FONT_TIMES_ITALIC:
  444. $font = new Zend_Pdf_Resource_Font_Standard_TimesItalic();
  445. break;
  446. case Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC:
  447. $font = new Zend_Pdf_Resource_Font_Standard_TimesBoldItalic();
  448. break;
  449. case Zend_Pdf_Font::FONT_ZAPFDINGBATS:
  450. $font = new Zend_Pdf_Resource_Font_Standard_ZapfDingbats();
  451. break;
  452. default:
  453. throw new Zend_Pdf_Exception("Unknown font name: $name",
  454. Zend_Pdf_Exception::BAD_FONT_NAME);
  455. }
  456. /* Add this new font to the cache array and return it for use.
  457. */
  458. Zend_Pdf_Font::$_fontNames[$name] = $font;
  459. return $font;
  460. }
  461. /**
  462. * Returns a {@link Zend_Pdf_Resource_Font} object by file path.
  463. *
  464. * The result of this method is cached, preventing unnecessary duplication
  465. * of font objects. Repetitive calls for the font with the same path will
  466. * return the same object.
  467. *
  468. * The $embeddingOptions parameter allows you to set certain flags related
  469. * to font embedding. You may combine options by OR-ing them together. See
  470. * the EMBED_ constants defined in {@link Zend_Pdf_Font} for the list of
  471. * available options and their descriptions. Note that this value is only
  472. * used when creating a font for the first time. If a font with the same
  473. * name already exists, you will get that object and the options you specify
  474. * here will be ignored. This is because fonts are only embedded within the
  475. * PDF file once.
  476. *
  477. * If the file path supplied does not match the path of a previously
  478. * instantiated object or the font type cannot be determined, an exception
  479. * will be thrown.
  480. *
  481. * @param string $filePath Full path to the font file.
  482. * @param integer $embeddingOptions (optional) Options for font embedding.
  483. * @return Zend_Pdf_Resource_Font
  484. * @throws Zend_Pdf_Exception
  485. */
  486. public static function fontWithPath($filePath, $embeddingOptions = 0)
  487. {
  488. /* First check the cache. Don't duplicate font objects.
  489. */
  490. $filePathKey = md5($filePath);
  491. if (isset(Zend_Pdf_Font::$_fontFilePaths[$filePathKey])) {
  492. return Zend_Pdf_Font::$_fontFilePaths[$filePathKey];
  493. }
  494. /* Create a file parser data source object for this file. File path and
  495. * access permission checks are handled here.
  496. */
  497. $dataSource = new Zend_Pdf_FileParserDataSource_File($filePath);
  498. /* Attempt to determine the type of font. We can't always trust file
  499. * extensions, but try that first since it's fastest.
  500. */
  501. $fileExtension = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
  502. /* If it turns out that the file is named improperly and we guess the
  503. * wrong type, we'll get null instead of a font object.
  504. */
  505. switch ($fileExtension) {
  506. case 'ttf':
  507. $font = Zend_Pdf_Font::_extractTrueTypeFont($dataSource, $embeddingOptions);
  508. break;
  509. default:
  510. /* Unrecognized extension. Try to determine the type by actually
  511. * parsing it below.
  512. */
  513. $font = null;
  514. break;
  515. }
  516. if (is_null($font)) {
  517. /* There was no match for the file extension or the extension was
  518. * wrong. Attempt to detect the type of font by actually parsing it.
  519. * We'll do the checks in order of most likely format to try to
  520. * reduce the detection time.
  521. */
  522. // OpenType
  523. // TrueType
  524. if ((is_null($font)) && ($fileExtension != 'ttf')) {
  525. $font = Zend_Pdf_Font::_extractTrueTypeFont($dataSource, $embeddingOptions);
  526. }
  527. // Type 1 PostScript
  528. // Mac OS X dfont
  529. // others?
  530. }
  531. /* Done with the data source object.
  532. */
  533. $dataSource = null;
  534. if (! is_null($font)) {
  535. /* Parsing was successful. Add this font instance to the cache arrays
  536. * and return it for use.
  537. */
  538. $fontName = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, '', '');
  539. Zend_Pdf_Font::$_fontNames[$fontName] = $font;
  540. $filePathKey = md5($filePath);
  541. Zend_Pdf_Font::$_fontFilePaths[$filePathKey] = $font;
  542. return $font;
  543. } else {
  544. /* The type of font could not be determined. Give up.
  545. */
  546. throw new Zend_Pdf_Exception("Cannot determine font type: $filePath",
  547. Zend_Pdf_Exception::CANT_DETERMINE_FONT_TYPE);
  548. }
  549. }
  550. /**** Internal Methods ****/
  551. /* Font Extraction Methods */
  552. /**
  553. * Attempts to extract a TrueType font from the data source.
  554. *
  555. * If the font parser throws an exception that suggests the data source
  556. * simply doesn't contain a TrueType font, catches it and returns null. If
  557. * an exception is thrown that suggests the TrueType font is corrupt or
  558. * otherwise unusable, throws that exception. If successful, returns the
  559. * font object.
  560. *
  561. * @param Zend_Pdf_FileParserDataSource $dataSource
  562. * @param integer $embeddingOptions Options for font embedding.
  563. * @return Zend_Pdf_Resource_Font_OpenType_TrueType May also return null if
  564. * the data source does not appear to contain a TrueType font.
  565. * @throws Zend_Pdf_Exception
  566. */
  567. protected static function _extractTrueTypeFont($dataSource, $embeddingOptions)
  568. {
  569. try {
  570. $fontParser = new Zend_Pdf_FileParser_Font_OpenType_TrueType($dataSource);
  571. $font = new Zend_Pdf_Resource_Font_OpenType_TrueType($fontParser, $embeddingOptions);
  572. $fontParser = null;
  573. } catch (Zend_Pdf_Exception $exception) {
  574. /* The following exception codes suggest that this isn't really a
  575. * TrueType font. If we caught such an exception, simply return
  576. * null. For all other cases, it probably is a TrueType font but has
  577. * a problem; throw the exception again.
  578. */
  579. $fontParser = null;
  580. switch ($exception->getCode()) {
  581. case Zend_Pdf_Exception::WRONG_FONT_TYPE: // break intentionally omitted
  582. case Zend_Pdf_Exception::BAD_TABLE_COUNT: // break intentionally omitted
  583. case Zend_Pdf_Exception::BAD_MAGIC_NUMBER:
  584. return null;
  585. default:
  586. throw $exception;
  587. }
  588. }
  589. return $font;
  590. }
  591. }