public static VertexStore ScaleToNewVxs(this VertexStore src, double sx, double sy, VertexStore outputVxs)
 {
     return(AffineMat.GetScaleMat(sx, sy).TransformToVxs(src, outputVxs));
     ////TODO: review here, use struct mat
     //Affine aff = Affine.NewScaling(sx, sy);
     //return aff.TransformToVxs(src, outputVxs);
 }
Esempio n. 2
0
        VertexStore BuildVxsForGlyph(GlyphOutlineBuilder builder, char character, float size)
        {
            //-----------
            //TODO: review here
            builder.Build(character, size);
            var txToVxs = new GlyphTranslatorToVxs();

            builder.ReadShapes(txToVxs);

            VertexStore v2 = new VertexStore();

            using (Tools.BorrowVxs(out var v0))
                using (Tools.BorrowCurveFlattener(out var flattener))
                {
                    txToVxs.WriteOutput(v0);

                    Q1RectD bounds = v0.GetBoundingRect();

                    AffineMat mat = AffineMat.Iden();
                    mat.Scale(1, -1);//flipY
                    mat.Translate(0, bounds.Height);

                    flattener.MakeVxs(v0, mat, v2);
                }
            return(v2);
        }
        public static VertexStore RotateDegToNewVxs(this VertexStore src, double deg, VertexStore outputVxs)
        {
            return(AffineMat.GetRotateDegMat(deg).TransformToVxs(src, outputVxs));

            //TODO: review here, use struct mat
            //Affine aff = Affine.NewRotationDeg(deg);
            //return aff.TransformToVxs(src, outputVxs);
        }
Esempio n. 4
0
 static GlyphMeshStore()
 {
     s_flipY = AffineMat.Iden();
     s_flipY.Scale(1, -1);
     //
     s_slantHorizontal = AffineMat.Iden();
     s_slantHorizontal.Skew(AggMath.deg2rad(-15), 0);
 }
Esempio n. 5
0
 public void WriteUnFlattenOutput(VertexStore output, float scale)
 {
     if (scale == 1)
     {
         output.AppendVertexStore(_vxs);
     }
     else
     {
         AffineMat.GetScaleMat(scale).TransformToVxs(_vxs, output);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// write output to vxs, use user's curve flattener
 /// </summary>
 /// <param name="output"></param>
 /// <param name="scale"></param>
 public void WriteOutput(VertexStore output, CurveFlattener curveFlattener, float scale = 1)
 {
     if (scale == 1)
     {
         curveFlattener.MakeVxs(_vxs, output);
     }
     else
     {
         AffineMat mat = AffineMat.GetScaleMat(scale);
         curveFlattener.MakeVxs(_vxs, mat, output);
     }
 }
Esempio n. 7
0
 MemBitmap CreateHalfSize(MemBitmap orgBmp)
 {
     //TODO: ...
     //
     //1. create a new one
     MemBitmap smallBmp = new MemBitmap(orgBmp.Width / 2, orgBmp.Height / 2);
     using (Tools.BorrowAggPainter(smallBmp, out var painter))
     {
         AffineMat mat = AffineMat.GetScaleMat(0.5);
         painter.DrawImage(orgBmp, mat);
     }
     return smallBmp;
 }
        public static void ReverseClockDirection(this VertexStore src, VertexStore outputVxs)
        {
            //temp fix for reverse clock direction
            Q1RectD bounds  = src.GetBoundingRect();
            double  centerX = (bounds.Left + bounds.Width) / 2;
            double  centerY = (bounds.Top + bounds.Height) / 2;

            //Affine aff = Affine.New(AffinePlan.Translate(-centerX, -centerY),
            //     AffinePlan.Scale(1, -1),//flipY,
            //     AffinePlan.Translate(centerX, centerY));
            AffineMat aff = AffineMat.Iden();

            aff.Translate(-centerX, -centerY);
            aff.Translate(1, -1);//flipY
            aff.Translate(centerX, centerY);
            aff.TransformToVxs(src, outputVxs);
        }
Esempio n. 9
0
        public override void Draw(Painter p)
        {
            p.Clear(Drawing.Color.Yellow);

            ////
            ////---reference line--
            p.StrokeColor = Color.Black;
            p.DrawLine(0, 400, 800, 400); //draw reference line
            p.DrawImage(_lionImg, 300, 0);

            int _imgW = _lionImg.Width;
            int _imgH = _lionImg.Height;


            int x_pos = 0;
            for (int i = 0; i < 360; i += 30)
            {

                AffineMat aff = AffineMat.Iden();
                aff.Translate(-_imgW / 2f, -_imgH / 2f);
                aff.Scale(0.5, 0.5);
                aff.RotateDeg(i);
                aff.Translate((_imgW / 2f) + x_pos, _imgH / 2f);

                p.DrawImage(_lionImg, aff);

                x_pos += _imgW / 3;
            }


            using (Tools.BorrowVxs(out var vxs1, out var vxs2))
            using (Tools.BorrowRect(out var rect))
            {
                int x = 5, y = 5, w = 100, h = 100;
                rect.SetRect(x, y, x + w, y + h);
                rect.MakeVxs(vxs1);
                p.Fill(vxs1, Color.Blue);
                //-------------------
                AffineMat af = AffineMat.GetRotateDegMat(30, w / 2f, h / 2f);

                af.TransformToVxs(vxs1, vxs2);
                p.Fill(vxs2, Color.Red);
                //-------------------
            }

        }
Esempio n. 10
0
        private void button2_Click(object sender, EventArgs e)
        {
            //EXAMPLE, low-level

            //this show how to render a glyph on screen
            //read font file
            LoadFont();
            //inside a font
            //get some glyph by its name
            //Glyph oneGlyph = _latinModernMathFont.GetGlyphByName("one"); //for get glyph by name

            ushort glyphIndex = _latinModernMathFont.GetGlyphIndex((int)'1');


            //a glyph contains coordinates of line and curves
            //we transform data inside it to vxs
            //this is done by GlyphContour builder
            GlyphTranslatorToVxs glyphTxToVxs   = new GlyphTranslatorToVxs();
            GlyphOutlineBuilder  outlineBuilder = new GlyphOutlineBuilder(_latinModernMathFont);

            outlineBuilder.BuildFromGlyphIndex(glyphIndex, 20); //read data into outline builder
            outlineBuilder.ReadShapes(glyphTxToVxs);            //translate data inside outline builder to vxs
            using (Tools.BorrowVxs(out var v1, out var v2))
                using (Tools.BorrowAggPainter(_memBmp, out var p))
                {
                    glyphTxToVxs.WriteOutput(v1);
                    //original v1 is head-down
                    Q1RectD bounds = v1.GetBoundingRect(); //with this bounds you also know glyph width/height
                    //we want head up, so => flip it
                    AffineMat aff = AffineMat.Iden();
                    aff.Translate(-bounds.Width / 2, -bounds.Height / 2);
                    aff.Scale(1, -1);
                    aff.Translate(bounds.Width / 2, bounds.Height / 2);

                    aff.TransformToVxs(v1, v2);

                    //copy data
                    //now the glyph data is inside v1
                    //test paint this glyph
                    p.Clear(PixelFarm.Drawing.Color.White);
                    p.Fill(v2, PixelFarm.Drawing.Color.Black);
                }

            //-----------
            CopyBitmapToScreen();
        }
Esempio n. 11
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;
            }

            AffineMat mat = AffineMat.Iden();

            mat.RotateDeg(_rotationDeg, _imgW / 2.0, _imgH / 2.0);
            p.DrawImage(_orgImg, mat);

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

            base.Draw(p);
        }
