Exemplo n.º 1
0
        public Size MeasureString(char[] str, int startAt, int len, RequestFont font)
        {
            //resolve type face
            Typeface typeface = typefaceStore.GetTypeface(font.Name, InstalledFontStyle.Normal);

            glyphLayout.Typeface = typeface;
            MeasuredStringBox result;
            float             scale = typeface.CalculateToPixelScaleFromPointSize(font.SizeInPoints);

            //measure string at specific px scale
            glyphLayout.MeasureString(str, startAt, len, out result, scale);

            return(new Size((int)result.width, (int)result.CalculateLineHeight()));
        }
Exemplo n.º 2
0
        public Form2()
        {
            InitializeComponent();

            //choose Thai script for 'complex script' testing.
            //you can change this to test other script.
            _currentTextPrinter.ScriptLang = Typography.OpenFont.ScriptLangs.Latin;
            //----------
            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();

            //----------
            //share text printer to our sample textbox
            //but you can create another text printer that specific to text textbox control
            _textBoxControllerForGdi.TextPrinter = _currentTextPrinter;
            _textBoxControllerForGdi.BindHostGraphics(this.sampleTextBox1.CreateGraphics());

            this.sampleTextBox1.SetController(_textBoxControllerForGdi);

            //----------
            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            //1. create font collection
            installedFontCollection = new InstalledFontCollection();
            //set some essential handler
            installedFontCollection.SetFontNameDuplicatedHandler((f1, f2) => FontNameDuplicatedDecision.Skip);
            foreach (string file in Directory.GetFiles("../../../TestFonts", "*.ttf"))
            {
                //eg. this is our custom font folder
                installedFontCollection.AddFont(new FontFileStreamProvider(file));
            }
            //
            _typefaceStore = new TypefaceStore();
            _typefaceStore.FontCollection = installedFontCollection;

            //----------
            //show result
            InstalledFont selectedFF     = null;
            int           selected_index = 0;
            int           ffcount        = 0;
            bool          found          = false;

            foreach (InstalledFont ff in installedFontCollection.GetInstalledFontIter())
            {
                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
            _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(selectedFF.FontName, selectedFF.FontSubFamily);
            //----------

            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledFont ff = lstFontList.SelectedItem as InstalledFont;
                if (ff != null)
                {
                    //direct set
                    _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(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";
            //------
        }
Exemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();



            _devGdiTextPrinter          = new DevGdiTextPrinter();
            this.sampleTextBox1.Visible = false;
            _openFontStore = new OpenFontStore();

            //default
            //set script lang,
            //test with Thai for 'complex script'
            _current_script = Typography.OpenFont.ScriptLangs.Latin;
            _devGdiTextPrinter.ScriptLang        = _current_script;
            _devGdiTextPrinter.PositionTechnique = PositionTechnique.OpenFont;


            this.Load += new EventHandler(Form1_Load);

            this.txtGridSize.KeyDown += TxtGridSize_KeyDown;
            //----------
            txtInputChar.TextChanged += (s, e) => UpdateRenderOutput();
            //----------
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithTextPrinterAndMiniAgg);
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithMiniAgg_SingleGlyph);
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithGdiPlusPath);
            cmbRenderChoices.Items.Add(RenderChoice.RenderWithMsdfGen);
            cmbRenderChoices.SelectedIndex         = 0;
            cmbRenderChoices.SelectedIndexChanged += (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();
            //edge offset
            lstEdgeOffset.Items.Add(0f);
            lstEdgeOffset.Items.Add(-10f);
            lstEdgeOffset.Items.Add(-8f);
            lstEdgeOffset.Items.Add(-6f);
            lstEdgeOffset.Items.Add(-4f);
            lstEdgeOffset.Items.Add(4f);
            lstEdgeOffset.Items.Add(6f);
            lstEdgeOffset.Items.Add(8f);
            lstEdgeOffset.Items.Add(10f);
            lstEdgeOffset.SelectedIndex         = 0;
            lstEdgeOffset.SelectedIndexChanged += (s, e) => UpdateRenderOutput();

            //share text printer to our sample textbox
            //but you can create another text printer that specific to text textbox control
            Graphics gx = this.sampleTextBox1.CreateGraphics();

            _controllerForGdi.BindHostGraphics(gx);
            _controllerForGdi.TextPrinter = _devGdiTextPrinter;
            //----------
            _controllerForPixelFarm.BindHostGraphics(gx);
            _controllerForPixelFarm.TextPrinter = _devVxsTextPrinter;

            //----------
            this.sampleTextBox1.SetController(_controllerForPixelFarm);


            button1.Click += (s, e) => UpdateRenderOutput();
            chkShowGrid.CheckedChanged           += (s, e) => UpdateRenderOutput();
            chkShowTess.CheckedChanged           += (s, e) => UpdateRenderOutput();
            chkXGridFitting.CheckedChanged       += (s, e) => UpdateRenderOutput();
            chkYGridFitting.CheckedChanged       += (s, e) => UpdateRenderOutput();
            chkFillBackground.CheckedChanged     += (s, e) => UpdateRenderOutput();
            chkLcdTechnique.CheckedChanged       += (s, e) => UpdateRenderOutput();
            chkGsubEnableLigature.CheckedChanged += (s, e) => UpdateRenderOutput();
            //----------
            chkShowTess.CheckedChanged                     += (s, e) => UpdateRenderOutput();
            chkDrawCentroidBone.CheckedChanged             += (s, e) => UpdateRenderOutput();
            chkDrawGlyphBone.CheckedChanged                += (s, e) => UpdateRenderOutput();
            chkDynamicOutline.CheckedChanged               += (s, e) => UpdateRenderOutput();
            chkSetPrinterLayoutForLcdSubPix.CheckedChanged += (s, e) => UpdateRenderOutput();
            chkDrawTriangles.CheckedChanged                += (s, e) => UpdateRenderOutput();
            chkDrawRegenerateOutline.CheckedChanged        += (s, e) => UpdateRenderOutput();
            chkBorder.CheckedChanged                  += (s, e) => UpdateRenderOutput();
            chkDrawLineHubConn.CheckedChanged         += (s, e) => UpdateRenderOutput();
            chkDrawPerpendicularLine.CheckedChanged   += (s, e) => UpdateRenderOutput();
            chkDrawGlyphPoint.CheckedChanged          += (s, e) => UpdateRenderOutput();
            chkTestGridFit.CheckedChanged             += (s, e) => UpdateRenderOutput();
            chkUseHorizontalFitAlign.CheckedChanged   += (s, e) => UpdateRenderOutput();
            chkWriteFitOutputToConsole.CheckedChanged += (s, e) => UpdateRenderOutput();

            //----------
            //1. create font collection
            installedFontCollection = new InstalledFontCollection();
            //2. set some essential handler
            installedFontCollection.SetFontNameDuplicatedHandler((f1, f2) => FontNameDuplicatedDecision.Skip);
            foreach (string file in Directory.GetFiles(Path.Combine("..", "..", "..", "TestFonts"), "*.ttf"))
            {
                //eg. this is our custom font folder
                installedFontCollection.AddFont(new FontFileStreamProvider(file));
            }
            //3.
            //installedFontCollection.LoadSystemFonts();
            //----------
            //show result
            InstalledFont selectedFF     = null;
            int           selected_index = 0;
            int           ffcount        = 0;
            bool          found          = false;

            string defaultFont = "Tahoma";

            //string defaultFont = "Alef"; //test hebrew
            //string defaultFont = "Century";
            foreach (InstalledFont ff in installedFontCollection.GetInstalledFontIter())
            {
                if (!found && ff.FontName == defaultFont)
                {
                    selectedFF           = ff;
                    selected_index       = ffcount;
                    _selectedInstallFont = ff;
                    found = true;
                }
                lstFontList.Items.Add(ff);
                ffcount++;
            }
            //set default font for current text printer
            //
            _typefaceStore = new TypefaceStore();
            _typefaceStore.FontCollection = installedFontCollection;


            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledFont ff = lstFontList.SelectedItem as InstalledFont;
                if (ff != null)
                {
                    _selectedInstallFont         = ff;
                    selectedTextPrinter.Typeface = _typefaceStore.GetTypeface(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, 280, 300, 360, 400, 420, 460,
                620, 720, 860, 920, 1024
            });
            lstFontSizes.SelectedIndexChanged += (s, e) =>
            {
                //new font size
                _fontSizeInPts = (int)lstFontSizes.SelectedItem;
                UpdateRenderOutput();
            };

            //----------------
            //string inputstr = "ก้า";
            //string inputstr = "น้ำน้ำ";
            //string inputstr = "example";
            //string inputstr = "lllll";
            //string inputstr = "e";
            //string inputstr = "T";
            //string inputstr = "u";
            //string inputstr = "t";
            //string inputstr = "2";
            //string inputstr = "3";
            //string inputstr = "o";
            //string inputstr = "l";
            //string inputstr = "k";
            //string inputstr = "8";
            //string inputstr = "#";
            //string inputstr = "a";
            //string inputstr = "e";
            //string inputstr = "l";
            //string inputstr = "t";
            //string inputstr = "i";
            string inputstr = "ma";

            //string inputstr = "po";
            //string inputstr = "Å";
            //string inputstr = "fi";
            //string inputstr = "ก่นกิ่น";
            //string inputstr = "ญญู";
            //string inputstr = "ป่า"; //for gpos test
            //string inputstr = "快速上手";
            //string inputstr = "啊";

            //----------------
            this.txtInputChar.Text         = inputstr;
            this.chkFillBackground.Checked = true;
            _readyToRender = true;
        }
