Ejemplo n.º 1
0
        public CpuBlitTextSpanPrinter(GLPainter canvasPainter, int w, int h)
        {
            //this class print long text into agg canvas
            //then copy pixel buffer from aff canvas to gl-bmp
            //then draw the  gl-bmp into target gl canvas


            //TODO: review here
            _canvasPainter = canvasPainter;
            _pcx           = canvasPainter.Canvas;
            _bmpWidth      = w;
            _bmpHeight     = h;

            _memBmp = new MemBitmap(_bmpWidth, _bmpHeight);
#if DEBUG
            _memBmp._dbugNote = "AggTextSpanPrinter.ctor";
#endif
            _aggPainter             = AggPainter.Create(_memBmp);
            _aggPainter.FillColor   = Color.Black;
            _aggPainter.StrokeColor = Color.Black;

            //set default1
            _aggPainter.CurrentFont = canvasPainter.CurrentFont;
            _openFontTextServices   = new LayoutFarm.OpenFontTextService();
            _vxsTextPrinter         = new VxsTextPrinter(_aggPainter, _openFontTextServices);
            _aggPainter.TextPrinter = _vxsTextPrinter;
        }
Ejemplo n.º 2
0
        void SetupMaskPixelBlender(int width, int height)
        {
            //----------
            //same size
            _alphaBitmap = new MemBitmap(width, height);
            var alphaPainter = AggPainter.Create(_alphaBitmap, new PixelBlenderBGRA());

            alphaPainter.Clear(Color.Black);
            //------------

            System.Random randGenerator = new Random(1432);
            int           i;
            int           num = (int)_maskAlphaSliderValue;

            num = 50;

            int elliseFlattenStep = 64;

            using (VxsTemp.Borrow(out var v1))
                using (VectorToolBox.Borrow(out Ellipse ellipseForMask))
                {
                    for (i = 0; i < num; i++)
                    {
                        if (i == num - 1)
                        {
                            ////for the last one
                            ellipseForMask.Set(Width / 2, (Height / 2) - 90, 110, 110, elliseFlattenStep);
                            ellipseForMask.MakeVxs(v1);
                            alphaPainter.FillColor = new Color(255, 255, 255, 0);
                            alphaPainter.Fill(v1);
                            v1.Clear();
                            //
                            ellipseForMask.Set(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, elliseFlattenStep);
                            ellipseForMask.MakeVxs(v1);
                            alphaPainter.FillColor = new Color(255, 255, 0, 0);
                            alphaPainter.Fill(v1);
                            v1.Clear();
                            //
                        }
                        else
                        {
                            ellipseForMask.Set(randGenerator.Next() % width,
                                               randGenerator.Next() % height,
                                               randGenerator.Next() % 100 + 20,
                                               randGenerator.Next() % 100 + 20,
                                               elliseFlattenStep);
                            ellipseForMask.MakeVxs(v1);
                            alphaPainter.FillColor = new Color(100, 255, 0, 0);
                            alphaPainter.Fill(v1);
                            v1.Clear();
                        }
                    }
                }



            maskPixelBlender.SetMaskBitmap(_alphaBitmap);
            maskPixelBlenderPerCompo.SetMaskBitmap(_alphaBitmap);
        }
        public MiniAggCanvasRenderElement(int width, int height)
            : base(width, height)
        {
            _memBmp = new MemBitmap(width, height);
#if DEBUG
            _memBmp._dbugNote = "MiniAggCanvasRenderElement";
#endif
            _painter       = AggPainter.Create(_memBmp);
            _needUpdate    = true;
            this.BackColor = Color.White;
        }
Ejemplo n.º 4
0
 void SetupMaskPixelBlender(int width, int height)
 {
     //----------
     //same size
     _alphaBmp          = new MemBitmap(width, height);
     _maskBufferPainter = AggPainter.Create(_alphaBmp, new PixelBlenderBGRA());
     _maskBufferPainter.Clear(Color.Black);
     //------------
     //draw glyph bmp to _alpha bmp
     //_maskBufferPainter.DrawImage(_glyphBmp, 0, 0);
     _maskPixelBlender.SetMaskBitmap(_alphaBmp);
     _maskPixelBlenderPerCompo.SetMaskBitmap(_alphaBmp);
 }