Esempio n. 12
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            using (Tools.BorrowVxs(out var v1, out var v2, out var v3))
                using (Tools.BorrowPathWriter(v1, out PathWriter p))
                {
                    p.MoveTo(0, 50);
                    p.LineTo(50, 50);
                    p.LineTo(10, 100);
                    p.CloseFigure();

                    _polygon1 = _painter.CreateRenderVx(v1.CreateTrim());
                    AffineMat tx = AffineMat.Iden();
                    tx.Translate(200, 0);

                    tx.TransformToVxs(v1, v2); //v1=>v2
                    _polygon2 = _painter.CreateRenderVx(v2.CreateTrim());

                    tx.TransformToVxs(v2, v3); //v2=>v3
                    _polygon3 = _painter.CreateRenderVx(v3.CreateTrim());
                }
        }
Esempio n. 13
0
 public MatrixTransform(AffineMat affine)
 {
     _affine = affine;
 }
Esempio n. 14
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            //reset
            _pcx.SmoothMode = SmoothMode.Smooth;
            _pcx.ClearColorBuffer();
            _painter.Clear(Color.Yellow);

            switch (DrawSet)
            {
            case T408_DrawSet.A:
            {
                //draw msdf bitmap to mask surface
                if (_maskRenderSurface == null)
                {
                    GLRenderSurface currentSurface = _pcx.CurrentRenderSurface;
                    _maskRenderSurface = new GLRenderSurface(100, 100);
                    _pcx.AttachToRenderSurface(_maskRenderSurface);
                    //draw mask
                    _pcx.Clear(Color.Black);
                    _pcx.DrawImageWithMsdf(_msdfMaskGLBmp, 0, 0, 5, Color.White);
                    //switch back to normal surface
                    _pcx.AttachToRenderSurface(currentSurface);
                }

                //render with simple mask
                _pcx.DrawImageWithMask(
                    _maskRenderSurface.GetInnerGLData().GLBmp,
                    _colorGLBmp, 0, 0);
            }
            break;

            case T408_DrawSet.B:
            {
                RectangleF maskSrc = new RectangleF(0, 0, _msdfMaskBmp.Width, _msdfMaskBmp.Height);

                Rectangle rect = new Rectangle(10, 10, 120, 120);
                Quad2f    quad = new Quad2f();
                quad.SetCornersFromRect(rect);

                AffineMat mat1 = AffineMat.Iden();
                mat1.Translate(-rect.Width / 2, -rect.Height / 2);
                mat1.RotateDeg(45);
                mat1.Translate(rect.Width / 2, rect.Height / 2);
                quad.Transform(mat1);        //***test transform

                //-----------------------
                //create mask surface, this quite low leve step.
                //user should use this through drawboard
                //-----------------------

                if (_maskRenderSurface2 == null)
                {
                    //before we switch to another GLRenderSurface.
                    //we save current setting of current GLRenderSurface


                    _pcx.SaveStates(out GLPainterStatesData saveData1);

                    _maskRenderSurface2 = new GLRenderSurface(100, 100);

                    _pcx.AttachToRenderSurface(_maskRenderSurface2);
                    _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;


                    //draw mask
                    _pcx.Clear(Color.Black);
                    //draw image to specific quad
                    _pcx.DrawImageWithMsdf(_msdfMaskGLBmp, quad, Color.White);

                    //switch back to normal surface
                    _pcx.RestoreStates(saveData1);
                }


                _pcx.DrawImageWithMask(
                    _maskRenderSurface2.GetInnerGLData().GLBmp,
                    _colorGLBmp, 20, 20);
            }
            break;
            }

            SwapBuffers();
        }
Esempio n. 15
0
 public static VertexStore RotateRadToNewVxs(this VertexStore src, double rad, VertexStore outputVxs)
 {
     return(AffineMat.GetRotateMat(rad).TransformToVxs(src, outputVxs));
     //Affine aff = Affine.NewRotation(rad);
     //return aff.TransformToVxs(src, outputVxs);
 }
