コード例 #1
0
        /// <summary>
        /// Reads a <see cref="FontDescription"/> from the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>a <see cref="FontDescription"/>.</returns>
        public static FontDescription LoadDescription(Stream stream)
        {
            // only read the name table
            var reader = new FontReader(stream);

            return(LoadDescription(reader));
        }
コード例 #2
0
ファイル: FontInstance.cs プロジェクト: hongweichang/NFinal2
        internal static FontInstance LoadFont(FontReader reader)
        {
            // https://www.microsoft.com/typography/otspec/recom.htm#TableOrdering
            // recomended order
            var head = reader.GetTable <HeadTable>();                           // head - not saving but loading in suggested order

            reader.GetTable <HoizontalHeadTable>();                             // hhea
            reader.GetTable <MaximumProfileTable>();                            // maxp
            var os2 = reader.GetTable <OS2Table>();                             // OS/2
            var horizontalMetrics = reader.GetTable <HorizontalMetricsTable>(); // hmtx
            // LTSH - Linear threshold data
            // VDMX - Vertical device metrics
            // hdmx - Horizontal device metrics
            var cmap = reader.GetTable <CMapTable>(); // cmap

            // fpgm - Font Program
            // prep - Control Value Program
            // cvt  - Control Value Table
            reader.GetTable <IndexLocationTable>();           // loca
            var glyphs    = reader.GetTable <GlyphTable>();   // glyf
            var kern      = reader.GetTable <KerningTable>(); // kern - Kerning
            var nameTable = reader.GetTable <NameTable>();    // name

            // post - PostScript information
            // gasp - Grid-fitting/Scan-conversion (optional table)
            // PCLT - PCL 5 data
            // DSIG - Digital signature
            return(new FontInstance(nameTable, cmap, glyphs, os2, horizontalMetrics, head, kern));
        }
コード例 #3
0
ファイル: FontInstance.cs プロジェクト: hongweichang/NFinal2
 /// <summary>
 /// Reads a <see cref="FontInstance"/> from the specified stream.
 /// </summary>
 /// <param name="path">The file path.</param>
 /// <returns>a <see cref="FontInstance"/>.</returns>
 public static FontInstance LoadFont(string path)
 {
     using (var fs = File.OpenRead(path))
     {
         var reader = new FontReader(fs);
         return(LoadFont(reader));
     }
 }
コード例 #4
0
 /// <summary>
 /// Reads a <see cref="FontDescription"/> from the specified stream.
 /// </summary>
 /// <param name="path">The file path.</param>
 /// <returns>a <see cref="FontDescription"/>.</returns>
 public static FontDescription LoadDescription(string path)
 {
     using (FileStream fs = File.OpenRead(path))
     {
         FontReader reader = new FontReader(fs);
         return(LoadDescription(reader));
     }
 }
コード例 #5
0
        /// <summary>
        /// Reads a <see cref="FontDescription" /> from the specified stream.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>
        /// a <see cref="FontDescription" />.
        /// </returns>
        internal static FontDescription LoadDescription(FontReader reader)
        {
            var head      = reader.GetTable <HeadTable>();
            var os2       = reader.GetTable <OS2Table>();
            var nameTable = reader.GetTable <NameTable>();

            return(new FontDescription(nameTable, os2, head));
        }
コード例 #6
0
        /// <summary>
        /// Reads a <see cref="FontDescription"/> from the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>a <see cref="FontDescription"/>.</returns>
        public static FontDescription LoadDescription(Stream stream)
        {
            Guard.NotNull(stream, nameof(stream));

            // only read the name table
            var reader = new FontReader(stream);

            return(LoadDescription(reader));
        }
コード例 #7
0
        /// <summary>
        /// Reads a <see cref="FontDescription"/> from the specified stream.
        /// </summary>
        /// <param name="path">The file path.</param>
        /// <returns>a <see cref="FontDescription"/>.</returns>
        public static FontDescription LoadDescription(string path)
        {
            Guard.NotNullOrWhiteSpace(path, nameof(path));

            using FileStream fs = File.OpenRead(path);
            var reader = new FontReader(fs);

            return(LoadDescription(reader));
        }
