public static TTFStringMeasurer Create(TrueTypeFile forfont, CMapEncoding encoding, TypeMeasureOptions options)
        {
            HorizontalMetrics table = forfont.Directories["hmtx"].Table as HorizontalMetrics;
            CMAPTable         cmap  = forfont.Directories["cmap"].Table as CMAPTable;
            OS2Table          os2   = forfont.Directories["OS/2"].Table as OS2Table;
            FontHeader        head  = forfont.Directories["head"].Table as FontHeader;
            HorizontalHeader  hhead = forfont.Directories["hhea"].Table as HorizontalHeader;

            CMAPSubTable map = cmap.GetOffsetTable(encoding);

            if (map == null)
            {
                encoding = CMapEncoding.Unicode_20;
                map      = cmap.GetOffsetTable(CMapEncoding.Unicode_20);
            }

            if (map == null)
            {
                encoding = CMapEncoding.MacRoman;
                map      = cmap.GetOffsetTable(CMapEncoding.MacRoman);
            }



            return(new TTFStringMeasurer(head.UnitsPerEm, map, os2, hhead, table.HMetrics, forfont, encoding, options));
        }
Exemple #2
0
        protected virtual ITypefaceFont ReadFile(TrueTypeHeader header, IEnumerable <TrueTypeTableEntry> dirs, BigEndianReader reader, long startOffset, IFontInfo reference)
        {
            var entries = new TrueTypeTableEntryList(dirs);

            TrueTypeFile file = new TrueTypeFile(header, entries);

            TrueTypeTableFactory factory = this.GetTableFactory();

            foreach (TrueTypeTableEntry dir in dirs)
            {
                TrueTypeFontTable tbl = factory.ReadTable(dir, entries, reader);
                if (tbl != null)
                {
                    dir.SetTable(tbl);
                }
            }

            file.EnsureReferenceMatched(reference);


            byte[] data = CopyStreamData(reader.BaseStream, startOffset);
            file.SetFileData(data, this.DataFormat);

            return(file);
        }
        private TTFStringMeasurer(int unitsPerEm, CMAPSubTable offsets, OS2Table oS2, HorizontalHeader hheader, List <HMetric> metrics, TrueTypeFile font, CMapEncoding encoding, TypeMeasureOptions options)
        {
            this._unitsPerEm  = unitsPerEm;
            this._offsets     = offsets;
            this._os2         = oS2;
            this._metrics     = metrics;
            this._lookup      = new Dictionary <char, HMetric>();
            this._options     = options;
            this._fontUseTypo = (oS2.Version >= OS2TableVersion.OpenType15) && ((oS2.Selection & FontSelection.UseTypographicSizes) > 0);

            this._hheader      = hheader;
            this._fontfile     = font;
            this._cMapEncoding = encoding;
        }