Ejemplo n.º 5
0
        public void BindHostGraphics(Graphics hostControlGraphics)
        {
            g = hostControlGraphics;
            //
            destImg = new ActualBitmap(400, 300);
            p       = AggPainter.Create(destImg);
            winBmp  = new Bitmap(400, 300, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            _openFontTextServices = new LayoutFarm.OpenFontTextService();

            _printer    = new VxsTextPrinter(p, _openFontTextServices);
            _visualLine = new VisualLine();
            _visualLine.BindLine(_line);
            _visualLine.Y = 100;
        }
Ejemplo n.º 6
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            PaintLab.Svg.VgVisualDoc vgVisualDoc = PaintLab.Svg.VgVisualDocHelper.CreateVgVisualDocFromFile("Samples/lion.svg");
            _lionShape = new SpriteShape(vgVisualDoc.VgRootElem);

            var lionBounds = _lionShape.Bounds;

            //-------------
            _memBmp     = new MemBitmap((int)lionBounds.Width, (int)lionBounds.Height);
            _aggPainter = AggPainter.Create(_memBmp);


            DrawLion(_aggPainter, _lionShape);
            //convert affImage to texture
            _glBmp = DemoHelper.LoadTexture(_memBmp);
        }
Ejemplo n.º 7
0
        //----------------------------------------------
        /// <summary>
        /// set-up CpuBlit(software-rendering surface)
        /// </summary>
        protected virtual void SetupCpuBlitRenderSurface()
        {
            //***
            _memBmp = new MemBitmap(_width, _height);
#if DEBUG
            _memBmp._dbugNote = "CpuBlitGLESUIElement.SetupCpuBlitRenderSurface()";
#endif
            _aggPainter = AggPainter.Create(_memBmp);

            //optional if we want to print text on agg surface
            _aggPainter.CurrentFont = new PixelFarm.Drawing.RequestFont("Tahoma", 10);
            _aggPainter.TextPrinter = new PixelFarm.Drawing.Fonts.FontAtlasTextPrinter(_aggPainter);

            _memBitmapBinder = new MemBitmapBinder(_memBmp, false);
            //
        }
Ejemplo n.º 8
0
        //----------------------------------------------
        /// <summary>
        /// set-up CpuBlit(software-rendering surface)
        /// </summary>
        protected virtual void SetupCpuBlitRenderSurface()
        {
            //***
            _memBmp = new MemBitmap(_width, _height);
#if DEBUG
            _memBmp._dbugNote = "CpuBlitGLESUIElement.SetupCpuBlitRenderSurface()";
#endif
            _aggPainter = AggPainter.Create(_memBmp);

            //optional if we want to print text on agg surface
            _aggPainter.CurrentFont = MyFontSettings.DefaultRootGraphicsFont;//
            _aggPainter.TextPrinter = new PixelFarm.CpuBlit.BitmapAtlas.FontAtlasTextPrinter(_aggPainter);

            _memBitmapBinder = new MemBitmapBinder(_memBmp, false);
            //
        }
Ejemplo n.º 9
0
        public FloodFillDemo()
        {
            //
            _magicWandConfigs = new MagicWandConfigGroup();

            BackgroundColor = Color.White;

            _defaultImg = new MemBitmap(400, 300);

            AggPainter p = AggPainter.Create(_defaultImg);

            p.Clear(Color.White);
            p.FillColor = Color.Black;
            p.FillEllipse(20, 20, 30, 30);


            for (int i = 0; i < 20; i++)
            {
                p.StrokeColor = Color.Black;
                p.DrawEllipse(i * 10, i * 10, 20, 20);
            }

            //
            this.PixelSize = 32;
            this.Gamma     = 1;
            _tolerance     = 30;

            _floodFill = new ColorBucket(Color.Red, _tolerance);
            _magicWand = new MagicWand(_tolerance);

            //
            //_lionPng = MemBitmapExtensions.LoadBitmap("../Data/lion1_v2_2.png");
            //_lionPng =  MemBitmapExtensions.LoadBitmap("../Data/lion1_v2_4_1.png");
            _lionPng = MemBitmapExt.LoadBitmap("../Data/lion1.png");
            //_lionPng =  MemBitmapExtensions.LoadBitmap("../Data/lion_1_v3_2.png");
            //_lionPng = MemBitmapExtensions.LoadBitmap("../Data/glyph_a.png");
            _starsPng    = MemBitmapExt.LoadBitmap("../Data/stars.png");
            _test_glyphs = MemBitmapExt.LoadBitmap("../Data/test_glyphs.png");
            _rect01      = MemBitmapExt.LoadBitmap("../Data/rect01.png");
            //_v_shape =  MemBitmapExtensions.LoadBitmap("../Data/shape_v.png");
            //_v_shape = MemBitmapExtensions.LoadBitmap("../Data/shape_v3.png");
            _bmpToFillOn = _defaultImg;

            OutlineReconstruction = true;
            WithOutlineSimplifier = true;
        }
