/// <summary>
        /// use vertex buffer object
        /// </summary>

        public GLBitmapGlyphTextPrinter(GLPainter painter, OpenFontTextService textServices)
        {
            //create text printer for use with canvas painter
            _painter = painter;
            _pcx     = painter.Core;

            _txtClient = textServices.CreateNewServiceClient();

            //_currentTextureKind = TextureKind.Msdf;
            //_currentTextureKind = TextureKind.StencilGreyScale;

            _myGLBitmapFontMx = new MySimpleGLBitmapFontManager(textServices);

            //--------
            //load preview of pre-built texture font
            //temp fix, TODO: review this again
            string[] maybeTextureInfoFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.tx_info");
            if (maybeTextureInfoFiles.Length > 0)
            {
                for (int i = 0; i < maybeTextureInfoFiles.Length; ++i)
                {
                    //try read
                    using (FileStream fs = new FileStream(maybeTextureInfoFiles[i], FileMode.Open))
                    {
                        try
                        {
                            _myGLBitmapFontMx.LoadBitmapAtlasPreview(fs);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }



            //LoadFontAtlas("tahoma_set1.multisize_fontAtlas", "tahoma_set1.multisize_fontAtlas.png");

            //test textures...

            //GlyphPosPixelSnapX = GlyphPosPixelSnapKind.Integer;
            //GlyphPosPixelSnapY = GlyphPosPixelSnapKind.Integer;
            //**
            //ChangeFont(painter.CurrentFont);
            //
            //TextDrawingTechnique = GlyphTexturePrinterDrawingTechnique.LcdSubPixelRendering; //default
            TextDrawingTechnique = GlyphTexturePrinterDrawingTechnique.Stencil; //default
            UseVBO = true;

            TextBaseline = PixelFarm.Drawing.TextBaseline.Top;
            //TextBaseline = TextBaseline.Alphabetic;
            //TextBaseline = TextBaseline.Bottom;


            //TODO: temp fix,
            //...
            var myAlternativeTypefaceSelector = new AlternativeTypefaceSelector();

            {
                var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                preferTypefaces.AddTypefaceName("Source Sans Pro");
                preferTypefaces.AddTypefaceName("Sarabun");


                myAlternativeTypefaceSelector.SetPreferredTypefaces(
                    new[] { Typography.TextBreak.Unicode13RangeInfoList.C0_Controls_and_Basic_Latin,
                            Typography.TextBreak.Unicode13RangeInfoList.C1_Controls_and_Latin_1_Supplement,
                            Typography.TextBreak.Unicode13RangeInfoList.Latin_Extended_A,
                            Typography.TextBreak.Unicode13RangeInfoList.Latin_Extended_B, },
                    preferTypefaces);
            }
            {
                var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                preferTypefaces.AddTypefaceName("Twitter Color Emoji");
                myAlternativeTypefaceSelector.SetPerferredEmoji(preferTypefaces);
            }

            AlternativeTypefaceSelector = myAlternativeTypefaceSelector;
        }
Пример #2
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";
            //------
        }