const string KeyPrefix = "tk:"; // "typeface key" XGlyphTypeface(string key, XFontFamily fontFamily, XFontSource fontSource, XStyleSimulations styleSimulations) { _key = key; _fontFamily = fontFamily; _fontSource = fontSource; _fontface = OpenTypeFontface.CetOrCreateFrom(fontSource); Debug.Assert(ReferenceEquals(_fontSource.Fontface, _fontface)); _styleSimulations = styleSimulations; Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="XGlyphTypeface"/> class by a font source. /// </summary> public XGlyphTypeface(XFontSource fontSource) { string familyName = fontSource.Fontface.name.Name; _fontFamily = new XFontFamily(familyName, false); _fontface = fontSource.Fontface; _isBold = _fontface.os2.IsBold; _isItalic = _fontface.os2.IsItalic; _key = ComputeKey(familyName, _isBold, _isItalic); //_fontFamily =xfont FontFamilyCache.GetFamilyByName(familyName); _fontSource = fontSource; Initialize(); }
//public XFontFamily(GdiFontFamily gdiFontFamily) //{ // FamilyInternal = FontFamilyInternal.GetOrCreateFromGdi(gdiFontFamily); //} #endif #if WPF //public XFontFamily(WpfFontFamily wpfFontFamily) //{ // FamilyInternal = FontFamilyInternal.GetOrCreateFromWpf(wpfFontFamily); // //// HACK // //int idxHash = _name.LastIndexOf('#'); // //if (idxHash > 0) // // _name = _name.Substring(idxHash + 1); // //_wpfFamily = family; //} #endif internal static XFontFamily CreateFromName_not_used(string name, bool createPlatformFamily) { XFontFamily fontFamily = new XFontFamily(name); if (createPlatformFamily) { #if GDI //fontFamily._gdiFamily = new System.Drawing.FontFamily(name); #endif #if WPF //fontFamily._wpfFamily = new System.Windows.Media.FontFamily(name); #endif } return(fontFamily); }
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."); } // Now create the font family at the first. // Create new and exclusively used font family for custom font resolver retrieved font source. XFontFamily 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. glyphTypeface = new XGlyphTypeface(typefaceKey, fontFamily, fontSource, fontResolverInfo.StyleSimulations); GlyphTypefaceCache.AddGlyphTypeface(glyphTypeface); return(glyphTypeface); }