Esempio n. 16
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _pcx.SmoothMode  = SmoothMode.Smooth;
            _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _pcx.Clear(PixelFarm.Drawing.Color.White); //set clear color and clear all buffer
            _pcx.ClearColorBuffer();                   //test , clear only color buffer
            //-------------------------------
            if (!_isInit)
            {
                _glbmp  = DemoHelper.LoadTexture(RootDemoPath.Path + @"\logo-dark.jpg");
                _isInit = true;
            }

            PixelFarm.Drawing.RenderSurfaceOriginKind prevOrgKind = _pcx.OriginKind; //save
            switch (DrawSet)
            {
            default:
            case T107_1_DrawImageSet.Full:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImage(_glbmp, i, i);         //left,top (NOT x,y)
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImage(_glbmp, i, i);         //left,top (NOT x,y)
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.Half:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);         //left,top (NOT x,y)
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToRect:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    //PixelFarm.Drawing.RectangleF srcRect = new PixelFarm.Drawing.RectangleF(i, i, _glbmp.Width, _glbmp.Height);
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    //PixelFarm.Drawing.RectangleF srcRect = new PixelFarm.Drawing.RectangleF(i, i, _glbmp.Width, _glbmp.Height);
                    _pcx.DrawImage(_glbmp, i, i, _glbmp.Width / 2, _glbmp.Height / 2);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToQuad1:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;

                Quad2f quad = new Quad2f();
                quad.SetCornersFromRect(0, 0, _glbmp.Width / 2, _glbmp.Height / 2);        //half size

                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)

                    _pcx.DrawImageToQuad(_glbmp, quad);

                    quad.Offset(50, 50);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                quad.SetCornersFromRect(0, 0, _glbmp.Width / 2, _glbmp.Height / 2);        //half size
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageToQuad(_glbmp, quad);
                    quad.Offset(50, 50);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToQuad2:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;

                float rotateDegree = 20;

                //float[] quad = new float[8];

                Quad2f quad = new Quad2f();

                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    quad.SetCornersFromRect(0, 0, _glbmp.Width, _glbmp.Height);

                    AffineMat aff = AffineMat.Iden();
                    aff.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2);        //move to bitmap's center
                    aff.RotateDeg(rotateDegree);
                    aff.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2);

                    quad.Transform(aff);

                    _pcx.DrawImageToQuad(_glbmp, quad);

                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;


                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    quad.SetCornersFromRect(0, 0, _glbmp.Width, -_glbmp.Height);

                    AffineMat aff = AffineMat.Iden();
                    aff.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2);        //move to bitmap's center
                    aff.RotateDeg(rotateDegree);
                    aff.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2);

                    quad.Transform(aff);

                    _pcx.DrawImageToQuad(_glbmp, quad);

                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.ToQuad3:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;

                float rotateDegree = 60;

                for (int i = 0; i < 400;)
                {
                    AffineMat aff = AffineMat.Iden();
                    aff.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2);        //move to bitmap's center
                    aff.RotateDeg(rotateDegree);
                    aff.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2);

                    _pcx.DrawImageToQuad(_glbmp, aff);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    AffineMat aff = AffineMat.Iden();
                    aff.Translate(-_glbmp.Width / 2, -_glbmp.Height / 2);        //move to bitmap's center
                    aff.RotateDeg(rotateDegree);
                    aff.Translate(i + _glbmp.Width / 2, i + _glbmp.Height / 2);

                    _pcx.DrawImageToQuad(_glbmp, aff);


                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImages0:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(0, 0, _glbmp.Width, _glbmp.Height);
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawSubImage(_glbmp, srcRect, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawSubImage(_glbmp, srcRect, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImages1:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(0, 0, _glbmp.Width / 2, _glbmp.Height / 2);

                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)

                    _pcx.DrawSubImage(_glbmp, srcRect, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawSubImage(_glbmp, srcRect, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImages2:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(20, 20, 50, 50);

                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)

                    _pcx.DrawSubImage(_glbmp, srcRect, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawSubImage(_glbmp, srcRect, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImagesWithScale:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                PixelFarm.Drawing.Rectangle srcRect = new PixelFarm.Drawing.Rectangle(20, 20, 50, 50);

                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawSubImage(_glbmp, srcRect, i, i, 2f);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawSubImage(_glbmp, srcRect, i, i, 2f);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImageWithBlurX:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImageWithBlurX(_glbmp, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageWithBlurX(_glbmp, i, i);
                    i += 50;
                }
            }
            break;

            case T107_1_DrawImageSet.SubImageWithBlurY:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImageWithBlurY(_glbmp, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageWithBlurY(_glbmp, i, i);
                    i += 50;
                }

                //
            }
            break;

            case T107_1_DrawImageSet.DrawWithConv3x3:
            {
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftTop;
                for (int i = 0; i < 400;)
                {
                    //left,top (NOT x,y)
                    _pcx.DrawImageWithConv3x3(_glbmp, Mat3x3ConvGen.sobelHorizontal, i, i);
                    i += 50;
                }
                //
                _pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOriginKind.LeftBottom;
                for (int i = 0; i < 400;)
                {
                    _pcx.DrawImageWithConv3x3(_glbmp, Mat3x3ConvGen.emboss, i, i);
                    i += 50;
                }
            }
            break;
            }
            _pcx.OriginKind = prevOrgKind;//restore
        }
Esempio n. 17
0
        VgVisualElement CreatePolyline(VgVisualElement parentNode, SvgPolylineSpec polylineSpec)
        {
            VgVisualElement vgPolyline = new VgVisualElement(WellknownSvgElementName.Polyline, polylineSpec, _vgVisualDoc);

            PointF[] points = polylineSpec.Points;
            int      j      = points.Length;

            if (j > 1)
            {
                using (Tools.BorrowVxs(out var v1))
                {
                    PointF p = points[0];
                    v1.AddMoveTo(p.X, p.Y);
                    for (int i = 1; i < j; ++i)
                    {
                        p = points[i];
                        v1.AddLineTo(p.X, p.Y);
                    }
                    vgPolyline.VxsPath = v1.CreateTrim();
                }
                AssignAttributes(polylineSpec);

                //--------------------------------------------------------------------
                ResolveMarkers(vgPolyline, polylineSpec);
                if (vgPolyline._pathMarkers != null)
                {
                    //create primary instance plan for this polyline
                    VgPathVisualMarkers pathMarkers = vgPolyline._pathMarkers;
                    pathMarkers.AllPoints = points;

                    //start, mid, end
                    if (pathMarkers.StartMarker != null)
                    {
                        //turn marker to the start direction
                        PointF p0 = points[0];
                        PointF p1 = points[1];
                        //find rotation angle
                        double        rotateRad  = Math.Atan2(p0.Y - p1.Y, p0.X - p1.X);
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.StartMarker._visualSpec;

                        //create local-transformation matrix
                        pathMarkers.StartMarkerPos = new PointF(p0.X, p0.Y);

                        AffineMat mat = AffineMat.Iden();
                        mat.Translate(-markerSpec.RefX.Number, -markerSpec.RefY.Number); //move to the ref point
                        mat.Rotate(rotateRad);

                        pathMarkers.StartMarkerAffine = new Affine(mat);
                    }
                    //-------------------------------
                    if (pathMarkers.MidMarker != null)
                    {
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.StartMarker._visualSpec;
                        pathMarkers.MidMarkerAffine = Affine.NewTranslation(-markerSpec.RefX.Number, -markerSpec.RefY.Number);
                    }
                    //-------------------------------
                    if (pathMarkers.EndMarker != null)
                    {
                        //turn marker to the start direction
                        PointF p0 = points[j - 2]; //before the last one
                        PointF p1 = points[j - 1]; //the last one
                                                   //find rotation angle
                        double        rotateRad  = Math.Atan2(p1.Y - p0.Y, p1.X - p0.X);
                        SvgMarkerSpec markerSpec = (SvgMarkerSpec)pathMarkers.EndMarker._visualSpec;


                        //create local-transformation matrix
                        pathMarkers.EndMarkerPos = new PointF(p1.X, p1.Y);

                        AffineMat mat = AffineMat.Iden();
                        mat.Translate(-markerSpec.RefX.Number, -markerSpec.RefY.Number); //move to the ref point
                        mat.Rotate(rotateRad);
                        pathMarkers.EndMarkerAffine = new Affine(mat);
                    }
                }
            }
            return(vgPolyline);
        }
        /// <summary>
        /// we do not store input linearGradient
        /// </summary>
        /// <param name="linearGradient"></param>
        static void Build(Drawing.LinearGradientBrush linearGradient,
                          out float[] v2f,
                          out float[] colors)
        {
            ColorStop[] colorStops = linearGradient.ColorStops;


            s_vertices.Clear();
            s_v2fList.Clear();
            s_colorList.Clear();

            float x_1 = linearGradient.StartPoint.X;
            float y_1 = linearGradient.StartPoint.Y;

            double angleRad = linearGradient.Angle;
            double totalLen = linearGradient.Length;

            int pairCount = colorStops.Length - 1;

            ColorStop c0;
            ColorStop c1;

            //create a simple horizontal linear gradient bar
            //and we will rotate and translate it to target pos
            for (int i = 0; i < pairCount; ++i)
            {
                c0 = colorStops[i];
                c1 = colorStops[i + 1];

                CalculateLinearGradientVxs(s_vertices,
                                           i == 0,
                                           i == pairCount - 1,
                                           (float)(x_1 + (c0.Offset * totalLen)),
                                           (float)((c1.Offset - c0.Offset) * totalLen),
                                           c0,
                                           c1);
            }

            var txMatrix = AffineMat.Iden();

            txMatrix.Rotate(angleRad, x_1, y_1); //rotate around x_1,y_1

            int j = s_vertices.Count;

            for (int m = 0; m < j; ++m)
            {
                ColorAndCoord v   = s_vertices[m];
                double        v_x = v.x;
                double        v_y = v.y;

                txMatrix.Transform(ref v_x, ref v_y);

                s_v2fList.Add((float)v_x);
                s_v2fList.Add((float)v_y);

                Color color = v.color;

                s_colorList.Add(color.R / 255f);
                s_colorList.Add(color.G / 255f);
                s_colorList.Add(color.B / 255f);
                s_colorList.Add(color.A / 255f);
            }

            v2f    = s_v2fList.ToArray();
            colors = s_colorList.ToArray();
        }
Esempio n. 19
0
        protected override void CreateCustomNotation(EncloseNotation notation,
                                                     float thickness, float w, float h,
                                                     HorizontalStackBox hbox, float maxLeft, float maxTop, float extend, float over,
                                                     EncloseBox encloseBox)
        {
            //notations that only custom lines

            using (Tools.BorrowVxs(out VertexStore vsx1, out VertexStore vsx2))
                using (Tools.BorrowStroke(out Stroke stroke))
                    using (Tools.BorrowPathWriter(vsx1, out PathWriter pathWriter))
                    {
                        var customVsxBox = new MyCustomNotationVsxBox();
                        stroke.LineJoin = LineJoin.Bevel;
                        stroke.Width    = thickness;
                        int useVxs = 1;//default = vxs1
                        switch (notation)
                        {
                        default:
                            useVxs = 0;//not match only lines notation
                            break;

                        case EncloseNotation.actuarial:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(w, 0);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.box:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(0, h);
                            pathWriter.LineTo(w, h);
                            pathWriter.LineTo(w, 0);
                            pathWriter.LineTo(0, 0);
                            break;

                        case EncloseNotation.left:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(0, h);
                            break;

                        case EncloseNotation.right:
                            pathWriter.MoveTo(w, 0);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.top:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(w, 0);
                            break;

                        case EncloseNotation.bottom:
                            pathWriter.MoveTo(0, h);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.updiagonalstrike:
                            pathWriter.MoveTo(0, h);
                            pathWriter.LineTo(w, 0);
                            break;

                        case EncloseNotation.downdiagonalstrike:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.verticalstrike:
                            pathWriter.MoveTo(w / 2f, 0);
                            pathWriter.LineTo(w / 2f, h);
                            break;

                        case EncloseNotation.horizontalstrike:
                            pathWriter.MoveTo(0, h / 2f);
                            pathWriter.LineTo(w, h / 2f);
                            break;

                        case EncloseNotation.madruwb:
                            pathWriter.MoveTo(w, 0);
                            pathWriter.LineTo(w, h);
                            pathWriter.LineTo(0, h);
                            break;

                        case EncloseNotation.updiagonalarrow:
                            double arrowAngleDegree = Math.Atan(h / w) * 180.0 / Math.PI;
                            double arrowLength      = Math.Sqrt(Math.Pow(h, 2) + Math.Pow(w, 2));//pythagoras

                            float arrowWing = GetPixelScale() * 150;
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(arrowLength, 0);
                            pathWriter.LineTo(arrowLength - arrowWing, -arrowWing);
                            pathWriter.LineTo(arrowLength - arrowWing, arrowWing);
                            pathWriter.LineTo(arrowLength, 0);

                            AffineMat mat = AffineMat.Iden();
                            mat.RotateDeg(-arrowAngleDegree);
                            mat.Translate(0, h);
                            mat.TransformToVxs(vsx1, vsx2);

                            useVxs = 2;
                            break;

                        case EncloseNotation.phasorangle:
                            float angleWidth  = 640 * GetPixelScale();  //x 637.5
                            float angleHeight = 1160 * GetPixelScale(); //y 1162.5
                            float shiftH      = h - angleHeight;
                            pathWriter.MoveTo(angleWidth, shiftH);
                            pathWriter.LineTo(0, angleHeight + shiftH);
                            pathWriter.LineTo(maxLeft - angleWidth + w, angleHeight + shiftH);

                            customVsxBox.BeforeBaseBox = angleWidth;
                            break;

                        case EncloseNotation.longdiv:
                            GlyphBox ldiv = NewGlyphBox();
                            ldiv.Character = ')';
                            AssignGlyphVxs(ldiv);
                            ldiv.Layout();

                            Box actualDiv = StretchHeightIfStretchable(ldiv, hbox.Height + over);
                            actualDiv.Layout();
                            customVsxBox.NotationBox = actualDiv;
                            float shiftLeft = maxLeft - actualDiv.Width;
                            float shiftTop  = maxTop - over;
                            actualDiv.SetLocation(shiftLeft, -shiftTop - over);
                            pathWriter.MoveTo(shiftLeft, shiftTop);
                            pathWriter.LineTo(shiftLeft + hbox.Width + actualDiv.Width + extend, shiftTop);
                            pathWriter.Stop();

                            customVsxBox.BeforeBaseBox = actualDiv.Width + extend;
                            break;

                        case EncloseNotation.radical:
                            GlyphBox radical = NewGlyphBox();
                            radical.Character = (char)0x221A;
                            AssignGlyphVxs(radical);
                            radical.Layout();

                            Box actualRadical = StretchHeightIfStretchable(radical, hbox.Height + over);
                            actualRadical.Layout();
                            float shiftLeft1 = maxLeft - actualRadical.Width;
                            float shiftTop1  = maxTop - over;
                            actualRadical.SetLocation(shiftLeft1, -shiftTop1 - over);
                            customVsxBox.NotationBox = actualRadical;

                            pathWriter.MoveTo(shiftLeft1 + actualRadical.Width, shiftTop1);
                            pathWriter.LineTo(shiftLeft1 + actualRadical.Width + hbox.Width + extend, shiftTop1);
                            pathWriter.Stop();

                            customVsxBox.BeforeBaseBox = actualRadical.Width + extend;
                            break;

                        case EncloseNotation.roundedbox:
                            using (Tools.BorrowRoundedRect(out var roundedRect))
                            {
                                roundedRect.SetRadius(over, over, over, over, over, over, over, over);
                                roundedRect.SetRect(0, 0, w, h);
                                roundedRect.MakeVxs(vsx1);
                                customVsxBox.CustomVxs = stroke.CreateTrim(vsx1);
                            }
                            customVsxBox.BeforeBaseBox = over;
                            break;

                        case EncloseNotation.circle:
                            using (Tools.BorrowEllipse(out Ellipse ellipse))
                            {
                                float xLength = hbox.Width / 2 + maxLeft;
                                float yLength = hbox.Height / 2 + maxTop;

                                ellipse.Set(xLength, yLength, xLength, yLength);
                                ellipse.MakeVxs(vsx1);
                                customVsxBox.CustomVxs     = stroke.CreateTrim(vsx1);
                                customVsxBox.BeforeBaseBox = maxLeft;
                            }
                            break;
                        }
                        if (useVxs > 0)
                        {
                            if (useVxs == 1)
                            {
                                customVsxBox.CustomVxs = stroke.CreateTrim(vsx1);
                            }
                            else if (useVxs == 2)
                            {
                                customVsxBox.CustomVxs = stroke.CreateTrim(vsx2);
                            }
                            encloseBox.NotationBoxs.Add(customVsxBox);
                        }
                    }
        }
Esempio n. 20
0
        /// <summary>
        /// serialize coord-transform-chain to specific stream
        /// </summary>
        /// <param name="coordTx"></param>
        /// <param name="writer"></param>
        public static void Write(ICoordTransformer coordTx, System.IO.BinaryWriter writer)
        {
            //write transformation matrix to binary stream
            CoordTransformerKind txKind = coordTx.Kind;

            switch (txKind)
            {
            case CoordTransformerKind.Unknown:
            default:
                throw new System.NotSupportedException();

            case CoordTransformerKind.Affine3x2:
            {
                Affine aff = (Affine)coordTx;
                writer.Write((ushort)txKind);         //type
                AffineMat affMat = aff.GetInternalMat();
                //write elements
                writer.Write(affMat.sx); writer.Write(affMat.shy);
                writer.Write(affMat.shx); writer.Write(affMat.sy);
                writer.Write(affMat.tx); writer.Write(affMat.ty);
            }
            break;

            case CoordTransformerKind.Bilinear:
            {
                Bilinear binTx = (Bilinear)coordTx;
                writer.Write((ushort)txKind);
                //write elements
                BilinearMat binMat = binTx.GetInternalElements();
                writer.Write(binMat.rc00); writer.Write(binMat.rc01);
                writer.Write(binMat.rc10); writer.Write(binMat.rc11);
                writer.Write(binMat.rc20); writer.Write(binMat.rc21);
                writer.Write(binMat.rc30); writer.Write(binMat.rc31);
            }
            break;

            case CoordTransformerKind.Perspective:
            {
                Perspective perTx = (Perspective)coordTx;
                writer.Write((ushort)txKind);
                PerspectiveMat perMat = perTx.GetInternalElements();
                writer.Write(perMat.sx); writer.Write(perMat.shx); writer.Write(perMat.w0);
                writer.Write(perMat.shy); writer.Write(perMat.sy); writer.Write(perMat.w1);
                writer.Write(perMat.tx); writer.Write(perMat.ty); writer.Write(perMat.w2);

                //sx, shy, w0,
                //shx, sy, w1,
                //tx, ty, w2;
            }
            break;

            case CoordTransformerKind.TransformChain:
            {
                CoordTransformationChain chainTx = (CoordTransformationChain)coordTx;
                writer.Write((ushort)txKind);
                //*** left, right
                Write(chainTx.Left, writer);
                Write(chainTx.Right, writer);
            }
            break;
            }
        }
