//private string CreateFont(string fontName, float fontSize, CCRawList<char> charset) private Font CreateFont(string fontName, float fontSize) { Font _currentFont; if (Factory2D == null) { Factory2D = new SharpDX.Direct2D1.Factory(); FactoryDWrite = new SharpDX.DirectWrite.Factory(); FactoryImaging = new SharpDX.WIC.ImagingFactory(); dpi = Factory2D.DesktopDpi; dpiScale = dpi.Height / 72f; } _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true); if (_defaultFont == null) { _defaultFont = GenericSanSerif(); } FontFamily fontFamily = GetFontFamily(fontName); FontCollection fontCollection; if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection)) { var ext = Path.GetExtension(fontName); if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf") { try { var fileFontLoader = new FileFontLoader(FactoryDWrite, fontName); var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key); _currentFontCollection = fileFontCollection; fontFamily = _currentFontCollection.GetFontFamily(0); var ffn = fontFamily.FamilyNames; _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal); _fontCollectionCache.Add(fontName, fileFontCollection); _currentFontCollection = fileFontCollection; } catch { _currentFont = GetFont(fontName, fontSize); CCLog.Log("{0} not found. Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0)); } } else { _currentFont = GetFont(fontName, fontSize); } } else { fontFamily = fontCollection.GetFontFamily(0); _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal); _currentFontCollection = fontCollection; } return _currentFont; }
//private string CreateFont(string fontName, float fontSize, CCRawList<char> charset) private Font CreateFont(string fontName, float fontSize) { Font _currentFont; if (Factory2D == null) { Factory2D = new SharpDX.Direct2D1.Factory(); FactoryDWrite = new SharpDX.DirectWrite.Factory(); FactoryImaging = new SharpDX.WIC.ImagingFactory(); dpi = Factory2D.DesktopDpi; dpiScale = dpi.Height / 72f; } _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true); if (_defaultFont == null) { _defaultFont = GenericSanSerif(); } FontFamily fontFamily = GetFontFamily(fontName); FontCollection fontCollection; if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection)) { var ext = Path.GetExtension(fontName); if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf") { try { var fileFontLoader = new FileFontLoader(FactoryDWrite, fontName); var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key); _currentFontCollection = fileFontCollection; fontFamily = _currentFontCollection.GetFontFamily(0); var ffn = fontFamily.FamilyNames; _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal); _fontCollectionCache.Add(fontName, fileFontCollection); _currentFontCollection = fileFontCollection; } catch { _currentFont = GetFont(fontName, fontSize); CCLog.Log("{0} not found. Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0)); } } else { _currentFont = GetFont(fontName, fontSize); } } else { fontFamily = fontCollection.GetFontFamily(0); _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal); _currentFontCollection = fontCollection; } return(_currentFont); }