Ejemplo n.º 10
0
        void UpdateOutput()
        {
            string oneChar = this.textBox1.Text.Trim();

            if (string.IsNullOrEmpty(oneChar))
            {
                return;
            }
            //
            char selectedChar = oneChar[0];

            using (System.Drawing.Graphics gfx = panel1.CreateGraphics())
                using (MemBitmap destImg = new MemBitmap(panel1.Width, panel1.Height))
                {
                    //create mini agg drawboard
                    AggPainter painter = AggPainter.Create(destImg);
                    DrawOutput(painter, _typeface, selectedChar);
                    painter.CopyToGdiPlusGraphics(gfx);
                }
        }
Ejemplo n.º 11
0
 void RunSampleB(PixelFarm.Drawing.Painter p)
 {
     //version 2:
     //1. create simple vertical line to test agg's lcd rendernig technique
     //create gray-scale actual image
     using (MemBitmap glyphBmp = new MemBitmap(100, 100))
     {
         AggPainter painter = AggPainter.Create(glyphBmp);
         //
         painter.StrokeColor = PixelFarm.Drawing.Color.Black;
         painter.StrokeWidth = 2.0f;
         painter.DrawLine(2, 0, 3, 15); //not need to scale3
                                        //
                                        //clear surface bg
         p.Clear(PixelFarm.Drawing.Color.White);
         //--------------------------
         var aggPainer = (PixelFarm.CpuBlit.AggPainter)p;
         BlendWithLcdTechnique(aggPainer.RenderSurface.DestBitmap, glyphBmp, PixelFarm.Drawing.Color.Black);
         //---------------
         p.DrawImage(glyphBmp, 0, 50);
         //---------------
     }
 }
Ejemplo n.º 12
0
        void InitGraphics()
        {
            //INIT ONCE
            if (_g != null)
            {
                return;
            }
            //

            _destImg = new MemBitmap(800, 600);
            _painter = AggPainter.Create(_destImg);
            _winBmp  = new Bitmap(_destImg.Width, _destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            _g       = this.CreateGraphics();

            _defaultReqFont      = new PixelFarm.Drawing.RequestFont("Source Sans Pro", 10);
            _painter.CurrentFont = _defaultReqFont;


            _textService = new Typography.Text.OpenFontTextService();
            _textService.LoadFontsFromFolder("../../../TestFonts");
            _textService.UpdateUnicodeRanges();

            _devVxsTextPrinter = new PixelFarm.Drawing.VxsTextSpanPrinter(_painter, _textService.CreateNewServiceClient());
            _devVxsTextPrinter.SetSvgBmpBuilderFunc(PaintLab.SvgBuilderHelper.ParseAndRenderSvg);

            _devVxsTextPrinter.ScriptLang        = new ScriptLang(ScriptTagDefs.Latin.Tag);
            _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;

            //Alternative Typeface selector..
            _myAlternativeTypefaceSelector = new Typography.Text.AlternativeTypefaceSelector();
            {
                //------------
                //TODO: review this again
                //load from config?
                //------------

                //arabic
                //1. create prefer typeface list for arabic script
                var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                preferTypefaces.AddTypefaceName("Noto Sans Arabic UI");

                //2. set unicode ranges and prefered typeface list.
                _myAlternativeTypefaceSelector.SetPreferredTypefaces(
                    new[] { Typography.TextBreak.Unicode13RangeInfoList.Arabic,
                            Typography.TextBreak.Unicode13RangeInfoList.Arabic_Supplement,
                            Typography.TextBreak.Unicode13RangeInfoList.Arabic_Extended_A },
                    preferTypefaces);
            }
            {
                //latin

                var preferTypefaces = new Typography.FontCollections.PreferredTypefaceList();
                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);
            }

            _devVxsTextPrinter.AlternativeTypefaceSelector = _myAlternativeTypefaceSelector;
        }