Esempio n. 21
0
        public override void Draw(Painter p)
        {
            if (UseBitmapExt)
            {
                p.RenderQuality = RenderQuality.Fast;
            }
            else
            {
                p.RenderQuality = RenderQuality.HighQuality;
            }

            p.StrokeColor = Color.Blue;
            p.Clear(Drawing.Color.White);
            p.UseLcdEffectSubPixelRendering = false;
            //string teststr = "ABCDE pqyt 1230";
            //p.FillColor = Color.Black;
            //p.CurrentFont = new RequestFont("tahoma", 10);
            //p.StrokeColor = Color.Red;

            p.RenderQuality = RenderQuality.Fast;
            //
            //---red reference line--
            p.DrawLine(0, 400, 800, 400);
            p.DrawLine(0, 400, 800, 500); //test oblique line

            //p.DrawString(teststr, 300, 400);
            //
            p.DrawRect(0.5, 400, 40, 40);
            //

            p.FillColor = Color.Yellow;


            p.FillEllipse(100.5, 400, 40, 60);
            p.DrawEllipse(50.5, 400, 40, 60);

            //---red reference line--
            p.StrokeColor = Color.Red;
            p.DrawLine(0, 500, 800, 500);

            p.StrokeColor = Color.Blue;
            p.FillColor   = Color.Yellow;
            p.FillRect(0.5, 500, 40, 40);
            //---red reference line--


            p.RenderQuality = RenderQuality.Fast;
            //p.DrawImage(lionImg, 0, 0); //reference at 0,0
            p.DrawImage(_lionImg, 300, 0);

            int _imgW = _lionImg.Width;
            int _imgH = _lionImg.Height;

            //p.RenderQuality = RenderQuality.Fast;

            AffineMat mat = AffineMat.GetRotateDegMat(30, _imgW / 2, _imgH / 2);

            p.DrawImage(_lionImg, mat);

            //AffinePlan.Scale(0.75, 0.75),
            //move to target

            //p.DrawImage(lionImg,
            //   //move to center of the image (hotspot x,y)
            //   AffinePlan.Translate(-_imgW / 2, -_imgH / 2),
            //   AffinePlan.Rotate(AggMath.deg2rad(45)),
            //   AffinePlan.Scale(0.75, 0.75),
            //   //move to target
            //   AffinePlan.Translate(400, 200));
        }
Esempio n. 22
0
 public MatrixTransform()
 {
     _affine = AffineMat.Iden();
 }
Esempio n. 23
0
        public override void Draw(Painter p)
        {


            p.Clear(Drawing.Color.White);
            p.UseLcdEffectSubPixelRendering = false;

            //---red reference line--
            p.StrokeColor = Color.Black;
            p.DrawLine(0, 400, 800, 400); //draw reference line
            p.DrawImage(_lionImg, 300, 0);
            //p.DrawImage(lionImg, 0, 0, 10, 10, 100, 100);

            //
            //p.DrawImage(halfLion, 50, 0);

            int _imgW = _lionImg.Width;
            int _imgH = _lionImg.Height;
            int x_pos = 0;
            int y_pos = 0;


            //1. create new half-size lion image 

            //for (int i = 0; i < 360; i += 30)
            //{
            //    affPlans[0] = AffinePlan.Translate(-_imgW / 2f, -_imgH / 2f);
            //    affPlans[1] = AffinePlan.Scale(1, 1);
            //    affPlans[2] = AffinePlan.Rotate(AggMath.deg2rad(i));
            //    affPlans[3] = AffinePlan.Translate((_imgW / 2f) + x_pos, (_imgH / 2f) + y_pos);
            //    p.DrawImage(halfLion, affPlans);

            //    x_pos += _imgW / 3;
            //}


            x_pos = 0;
            y_pos = 100;


            for (int i = 0; i < 360; i += 30)
            {

                AffineMat aff = AffineMat.Iden();
                aff.Translate(-_imgW / 2f, -_imgH / 2f);
                aff.Scale(0.5, 0.5);
                aff.RotateDeg(i);
                aff.Translate((_imgW / 2f) + x_pos, (_imgH / 2f) + y_pos);

                p.DrawImage(_lionImg, aff);
                x_pos += _imgW / 3;
            }




            //----
            //

            using (Tools.BorrowVxs(out var vxs1, out var vxs2))
            using (Tools.BorrowRect(out var rect))
            {
               
                int x = 5, y = 5, w = 100, h = 100;
                rect.SetRect(x, y, x + w, y + h);
                rect.MakeVxs(vxs1);
                p.Fill(vxs1, Color.Blue);
                //-------------------

                AffineMat mat = AffineMat.GetRotateDegMat(30, w / 2f, h / 2f);

                mat.TransformToVxs(vxs1, vxs2);
                p.Fill(vxs2, Color.Red);
            }
        }
