Пример #1
0
        /// <summary>Reads the glyphs widths.</summary>
        /// <remarks>
        /// Reads the glyphs widths. The widths are extracted from the table 'hmtx'.
        /// The glyphs are normalized to 1000 units (TrueTypeFont.UNITS_NORMALIZATION).
        /// Depends on
        /// <see cref="HorizontalHeader.numberOfHMetrics"/>
        /// and
        /// <see cref="HeaderTable.unitsPerEm"/>.
        /// </remarks>
        protected internal virtual void ReadGlyphWidths()
        {
            int numberOfHMetrics = hhea.numberOfHMetrics;
            int unitsPerEm       = head.unitsPerEm;

            int[] table_location;
            table_location = tables.Get("hmtx");
            if (table_location == null)
            {
                if (fileName != null)
                {
                    throw new iText.IO.IOException(iText.IO.IOException.TableDoesNotExistsIn).SetMessageParams("hmtx", fileName
                                                                                                               );
                }
                else
                {
                    throw new iText.IO.IOException(iText.IO.IOException.TableDoesNotExist).SetMessageParams("hmtx");
                }
            }
            glyphWidthsByIndex = new int[ReadNumGlyphs()];
            raf.Seek(table_location[0]);
            for (int k = 0; k < numberOfHMetrics; ++k)
            {
                glyphWidthsByIndex[k] = raf.ReadUnsignedShort() * TrueTypeFont.UNITS_NORMALIZATION / unitsPerEm;
                int leftSideBearing = raf.ReadShort() * TrueTypeFont.UNITS_NORMALIZATION / unitsPerEm;
            }
            // If the font is monospaced, only one entry need be in the array, but that entry is required.
            // The last entry applies to all subsequent glyphs.
            if (numberOfHMetrics > 0)
            {
                for (int k = numberOfHMetrics; k < glyphWidthsByIndex.Length; k++)
                {
                    glyphWidthsByIndex[k] = glyphWidthsByIndex[numberOfHMetrics - 1];
                }
            }
        }
Пример #2
0
        /// <summary>Reads the glyphs widths.</summary>
        /// <remarks>
        /// Reads the glyphs widths. The widths are extracted from the table 'hmtx'.
        /// The glyphs are normalized to 1000 units (TrueTypeFont.UNITS_NORMALIZATION).
        /// Depends from
        /// <c>hhea.numberOfHMetrics</c>
        /// property,
        /// <seealso>HorizontalHeader</seealso>
        /// and
        /// <c>head.unitsPerEm</c>
        /// property,
        /// <seealso>HeaderTable</seealso>
        /// .
        /// </remarks>
        /// <exception cref="System.IO.IOException">the font file could not be read.</exception>
        protected internal virtual void ReadGlyphWidths()
        {
            int numberOfHMetrics = hhea.numberOfHMetrics;
            int unitsPerEm       = head.unitsPerEm;

            int[] table_location;
            table_location = tables.Get("hmtx");
            if (table_location == null)
            {
                if (fileName != null)
                {
                    throw new iText.IO.IOException("table.1.does.not.exist.in.2").SetMessageParams("hmtx", fileName);
                }
                else
                {
                    throw new iText.IO.IOException("table.1.does.not.exist").SetMessageParams("hmtx");
                }
            }
            raf.Seek(table_location[0]);
            glyphWidthsByIndex = new int[numberOfHMetrics];
            for (int k = 0; k < numberOfHMetrics; ++k)
            {
                glyphWidthsByIndex[k] = raf.ReadUnsignedShort() * TrueTypeFont.UNITS_NORMALIZATION / unitsPerEm;
                int leftSideBearing = raf.ReadShort() * TrueTypeFont.UNITS_NORMALIZATION / unitsPerEm;
            }
        }