Пример #1
0
        void ShowSupportedScripts(InstalledTypeface installedTypeface)
        {
            //show supported lang

            lstScriptLangs.Items.Clear();

            Dictionary <string, ScriptLang> dic = new Dictionary <string, ScriptLang>();

            installedTypeface.CollectScriptLang(dic);
            foreach (var kv in dic)
            {
                ScriptLang s = kv.Value;
                if (s.sysLangTag != 0 && LanguageSystemNames.TryGetLangSystem(s.GetScriptTagString(), out LangSys found))
                {
                }
                else
                {
                }
                lstScriptLangs.Items.Add(s);
            }


            lstSupportedUnicodeLangs.Items.Clear();

            foreach (BitposAndAssciatedUnicodeRanges bitposAndUnicodeRanges in installedTypeface.GetSupportedUnicodeLangIter())
            {
                lstSupportedUnicodeLangs.Items.Add(bitposAndUnicodeRanges.ToString());
            }
        }
Пример #2
0
        public Typeface GetTypeface(string name, TypefaceStyle installedFontStyle)
        {
            InstalledTypeface inst = _installedTypefaceCollection.GetInstalledTypeface(name, InstalledTypefaceCollection.GetSubFam(installedFontStyle));

            if (inst != null)
            {
                return(typefaceStore.GetTypeface(inst));
            }
            return(null);
        }
Пример #3
0
 void ChangeSelectedTypeface(InstalledTypeface typeface)
 {
     if (typeface == null)
     {
         return;
     }
     //
     _options.InstalledTypeface = typeface;
     _options.InvokeAttachEvents();
     _txtTypefaceInfo.Text = "file: " + typeface.FontPath + "\r\n" + "weight:" + typeface.Weight;
 }
Пример #4
0
        void SetupFontList()
        {
            InstalledTypeface selectedInstalledTypeface = null;
            int  selected_index = 0;
            int  ffcount        = 0;
            bool found          = false;


            var tempList = new System.Collections.Generic.List <InstalledTypeface>();

            tempList.AddRange(_options.GetInstalledTypefaceIter());
            tempList.Sort((f1, f2) => f1.ToString().CompareTo(f2.ToString()));

            //add to list and find default font
            string defaultFont = "Tahoma";

            //string defaultFont = "Alef"; //test hebrew
            //string defaultFont = "Century";
            foreach (InstalledTypeface installedTypeface in tempList)
            {
                if (!found && installedTypeface.FontName == defaultFont)
                {
                    selectedInstalledTypeface  = installedTypeface;
                    selected_index             = ffcount;
                    _options.InstalledTypeface = installedTypeface;
                    found = true;
                }
                lstFontList.Items.Add(installedTypeface);
                ffcount++;
            }
            //set default font for current text printer
            //


            if (selected_index < 0)
            {
                selected_index = 0;
            }



            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledTypeface ff = lstFontList.SelectedItem as InstalledTypeface;
                if (ff != null)
                {
                    _options.InstalledTypeface = ff;
                    _options.InvokeAttachEvents();
                }
            };
        }
Пример #5
0
        public WinGdiFontFace(RequestFont f)
        {
            _style = f.Style;
            //resolve
            InstalledTypeface foundInstalledFont = s_installedTypefaceProvider.GetInstalledTypeface(f.Name, _style.ConvToInstalledFontStyle());

            //TODO: review
            if (foundInstalledFont == null)
            {
                //not found
            }
            _nopenTypeFontFace = OpenFontLoader.LoadFont(foundInstalledFont.FontPath);
        }
Пример #6
0
        void ChangeSelectedTypeface(InstalledTypeface installedTypeface)
        {
            if (installedTypeface == null)
            {
                return;
            }
            //
            _options.InstalledTypeface = installedTypeface;
            _options.InvokeAttachEvents();
            _txtTypefaceInfo.Text = "file: " + installedTypeface.FontPath + "\r\n" + "weight:" + installedTypeface.WeightClass;

            //
            ShowSupportedScripts(installedTypeface);
        }
