⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opentype.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 3 页
字号:
     * thickness for an underline, which is used by our layout code.     *     * @throws Zend_Pdf_Exception     */    protected function _parsePostTable()    {        $this->_jumpToTable('post');        /* We can read versions 1-4 tables.         */        $tableVersion = $this->_readTableVersion(1, 4);        $this->italicAngle = $this->readFixed(16, 16);        $this->underlinePosition = $this->readInt(2);        $this->underlineThickness = $this->readInt(2);        $fixedPitch = $this->readUInt(4);        $this->isMonospaced = ($fixedPitch !== 0);        /* Skip over PostScript virtual memory usage.         */        $this->skipBytes(16);        /* The format of the remainder of this table is dependent on the table         * version. However, since it contains glyph ordering information and         * PostScript names which we don't use, move on. (This may change at         * some point in the future though...)         */    }    /**     * Parses the OpenType hhea (Horizontal Header) table.     *     * The hhea table contains information used for horizontal layout. It also     * contains some vertical layout information for Apple systems. The vertical     * layout information for the PDF file is usually taken from the OS/2 table.     *     * @throws Zend_Pdf_Exception     */    protected function _parseHheaTable()    {        $this->_jumpToTable('hhea');        /* We can read any version 1 table.         */        $tableVersion = $this->_readTableVersion(1, 1);        /* The typographic ascent, descent, and line gap values are Apple-         * specific. Similar values exist in the OS/2 table. We'll use these         * values unless better values are found in OS/2.         */        $this->ascent = $this->readInt(2);        $this->descent = $this->readInt(2);        $this->lineGap = $this->readInt(2);        /* The descent value is supposed to be negative--it's the distance         * relative to the baseline. However, some fonts improperly store a         * positive value in this field. If a positive value is found, flip the         * sign and record a warning in the debug log that we did this.         */        if ($this->descent > 0) {            $this->_debugLog('Warning: Font should specify negative descent. Actual: %d; Using %d',                             $this->descent, -$this->descent);            $this->descent = -$this->descent;        }        /* Skip over advance width, left and right sidebearing, max x extent,         * caret slope rise, run, and offset, and the four reserved fields.         */        $this->skipBytes(22);        /* These values are needed to read the hmtx table.         */        $this->metricDataFormat = $this->readInt(2);        $this->numberHMetrics = $this->readUInt(2);        $this->_debugLog('hmtx data format: %d; number of metrics: %d',                         $this->metricDataFormat, $this->numberHMetrics);    }    /**
     * Parses the OpenType hhea (Horizontal Header) table.
     *
     * The hhea table contains information used for horizontal layout. It also
     * contains some vertical layout information for Apple systems. The vertical
     * layout information for the PDF file is usually taken from the OS/2 table.
     *
     * @throws Zend_Pdf_Exception
     */
    protected function _parseMaxpTable()
    {
        $this->_jumpToTable('maxp');

        /* We don't care about table version.
         */
        $this->_readTableVersion(0, 1);

        /* The number of glyphs in the font.
         */
        $this->numGlyphs = $this->readUInt(2);
        $this->_debugLog('number of glyphs: %d', $this->numGlyphs);
        
        // Skip other maxp table entries (if presented with table version 1.0)...
    }


    /**     * Parses the OpenType OS/2 (OS/2 and Windows Metrics) table.     *     * The OS/2 table contains additional metrics data that is required to use     * the font on the OS/2 or Microsoft Windows platforms. It is not required     * for Macintosh fonts, so may not always be present. When available, we use     * this table to determine most of the vertical layout and stylistic     * information and for the font.     *     * @throws Zend_Pdf_Exception     */    protected function _parseOs2Table()    {        if (! $this->numberHMetrics) {            throw new Zend_Pdf_Exception("hhea table must be parsed prior to calling this method",                                         Zend_Pdf_Exception::PARSED_OUT_OF_ORDER);        }        try {            $this->_jumpToTable('OS/2');        } catch (Zend_Pdf_Exception $exception) {            /* This table is not always present. If missing, use default values.             */            if ($exception->getCode() == Zend_Pdf_Exception::REQUIRED_TABLE_NOT_FOUND) {                $this->_debugLog('No OS/2 table found. Using default values');                $this->fontWeight = Zend_Pdf_Font::WEIGHT_NORMAL;                $this->fontWidth = Zend_Pdf_Font::WIDTH_NORMAL;                $this->isEmbeddable = true;                $this->isSubsettable = true;                $this->strikeThickness = $this->unitsPerEm * 0.05;                $this->strikePosition  = $this->unitsPerEm * 0.225;                $this->isSerifFont      = false;    // the style of the font is unknown                $this->isSansSerifFont  = false;                $this->isOrnamentalFont = false;                $this->isScriptFont     = false;                $this->isSymbolicFont   = false;                $this->isAdobeLatinSubset = false;                $this->vendorID = '';                $this->xHeight = 0;                $this->capitalHeight = 0;                return;            } else {                /* Something else went wrong. Throw this exception higher up the chain.                 */                throw $exception;            }        }        /* Version 0 tables are becoming rarer these days. They are only found         * in older fonts.         *         * Version 1 formally defines the Unicode character range bits and adds         * two new fields to the end of the table.         *         * Version 2 defines several additional flags to the embedding bits         * (fsType field) and five new fields to the end of the table.         *         * Versions 2 and 3 are structurally identical. There are only two         * significant differences between the two: First, in version 3, the         * average character width (xAvgCharWidth field) is calculated using all         * non-zero width glyphs in the font instead of just the Latin lower-         * case alphabetic characters; this doesn't affect us. Second, in         * version 3, the embedding bits (fsType field) have been made mutually         * exclusive; see additional discusson on this below.         *         * We can understand all four of these table versions.         */        $tableVersion = $this->readUInt(2);        if (($tableVersion < 0) || ($tableVersion > 3)) {            throw new Zend_Pdf_Exception("Unable to read version $tableVersion table",                                         Zend_Pdf_Exception::DONT_UNDERSTAND_TABLE_VERSION);        }        $this->_debugLog('Version %d table', $tableVersion);        $this->averageCharWidth = $this->readInt(2);        /* Indicates the visual weight and aspect ratio of the characters. Used         * primarily to logically sort fonts in lists. Also used to help choose         * a more appropriate substitute font when necessary. See the WEIGHT_         * and WIDTH_ constants defined in Zend_Pdf_Font.         */        $this->fontWeight = $this->readUInt(2);        $this->fontWidth  = $this->readUInt(2);        /* Describes the font embedding licensing rights. We can only embed and         * subset a font when given explicit permission.         *         * NOTE: We always interpret these bits according to the rules defined         * in version 3 of this table, regardless of the actual version. This         * means we will perform our checks in order from the most-restrictive         * to the least.         */        $embeddingFlags = $this->readUInt(2);        $this->_debugLog('Embedding flags: %d', $embeddingFlags);        if ($this->isBitSet(9, $embeddingFlags)) {            /* Only bitmaps may be embedded. We don't have the ability to strip             * outlines from fonts yet, so this means no embed.             */            $this->isEmbeddable = false;        } else if ($this->isBitSet(1, $embeddingFlags)) {            /* Restricted license embedding. We currently don't have any way to             * enforce this, so interpret this as no embed. This may be revised             * in the future...             */            $this->isEmbeddable = false;        } else {            /* The remainder of the bit settings grant us permission to embed             * the font. There may be additional usage rights granted or denied             * but those only affect the PDF viewer application, not our code.             */            $this->isEmbeddable = true;        }        $this->_debugLog('Font ' . ($this->isEmbeddable ? 'may' : 'may not') . ' be embedded');        $isSubsettable = $this->isBitSet($embeddingFlags, 8);        /* Recommended size and offset for synthesized subscript characters.         */        $this->subscriptXSize = $this->readInt(2);        $this->subscriptYSize = $this->readInt(2);        $this->subscriptXOffset = $this->readInt(2);        $this->subscriptYOffset = $this->readInt(2);        /* Recommended size and offset for synthesized superscript characters.         */        $this->superscriptXSize = $this->readInt(2);        $this->superscriptYSize = $this->readInt(2);        $this->superscriptXOffset = $this->readInt(2);        $this->superscriptYOffset = $this->readInt(2);        /* Size and vertical offset for the strikethrough.         */        $this->strikeThickness = $this->readInt(2);        $this->strikePosition  = $this->readInt(2);        /* Describes the class of font: serif, sans serif, script. etc. These         * values are defined here:         *   http://www.microsoft.com/OpenType/OTSpec/ibmfc.htm         */        $familyClass = ($this->readUInt(2) >> 8);    // don't care about subclass        $this->_debugLog('Font family class: %d', $familyClass);        $this->isSerifFont      = ((($familyClass >= 1) && ($familyClass <= 5)) ||                                   ($familyClass == 7));        $this->isSansSerifFont  = ($familyClass == 8);        $this->isOrnamentalFont = ($familyClass == 9);        $this->isScriptFont     = ($familyClass == 10);        $this->isSymbolicFont   = ($familyClass == 12);        /* Skip over the PANOSE number. The interesting values for us overlap         * with the font family class defined above.         */        $this->skipBytes(10);        /* The Unicode range is made up of four 4-byte unsigned long integers         * which are used as bitfields covering a 128-bit range. Each bit         * represents a Unicode code block. If the bit is set, this font at         * least partially covers the characters in that block.         */        $unicodeRange1 = $this->readUInt(4);        $unicodeRange2 = $this->readUInt(4);        $unicodeRange3 = $this->readUInt(4);        $unicodeRange4 = $this->readUInt(4);        $this->_debugLog('Unicode ranges: 0x%x 0x%x 0x%x 0x%x',                        $unicodeRange1, $unicodeRange2, $unicodeRange3, $unicodeRange4);        /* The Unicode range is currently only used to decide if the character         * set covered by the font is a subset of the Adobe Latin set, meaning         * it only has the basic latin set. If it covers any other characters,         * even any of the extended latin characters, it is considered symbolic         * to PDF and must be described differently in the Font Descriptor.         */        /**          * @todo Font is recognized as Adobe Latin subset font if it only contains         * Basic Latin characters (only bit 0 of Unicode range bits is set).         * Actually, other Unicode subranges like General Punctuation (bit 31) also          * fall into Adobe Latin characters. So this code has to be modified.         */        $this->isAdobeLatinSubset = (($unicodeRange1 == 1) && ($unicodeRange2 == 0) &&                                      ($unicodeRange3 == 0) && ($unicodeRange4 == 0));        $this->_debugLog(($this->isAdobeLatinSubset ? 'Is' : 'Is not') . ' a subset of Adobe Latin');        $this->vendorID = $this->readBytes(4);        /* Skip the font style bits. We use the values found in the 'head' table.         * Also skip the first Unicode and last Unicode character indicies. Our         * cmap implementation does not need these values.         */        $this->skipBytes(6);        /* Typographic ascender, descender, and line gap. These values are         * preferred to those in the 'hhea' table.         */        $this->ascent = $this->readInt(2);        $this->descent = $this->readInt(2);        $this->lineGap = $this->readInt(2);        /* The descent value is supposed to be negative--it's the distance         * relative to the baseline. However, some fonts improperly store a         * positive value in this field. If a positive value is found, flip the         * sign and record a warning in the debug log that we did this.         */        if ($this->descent > 0) {            $this->_debugLog('Warning: Font should specify negative descent. Actual: %d; Using %d',                             $this->descent, -$this->descent);            $this->descent = -$this->descent;        }        /* Skip over Windows-specific ascent and descent.         */        $this->skipBytes(4);        /* Versions 0 and 1 tables do not contain the x or capital height         * fields. Record zero for unknown.         */        if ($tableVersion < 2) {            $this->xHeight = 0;            $this->capitalHeight = 0;        } else {            /* Skip over the Windows code page coverages. We are only concerned             * with Unicode coverage.             */            $this->skipBytes(8);            $this->xHeight = $this->readInt(2);            $this->capitalHeight = $this->readInt(2);            /* Ignore the remaining fields in this table. They are Windows-specific.             */        }        /**         * @todo Obtain the x and capital heights from the 'glyf' table if they         *   haven't been supplied here instead of storing zero.         */    }    /**     * Parses the OpenType hmtx (Horizontal Metrics) table.     *     * The hmtx table contains the horizontal metrics for every glyph contained     * within the font. These are the critical values for horizontal layout of     * text.     *     * @throws Zend_Pdf_Exception     */    protected function _parseHmtxTable()    {        $this->_jumpToTable('hmtx');        if (! $this->numberHMetrics) {            throw new Zend_Pdf_Exception("hhea table must be parsed prior to calling this method",                                         Zend_Pdf_Exception::PARSED_OUT_OF_ORDER);        }        /* We only understand version 0 tables.         */        if ($this->metricDataFormat != 0) {            throw new Zend_Pdf_Exception("Unable to read format $this->metricDataFormat table.",                                         Zend_Pdf_Exception::DONT_UNDERSTAND_TABLE_VERSION);        }        /* The hmtx table has no header. For each glpyh in the font, it contains

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -