public void DrawString(char[] text, int startAt, int len, double x, double y)
        {
            if (this.UseSubPixelRendering)
            {
                //1. clear prev drawing result
                _aggPainter.Clear(Drawing.Color.FromArgb(0, 0, 0, 0));
                //aggPainter.Clear(Drawing.Color.White);
                //aggPainter.Clear(Drawing.Color.FromArgb(0, 0, 0, 0));
                //2. print text span into Agg Canvas
                _vxsTextPrinter.DrawString(text, startAt, len, 0, 0);
                //3.copy to gl bitmap
                //byte[] buffer = PixelFarm.Agg.ActualImage.GetBuffer(_actualImage);
                //------------------------------------------------------
                GLBitmap glBmp = new GLBitmap(_actualImage);
                glBmp.IsInvert = false;
                //TODO: review font height
                if (StartDrawOnLeftTop)
                {
                    y -= _vxsTextPrinter.FontLineSpacingPx;
                }
                _glsx.DrawGlyphImageWithSubPixelRenderingTechnique(glBmp, (float)x, (float)y);
                glBmp.Dispose();
            }
            else
            {
                //1. clear prev drawing result
                _aggPainter.Clear(Drawing.Color.White);
                _aggPainter.StrokeColor = Color.Black;

                //2. print text span into Agg Canvas
                _vxsTextPrinter.StartDrawOnLeftTop = false;

                float dyOffset = _vxsTextPrinter.FontDescedingPx;
                _vxsTextPrinter.DrawString(text, startAt, len, 0, -dyOffset);
                //------------------------------------------------------
                //debug save image from agg's buffer
#if DEBUG
                //actualImage.dbugSaveToPngFile("d:\\WImageTest\\aa1.png");
#endif
                //------------------------------------------------------

                //3.copy to gl bitmap
                //byte[] buffer = PixelFarm.Agg.ActualImage.GetBuffer(_actualImage);
                //------------------------------------------------------
                //debug save image from agg's buffer

                //------------------------------------------------------
                //GLBitmap glBmp = new GLBitmap(bmpWidth, bmpHeight, buffer, true);
                GLBitmap glBmp = new GLBitmap(_actualImage);
                glBmp.IsInvert = false;
                //TODO: review font height
                //if (StartDrawOnLeftTop)
                //{
                y += _vxsTextPrinter.FontLineSpacingPx;
                //}
                _glsx.DrawGlyphImage(glBmp, (float)x, (float)y + dyOffset);
                glBmp.Dispose();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //clear previous draw
            _painter.Clear(PixelFarm.Drawing.Color.White);

            string textOutput  = "Hello!";
            string textOutput2 = "شمس حب ";

            textOutput += textOutput2;
            {
                //RequestFont reqFont1 = new RequestFont("Source Sans Pro", 20);
                RequestFont reqFont1 = new RequestFont("Droid Sans", 20);
                DrawStringToMemBitmap(reqFont1, textOutput, 0, 50);
            }

            //{
            //    RequestFont reqFont1 = new RequestFont("Source Sans Pro", 18);

            //    "Source Sans Pro" does not have arabic , CJK, and Emoji glyphs
            //     so this will use AlternativeTypefaceSelector to select a proper typeface for
            //     a specific unicode range
            //     eg. for Emoticon=> use TwitterColorEmoji (global settings)
            //             CJK => use "Noto CJK" (global settings)
            //             Arabic => use "Noto Sans Arabic UI"



            //    //***TODO: please improve 1st loading time for CJK font***

            //    textOutput = "😁こんにちは, 你好, 여보세요 abc 0123 ";

            //    DrawStringToMemBitmap(reqFont1, textOutput, 100, 50);
            //}


            //{
            //    RequestFont reqFont1 = new RequestFont("Source Sans Pro", 30);

            //    //"Source Sans Pro" does not have arabic glyphs
            //    //so this will switch to "Noto Sans Arabic UI" as described in AlternativeTypefaceSelector above.

            //    textOutput = "شمس حب ";

            //    //DrawStringToMemBitmap(reqFont1, textOutput, 150, 100);
            //    DrawStringToMemBitmap(reqFont1, textOutput, 0, 0);
            //}

            {
                //use Roboto
                RequestFont reqFont1 = new RequestFont("Roboto", 20);

                textOutput = "hello Roboto";

                DrawStringToMemBitmap(reqFont1, textOutput, 0, 150);
            }

            CopyMemBitmapToScreen();
        }
Beispiel #3
0
        void RenderByGlyphName(string selectedGlyphName)
        {
            //---------------------------------------------
            //this version only render with MiniAgg**
            //---------------------------------------------

            _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;

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


            float x_pos = 0, y_pos = 100;
            var   glyphPlanList = new Typography.TextLayout.UnscaledGlyphPlanList();


            //in this version
            //create a glyph-plan manully
            ushort selectedGlyphIndex =
                glyphNameListUserControl1.Typeface.GetGlyphIndexByName(selectedGlyphName);

            glyphPlanList.Append(
                new Typography.TextLayout.UnscaledGlyphPlan(0, selectedGlyphIndex, 0, 0, 0));

            var seq = new Typography.TextLayout.GlyphPlanSequence(
                glyphPlanList,
                0, 1);
            _selectedTextPrinter.DrawFromGlyphPlans(seq, x_pos, y_pos);

            char[] printTextBuffer = this.txtInputChar.Text.ToCharArray();
            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(System.Drawing.Color.White);
            _g.DrawImage(_winBmp, new System.Drawing.Point(10, 0));
        }
Beispiel #4
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //

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

            //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 = false;
                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  = HintTechnique.None;
                selectedTextPrinter.EnableLigature = true;
                _devVxsTextPrinter.UpdateGlyphLayoutSettings();
                //
                _controllerForPixelFarm.ReadyToRender = true;
                _controllerForPixelFarm.UpdateOutput();

                //----------------
                //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;

            default:
                throw new NotSupportedException();
            }
        }
