Ejemplo n.º 1
0
        private void Initialize()
        {
            // TTC header
            string tag = stream.ReadTag();

            if (!tag.Equals("ttcf", StringComparison.Ordinal))
            {
                throw new IOException("Missing TTC header");
            }
            float version = stream.Read32Fixed();

            numFonts    = (int)stream.ReadUnsignedInt();
            fontOffsets = new long[numFonts];
            for (int i = 0; i < numFonts; i++)
            {
                fontOffsets[i] = stream.ReadUnsignedInt();
            }
            if (version >= 2)
            {
                // not used at this time
                int ulDsigTag    = stream.ReadUnsignedShort();
                int ulDsigLength = stream.ReadUnsignedShort();
                int ulDsigOffset = stream.ReadUnsignedShort();
            }
        }
Ejemplo n.º 2
0
 /**
  * This will read the required data from the stream.
  *
  * @param ttf The font that is being read.
  * @param data The stream to read the data from.
  * @ If there is an error reading the data.
  */
 public override void Read(TrueTypeFont ttf, TTFDataStream data)
 {
     version            = data.Read32Fixed();
     fontRevision       = data.Read32Fixed();
     checkSumAdjustment = data.ReadUnsignedInt();
     magicNumber        = data.ReadUnsignedInt();
     flags             = data.ReadUnsignedShort();
     unitsPerEm        = data.ReadUnsignedShort();
     created           = data.ReadInternationalDate();
     modified          = data.ReadInternationalDate();
     xMin              = data.ReadSignedShort();
     yMin              = data.ReadSignedShort();
     xMax              = data.ReadSignedShort();
     yMax              = data.ReadSignedShort();
     macStyle          = data.ReadUnsignedShort();
     lowestRecPPEM     = data.ReadUnsignedShort();
     fontDirectionHint = data.ReadSignedShort();
     indexToLocFormat  = data.ReadSignedShort();
     glyphDataFormat   = data.ReadSignedShort();
     initialized       = true;
 }
Ejemplo n.º 3
0
        /**
         * This will read the required data from the stream.
         *
         * @param ttf The font that is being read.
         * @param data The stream to read the data from.
         * @ If there is an error reading the data.
         */
        public override void Read(TrueTypeFont ttf, TTFDataStream data)
        {
            version            = data.Read32Fixed();
            defaultVertOriginY = data.ReadSignedShort();
            int numVertOriginYMetrics = data.ReadUnsignedShort();

            origins = new Dictionary <int, int>(numVertOriginYMetrics);
            for (int i = 0; i < numVertOriginYMetrics; ++i)
            {
                int g = data.ReadUnsignedShort();
                int y = data.ReadSignedShort();
                origins[g] = y;
            }
            initialized = true;
        }
Ejemplo n.º 4
0
        /**
         * Parse a file and get a true type font.
         *
         * @param raf The TTF file.
         * @return A TrueType font.
         * @ If there is an error parsing the TrueType font.
         */
        public TrueTypeFont Parse(TTFDataStream raf, string fontName = null)
        {
            if (string.Equals(raf.ReadString(4), TrueTypeCollection.TAG, StringComparison.Ordinal))
            {
                raf.Seek(raf.CurrentPosition - 4);
                TrueTypeCollection fontCollection = new TrueTypeCollection(raf);

                var nameFont = fontCollection.GetFontByName(fontName);
                if (nameFont == null)
                {
                    nameFont = fontCollection.GetFontAtIndex(0);
                }
                return(nameFont);
            }
            raf.Seek(raf.CurrentPosition - 4);

            TrueTypeFont font = NewFont(raf);

            font.Version = raf.Read32Fixed();
            int numberOfTables = raf.ReadUnsignedShort();
            int searchRange    = raf.ReadUnsignedShort();
            int entrySelector  = raf.ReadUnsignedShort();
            int rangeShift     = raf.ReadUnsignedShort();

            for (int i = 0; i < numberOfTables; i++)
            {
                TTFTable table = ReadTableDirectory(font, raf);

                // skip tables with zero length
                if (table != null)
                {
                    font.AddTable(table);
                }
            }
            // parse tables if wanted
            if (!parseOnDemandOnly)
            {
                ParseTables(font);
            }

            return(font);
        }
Ejemplo n.º 5
0
 /**
  * This will read the required data from the stream.
  *
  * @param ttf The font that is being read.
  * @param data The stream to read the data from.
  * @ If there is an error reading the data.
  */
 public override void Read(TrueTypeFont ttf, TTFDataStream data)
 {
     version              = data.Read32Fixed();
     ascender             = data.ReadSignedShort();
     descender            = data.ReadSignedShort();
     lineGap              = data.ReadSignedShort();
     advanceHeightMax     = data.ReadUnsignedShort();
     minTopSideBearing    = data.ReadSignedShort();
     minBottomSideBearing = data.ReadSignedShort();
     yMaxExtent           = data.ReadSignedShort();
     caretSlopeRise       = data.ReadSignedShort();
     caretSlopeRun        = data.ReadSignedShort();
     caretOffset          = data.ReadSignedShort();
     reserved1            = data.ReadSignedShort();
     reserved2            = data.ReadSignedShort();
     reserved3            = data.ReadSignedShort();
     reserved4            = data.ReadSignedShort();
     metricDataFormat     = data.ReadSignedShort();
     numberOfVMetrics     = data.ReadUnsignedShort();
     initialized          = true;
 }
