public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontStretch fontStretch, FontFamily fontFamily, CultureInfo culture, out Typeface typeface) { var familyCount = Direct2D1FontCollectionCache.InstalledFontCollection.FontFamilyCount; for (var i = 0; i < familyCount; i++) { var font = Direct2D1FontCollectionCache.InstalledFontCollection.GetFontFamily(i) .GetMatchingFonts((SharpDX.DirectWrite.FontWeight)fontWeight, (SharpDX.DirectWrite.FontStretch)fontStretch, (SharpDX.DirectWrite.FontStyle)fontStyle).GetFont(0); if (!font.HasCharacter(codepoint)) { continue; } var fontFamilyName = font.FontFamily.FamilyNames.GetString(0); typeface = new Typeface(fontFamilyName, fontStyle, fontWeight, fontStretch); return(true); } typeface = default; return(false); }
public Typeface MatchCharacter(int codepoint, FontWeight fontWeight = default, FontStyle fontStyle = default, FontFamily fontFamily = null, CultureInfo culture = null) { var fontFamilyName = FontFamily.Default.Name; var familyCount = Direct2D1FontCollectionCache.InstalledFontCollection.FontFamilyCount; for (var i = 0; i < familyCount; i++) { var font = Direct2D1FontCollectionCache.InstalledFontCollection.GetFontFamily(i) .GetMatchingFonts((SharpDX.DirectWrite.FontWeight)fontWeight, FontStretch.Normal, (SharpDX.DirectWrite.FontStyle)fontStyle).GetFont(0); if (!font.HasCharacter(codepoint)) { continue; } fontFamilyName = font.FontFamily.FamilyNames.GetString(0); break; } return(GetTypeface(new FontFamily(fontFamilyName), fontWeight, fontStyle)); }
public bool TryMatchCharacter(int codepoint, FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, CultureInfo culture, out FontKey fontKey) { var familyCount = Direct2D1FontCollectionCache.InstalledFontCollection.FontFamilyCount; for (var i = 0; i < familyCount; i++) { var font = Direct2D1FontCollectionCache.InstalledFontCollection.GetFontFamily(i) .GetMatchingFonts((SharpDX.DirectWrite.FontWeight)fontWeight, FontStretch.Normal, (SharpDX.DirectWrite.FontStyle)fontStyle).GetFont(0); if (!font.HasCharacter(codepoint)) { continue; } var fontFamilyName = font.FontFamily.FamilyNames.GetString(0); fontKey = new FontKey(new FontFamily(fontFamilyName), fontWeight, fontStyle); return true; } fontKey = default; return false; }
/// <summary> /// Creates formatted text. /// </summary> /// <param name="element">The owner element. The text formatter setting are read from this element.</param> /// <param name="text">The text.</param> /// <param name="typeface">The typeface to use. If this parameter is null, the typeface of the <paramref name="element"/> will be used.</param> /// <param name="emSize">The font size. If this parameter is null, the font size of the <paramref name="element"/> will be used.</param> /// <param name="foreground">The foreground color. If this parameter is null, the foreground of the <paramref name="element"/> will be used.</param> /// <returns>A FormattedText object using the specified settings.</returns> public static FormattedText CreateFormattedText(Control element, string text, Avalonia.Media.FontFamily typeface, double?emSize, IBrush foreground) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (text == null) { throw new ArgumentNullException(nameof(text)); } if (typeface == null) { typeface = TextBlock.GetFontFamily(element); } if (emSize == null) { emSize = TextBlock.GetFontSize(element); } if (foreground == null) { foreground = TextBlock.GetForeground(element); } var formattedText = new FormattedText { Text = text, Typeface = new Typeface(typeface), FontSize = emSize.Value }; formattedText.SetTextStyle(0, text.Length, foreground); return(formattedText); }
private static FontCollection GetOrAddFontCollection(FontFamily fontFamily) { return(fontFamily.Key == null ? InstalledFontCollection : s_cachedCollections.GetOrAdd(fontFamily.Key, CreateFontCollection)); }
public Typeface GetTypeface(FontFamily fontFamily, FontWeight fontWeight, FontStyle fontStyle) { //ToDo: Implement caching. return(new Typeface(fontFamily, fontWeight, fontStyle)); }