Esempio n. 24
0
        public GradientDemo()
        {
            //solid brush
            _solidBrush = new SolidBrush(Color.Blue);

            //1. linear gradient
            _linearGrBrush = new LinearGradientBrush(
                new PointF(0, 0), new PointF(200, 200),
                new ColorStop[]
            {
                new ColorStop(0.0f, Drawing.Color.Black),
                new ColorStop(0.20f, Drawing.Color.Red),
                new ColorStop(0.50f, Drawing.KnownColors.OrangeRed),
                new ColorStop(0.75f, Drawing.Color.Yellow)
            });


            //2. circular gradient
            _circularGrBrush = new RadialGradientBrush(
                new PointF(50, 20), new PointF(300, 20),
                new ColorStop[]
            {
                //for test different colors
                new ColorStop(0.0f, Drawing.Color.Yellow),
                new ColorStop(0.25f, Drawing.Color.Blue),
                new ColorStop(0.50f, Drawing.Color.Green),
                new ColorStop(0.75f, Drawing.Color.Yellow),
            });



            //3. polygon gradient: this version, just a simple rect

            //PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            // {
            //        new PolygonGradientBrush.ColorVertex2d(5,50,KnownColors.OrangeRed),
            //        new PolygonGradientBrush.ColorVertex2d(50,50,Color.Black),
            //        new PolygonGradientBrush.ColorVertex2d(50,5,Color.Yellow),
            //        new PolygonGradientBrush.ColorVertex2d(5,5,Color.Blue),
            // };
            //PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            //{
            //        new PolygonGradientBrush.ColorVertex2d(5,300,KnownColors.OrangeRed),
            //        new PolygonGradientBrush.ColorVertex2d(300,300,Color.Black),
            //        new PolygonGradientBrush.ColorVertex2d(300,5,Color.Yellow),
            //        new PolygonGradientBrush.ColorVertex2d(5,5,Color.Blue),
            //};
            //PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            //{
            //    new PolygonGradientBrush.ColorVertex2d(5,5,Color.Blue),
            //    new PolygonGradientBrush.ColorVertex2d(220,5,Color.Yellow),
            //    new PolygonGradientBrush.ColorVertex2d(220,100,Color.Black),
            //    new PolygonGradientBrush.ColorVertex2d(5,220,KnownColors.OrangeRed),
            //};
            PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            {
                new PolygonGradientBrush.ColorVertex2d(0, 0, Color.Blue),
                new PolygonGradientBrush.ColorVertex2d(300, 0, Color.Yellow),
                new PolygonGradientBrush.ColorVertex2d(300, 300, Color.Black),
                new PolygonGradientBrush.ColorVertex2d(0, 300, KnownColors.OrangeRed),
            };
            _polygonGradientBrush = new PolygonGradientBrush(vertices);

            using (Tools.BorrowVxs(out var v1, out var v2))
                using (Tools.BorrowPathWriter(v1, out PathWriter p))
                {
                    p.MoveTo(0, 0);
                    p.LineTo(50, 20);
                    p.LineTo(10, 100);
                    p.CloseFigure();

                    AffineMat aff1 = AffineMat.GetScaleMat(2);
                    _triangleVxs = v1.CreateTrim(aff1);

                    AffineMat tx = AffineMat.GetTranslateMat(200, 220);
                    _triangleVxs2 = tx.TransformToVxs(_triangleVxs, v2).CreateTrim();
                }
        }
Esempio n. 25
0
 public override void Init()
 {
     //actualImage2 = LoadImage(RootDemoPath.Path + "\\plain01.png");
     _memBmp = LoadImage(RootDemoPath.Path + "\\02.jpg");
     _mat    = AffineMat.GetTranslateMat(50, 50);
 }
Esempio n. 26
0
        void RenderPolygon(Painter p)
        {
            switch (this.PolygonSet)
            {
            case PolygonExampleSet.TwoSimplePaths:
            {
                //------------------------------------
                // Two simple paths
                using (Tools.BorrowVxs(out var v1, out var v2))
                {
                    double x = _x - Width / 2 + 100;
                    double y = _y - Height / 2 + 100;

                    PolygonClippingDemoHelper.WritePath1(v1, x, y);
                    PolygonClippingDemoHelper.WritePath2(v2, x, y);

                    p.Fill(v1, ColorEx.Make(0f, 0f, 0f, 0.1f));
                    p.Fill(v2, ColorEx.Make(0f, 0.6f, 0f, 0.1f));

                    CreateAndRenderCombined(p, v1, v2);
                }
            }
            break;

            case PolygonExampleSet.CloseStroke:
            {
                //------------------------------------
                // Closed stroke
                using (Tools.BorrowVxs(out var v1, out var v2))
                {
                    double x = _x - Width / 2 + 100;
                    double y = _y - Height / 2 + 100;

                    PolygonClippingDemoHelper.WritePath1(v1, x, y);
                    PolygonClippingDemoHelper.WritePath2(v2, x, y);

                    p.FillStroke(v1, 2, ColorEx.Make(0f, 0f, 0f, 0.1f));
                    p.FillStroke(v2, 3, ColorEx.Make(0f, 0.6f, 0f, 0.1f));

                    CreateAndRenderCombined(p, v1, v2);
                }
            }
            break;

            case PolygonExampleSet.GBAndArrow:
            {
                //------------------------------------
                // Great Britain and Arrows
                using (Tools.BorrowVxs(out var v1_gb_poly, out var v2_arrows))
                {
                    AffineMat mat1 = AffineMat.Iden();
                    mat1.Translate(-1150, -1150);
                    mat1.Scale(2);

                    Affine mtx1 = new Affine(mat1);


                    PolygonClippingDemoHelper.WriteGBObject(v1_gb_poly, 0, 0, mtx1);

                    p.Fill(v1_gb_poly, ColorEx.Make(0.5f, 0.5f, 0f, 0.1f));
                    p.FillStroke(v1_gb_poly, 0.1f, ColorEx.Make(0, 0, 0));

                    //
                    Affine mtx2 = mtx1 * Affine.NewTranslation(_x - Width / 2, _y - Height / 2);
                    PolygonClippingDemoHelper.WriteArrow(v2_arrows, 0, 0, mtx2);
                    p.Fill(v2_arrows, ColorEx.Make(0f, 0.5f, 0.5f, 0.1f));

                    CreateAndRenderCombined(p, v1_gb_poly, v2_arrows);
                }
            }
            break;

            case PolygonExampleSet.GBAndSpiral:
            {
                //------------------------------------
                // Great Britain and a Spiral
                //
                using (Tools.BorrowVxs(out var v1_gb_poly))
                    using (Tools.BorrowVxs(out var v2_spiral, out var v2_spiral_outline))
                        using (Tools.BorrowStroke(out var stroke))
                        {
                            AffineMat mat = AffineMat.Iden();
                            mat.Translate(-1150, -1150);
                            mat.Scale(2);

                            Affine mtx = new Affine(mat);

                            PolygonClippingDemoHelper.WriteGBObject(v1_gb_poly, 0, 0, mtx);
                            PolygonClippingDemoHelper.WriteSpiral(v2_spiral, _x, _y);

                            p.Fill(v1_gb_poly, ColorEx.Make(0.5f, 0.5f, 0f, 0.1f));
                            p.FillStroke(v1_gb_poly, 0.1f, Color.Black);

                            stroke.Width = 15;
                            p.Fill(stroke.MakeVxs(v2_spiral, v2_spiral_outline), ColorEx.Make(0.0f, 0.5f, 0.5f, 0.1f));

                            CreateAndRenderCombined(p, v1_gb_poly, v2_spiral_outline);
                        }
            }
            break;

            case PolygonExampleSet.SprialAndGlyph:
            {
                //------------------------------------
                // Spiral and glyph
                using (Tools.BorrowVxs(out var v1_spiral, out var v1_spiralOutline, out var v3))
                    using (Tools.BorrowVxs(out var glyph_vxs))
                        using (Tools.BorrowStroke(out var stroke))
                        {
                            //Affine mtx = Affine.New(
                            //   AffinePlan.Scale(4),
                            //   AffinePlan.Translate(220, 200));
                            AffineMat mat = AffineMat.Iden();
                            mat.Scale(4);
                            mat.Translate(220, 200);

                            PolygonClippingDemoHelper.WriteSpiral(v1_spiral, _x, _y);
                            PolygonClippingDemoHelper.WriteGlyphObj(glyph_vxs, 0, 0, new Affine(mat));

                            //-----------------------------------------
                            stroke.Width = 1;
                            stroke.MakeVxs(v1_spiral, v1_spiralOutline);

                            CreateAndRenderCombined(p, v1_spiralOutline, glyph_vxs);

                            p.Fill(v1_spiralOutline, ColorEx.Make(0f, 0f, 0f, 0.1f));
                            p.Fill(glyph_vxs, ColorEx.Make(0f, 0.6f, 0f, 0.1f));
                        }
            }
            break;
            }
        }