コード例 #8
0
        /// <summary>
        /// Reads a <see cref="FontDescription" /> from the specified stream.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>
        /// a <see cref="FontDescription" />.
        /// </returns>
        internal static FontDescription LoadDescription(FontReader reader)
        {
            // NOTE: These fields are read in their optimized order
            // https://docs.microsoft.com/en-gb/typography/opentype/spec/recom#optimized-table-ordering
            HeadTable head      = reader.GetTable <HeadTable>();
            OS2Table  os2       = reader.GetTable <OS2Table>();
            NameTable nameTable = reader.GetTable <NameTable>();

            return(new FontDescription(nameTable, os2, head));
        }
コード例 #9
0
ファイル: FontInstance.cs プロジェクト: KinsonDigital/Fonts
        internal static FontInstance LoadFont(FontReader reader)
        {
            // https://www.microsoft.com/typography/otspec/recom.htm#TableOrdering
            // recomended order
            HeadTable           head = reader.GetTable <HeadTable>();                              // head - not saving but loading in suggested order
            HorizontalHeadTable hhea = reader.GetTable <HorizontalHeadTable>();                    // hhea

            reader.GetTable <MaximumProfileTable>();                                               // maxp
            OS2Table os2 = reader.GetTable <OS2Table>();                                           // OS/2
            HorizontalMetricsTable horizontalMetrics = reader.GetTable <HorizontalMetricsTable>(); // hmtx

            // LTSH - Linear threshold data
            // VDMX - Vertical device metrics
            // hdmx - Horizontal device metrics
            CMapTable cmap = reader.GetTable <CMapTable>(); // cmap

            // fpgm - Font Program
            // prep - Control Value Program
            // cvt  - Control Value Table
            reader.GetTable <IndexLocationTable>();                    // loca
            GlyphTable   glyphs    = reader.GetTable <GlyphTable>();   // glyf
            KerningTable kern      = reader.GetTable <KerningTable>(); // kern - Kerning
            NameTable    nameTable = reader.GetTable <NameTable>();    // name

            ColrTable?colrTable = reader.TryGetTable <ColrTable>();    // colr
            CpalTable?cpalTable;

            if (colrTable != null)
            {
                cpalTable = reader.GetTable <CpalTable>(); // CPAL - required if COLR is provided
            }
            else
            {
                cpalTable = reader.TryGetTable <CpalTable>(); // colr
            }

            // post - PostScript information
            // gasp - Grid-fitting/Scan-conversion (optional table)
            // PCLT - PCL 5 data
            // DSIG - Digital signature
            return(new FontInstance(
                       nameTable,
                       cmap,
                       glyphs,
                       os2,
                       hhea,
                       horizontalMetrics,
                       head,
                       kern,
                       colrTable,
                       cpalTable));
        }
コード例 #10
0
        /// <summary>
        /// Reads all the <see cref="FontDescription"/>s from the specified stream (typically a .ttc file like simsun.ttc).
        /// </summary>
        /// <param name="stream">The stream to read the font collection from.</param>
        /// <returns>a <see cref="FontDescription"/>.</returns>
        public static FontDescription[] LoadFontCollectionDescriptions(Stream stream)
        {
            long startPos  = stream.Position;
            var  reader    = new BinaryReader(stream, true);
            var  ttcHeader = TtcHeader.Read(reader);

            var result = new FontDescription[(int)ttcHeader.NumFonts];

            for (int i = 0; i < ttcHeader.NumFonts; ++i)
            {
                stream.Position = startPos + ttcHeader.OffsetTable[i];
                var fontReader = new FontReader(stream);
                result[i] = LoadDescription(fontReader);
            }

            return(result);
        }
コード例 #11
0
ファイル: FontInstance.cs プロジェクト: hongweichang/NFinal2
        /// <summary>
        /// Reads a <see cref="FontInstance"/> from the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <returns>a <see cref="FontInstance"/>.</returns>
        public static FontInstance LoadFont(Stream stream)
        {
            var reader = new FontReader(stream);

            return(LoadFont(reader));
        }