예제 #1
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);
        }
예제 #2
0
 static GlyphMeshStore()
 {
     s_flipY = AffineMat.Iden();
     s_flipY.Scale(1, -1);
     //
     s_slantHorizontal = AffineMat.Iden();
     s_slantHorizontal.Skew(AggMath.deg2rad(-15), 0);
 }
예제 #3
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();
        }
예제 #4
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);
                //-------------------
            }

        }
예제 #5
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;
            }
        }
예제 #6
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);
            }
        }