Пример #7
0
        public static Typeface ResolveTypefaceFromFile(this InstalledTypefaceCollection fontCollection, string filename)
        {
            //from user input typeface filename

            bool enable_absPath = false; //enable abs path or not

#if DEBUG
            enable_absPath = true;//in debug mode
#endif
            //TODO: review here again!!!
            if (!fontCollection._installedTypefacesByFilenames.TryGetValue(filename, out InstalledTypeface found))
            {
                if (!enable_absPath && Path.IsPathRooted(filename))
                {
                    return(null);//***
                }

                //search for a file
                if (File.Exists(filename))
                {
                    //TODO: handle duplicated font!!
                    //try read this
                    InstalledTypeface instTypeface;
                    using (FileStream fs = new FileStream(filename, FileMode.Open))
                    {
                        OpenFontReader reader   = new OpenFontReader();
                        Typeface       typeface = reader.Read(fs);

                        //
                        OpenFont.Extensions.TypefaceExtensions.SetCustomTypefaceKey(
                            typeface,
                            TinyCRC32Calculator.CalculateCrc32(typeface.Name.ToUpper()));

                        instTypeface = new InstalledTypeface(typeface, filename);
                        fontCollection._installedTypefacesByFilenames.Add(filename, instTypeface);

                        return(instTypeface.ResolvedTypeface = typeface);//assign  and return
                    }
                }
            }
            else
            {
                //found inst type
                return(ResolveTypeface(fontCollection, found));
            }
            return(null);
        }
Пример #8
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            InstalledTypefaceCollection collection = new InstalledTypefaceCollection();

            collection.LoadSystemFonts();
            InstalledTypeface tahomaFont = collection.GetInstalledTypeface("tahoma", TypefaceStyle.Regular);
            FontFace          tahomaFace = OpenFontLoader.LoadFont(tahomaFont.FontPath);
            ActualFont        actualFont = tahomaFace.GetFontAtPointSize(72);
            FontGlyph         glyph      = (FontGlyph)actualFont.GetGlyph('K');


            _glyph_vx = _painter.CreateRenderVx(_tempSnap1 = glyph.flattenVxs);

            _linearGrBrush2 = new LinearGradientBrush(
                new PointF(0, 0), new PointF(100, 100),
                Color.Red, Color.Black);
        }
Пример #9
0
        internal static SkiaSharp.SKTypeface GetInstalledFont(string typefaceName)
        {
            InstalledTypeface installedFont = s_installedTypefaceProvider.GetInstalledTypeface(typefaceName, Typography.FontManagement.TypefaceStyle.Regular);

            if (installedFont == null)
            {
                return(null);
            }
            else
            {
                SkiaSharp.SKTypeface loadedTypeFace;
                if (!skTypeFaces.TryGetValue(installedFont, out loadedTypeFace))
                {
                    loadedTypeFace = SkiaSharp.SKTypeface.FromFile(installedFont.FontPath);
                    skTypeFaces.Add(installedFont, loadedTypeFace);
                }
                return(loadedTypeFace);
            }
        }
Пример #10
0
        Typeface GetTypefaceOrCreateNew(InstalledTypeface installedFont)
        {
            //load
            //check if we have create this typeface or not
            Typeface typeface;

            if (!_loadedTypefaces.TryGetValue(installedFont, out typeface))
            {
                //TODO: review how to load font here
                using (var fs = new FileStream(installedFont.FontPath, FileMode.Open, FileAccess.Read))
                {
                    var reader = new OpenFontReader();
                    typeface          = reader.Read(fs);
                    typeface.Filename = installedFont.FontPath;
                }
                return(_loadedTypefaces[installedFont] = typeface);
            }
            return(typeface);
        }
        void SetupFontList()
        {
            InstalledTypeface selectedInstalledTypeface = null;
            int  selected_index = 0;
            int  ffcount        = 0;
            bool found          = false;

            string defaultFont = "Tahoma";

            //string defaultFont = "Alef"; //test hebrew
            //string defaultFont = "Century";
            foreach (InstalledTypeface installedTypeface in _options.GetInstalledTypefaceIter())
            {
                if (!found && installedTypeface.FontName == defaultFont)
                {
                    selectedInstalledTypeface  = installedTypeface;
                    selected_index             = ffcount;
                    _options.InstalledTypeface = installedTypeface;
                    found = true;
                }
                lstFontList.Items.Add(installedTypeface);
                ffcount++;
            }
            //set default font for current text printer
            //


            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledTypeface ff = lstFontList.SelectedItem as InstalledTypeface;
                if (ff != null)
                {
                    _options.InstalledTypeface = ff;
                    _options.InvokeAttachEvents();
                }
            };
        }
