예제 #1
0
        /// <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 FileFontInstance[] LoadFontCollection(string path)
        {
            using (FileStream fs = File.OpenRead(path))
            {
                long startPos  = fs.Position;
                var  reader    = new BinaryReader(fs, true);
                var  ttcHeader = TtcHeader.Read(reader);
                var  fonts     = new FileFontInstance[(int)ttcHeader.NumFonts];

                for (int i = 0; i < ttcHeader.NumFonts; ++i)
                {
                    fs.Position = startPos + ttcHeader.OffsetTable[i];
                    var description = FontDescription.LoadDescription(fs);
                    fonts[i] = new FileFontInstance(description, path, (long)ttcHeader.OffsetTable[i]);
                }

                return(fonts);
            }
        }
예제 #2
0
        private IEnumerable <FontFamily> InstallCollectionInternal(Stream fontCollectionStream, CultureInfo culture, out IEnumerable <FontDescription> fontDescriptions)
        {
            long startPos          = fontCollectionStream.Position;
            var  reader            = new BinaryReader(fontCollectionStream, true);
            var  ttcHeader         = TtcHeader.Read(reader);
            var  result            = new List <FontDescription>((int)ttcHeader.NumFonts);
            var  installedFamilies = new HashSet <FontFamily>();

            for (int i = 0; i < ttcHeader.NumFonts; ++i)
            {
                fontCollectionStream.Position = startPos + ttcHeader.OffsetTable[i];
                var instance = FontInstance.LoadFont(fontCollectionStream);
                installedFamilies.Add(this.Install(instance, culture));
                FontDescription fontDescription = instance.Description;
                result.Add(fontDescription);
            }

            fontDescriptions = result;
            return(installedFamilies);
        }
예제 #3
0
 internal FileFontInstance(FontDescription description, string path, long offset)
 {
     this.Description = description;
     this.Path        = path;
     this.font        = new Lazy <Fonts.IFontInstance>(() => FontInstance.LoadFont(path, offset));
 }
예제 #4
0
 public FileFontInstance(string path, long offset)
     : this(FontDescription.LoadDescription(path), path, offset)
 {
 }
예제 #5
0
 /// <summary>
 /// Installs the specified font stream.
 /// </summary>
 /// <param name="fontStream">The font stream.</param>
 /// <param name="fontDescription">The font description of the installed font.</param>
 /// <returns>the description of the font just loaded.</returns>
 public FontFamily Install(Stream fontStream, out FontDescription fontDescription)
 => this.InstallInternal(fontStream, CultureInfo.InvariantCulture, out fontDescription);
예제 #6
0
 /// <summary>
 /// Installs a font from the specified path.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="fontDescription">The font description of the installed font.</param>
 /// <returns>the description of the font just loaded.</returns>
 public FontFamily Install(string path, out FontDescription fontDescription)
 => this.InstallInternal(path, CultureInfo.CurrentCulture, out fontDescription);
예제 #7
0
 public FileFontInstance(string path)
 {
     this.Description = FontDescription.LoadDescription(path);
     this.font        = new Lazy <Fonts.FontInstance>(() => FontInstance.LoadFont(path));
 }
예제 #8
0
 internal FileFontMetrics(FontDescription description, string path, long offset)
 {
     this.Description = description;
     this.Path        = path;
     this.metrics     = new Lazy <StreamFontMetrics>(() => StreamFontMetrics.LoadFont(path, offset));
 }
예제 #9
0
 public FileFontMetrics(string path, long offset)
     : this(FontDescription.LoadDescription(path), path, offset)
 {
 }