public ResolvedFont ResolveFont(RequestFont font) { //cache level-1 (attached inside the request font) ResolvedFont resolvedFont = RequestFont.GetResolvedFont1 <ResolvedFont>(font); if (resolvedFont != null) { return(resolvedFont); } Typeface typeface; if (font.Src != null) { //this may not be loaded //so check if we have that file or not typeface = _installedTypefaceCollection.ResolveTypefaceFromFile(font.Src); if (typeface != null) { //found //TODO: handle FontStyle *** resolvedFont = new ResolvedFont(typeface, font.SizeInPoints); RequestFont.SetResolvedFont1(font, resolvedFont); return(resolvedFont); } } //cache level-2 (stored in this openfont service) int reqKey = font.GetReqKey(); if (_resolvedTypefaceCache.TryGetValue(reqKey, out resolvedFont)) { if (resolvedFont.Typeface == null) { //this is 'not found' resovled font //so don't return it return(null); } //---- //cache to level-1 RequestFont.SetResolvedFont1(font, resolvedFont); return(resolvedFont); } //----- //when not found //find it if ((typeface = _installedTypefaceCollection.ResolveTypeface(font.Name, PixelFarm.Drawing.FontStyleExtensions.ConvToInstalledFontStyle(font.Style), font.WeightClass)) == null) { //this come from other choices? int otherChoiceCount; if ((otherChoiceCount = font.OtherChoicesCount) > 0) { for (int i = 0; i < otherChoiceCount; ++i) { resolvedFont = ResolveFont(font.GetOtherChoice(i)); if (resolvedFont != null) { RequestFont.SetResolvedFont1(font, resolvedFont); return(resolvedFont); } } } //still not found if (typeface == null) { //we don't cache it in central service //open opportunity for another search //_resolvedTypefaceCache.Add(font.FontKey, ResolvedFont.s_empty); return(null); } return(null); } else { resolvedFont = new ResolvedFont(typeface, font.SizeInPoints); //cache to level2 _resolvedTypefaceCache.Add(reqKey, resolvedFont); RequestFont.SetResolvedFont1(font, resolvedFont); return(resolvedFont); } }
public override SelectedTypeface Select(List <InstalledTypeface> choices, UnicodeRangeInfo unicodeRangeInfo, int hintCodePoint) { //request font may have hint for typeface if (_reqFont != null) { for (int i = 0; i < _reqFont.OtherChoicesCount; ++i) { RequestFont.Choice choice = _reqFont.GetOtherChoice(i); ResolvedFont resolvedFont = _textService.ResolveFont(choice); //check if resolvedFont support specific unicodeRange info or not Typeface typeface = resolvedFont.Typeface; ushort codepoint = typeface.GetGlyphIndex(unicodeRangeInfo.StartCodepoint); if (codepoint > 0) { //use this return(new SelectedTypeface(typeface)); } } } List <PreferredTypeface> list = null; if (unicodeRangeInfo == Unicode13RangeInfoList.Emoticons) { list = _emojiPreferList; } else if (_dics.TryGetValue(unicodeRangeInfo.Name, out PreferredTypefaceList foundList)) { list = foundList; } if (list != null) { int j = list.Count; for (int i = 0; i < j; ++i) { //select that first one PreferredTypeface p = list[i]; if (p.InstalledTypeface == null && !p.ResolvedInstalledTypeface) { //find int choice_count = choices.Count; for (int m = 0; m < choice_count; ++m) { InstalledTypeface instTypeface = choices[m]; if (p.RequestTypefaceName == instTypeface.FontName) { //TODO: review here again p.InstalledTypeface = instTypeface; break; } } p.ResolvedInstalledTypeface = true; } //------- if (p.InstalledTypeface != null) { return(new SelectedTypeface(p.InstalledTypeface)); } } } //still not found if (choices.Count > 0) { //choose default return(new SelectedTypeface(choices[0])); } return(new SelectedTypeface());//empty }
public ResolvedFont ResolveFont(RequestFont.Choice choice) { ResolvedFont resolvedFont = RequestFont.Choice.GetResolvedFont1 <ResolvedFont>(choice); if (resolvedFont != null) { return(resolvedFont); } Typeface typeface; if (choice.Src != null) //specific path to... { //this may not be loaded //so check if we have that file or not typeface = _installedTypefaceCollection.ResolveTypefaceFromFile(choice.Src); if (typeface != null) { //found //TODO: handle FontStyle *** resolvedFont = new ResolvedFont(typeface, choice.SizeInPoints); RequestFont.Choice.SetResolvedFont1(choice, resolvedFont); return(resolvedFont); } } int reqKey = choice.GetReqKey(); //cache level-2 (stored in this openfont service) if (_resolvedTypefaceCache.TryGetValue(reqKey, out resolvedFont)) { if (resolvedFont.Typeface == null) { //this is 'not found' resovled font //so don't return it return(null); } //---- //cache to level-1 RequestFont.Choice.SetResolvedFont1(choice, resolvedFont); return(resolvedFont); } //----- //when not found //find it if ((typeface = _installedTypefaceCollection.ResolveTypeface(choice.Name, PixelFarm.Drawing.FontStyleExtensions.ConvToInstalledFontStyle(choice.Style), choice.WeightClass)) != null) { //NOT NULL=> found if (!_resolvedTypefaceCache.TryGetValue(reqKey, out resolvedFont)) { resolvedFont = new ResolvedFont(typeface, choice.SizeInPoints); //** cache it with otherChoice.GetFontKey()** _resolvedTypefaceCache.Add(reqKey, resolvedFont); } return(resolvedFont); } return(null); }