Beispiel #5
0
        public override void Draw(Painter p)
        {
            AggPainter painter = p as AggPainter;

            if (painter == null)
            {
                return;
            }

            painter.Clear(Color.White);

            int width  = painter.Width;
            int height = painter.Height;


            //switch to alpha mask
            painter.TargetBufferName = TargetBufferName.AlphaMask;
            //draw white rect on the mask
            painter.FillColor = Color.White;
            painter.FillRect(20, 20, 50, 50);
            painter.FillRect(20, 5, 20, 10);

            //------------------------------------
            //switch back to default color
            painter.TargetBufferName = TargetBufferName.Default;
            painter.FillColor        = Color.Red;
            //enable mask composite
            painter.EnableBuiltInMaskComposite = true;
            painter.FillRect(0, 0, 100, 100);
            //disable mask buffer
            painter.EnableBuiltInMaskComposite = false;
            painter.FillColor = Color.Yellow;
            painter.FillRect(0, 0, 20, 20);

            //if (!_maskReady)
            //{
            //    SetupMaskPixelBlender(width, height);
            //    _maskReady = true;
            //}

            ////
            ////painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlender; //change to new blender
            //painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlenderPerCompo; //change to new blender

            ////4.
            //painter.FillColor = Color.Black;
            ////this test lcd-effect => we need to draw it 3 times with different color component, on the same position
            ////(same as we do with OpenGLES rendering surface)
            //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.B;
            //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.B;
            //painter.FillRect(0, 0, 200, 100);
            ////
            //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.G;
            //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.G;
            //painter.FillRect(0, 0, 200, 100);
            ////
            //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.R;
            //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.R;
            //painter.FillRect(0, 0, 200, 100);
        }
Beispiel #6
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);
 }