Ejemplo n.º 6
0
        /**
         * This will read the required data from the stream.
         *
         * @param ttf The font that is being read.
         * @param data The stream to read the data from.
         * @ If there is an error reading the data.
         */
        public override void Read(TrueTypeFont ttf, TTFDataStream data)
        {
            formatType         = data.Read32Fixed();
            italicAngle        = data.Read32Fixed();
            underlinePosition  = data.ReadSignedShort();
            underlineThickness = data.ReadSignedShort();
            isFixedPitch       = data.ReadUnsignedInt();
            minMemType42       = data.ReadUnsignedInt();
            maxMemType42       = data.ReadUnsignedInt();
            mimMemType1        = data.ReadUnsignedInt();
            maxMemType1        = data.ReadUnsignedInt();

            if (formatType.CompareTo(1.0f) == 0)
            {
                /*
                 * This TrueType font file contains exactly the 258 glyphs in the standard Macintosh TrueType.
                 */
                glyphNames = new string[WGL4Names.NUMBER_OF_MAC_GLYPHS];
                Array.Copy(WGL4Names.MAC_GLYPH_NAMES, 0, glyphNames, 0, WGL4Names.NUMBER_OF_MAC_GLYPHS);
            }
            else if (formatType.CompareTo(2.0f) == 0)
            {
                int   numGlyphs      = data.ReadUnsignedShort();
                int[] glyphNameIndex = new int[numGlyphs];
                glyphNames = new string[numGlyphs];
                int maxIndex = int.MinValue;
                for (int i = 0; i < numGlyphs; i++)
                {
                    int index = data.ReadUnsignedShort();
                    glyphNameIndex[i] = index;
                    // PDFBOX-808: Index numbers between 32768 and 65535 are
                    // reserved for future use, so we should just ignore them
                    if (index <= 32767)
                    {
                        maxIndex = Math.Max(maxIndex, index);
                    }
                }
                string[] nameArray = null;
                if (maxIndex >= WGL4Names.NUMBER_OF_MAC_GLYPHS)
                {
                    nameArray = new string[maxIndex - WGL4Names.NUMBER_OF_MAC_GLYPHS + 1];
                    for (int i = 0; i < maxIndex - WGL4Names.NUMBER_OF_MAC_GLYPHS + 1; i++)
                    {
                        int numberOfChars = data.ReadUnsignedByte();
                        nameArray[i] = data.ReadString(numberOfChars);
                    }
                }
                for (int i = 0; i < numGlyphs; i++)
                {
                    int index = glyphNameIndex[i];
                    if (index >= 0 && index < WGL4Names.NUMBER_OF_MAC_GLYPHS)
                    {
                        glyphNames[i] = WGL4Names.MAC_GLYPH_NAMES[index];
                    }
                    else if (index >= WGL4Names.NUMBER_OF_MAC_GLYPHS && index <= 32767 && nameArray != null)
                    {
                        glyphNames[i] = nameArray[index - WGL4Names.NUMBER_OF_MAC_GLYPHS];
                    }
                    else
                    {
                        // PDFBOX-808: Index numbers between 32768 and 65535 are
                        // reserved for future use, so we should just ignore them
                        glyphNames[i] = ".undefined";
                    }
                }
            }
            else if (formatType.CompareTo(2.5f) == 0)
            {
                int[] glyphNameIndex = new int[ttf.NumberOfGlyphs];
                for (int i = 0; i < glyphNameIndex.Length; i++)
                {
                    int offset = data.ReadSignedByte();
                    glyphNameIndex[i] = i + 1 + offset;
                }
                glyphNames = new string[glyphNameIndex.Length];
                for (int i = 0; i < glyphNames.Length; i++)
                {
                    int index = glyphNameIndex[i];
                    if (index >= 0 && index < WGL4Names.NUMBER_OF_MAC_GLYPHS)
                    {
                        string name = WGL4Names.MAC_GLYPH_NAMES[index];
                        if (name != null)
                        {
                            glyphNames[i] = name;
                        }
                    }
                    else
                    {
                        Debug.WriteLine($"debug: incorrect glyph name index {index}, valid numbers 0..{WGL4Names.NUMBER_OF_MAC_GLYPHS}");
                    }
                }
            }
            else if (formatType.CompareTo(3.0f) == 0)
            {
                // no postscript information is provided.
                Debug.WriteLine($"debug: No PostScript name information is provided for the font {font.Name}");
            }
            initialized = true;
        }