Exemplo n.º 4
0
        public Form1()
        {
            InitializeComponent();

            //choose Thai script for 'complex script' testing.
            //you can change this to test other script.
            _currentTextPrinter.ScriptLang = Typography.OpenFont.ScriptLangs.Thai;
            //----------
            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();
            //

            //1. create font collection
            installedFontCollection = new InstalledFontCollection();
            //2. set some essential handler
            installedFontCollection.SetFontNameDuplicatedHandler((f1, f2) => FontNameDuplicatedDecision.Skip);

            installedFontCollection.LoadFontsFromFolder("../../../TestFonts_Err");
            installedFontCollection.LoadFontsFromFolder("../../../TestFonts");
            //installedFontCollection.LoadSystemFonts();

            //----------
            //show result
            InstalledFont selectedFF     = null;
            int           selected_index = 0;
            int           ffcount        = 0;
            bool          found          = false;

            foreach (InstalledFont ff in installedFontCollection.GetInstalledFontIter())
            {
                if (!found && ff.FontName == "Tahoma")
                {
                    selectedFF     = ff;
                    selected_index = ffcount;
                    found          = true;
                }
                lstFontList.Items.Add(ff);
                ffcount++;
            }
            //set default font for current text printer
            //
            _typefaceStore = new TypefaceStore();
            _typefaceStore.FontCollection = installedFontCollection;
            //set default font for current text printer
            _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(selectedFF);
            //----------


            if (selected_index < 0)
            {
                selected_index = 0;
            }
            lstFontList.SelectedIndex         = selected_index;
            lstFontList.SelectedIndexChanged += (s, e) =>
            {
                InstalledFont ff = lstFontList.SelectedItem as InstalledFont;
                if (ff != null)
                {
                    _currentTextPrinter.Typeface = _typefaceStore.GetTypeface(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";
            //------
        }
Exemplo n.º 5
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //
            if (g == null)
            {
                destImg  = new ActualImage(800, 600, PixelFormat.ARGB32);
                imgGfx2d = new ImageGraphics2D(destImg); //no platform
                painter  = new AggCanvasPainter(imgGfx2d);
                winBmp   = new Bitmap(destImg.Width, destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                g        = this.CreateGraphics();

                painter.CurrentFont = new PixelFarm.Drawing.RequestFont("tahoma", 14);

                _devVxsTextPrinter = new VxsTextPrinter(painter, _openFontStore);
                _devVxsTextPrinter.TargetCanvasPainter = painter;
                _devVxsTextPrinter.ScriptLang          = _current_script;
                _devVxsTextPrinter.PositionTechnique   = _devGdiTextPrinter.PositionTechnique;
                _devGdiTextPrinter.TargetGraphics      = g;
            }

            if (string.IsNullOrEmpty(this.txtInputChar.Text))
            {
                return;
            }

            //test option use be used with lcd subpixel rendering.
            //this demonstrate how we shift a pixel for subpixel rendering tech
            _devVxsTextPrinter.UseWithLcdSubPixelRenderingTechnique = chkSetPrinterLayoutForLcdSubPix.Checked;


            var hintTech = (HintTechnique)lstHintList.SelectedItem;

            //1. read typeface from font file
            RenderChoice renderChoice = (RenderChoice)this.cmbRenderChoices.SelectedItem;

            switch (renderChoice)
            {
            case RenderChoice.RenderWithGdiPlusPath:
            {
                selectedTextPrinter                   = _devGdiTextPrinter;
                selectedTextPrinter.Typeface          = _typefaceStore.GetTypeface(_selectedInstallFont);
                selectedTextPrinter.FontSizeInPoints  = _fontSizeInPts;
                selectedTextPrinter.HintTechnique     = hintTech;
                selectedTextPrinter.PositionTechnique = (PositionTechnique)cmbPositionTech.SelectedItem;

#if DEBUG
                GlyphDynamicOutline.dbugTestNewGridFitting    = chkTestGridFit.Checked;
                GlyphDynamicOutline.dbugActualPosToConsole    = chkWriteFitOutputToConsole.Checked;
                GlyphDynamicOutline.dbugUseHorizontalFitValue = chkUseHorizontalFitAlign.Checked;
#endif

                selectedTextPrinter.DrawString(this.txtInputChar.Text.ToCharArray(), 0, 0);
            }
            break;

            case RenderChoice.RenderWithTextPrinterAndMiniAgg:
            {
                //clear previous draw
                painter.Clear(PixelFarm.Drawing.Color.White);
                painter.UseSubPixelRendering = chkLcdTechnique.Checked;
                painter.FillColor            = PixelFarm.Drawing.Color.Black;

                selectedTextPrinter                   = _devVxsTextPrinter;
                selectedTextPrinter.Typeface          = _typefaceStore.GetTypeface(_selectedInstallFont);
                selectedTextPrinter.FontSizeInPoints  = _fontSizeInPts;
                selectedTextPrinter.HintTechnique     = hintTech;
                selectedTextPrinter.PositionTechnique = (PositionTechnique)cmbPositionTech.SelectedItem;

                //test print 3 lines
#if DEBUG
                GlyphDynamicOutline.dbugTestNewGridFitting    = chkTestGridFit.Checked;
                GlyphDynamicOutline.dbugActualPosToConsole    = chkWriteFitOutputToConsole.Checked;
                GlyphDynamicOutline.dbugUseHorizontalFitValue = chkUseHorizontalFitAlign.Checked;
#endif

                char[] printTextBuffer = this.txtInputChar.Text.ToCharArray();
                float  x_pos = 0, y_pos = 200;
                float  lineSpacingPx = selectedTextPrinter.FontLineSpacingPx;
                for (int i = 0; i < 1; ++i)
                {
                    selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos);
                    y_pos -= lineSpacingPx;
                }


                //copy from Agg's memory buffer to gdi
                PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(destImg, winBmp);
                g.Clear(Color.White);
                g.DrawImage(winBmp, new Point(10, 0));
            }
            break;

            //==============================================
            //render 1 glyph for debug and test
            case RenderChoice.RenderWithMsdfGen:
            case RenderChoice.RenderWithSdfGen:
            {
                char     testChar = this.txtInputChar.Text[0];
                Typeface typeFace = _typefaceStore.GetTypeface(_selectedInstallFont);
                RenderWithMsdfImg(typeFace, testChar, _fontSizeInPts);
            }
            break;

            case RenderChoice.RenderWithMiniAgg_SingleGlyph:
            {
                selectedTextPrinter = _devVxsTextPrinter;
                //for test only 1 char
                RenderSingleCharWithMiniAgg(
                    _typefaceStore.GetTypeface(_selectedInstallFont),
                    this.txtInputChar.Text[0],
                    _fontSizeInPts);
            }
            break;

            default:
                throw new NotSupportedException();
            }
        }