Beispiel #7
0
        public override void Draw(Painter p)
        {
            AggPainter painter = p as AggPainter;

            if (painter == null)
            {
                return;
            }
            //
            painter.Clear(Color.White);

            int width  = painter.Width;
            int height = painter.Height;

            //change value ***
            if (_isMaskSliderValueChanged)
            {
                SetupMaskPixelBlender(width, height);
                _isMaskSliderValueChanged = false;
                //
                //painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlender; //change to new blender
                painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlenderPerCompo; //change to new blender
            }
            //1. alpha mask...
            //p2.DrawImage(alphaBitmap, 0, 0);

            //2.
            painter.FillColor = Color.Black;
            painter.FillRect(0, 0, 200, 100);

            //3.
            painter.FillColor = Color.Blue;
            painter.FillCircle(300, 300, 100);
            painter.DrawImage(lionImg, 20, 20);



            ////4.
            //painter.FillColor = Color.Black;
            ////this test lcd-effect => we need to draw it 3 times with different color component, on the same position
            ////(same as we do with OpenGLES rendering surface)
            //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.B;
            //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.B;
            //painter.FillRect(0, 0, 200, 100);
            //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.G;
            //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.G;
            //painter.FillRect(0, 0, 200, 100);
            //maskPixelBlenderPerCompo.SelectedMaskComponent = PixelBlenderColorComponent.R;
            //maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.R;
            //painter.FillRect(0, 0, 200, 100);
        }
Beispiel #8
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;
        }
Beispiel #9
0
        public override void Draw(Painter p)
        {
            AggPainter painter = p as AggPainter;

            if (painter == null)
            {
                return;
            }

            painter.Clear(Color.White);

            switch (FilterName)
            {
            case FilterName.Unknown:
                painter.RenderSurface.CustomImgSpanGen = null;
                break;

            case FilterName.NearestNeighbor:
                painter.RenderSurface.CustomImgSpanGen = _imgSpanGenNN;
                break;

            default:
                DrawWeightDistributionGraph(p, _lut.WeightArray);
                painter.RenderSurface.CustomImgSpanGen = _imgSpanGenCustom;
                break;
            }

            VertexProcessing.AffinePlan[] p1 = new VertexProcessing.AffinePlan[]
            {
                VertexProcessing.AffinePlan.Translate(-_imgW / 2.0, -_imgH / 2.0),
                VertexProcessing.AffinePlan.RotateDeg(_rotationDeg),
                VertexProcessing.AffinePlan.Translate(_imgW / 2.0, _imgH / 2.0),
            };

            p.DrawImage(_orgImg, p1);

            if (_thumbnailScaleDown > 0 && _thumbnailScaleDown < 1)
            {
                using (MemBitmap thumbnail = _orgImg.CreateThumbnailWithSuperSamplingTechnique(_thumbnailScaleDown))
                {
                    painter.DrawImage(thumbnail, 400, 300);
                }
            }

            base.Draw(p);
        }
Beispiel #10
0
        public override void Draw(Painter p)
        {
            AggPainter painter = p as AggPainter;

            if (painter == null)
            {
                return;
            }
            //

            painter.Clear(Color.White);

            int width  = painter.Width;
            int height = painter.Height;

            //change value ***

            if (!_maskReady)
            {
                SetupMaskPixelBlender(width, height);
                _maskReady = true;
            }

            //
            //painter.DestBitmapBlender.OutputPixelBlender = maskPixelBlender; //change to new blender
            painter.DestBitmapBlender.OutputPixelBlender = _maskPixelBlenderPerCompo; //change to new blender

            //4.
            painter.FillColor = Color.Black;
            //this test lcd-effect => we need to draw it 3 times with different color component, on the same position
            //(same as we do with OpenGLES rendering surface)
            _maskPixelBlenderPerCompo.SelectedMaskComponent      = PixelBlenderColorComponent.B;
            _maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.B;
            painter.FillRect(0, 0, 200, 100);
            //
            _maskPixelBlenderPerCompo.SelectedMaskComponent      = PixelBlenderColorComponent.G;
            _maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.G;
            painter.FillRect(0, 0, 200, 100);
            //
            _maskPixelBlenderPerCompo.SelectedMaskComponent      = PixelBlenderColorComponent.R;
            _maskPixelBlenderPerCompo.EnableOutputColorComponent = EnableOutputColorComponent.R;
            painter.FillRect(0, 0, 200, 100);
        }