Esempio n. 27
0
        public override void Draw(Painter p)
        {
            if (UseBitmapExt)
            {
                p.RenderQuality = RenderQuality.Fast;
            }
            else
            {
                p.RenderQuality = RenderQuality.HighQuality;
            }

            int width  = 800;
            int height = 600;

            //clear the image to white
            // draw a circle
            p.Clear(Drawing.Color.White);

            //Ellipse ellipseVxsGen = new Ellipse(0, 0, 100, 50);
            using (Tools.BorrowEllipse(out var ellipseVxsGen))
                using (Tools.BorrowStroke(out var stroke))
                {
                    ellipseVxsGen.Set(0, 0, 100, 50);
                    stroke.Width = 3;



                    for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
                    {
                        //TODO: use AffineMat (stack-base matrix)
                        //var mat = Affine.New(
                        //    AffinePlan.Rotate(MathHelper.DegreesToRadians(angleDegrees)),
                        //    AffinePlan.Translate(width / 2, 150));

                        AffineMat mat = AffineMat.Iden();
                        mat.RotateDeg(angleDegrees);
                        mat.Translate(width / 2, 150);
                        _reusableAff.SetElems(mat);

                        using (Tools.BorrowVxs(out var v1, out var v2, out var v3))
                        {
                            //ellipseVxsGen.MakeVxs(mat, v2);
                            //p.FillColor = Drawing.Color.Yellow;
                            //p.Fill(v2);
                            ////------------------------------------
                            //p.FillColor = Drawing.Color.Blue;
                            //p.Fill(stroke.MakeVxs(v2, v3));
                        }
                    }
                }


            // and a little polygon
            using (Tools.BorrowVxs(out var v1))
                using (Tools.BorrowPathWriter(v1, out PathWriter littlePoly))
                {
                    littlePoly.MoveTo(50, 50);
                    littlePoly.LineTo(150, 50);
                    littlePoly.LineTo(200, 200);
                    littlePoly.LineTo(50, 150);
                    littlePoly.LineTo(50, 50);
                    p.FillColor = Drawing.Color.Blue;
                    p.Fill(v1);
                }
            //---



            //----
            //test draw img



            //
            //g.Render(littlePoly.MakeVertexSnap(), ColorRGBA.Cyan);
            // draw some text
            // draw some text

            //var textPrinter = new TextPrinter();
            //textPrinter.CurrentActualFont = svgFontStore.LoadFont(SvgFontStore.DEFAULT_SVG_FONTNAME, 30);
            //new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);

            //VertexStore vxs = textPrinter.CreateVxs("Printing from a printer".ToCharArray());
            //var affTx = Affine.NewTranslation(width / 2, height / 4 * 3);
            //VertexStore s1 = affTx.TransformToVxs(vxs);
            //p.FillColor = Drawing.Color.Black;
            //p.Fill(s1);
            ////g.Render(s1, ColorRGBA.Black);
            //p.FillColor = Drawing.Color.Red;
            //p.Fill(StrokeHelp.MakeVxs(s1, 1));
            ////g.Render(StrokeHelp.MakeVxs(s1, 1), ColorRGBA.Red);
            //var aff2 = Affine.NewMatix(
            //    AffinePlan.Rotate(MathHelper.DegreesToRadians(90)),
            //    AffinePlan.Translate(40, height / 2));
            //p.FillColor = Drawing.Color.Black;
            //p.Fill(aff2.TransformToVertexSnap(vxs));
            ////g.Render(aff2.TransformToVertexSnap(vxs), ColorRGBA.Black);
        }