Ejemplo n.º 13
0
        public void BuildMultiFontSize(string multiFontSizeAtlasFilename, string imgOutputFilename)
        {
            //merge to the new one
            //1. ensure same atlas width
            int atlasW      = 0;
            int j           = _atlasList.Count;
            int totalHeight = 0;

            const int interAtlasSpace = 2;

            for (int i = 0; i < j; ++i)
            {
                TempMergingAtlasInfo atlasInfo = _atlasList[i];
                SimpleBitmapAtlas    fontAtlas = atlasInfo.fontAtlasFile.AtlasList[0];
                totalHeight += fontAtlas.Height + interAtlasSpace;
                if (i == 0)
                {
                    atlasW = fontAtlas.Width;
                }
                else
                {
                    if (atlasW != fontAtlas.Width)
                    {
                        throw new NotSupportedException();
                    }
                }
            }
            //--------------------------------------------
            //in this version, the glyph offsetY is measure from bottom***
            int[] offsetFromBottoms = new int[j];
            int   offsetFromBottom  = interAtlasSpace;//start offset

            for (int i = j - 1; i >= 0; --i)
            {
                TempMergingAtlasInfo atlasInfo = _atlasList[i];
                SimpleBitmapAtlas    fontAtlas = atlasInfo.fontAtlasFile.AtlasList[0];
                offsetFromBottoms[i] = offsetFromBottom;
                offsetFromBottom    += fontAtlas.Height + interAtlasSpace;
            }
            //--------------------------------------------
            //merge all img to one
            int top = 0;

            using (MemBitmap memBitmap = new MemBitmap(atlasW, totalHeight))
            {
                AggPainter painter = AggPainter.Create(memBitmap);
                for (int i = 0; i < j; ++i)
                {
                    TempMergingAtlasInfo atlasInfo = _atlasList[i];
                    BitmapAtlasFile      atlasFile = atlasInfo.fontAtlasFile;
                    SimpleBitmapAtlas    fontAtlas = atlasInfo.fontAtlasFile.AtlasList[0];

                    atlasInfo.NewCloneLocations = SimpleBitmapAtlas.CloneLocationWithOffset(fontAtlas, 0, offsetFromBottoms[i]);
                    atlasInfo.ImgUrlDict        = fontAtlas.ImgUrlDict;

                    using (Stream fontImgStream = PixelFarm.Platforms.StorageService.Provider.ReadDataStream(atlasInfo.imgFile))
                        using (MemBitmap atlasBmp = MemBitmapExt.LoadBitmap(fontImgStream))
                        {
                            painter.DrawImage(atlasBmp, 0, top);
                            top += atlasBmp.Height + interAtlasSpace;
                        }
                }
                memBitmap.SaveImage(imgOutputFilename);
            }
            //--------------------------------------------
            //save merged font atlas
            //TODO: use 'File' provider to access system file
            using (FileStream fs = new FileStream(multiFontSizeAtlasFilename, FileMode.Create))
                using (BinaryWriter w = new BinaryWriter(fs))
                {
                    //-----------
                    //overview
                    //total img info
                    BitmapAtlasFile fontAtlasFile = new BitmapAtlasFile();
                    fontAtlasFile.StartWrite(fs);

                    //1. simple atlas count
                    fontAtlasFile.WriteOverviewMultiSizeFontInfo((ushort)j);
                    //2.
                    for (int i = 0; i < j; ++i)
                    {
                        TempMergingAtlasInfo atlasInfo = _atlasList[i];

                        RequestFont reqFont = atlasInfo.reqFont;
                        fontAtlasFile.WriteOverviewFontInfo(reqFont.Name, reqFont.GetReqKey(), reqFont.SizeInPoints);//size in points

                        fontAtlasFile.WriteTotalImageInfo(
                            (ushort)atlasW,
                            (ushort)top,
                            4,
                            atlasInfo.textureKind);
                        //

                        fontAtlasFile.WriteAtlasItems(atlasInfo.NewCloneLocations);

                        if (atlasInfo.ImgUrlDict != null)
                        {
                            fontAtlasFile.WriteImgUrlDict(atlasInfo.ImgUrlDict);
                        }
                    }
                    fontAtlasFile.EndWrite();
                }
        }
