/** * Attempts to extract a TrueType font from the data source. * * If the font parser throws an exception that suggests the data source * simply doesn't contain a TrueType font, catches it and returns null. If * an exception is thrown that suggests the TrueType font is corrupt or * otherwise unusable, throws that exception. If successful, returns the * font object. * * @param Zend_Pdf_FileParserDataSource $dataSource * @param integer $embeddingOptions Options for font embedding. * @return Zend_Pdf_Resource_Font_OpenType_TrueType May also return null if * the data source does not appear to contain a TrueType font. * @throws Zend_Pdf_Exception */ protected static function _extractTrueTypeFont($dataSource, $embeddingOptions) { try { $fontParser = new Zend_Pdf_FileParser_Font_OpenType_TrueType($dataSource); $fontParser->parse(); if ($fontParser->isAdobeLatinSubset) { $font = new Zend_Pdf_Resource_Font_Simple_Parsed_TrueType($fontParser, $embeddingOptions); } else { /* Use Composite Type 0 font which supports Unicode character mapping */ $cidFont = new Zend_Pdf_Resource_Font_CidFont_TrueType($fontParser, $embeddingOptions); $font = new Zend_Pdf_Resource_Font_Type0($cidFont); } } catch (Zend_Pdf_Exception $exception) { /* The following exception codes suggest that this isn't really a * TrueType font. If we caught such an exception, simply return * null. For all other cases, it probably is a TrueType font but has * a problem; throw the exception again. */ $fontParser = null; switch ($exception->getCode()) { case Zend_Pdf_Exception::WRONG_FONT_TYPE: // break intentionally omitted // break intentionally omitted case Zend_Pdf_Exception::BAD_TABLE_COUNT: // break intentionally omitted // break intentionally omitted case Zend_Pdf_Exception::BAD_MAGIC_NUMBER: return null; default: throw $exception; } } return $font; }
protected static function _extractTrueTypeFont($dataSource, $embeddingOptions) { try { $fontParser = new Zend_Pdf_FileParser_Font_OpenType_TrueType($dataSource); $fontParser->parse(); if ($fontParser->isAdobeLatinSubset) { $font = new Zend_Pdf_Resource_Font_Simple_Parsed_TrueType($fontParser, $embeddingOptions); } else { $cidFont = new Zend_Pdf_Resource_Font_CidFont_TrueType($fontParser, $embeddingOptions); $font = new Zend_Pdf_Resource_Font_Type0($cidFont); } } catch (Zend_Pdf_Exception $e) { $fontParser = null; switch ($e->getCode()) { case Zend_Pdf_Exception::WRONG_FONT_TYPE: case Zend_Pdf_Exception::BAD_TABLE_COUNT: case Zend_Pdf_Exception::BAD_MAGIC_NUMBER: return null; default: throw new Zend_Pdf_Exception($e->getMessage(), $e->getCode(), $e); } } return $font; }