Пример #12
0
 public Typeface GetTypeface(InstalledTypeface installedFont)
 {
     return(GetTypefaceOrCreateNew(installedFont));
 }
Пример #13
0
 public static IEnumerable <BitposAndAssciatedUnicodeRanges> GetSupportedUnicodeLangIter(this InstalledTypeface instTypeface)
 {
     //check all 0-125 bits
     for (int i = 0; i <= OpenFontBitPosInfo.MAX_BITPOS; ++i)
     {
         if (instTypeface.DoesSupportUnicode(i))
         {
             yield return(OpenFontBitPosInfo.GetUnicodeRanges(i));
         }
     }
 }
Пример #14
0
        public Form1()
        {
            InitializeComponent();

            //choose Thai script for 'complex script' testing.
            //you can change this to test other script.


            _txtServiceClient              = OurOpenFontSystem.CreateTextServiceClient();
            _currentTextPrinter            = new DevGdiTextSpanPrinter(_txtServiceClient);
            _currentTextPrinter.ScriptLang = new ScriptLang(ScriptTagDefs.Latin.Tag);


            //----------
            button1.Click += (s, e) => UpdateRenderOutput();
            //simple load test fonts from local test dir
            //and send it into test list
            chkFillBackground.Checked         = true;
            chkBorder.CheckedChanged         += (s, e) => UpdateRenderOutput();
            chkFillBackground.CheckedChanged += (s, e) => UpdateRenderOutput();
            //----------
            cmbPositionTech.Items.Add(PositionTechnique.OpenFont);
            cmbPositionTech.Items.Add(PositionTechnique.Kerning);
            cmbPositionTech.Items.Add(PositionTechnique.None);
            cmbPositionTech.SelectedIndex         = 0;
            cmbPositionTech.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //----------
            lstHintList.Items.Add(HintTechnique.None);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction);
            lstHintList.Items.Add(HintTechnique.TrueTypeInstruction_VerticalOnly);
            //lstHintList.Items.Add(HintTechnique.CustomAutoFit);
            lstHintList.SelectedIndex         = 0;
            lstHintList.SelectedIndexChanged += (s, e) => UpdateRenderOutput();
            //----------
            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            //
            //----------
            //show result
            InstalledTypeface selectedFF = null;
            int  selected_index          = 0;
            int  ffcount = 0;
            bool found   = false;

            foreach (InstalledTypeface ff in OurOpenFontSystem.GetInstalledTypefaceIter())
            {
                if (!found && ff.FontName == "Source Sans Pro")
                {
                    selectedFF     = ff;
                    selected_index = ffcount;
                    found          = true;
                }
                lstFontList.Items.Add(ff);
                ffcount++;
            }
            //set default font for current text printer
            //

            //set default font for current text printer
            _currentTextPrinter.Typeface = OurOpenFontSystem.ResolveTypeface(selectedFF);


            //Alternative Typeface Selector
            {
                AlternativeTypefaceSelector alternativeTypefaceSelector = new AlternativeTypefaceSelector();
                PreferredTypefaceList       preferredTypefaces          = new PreferredTypefaceList();
                preferredTypefaces.AddTypefaceName("Segoe UI Emoji");
                alternativeTypefaceSelector.SetPerferredEmoji(preferredTypefaces);

                //set alternative typeface selector to printer
                _currentTextPrinter.AlternativeTypefaceSelector = alternativeTypefaceSelector;
            }

            //----------
#if DEBUG
            //test get font from typeface store
            //InstalledTypeface instFont = OurOpenFontSystem.GetFontCollection().GetFontByPostScriptName("SourceSansPro-Regular");
