Exemplo n.º 1
0
        /// <summary>
        /// Set the primary font family.
        /// </summary>
        /// <param name="fontFamilyName">Font family name.</param>
        /// <returns>True if the name is valid, otherwise false.</returns>
        public bool SetPrimaryFontFamily(string fontFamilyName)
        {
            if (FontFamilyCacheItem.TryCreate(this.fontCollection, fontFamilyName, out var item))
            {
                this.ClearFontCache();
                this.baseFontFamilyName = fontFamilyName;
                this.fontFamilies.Add(item);
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
 public static bool TryCreate(DWrite.FontCollection collection, string fontFamilyName, out FontFamilyCacheItem item)
 {
     if (collection.FindFamilyName(fontFamilyName, out var index))
     {
         var fontFamily = collection.GetFontFamily(index);
         item = new FontFamilyCacheItem(fontFamily);
         return(true);
     }
     else
     {
         item = null;
         return(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Get font face for specified codepoint, weight and style.
        /// </summary>
        /// <param name="codePoint">The code point.</param>
        /// <param name="weight">The font weight.</param>
        /// <param name="style">The font style.</param>
        /// <returns>Selected font face.</returns>
        public DWrite.FontFace GetFontFace(int codePoint, DWrite.FontWeight weight, DWrite.FontStyle style)
        {
            foreach (var f in this.fontFamilies)
            {
                var face = f.GetFontFace(codePoint, weight, style);
                if (face != null)
                {
                    return(face);
                }
            }

            using (var source = new SingleCharTextSource(this.factory, codePoint))
            {
                this.systemFontFallback.MapCharacters(
                    source,
                    0,
                    1,
                    this.fontCollection,
                    this.baseFontFamilyName,
                    weight,
                    style,
                    DWrite.FontStretch.Normal,
                    out var mappedLength,
                    out var font,
                    out var scale);

                if (font != null)
                {
                    FontFamilyCacheItem.TryCreate(this.fontCollection, font.FontFamily.FamilyNames.GetString(0), out var familyCache);
                    this.fontFamilies.Add(familyCache);
                    font.Dispose();

                    var fontFace = familyCache.GetFontFace(codePoint, weight, style);
                    if (fontFace != null)
                    {
                        return(fontFace);
                    }
                }
            }

            // OK we don't have the glyph for this codepoint in the fallbacks.
            // Use primary font to show something like '?'.
            return(this.fontFamilies[0].GetFontFace(weight, style));
        }