コード例 #1
0
ファイル: TrueTypeFont.cs プロジェクト: i-e-b/Form8sn
        public TrueTypeFont(string filename)
        {
            /*
             * TODO: Big refactor needed!
             *
             * We have a huge over-lap between "PortableGdi/Toolkit/Fonts/..."
             * and "PdfSharpStd/Fonts.OpenType/OpenTypeFontface.cs".
             *
             * The majority of "PdfSharpStd/Fonts.OpenType" is the better and more complete code.
             * However, we still need the separation of GDI and PdfSharp to be the current way
             * around, and we still need all the glyph outline logic in "Toolkit/Fonts".
             *
             * The "Fonts.OpenType" classes also load the entire file into managed memory,
             * which the "Toolkit/Fonts" no longer does.
             *
             * The Fonts.OpenType classes are very tied into the reading & writing required for
             * PDF generation.
             */


            _filename       = filename;
            _file           = new BinaryReader(filename);
            _unicodeIndexes = new Dictionary <char, int>();
            _glyphCache     = new Dictionary <int, Glyph>();

            // The order that things are read below is important
            // DO NOT REARRANGE CALLS!
            _tables = ReadOffsetTables();
            Header  = ReadHeadTable();
            _length = GlyphCount();

            if (!_tables.ContainsKey("glyf"))
            {
                throw new Exception("Bad font: glyf table missing");
            }
            if (!_tables.ContainsKey("loca"))
            {
                throw new Exception("Bad font: loca table missing");
            }
        }
コード例 #2
0
ファイル: TrueTypeFont.cs プロジェクト: i-e-b/Form8sn
        private FontHeader ReadHeadTable()
        {
            if (!_tables.ContainsKey("head"))
            {
                throw new BadImageFormatException("Bad font: Header table missing");
            }
            _file.Seek(_tables["head"].Offset);

            var h = new FontHeader();

            // DO NOT REARRANGE CALLS!
            h.Version            = _file.GetFixed();
            h.Revision           = _file.GetFixed();
            h.ChecksumAdjustment = _file.GetUint32();
            h.MagicNumber        = _file.GetUint32();

            if (h.MagicNumber != HeaderMagic)
            {
                throw new Exception("Bad font: incorrect identifier in header table");
            }

            h.Flags      = _file.GetUint16();
            h.UnitsPerEm = _file.GetUint16();
            h.Created    = _file.GetDate();
            h.Modified   = _file.GetDate();

            h.xMin = _file.GetFWord();
            h.yMin = _file.GetFWord();
            h.xMax = _file.GetFWord();
            h.yMax = _file.GetFWord();

            h.MacStyle          = _file.GetUint16();
            h.LowestRecPPEM     = _file.GetUint16();
            h.FontDirectionHint = _file.GetInt16();
            h.IndexToLocFormat  = _file.GetInt16();
            h.GlyphDataFormat   = _file.GetInt16();

            return(h);
        }