#endif

            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                if (lstFontList.SelectedItem is InstalledTypeface ff)
                {
                    _currentTextPrinter.Typeface = OurOpenFontSystem.ResolveTypeface(ff);
                    //sample text box
                    UpdateRenderOutput();
                }
            };
            //----------
            lstFontSizes.Items.AddRange(
                new object[] {
                8, 9,
                10, 11,
                12,
                14,
                16,
                18, 20, 22, 24, 26, 28, 36, 48, 72, 240, 300, 360
            });
            lstFontSizes.SelectedIndexChanged += (s, e) =>
            {
                //new font size
                _currentTextPrinter.FontSizeInPoints = (int)lstFontSizes.SelectedItem;
                UpdateRenderOutput();
            };
            lstFontSizes.SelectedIndex = 0;
            this.Text = "Gdi+ Sample";
            //------
        }
Пример #15
0
        public static Typeface ResolveTypeface(this InstalledTypefaceCollection fontCollection, string fontName, TypefaceStyle style, ushort weight)
        {
            InstalledTypeface inst = fontCollection.GetInstalledTypeface(fontName, style /*InstalledTypefaceCollection.GetSubFam(style)*/, weight);

            return((inst != null) ? fontCollection.ResolveTypeface(inst) : null);
        }
        public static void SetupDefaultValues()
        {
            if (s_intalledTypefaces != null)
            {
                return;
            }

            s_intalledTypefaces = new InstalledTypefaceCollection();
            s_intalledTypefaces.SetFontNameDuplicatedHandler((existing, newone) => FontNameDuplicatedDecision.Skip);

            s_intalledTypefaces.SetFontNotFoundHandler((collection, fontName, subFam) =>
            {
                //This is application specific ***
                //
                switch (fontName.ToUpper())
                {
                default:
                    {
                    }
                    break;

                case "SANS-SERIF":
                    {
                        //temp fix
                        InstalledTypeface ss = collection.GetInstalledTypeface("Microsoft Sans Serif", "REGULAR");
                        if (ss != null)
                        {
                            return(ss);
                        }
                    }
                    break;

                case "SERIF":
                    {
                        //temp fix
                        InstalledTypeface ss = collection.GetInstalledTypeface("Palatino linotype", "REGULAR");
                        if (ss != null)
                        {
                            return(ss);
                        }
                    }
                    break;

                case "TAHOMA":
                    {
                        switch (subFam)
                        {
                        case "ITALIC":
                            {
                                InstalledTypeface anotherCandidate = collection.GetInstalledTypeface(fontName, "NORMAL");
                                if (anotherCandidate != null)
                                {
                                    return(anotherCandidate);
                                }
                            }
                            break;
                        }
                    }
                    break;

                case "MONOSPACE":
                    //use Courier New
                    return(collection.GetInstalledTypeface("Courier New", subFam));

                case "HELVETICA":
                    return(collection.GetInstalledTypeface("Arial", subFam));
                }
                return(null);
            });


            //if you don't want to load entire system fonts
            //then you can add only specfic font by yourself
            //when the service can' resolve the requested font
            //=> the service will ask at 'SetFontNotFoundHandler'

            s_intalledTypefaces.LoadSystemFonts();
            //--------------------
            InstalledTypefaceCollection.SetAsSharedTypefaceCollection(s_intalledTypefaces);
        }
Пример #17
0
 public static void SetTypefaceName(BindableObject view, InstalledTypeface value)
 {
     view.SetValue(TypefaceNameProperty, value);
 }