Ejemplo n.º 14
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //
            if (_g == null)
            {
                _destImg = new MemBitmap(800, 600);
                _painter = AggPainter.Create(_destImg);
                _winBmp  = new Bitmap(_destImg.Width, _destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                _g       = this.CreateGraphics();

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


                _textService = new LayoutFarm.OpenFontTextService();
                _textService.LoadFontsFromFolder("../../../TestFonts");

                _devVxsTextPrinter                   = new VxsTextPrinter(_painter, _textService);
                _devVxsTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
                _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;
            }

            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

            if (_contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix)
            {
                //TODO: set lcd or not here
            }
            else
            {
                //TODO: set lcd or not here
            }

            //1. read typeface from font file
            TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice;
            switch (renderChoice)
            {
            case TypographyTest.RenderChoice.RenderWithGdiPlusPath:
                //not render in this example
                //see more at ...
                break;

            case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg:
            {
                //clear previous draw
                _painter.Clear(PixelFarm.Drawing.Color.White);
                _painter.UseSubPixelLcdEffect = _contourAnalysisOpts.LcdTechnique;
                _painter.FillColor            = PixelFarm.Drawing.Color.Black;

                _selectedTextPrinter                   = _devVxsTextPrinter;
                _selectedTextPrinter.Typeface          = _basicOptions.Typeface;
                _selectedTextPrinter.FontSizeInPoints  = _basicOptions.FontSizeInPoints;
                _selectedTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
                _selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech;

                _selectedTextPrinter.HintTechnique  = _glyphRenderOptions.HintTechnique;
                _selectedTextPrinter.EnableLigature = _glyphRenderOptions.EnableLigature;
                _selectedTextPrinter.SimulateSlant  = _contourAnalysisOpts.SimulateSlant;

                //test print 3 lines
#if DEBUG
                GlyphDynamicOutline.dbugTestNewGridFitting    = _contourAnalysisOpts.EnableGridFit;
                GlyphDynamicOutline.dbugActualPosToConsole    = _contourAnalysisOpts.WriteFitOutputToConsole;
                GlyphDynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment;
#endif

                char[] printTextBuffer = this.txtInputChar.Text.ToCharArray();
                float  x_pos = 0, y_pos = 50;
                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.CpuBlit.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 TypographyTest.RenderChoice.RenderWithMsdfGen:
            case TypographyTest.RenderChoice.RenderWithSdfGen:
            {
                char     testChar = this.txtInputChar.Text[0];
                Typeface typeFace = _basicOptions.Typeface;
                RenderWithMsdfImg(typeFace, testChar, _basicOptions.FontSizeInPoints);
            }
            break;

            case TypographyTest.RenderChoice.RenderWithMiniAgg_SingleGlyph:
            {
                _selectedTextPrinter = _devVxsTextPrinter;
                //for test only 1 char
                RenderSingleCharWithMiniAgg(
                    _basicOptions.Typeface,
                    this.txtInputChar.Text[0],
                    _basicOptions.FontSizeInPoints);
            }
            break;

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 15
0
        public GlyphImage CreateGlyphImage(GlyphPathBuilder builder, float pxscale)
        {
            //1. create

            var txToVxs = new GlyphTranslatorToVxs();

            builder.ReadShapes(txToVxs);
            //
            //create new one
            var glyphVxs = new VertexStore();

            txToVxs.WriteOutput(glyphVxs, pxscale);
            //find bound
            //--------------------------------------------
            //GlyphImage glyphImg = new GlyphImage()
            RectD bounds = RectD.ZeroIntersection;

            PixelFarm.CpuBlit.VertexProcessing.BoundingRect.GetBoundingRect(new VertexStoreSnap(glyphVxs), ref bounds);

            ////--------------------------------------------
            int w = (int)System.Math.Ceiling(bounds.Width);
            int h = (int)System.Math.Ceiling(bounds.Height);

            if (w < 5)
            {
                w = 5;
            }
            if (h < 5)
            {
                h = 5;
            }

            //translate to positive quadrant
            //
            double dx = (bounds.Left < 0) ? -bounds.Left : 0;
            double dy = (bounds.Bottom < 0) ? -bounds.Bottom : 0;

            //
            dx = Math.Ceiling(dx); //since we need to move it, then move it with integer value
            dy = Math.Ceiling(dy); //since we need to move it, then move it with integer value

            //we need some borders
            int horizontal_margin = 1;                         //'margin' 1px
            int vertical_margin   = 1;                         //margin 1 px

            dx += horizontal_margin;                           //+ left margin
            dy += vertical_margin;                             //+ top margin
                                                               //--------------------------------------------
                                                               //create glyph img
            w = (int)Math.Ceiling(dx + w + horizontal_margin); //+right margin
            h = (int)Math.Ceiling(dy + h + vertical_margin);   //+bottom margin

            ActualBitmap img     = new ActualBitmap(w, h);
            AggPainter   painter = AggPainter.Create(img);

            if (TextureKind == TextureKind.StencilLcdEffect)
            {
                VertexStore vxs2 = new VertexStore();
                glyphVxs.TranslateToNewVxs(dx + 0.33f, dy, vxs2); //offset to proper x of subpixel rendering  ***
                glyphVxs = vxs2;
                //
                painter.UseSubPixelLcdEffect = true;

                //we use white glyph on black bg for this texture
                painter.Clear(Color.Black);
                painter.FillColor = Color.White;
                painter.Fill(glyphVxs);

                //apply sharpen filter
                //painter.DoFilter(new RectInt(0, h, w, 0), 2);
                //painter.DoFilter(new RectInt(0, h, w, 0), 2); //?
            }
            else
            {
                VertexStore vxs2 = new VertexStore();
                glyphVxs.TranslateToNewVxs(dx, dy, vxs2);
                glyphVxs = vxs2;

                painter.UseSubPixelLcdEffect = false;

                if (TextureKind == TextureKind.StencilGreyScale)
                {
                    painter.Clear(Color.Empty);
                    painter.FillColor = Color.Black;
                }
                else
                {
                    painter.Clear(BackGroundColor);
                    painter.FillColor = this.GlyphColor;
                }
                painter.Fill(glyphVxs);
            }
            //
            var glyphImage = new GlyphImage(w, h);

            glyphImage.TextureOffsetX = dx;
            glyphImage.TextureOffsetY = dy;
            glyphImage.SetImageBuffer(ActualBitmapExtensions.CopyImgBuffer(img, w), false);
            //copy data from agg canvas to glyph image
            return(glyphImage);
        }
Ejemplo n.º 16
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //
            if (_g == null)
            {
                _destImg = new MemBitmap(800, 600);
                _painter = AggPainter.Create(_destImg);
                _winBmp  = new Bitmap(_destImg.Width, _destImg.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                _g       = this.CreateGraphics();

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

                _textService = new PixelFarm.Drawing.OpenFontTextService();
                _textService.LoadFontsFromFolder("../../../TestFonts");

                _devVxsTextPrinter = new PixelFarm.Drawing.VxsTextPrinter(_painter, _textService);
                _devVxsTextPrinter.SetSvgBmpBuilderFunc(ParseAndRenderSvg);

                _devVxsTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
                _devVxsTextPrinter.PositionTechnique = Typography.TextLayout.PositionTechnique.OpenFont;
            }

            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

            if (_contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix)
            {
                //TODO: set lcd or not here
            }
            else
            {
                //TODO: set lcd or not here
            }

            //1. read typeface from font file
            TypographyTest.RenderChoice renderChoice = _basicOptions.RenderChoice;
            switch (renderChoice)
            {
            case TypographyTest.RenderChoice.RenderWithGdiPlusPath:
                //not render in this example
                //see more at ...
                break;

            case TypographyTest.RenderChoice.RenderWithTextPrinterAndMiniAgg:
            {
                //clear previous draw
                _painter.Clear(PixelFarm.Drawing.Color.White);
                _painter.UseLcdEffectSubPixelRendering = _contourAnalysisOpts.LcdTechnique;
                _painter.FillColor = PixelFarm.Drawing.Color.Black;

                _selectedTextPrinter                   = _devVxsTextPrinter;
                _selectedTextPrinter.Typeface          = _basicOptions.Typeface;
                _selectedTextPrinter.FontSizeInPoints  = _basicOptions.FontSizeInPoints;
                _selectedTextPrinter.ScriptLang        = _basicOptions.ScriptLang;
                _selectedTextPrinter.PositionTechnique = _basicOptions.PositionTech;

                _selectedTextPrinter.HintTechnique  = _glyphRenderOptions.HintTechnique;
                _selectedTextPrinter.EnableLigature = _glyphRenderOptions.EnableLigature;
                _selectedTextPrinter.SimulateSlant  = _contourAnalysisOpts.SimulateSlant;


                _selectedTextPrinter.TextBaseline = (PixelFarm.Drawing.TextBaseline)lstTextBaseline.SelectedItem;

                //test print 3 lines
#if DEBUG
                DynamicOutline.dbugTestNewGridFitting    = _contourAnalysisOpts.EnableGridFit;
                DynamicOutline.dbugActualPosToConsole    = _contourAnalysisOpts.WriteFitOutputToConsole;
                DynamicOutline.dbugUseHorizontalFitValue = _contourAnalysisOpts.UseHorizontalFitAlignment;
#endif

                char[] printTextBuffer = this.txtInputChar.Text.ToCharArray();
                float  x_pos = 0, y_pos = 0;
                float  lineSpacingPx = _selectedTextPrinter.FontLineSpacingPx;

                const int REF_LINE_LEN = 300;
                for (int i = 0; i < 3; ++i)
                {
                    _selectedTextPrinter.DrawString(printTextBuffer, x_pos, y_pos);
#if DEBUG
                    //show debug info...
                    var prevColor      = _painter.FillColor;
                    var prevStrokColor = _painter.StrokeColor;
                    _painter.FillColor = PixelFarm.Drawing.Color.Red;
                    _painter.FillRect(x_pos, y_pos, 5, 5);         // start point

                    //see   //https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
                    switch (_selectedTextPrinter.TextBaseline)
                    {
                    default:
                    {
                        System.Diagnostics.Debug.WriteLine("UNIMPLEMENTED" + _selectedTextPrinter.TextBaseline.ToString());
                        goto case PixelFarm.Drawing.TextBaseline.Alphabetic;                //
                    }

                    case PixelFarm.Drawing.TextBaseline.Alphabetic:
                    {
                        //alphabetic baseline
                        _painter.StrokeColor = _grayColor;
                        _painter.DrawLine(x_pos, /**/ y_pos,
                                          x_pos + REF_LINE_LEN, y_pos);

                        _painter.StrokeColor = PixelFarm.Drawing.Color.Blue;
                        _painter.DrawLine(x_pos, /**/ y_pos - _selectedTextPrinter.FontDescedingPx,
                                          x_pos + REF_LINE_LEN, y_pos - _selectedTextPrinter.FontDescedingPx);                //bottom most
                    }
                    break;

                    case PixelFarm.Drawing.TextBaseline.Top:
                    {
                        //alphabetic baseline
                        _painter.StrokeColor = _grayColor;
                        _painter.DrawLine(x_pos, /**/ y_pos + _selectedTextPrinter.FontAscendingPx,
                                          x_pos + REF_LINE_LEN, y_pos + _selectedTextPrinter.FontAscendingPx);
                        //em bottom
                        _painter.StrokeColor = PixelFarm.Drawing.Color.Blue;
                        _painter.DrawLine(x_pos, /**/ y_pos + (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx),
                                          x_pos + REF_LINE_LEN, y_pos + (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx));                //bottom most
                    }
                    break;

                    case PixelFarm.Drawing.TextBaseline.Bottom:
                    {
                        //alphabetic baseline
                        _painter.StrokeColor = _grayColor;
                        _painter.DrawLine(x_pos, /**/ y_pos + _selectedTextPrinter.FontDescedingPx,
                                          x_pos + REF_LINE_LEN, y_pos + _selectedTextPrinter.FontDescedingPx);
                        //em bottom
                        _painter.StrokeColor = PixelFarm.Drawing.Color.Blue;
                        _painter.DrawLine(x_pos, /**/ y_pos,
                                          x_pos + REF_LINE_LEN, y_pos);                //bottom most
                    }
                    break;
                    }


                    _painter.FillColor   = prevColor;
                    _painter.StrokeColor = prevColor;
#endif
                    y_pos += (_selectedTextPrinter.FontAscendingPx - _selectedTextPrinter.FontDescedingPx);
                }


                //copy from Agg's memory buffer to gdi
                PixelFarm.CpuBlit.BitmapHelper.CopyToGdiPlusBitmapSameSizeNotFlip(_destImg, _winBmp);
                _g.Clear(Color.White);
                _g.DrawImage(_winBmp, new Point(0, 0));
            }
            break;

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

            case TypographyTest.RenderChoice.RenderWithMiniAgg_SingleGlyph:
            {
                _selectedTextPrinter = _devVxsTextPrinter;
                //for test only 1 char
                RenderSingleCharWithMiniAgg(
                    _basicOptions.Typeface,
                    this.txtInputChar.Text[0],
                    _basicOptions.FontSizeInPoints);
            }
            break;

            default:
                throw new NotSupportedException();
            }
        }