/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.Windows.Media.Typeface. /// </summary> /// <param name="typeface">The System.Windows.Media.Typeface.</param> /// <param name="emSize">The em size.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(WpfTypeface typeface, double emSize, XPdfFontOptions pdfOptions) { _wpfTypeface = typeface; //Debug.Assert(font.Name == font.FontFamily.Name); //_familyName = font.Name; _emSize = emSize; _pdfOptions = pdfOptions; InitializeFromWpf(); }
//#endif #if WPF && !SILVERLIGHT internal static WpfTypeface TryCreateTypeface(string name, XFontStyle style, out WpfFontFamily fontFamily) { if (Singleton._fontFamilies.TryGetValue(name, out fontFamily)) { WpfTypeface typeface = FontHelper.CreateTypeface(fontFamily, style); return(typeface); } return(null); }
public static XGlyphTypeface GetOrCreateFromWpf(WpfTypeface wpfTypeface) { #if DEBUG if (wpfTypeface.FontFamily.Source == "Segoe UI Semilight") { wpfTypeface.GetType(); } #endif //string typefaceKey = ComputeKey(wpfTypeface); //XGlyphTypeface glyphTypeface; //if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) //{ // // We have the glyph typeface already in cache. // return glyphTypeface; //} // Create WPF glyph typeface. WpfGlyphTypeface wpfGlyphTypeface; if (!wpfTypeface.TryGetGlyphTypeface(out wpfGlyphTypeface)) { return(null); } string typefaceKey = ComputeKey(wpfGlyphTypeface); string name1 = wpfGlyphTypeface.DesignerNames[FontHelper.CultureInfoEnUs]; string name2 = wpfGlyphTypeface.FaceNames[FontHelper.CultureInfoEnUs]; string name3 = wpfGlyphTypeface.FamilyNames[FontHelper.CultureInfoEnUs]; string name4 = wpfGlyphTypeface.ManufacturerNames[FontHelper.CultureInfoEnUs]; string name5 = wpfGlyphTypeface.Win32FaceNames[FontHelper.CultureInfoEnUs]; string name6 = wpfGlyphTypeface.Win32FamilyNames[FontHelper.CultureInfoEnUs]; XGlyphTypeface glyphTypeface; if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) { // We have the glyph typeface already in cache. return(glyphTypeface); } XFontFamily fontFamily = XFontFamily.GetOrCreateFromWpf(wpfTypeface.FontFamily); XFontSource fontSource = XFontSource.GetOrCreateFromWpf(typefaceKey, wpfGlyphTypeface); glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, (XStyleSimulations)wpfGlyphTypeface.StyleSimulations, wpfTypeface, wpfGlyphTypeface); GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); return(glyphTypeface); }
XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations, WpfTypeface wpfTypeface, WpfGlyphTypeface wpfGlyphTypeface) { _key = key; _fontFamily = fontFamily; _fontSource = fontSource; _styleSimulations = styleSimulations; _fontface = OpenTypeFontface.CetOrCreateFrom(fontSource); Debug.Assert(ReferenceEquals(_fontSource.Fontface, _fontface)); _wpfTypeface = wpfTypeface; _wpfGlyphTypeface = wpfGlyphTypeface; Initialize(); }
/// <summary> /// Create a WPF GlyphTypeface and retrieve font data from it. /// </summary> internal static XFontSource CreateFontSource(string familyName, FontResolvingOptions fontResolvingOptions, out WpfFontFamily wpfFontFamily, out WpfTypeface wpfTypeface, out WpfGlyphTypeface wpfGlyphTypeface, string typefaceKey) { if (string.IsNullOrEmpty(typefaceKey)) { typefaceKey = XGlyphTypeface.ComputeKey(familyName, fontResolvingOptions); } XFontStyle style = fontResolvingOptions.FontStyle; #if DEBUG if (StringComparer.OrdinalIgnoreCase.Compare(familyName, "Segoe UI Semilight") == 0 && (style & XFontStyle.BoldItalic) == XFontStyle.Italic) { familyName.GetType(); } #endif // Use WPF technique to create font data. wpfTypeface = XPrivateFontCollection.TryCreateTypeface(familyName, style, out wpfFontFamily); #if DEBUG__ if (wpfTypeface != null) { WpfGlyphTypeface glyphTypeface; ICollection <WpfTypeface> list = wpfFontFamily.GetTypefaces(); foreach (WpfTypeface tf in list) { if (!tf.TryGetGlyphTypeface(out glyphTypeface)) { Debug - Break.Break(); } } //if (!WpfTypeface.TryGetGlyphTypeface(out glyphTypeface)) // throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(familyName)); } #endif if (wpfFontFamily == null) { wpfFontFamily = new WpfFontFamily(familyName); } if (wpfTypeface == null) { wpfTypeface = FontHelper.CreateTypeface(wpfFontFamily, style); } // Let WPF choose the right glyph typeface. if (!wpfTypeface.TryGetGlyphTypeface(out wpfGlyphTypeface)) { throw new InvalidOperationException(PSSR.CannotGetGlyphTypeface(familyName)); } // Get or create the font source and cache it unter the specified typeface key. XFontSource fontSource = XFontSource.GetOrCreateFromWpf(typefaceKey, wpfGlyphTypeface); return(fontSource); }
public static XGlyphTypeface GetOrCreateFrom(string familyName, FontResolvingOptions fontResolvingOptions) { // Check cache for requested type face. string typefaceKey = ComputeKey(familyName, fontResolvingOptions); XGlyphTypeface glyphTypeface; if (GlyphTypefaceCache.TryGetGlyphTypeface(typefaceKey, out glyphTypeface)) { // Just return existing one. return(glyphTypeface); } // Resolve typeface by FontFactory. FontResolverInfo fontResolverInfo = FontFactory.ResolveTypeface(familyName, fontResolvingOptions, typefaceKey); if (fontResolverInfo == null) { // No fallback - just stop. throw new InvalidOperationException("No appropriate font found."); } #if CORE || GDI GdiFont gdiFont = null; #endif #if WPF WpfFontFamily wpfFontFamily = null; WpfTypeface wpfTypeface = null; WpfGlyphTypeface wpfGlyphTypeface = null; #endif #if UWP // Nothing to do. #endif // Now create the font family at the first. XFontFamily fontFamily; PlatformFontResolverInfo platformFontResolverInfo = fontResolverInfo as PlatformFontResolverInfo; if (platformFontResolverInfo != null) { #if CORE || GDI // $TODO THHO Lock??? // Reuse GDI+ font from platform font resolver. gdiFont = platformFontResolverInfo.GdiFont; fontFamily = XFontFamily.GetOrCreateFromGdi(gdiFont); #endif #if WPF #if !SILVERLIGHT // Reuse WPF font family created from platform font resolver. wpfFontFamily = platformFontResolverInfo.WpfFontFamily; wpfTypeface = platformFontResolverInfo.WpfTypeface; wpfGlyphTypeface = platformFontResolverInfo.WpfGlyphTypeface; fontFamily = XFontFamily.GetOrCreateFromWpf(wpfFontFamily); #else fontFamily = XFontFamily.GetOrCreateFromWpf(new WpfFontFamily(familyName)); #endif #endif #if NETFX_CORE || UWP fontFamily = null; #endif } else { // Create new and exclusively used font family for custom font resolver retrieved font source. fontFamily = XFontFamily.CreateSolitary(fontResolverInfo.FaceName); } // We have a valid font resolver info. That means we also have an XFontSource object loaded in the cache. ////XFontSource fontSource = FontFactory.GetFontSourceByTypefaceKey(fontResolverInfo.FaceName); XFontSource fontSource = FontFactory.GetFontSourceByFontName(fontResolverInfo.FaceName); Debug.Assert(fontSource != null); // Each font source already contains its OpenTypeFontface. #if CORE || GDI glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, gdiFont); #endif #if WPF glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations, wpfTypeface, wpfGlyphTypeface); #endif #if NETFX_CORE || UWP glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations); #endif GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); return(glyphTypeface); }
/// <summary> /// Initializes a new instance of the <see cref="XFont" /> class from a System.Windows.Media.Typeface. /// </summary> /// <param name="typeface">The System.Windows.Media.Typeface.</param> /// <param name="emSize">The em size.</param> public XFont(WpfTypeface typeface, double emSize) : this(typeface, emSize, new XPdfFontOptions(GlobalFontSettings.DefaultFontEncoding)) { }