Пример #18
0
            public static void Setup()
            {
                if (s_intalledTypefaces != null)
                {
                    //once
                    return;
                }
                s_intalledTypefaces = new InstalledTypefaceCollection();
                s_intalledTypefaces.SetFontNameDuplicatedHandler((existing, newone) => FontNameDuplicatedDecision.Skip);

                s_intalledTypefaces.SetFontNotFoundHandler((InstalledTypefaceCollection collection,
                                                            string fontName,
                                                            TypefaceStyle style,
                                                            ushort weightClass,
                                                            InstalledTypeface available,
                                                            List <InstalledTypeface> availableList) =>
                {
                    //This is application specific ***
                    //
                    switch (fontName.ToUpper())
                    {
                    default:
                        {
                        }
                        break;

                    case "SANS-SERIF":
                        {
                            //temp fix
                            InstalledTypeface ss = collection.GetInstalledTypeface("Microsoft Sans Serif", TypefaceStyle.Regular, (ushort)RequestFontWeight.Normal);
                            if (ss != null)
                            {
                                return(ss);
                            }
                        }
                        break;

                    case "SERIF":
                        {
                            //temp fix
                            InstalledTypeface ss = collection.GetInstalledTypeface("Palatino linotype", TypefaceStyle.Regular, (ushort)RequestFontWeight.Normal);
                            if (ss != null)
                            {
                                return(ss);
                            }
                        }
                        break;

                    case "TAHOMA":
                        {
                            switch (style)
                            {
                            case TypefaceStyle.Italic:
                                {
                                    InstalledTypeface anotherCandidate = collection.GetInstalledTypeface(fontName, TypefaceStyle.Italic, (ushort)RequestFontWeight.Normal);
                                    if (anotherCandidate != null)
                                    {
                                        return(anotherCandidate);
                                    }
                                }
                                break;
                            }
                        }
                        break;

                    case "MONOSPACE":
                        //use Courier New
                        return(collection.GetInstalledTypeface("Courier New", TypefaceStyle.Regular, (ushort)RequestFontWeight.Normal));

                    case "HELVETICA":
                        return(collection.GetInstalledTypeface("Arial", TypefaceStyle.Regular, (ushort)RequestFontWeight.Normal));
                    }
                    return(null);
                });


                //if you don't want to load entire system fonts
                //then you can add only specfic font by yourself
                //when the service can' resolve the requested font

                s_intalledTypefaces.LoadSystemFonts();
                s_intalledTypefaces.LoadFontsFromFolder(@"D:\projects\Typography\Demo\Windows\TestFonts");         //demo
                s_intalledTypefaces.LoadFontsFromFolder(@"D:\projects\Typography\Demo\Windows\Test_PrivateFonts"); //demo
                s_intalledTypefaces.UpdateUnicodeRanges();

                YourImplementation.CommonTextServiceSetup.SetInstalledTypefaceCollection(s_intalledTypefaces);
                InstalledTypefaceCollection.SetAsSharedTypefaceCollection(s_intalledTypefaces);
            }
Пример #19
0
 public static Typeface ResolveTypeface(InstalledTypeface instTypeface)
 {
     return(s_installedTypefaceCollection.ResolveTypeface(instTypeface));
 }
        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
        }
Пример #21
0
        public static Typeface ResolveTypeface(this InstalledTypefaceCollection fontCollection, InstalledTypeface installedFont)
        {
            if (installedFont.ResolvedTypeface != null)
            {
                return(installedFont.ResolvedTypeface);
            }

            //load
            Typeface typeface;

            if (CustomFontStreamLoader != null)
            {
                using (var fontStream = CustomFontStreamLoader(installedFont.FontPath))
                {
                    var reader = new OpenFontReader();
                    typeface          = reader.Read(fontStream, installedFont.ActualStreamOffset);
                    typeface.Filename = installedFont.FontPath;
                    installedFont.ResolvedTypeface = typeface;//cache
                }
            }
            else
            {
                using (var fs = new FileStream(installedFont.FontPath, FileMode.Open, FileAccess.Read))
                {
                    var reader = new OpenFontReader();
                    typeface          = reader.Read(fs, installedFont.ActualStreamOffset);
                    typeface.Filename = installedFont.FontPath;
                    installedFont.ResolvedTypeface = typeface;//cache
                }
            }

            //calculate typeface key for the new create typeface
            //custom key

            OpenFont.Extensions.TypefaceExtensions.SetCustomTypefaceKey(
                typeface,
                TinyCRC32Calculator.CalculateCrc32(typeface.Name.ToUpper()));

            return(typeface);
        }