Beispiel #11
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            //get image buffer from info
            if (_needContentUpdate)
            {
                _painter.Clear(PixelFarm.Drawing.Color.Yellow);
                _painter.StrokeColor = PixelFarm.Drawing.Color.Red;
                _painter.StrokeWidth = 2;
                _painter.DrawLine(0, 0, 100, 100);
                _needContentUpdate = false;
            }
            //draw entire bmp or draw some part of it
            canvas.DrawBitmap(_myCanvasBmp, 0, 0);
        }
Beispiel #12
0
        public override void UpdateOutput()
        {
            if (!ReadyToRender)
            {
                return;
            }
            //TODO: review here again
            //----------
            //set some Gdi+ props...
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.Clear(Color.White);
            //credit:
            //http://stackoverflow.com/questions/1485745/flip-coordinates-when-drawing-to-control
            g.ScaleTransform(1.0F, -1.0F);           // Flip the Y-Axis
            g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly

            p.FillColor = PixelFarm.Drawing.Color.Black;
            p.Clear(PixelFarm.Drawing.Color.White);

            // _printer.TargetCanvasPainter = p;
            _visualLine.Draw();


            //----------
            //transform back
            g.ScaleTransform(1.0F, -1.0F);           // Flip the Y-Axis
            g.TranslateTransform(0.0F, -(float)300); // Translate the drawing area accordingly

            //6. use this util to copy image from Agg actual image to System.Drawing.Bitmap

            PixelFarm.CpuBlit.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(p.RenderSurface.DestActualImage, winBmp);
            //---------------
            //7. just render our bitmap
            g.Clear(Color.White);
            g.DrawImage(winBmp, new Point(0, 20));
#if DEBUG
            //draw latest mousedown (x,y)
            g.FillRectangle(Brushes.Green, _mousedown_X, _mousedown_Y, 5, 5);
#endif
        }
Beispiel #13
0
        public FloodFillDemo()
        {
            //
            BackgroundColor = Color.White;
            imageToFillOn   = new ActualImage(400, 300, PixelFormat.ARGB32);
            AggRenderSurface aggsx = new AggRenderSurface(imageToFillOn);
            AggPainter       p     = new AggPainter(aggsx);

            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;
        }
Beispiel #14
0
        public GlyphImage CreateGlyphImage(GlyphPathBuilder builder, float pxscale)
        {
            _txToVxs.Reset();
            //1. builder read shape and translate it with _txToVxs
            builder.ReadShapes(_txToVxs);

            using (VxsTemp.Borrow(out var glyphVxs, out var vxs2))
            {
                //2. write translated data (in the _txToVxs) to glyphVxs

                _txToVxs.WriteOutput(glyphVxs, pxscale);

                RectD bounds = glyphVxs.GetBoundingRect();

                //--------------------------------------------
                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;
                }
                //we need some margin
                int horizontal_margin = 1;
                int vertical_margin   = 1;

                //translate to positive quadrant and use minimum space

                int dx = (int)Math.Ceiling((bounds.Left < 0) ? -bounds.Left : 0);
                int dy = 0;

                //vertical adjust =>since we need to move it, then move it with integer value
                if (bounds.Bottom < 0)
                {
                    dy = (int)Math.Ceiling(-bounds.Bottom);
                }
                else if (bounds.Bottom > 0)
                {
                    dy = (int)Math.Floor(-bounds.Bottom);
                }
                dx += horizontal_margin; //margin left
                dy += vertical_margin;
                //--------------------------------------------
                w = dx + w + horizontal_margin;            //+right margin

                h = vertical_margin + h + vertical_margin; //+bottom margin
                AggPainter painter = Painter;
                if (TextureKind == TextureKind.StencilLcdEffect)
                {
                    glyphVxs.TranslateToNewVxs(dx + 0.33f, dy, vxs2); //offset to proper x of subpixel rendering  ***
                    glyphVxs = vxs2;

                    RectD bounds2 = vxs2.GetBoundingRect();
                    if (w < bounds2.Right)
                    {
                        w = (int)Math.Ceiling(bounds2.Right);
                    }
                    //
                    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
                {
                    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);
                }
                //


                if (w > painter.RenderSurface.DestBitmap.Width)
                {
                    w = painter.RenderSurface.DestBitmap.Width;
                }
                if (h > painter.RenderSurface.DestBitmap.Height)
                {
                    h = painter.RenderSurface.DestBitmap.Height;
                }

                var glyphImage = new GlyphImage(w, h);

#if DEBUG
                if (dx < short.MinValue || dx > short.MaxValue)
                {
                    throw new NotSupportedException();
                }
                if (dy < short.MinValue || dy > short.MaxValue)
                {
                    throw new NotSupportedException();
                }
#endif

                glyphImage.TextureOffsetX = (short)dx;
                glyphImage.TextureOffsetY = (short)dy;

                glyphImage.SetImageBuffer(MemBitmapExtensions.CopyImgBuffer(painter.RenderSurface.DestBitmap, w, h), false);
                //copy data from agg canvas to glyph image
                return(glyphImage);
            }
        }
