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
        }
Esempio n. 2
0
        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);
        }