Beispiel #15
0
        void UpdateRenderOutput()
        {
            if (!_readyToRender)
            {
                return;
            }
            //
            if (g == null)
            {
                destImg = new ActualImage(800, 600, PixelFormat.ARGB32);
                _aggsx  = new AggRenderSurface(destImg); //no platform
                painter = new AggPainter(_aggsx);
                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, _basicOptions.OpenFontStore);
                _devVxsTextPrinter.TargetCanvasPainter = painter;
                _devVxsTextPrinter.ScriptLang          = _basicOptions.ScriptLang;
                _devVxsTextPrinter.PositionTechnique   = Typography.TextLayout.PositionTechnique.OpenFont;
                //_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 = _contourAnalysisOpts.SetupPrinterLayoutForLcdSubPix;



            //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;


                glyphTextureBitmapGenUserControl1.SelectedTypeface = _basicOptions.Typeface;
                glyphTextureBitmapGenUserControl1.FontSizeInPoints = _basicOptions.FontSizeInPoints;
                glyphTextureBitmapGenUserControl1.SelectedScriptLangs.Clear();
                glyphTextureBitmapGenUserControl1.SelectedScriptLangs.Add(_basicOptions.ScriptLang);

                //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 = 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(System.Drawing.Color.White);
                g.DrawImage(winBmp, new System.Drawing.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();
            }
        }
Beispiel #16
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);
        }
Beispiel #17
0
        public override void Draw(Painter painter)
        {
            AggPainter p = painter as AggPainter;

            if (p == null)
            {
                return;
            }
            if (!_fontAtlasPrinterReady)
            {
                SetupFontAtlasPrinter(p);
            }

            p.RenderQuality = RenderQuality.HighQuality;
            p.Orientation   = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;

            //clear the image to white
            // draw a circle
            p.Clear(Drawing.Color.Yellow);
            p.FillColor = Color.Black;


            int lineSpaceInPx = (int)p.CurrentFont.LineSpacingInPixels;

            if (lineSpaceInPx == 0)
            {
                lineSpaceInPx = 16; //tmp fix
            }
            int ypos = 0;


            DrawString(p, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", 10, ypos);
            ypos += lineSpaceInPx;
            //--------

            p.FillColor = Color.Black;
            if (_useFontAtlas)
            {
                DrawString(p, "Hello World from FontAtlasTextPrinter", 10, ypos);
            }
            else
            {
                DrawString(p, "Hello World from VxsTextPrinter", 10, ypos);
            }

            ypos += lineSpaceInPx;

            p.FillColor = Color.Blue;
            DrawString(p, "Hello World", 10, ypos);
            ypos += lineSpaceInPx;

            p.FillColor = Color.Red;
            DrawString(p, "Hello World", 10, ypos);
            ypos += lineSpaceInPx;

            p.FillColor = Color.Yellow;
            DrawString(p, "Hello World", 10, ypos);
            ypos += lineSpaceInPx;

            p.FillColor = Color.Gray;
            DrawString(p, "Hello World", 10, ypos);
            ypos += lineSpaceInPx;

            p.FillColor = Color.Black;
            DrawString(p, "Hello World", 10, ypos);
            ypos += lineSpaceInPx;

            if (!string.IsNullOrEmpty(UserText))
            {
                DrawString(p, UserText, 10, ypos);
                ypos += lineSpaceInPx;
            }
        }