Ejemplo n.º 1
0
        void RunSampleF(PixelFarm.Drawing.Painter p)
        {
            //version 4:
            p.Clear(PixelFarm.Drawing.Color.White);
            p.UseSubPixelLcdEffect = this.EnableSubPix;
            //--------------------------
            p.StrokeColor = PixelFarm.Drawing.Color.Black;
            p.StrokeWidth = 2.0f;
            p.DrawLine(2, 0, 10, 15);

            int lineLen = 10;
            int x       = 30;
            int y       = 30;

            p.FillColor = PixelFarm.Drawing.Color.Black;

            VertexStorePool pool = new VertexStorePool();

            using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Windows\\Fonts\\tahoma.ttf", System.IO.FileMode.Open, System.IO.FileAccess.Read))
            {
                Typography.OpenFont.OpenFontReader reader   = new Typography.OpenFont.OpenFontReader();
                Typography.OpenFont.Typeface       typeface = reader.Read(fs);


                var builder = new Typography.Contours.GlyphPathBuilder(typeface);
                builder.BuildFromGlyphIndex((ushort)typeface.LookupIndex('C'), 16);
                PixelFarm.Drawing.Fonts.GlyphTranslatorToVxs tovxs = new Drawing.Fonts.GlyphTranslatorToVxs();
                builder.ReadShapes(tovxs);
                VertexStore vxs = new VertexStore();
                tovxs.WriteOutput(vxs);
                p.Fill(vxs);
            }
            p.FillRect(0, 0, 20, 20);
        }
Ejemplo n.º 2
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            AggPainter aggPainter = (AggPainter)p;

            //----------------
            //5. use PixelFarm's Agg to render to bitmap...
            //5.1 clear background
            p.Clear(PixelFarm.Drawing.Color.White);

            if (FillBG)
            {
                //5.2
                p.FillColor = PixelFarm.Drawing.Color.Black;
                //5.3
                //p.Fill(vxs);

                float x = aggPainter.OriginX;
                float y = aggPainter.OriginY;

                p.Fill(left_vxs);
                aggPainter.SetOrigin(x + 50, y + 20);
                p.Fill(right_vxs);
                aggPainter.SetOrigin(x, y);
            }

            if (FillBorder)
            {
                //5.4
                p.StrokeColor = PixelFarm.Drawing.Color.Green;
                //user can specific border width here...
                //p.StrokeWidth = 2;
                //5.5
                //p.Draw(vxs);
                float x = aggPainter.OriginX;
                float y = aggPainter.OriginY;
                p.Fill(left_vxs);
                aggPainter.SetOrigin(x + 50, y + 20);
                p.Fill(right_vxs);
                aggPainter.SetOrigin(x, y);
            }
        }
Ejemplo n.º 3
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            p.Clear(Drawing.Color.White);
            p.FillColor = Drawing.Color.Black;
            int j = myBrushPathList.Count;

            for (int n = 0; n < j; ++n)
            {
                var brushPath = myBrushPathList[n];
                if (brushPath.Vxs != null)
                {
                    switch (brushPath.BrushMode)
                    {
                    case SmoothBrushMode.CutBrush:
                    {
                    }
                    break;

                    default:
                    {
                        //TODO: review PixelCache here
                        p.FillColor = brushPath.FillColor;
                        p.Fill(brushPath.Vxs);

#if DEBUG
                        //if (brushPath.StrokeColor.alpha > 0)
                        //{
                        //    p.StrokeColor = Drawing.Color.Red;
                        //    p.Draw(brushPath.Vxs);
                        //}
#endif
                    }
                    break;
                    }
                }
                else
                {
                    //current drawing brush
                    var contPoints = brushPath.contPoints;
                    int pcount     = contPoints.Count;
                    for (int i = 1; i < pcount; ++i)
                    {
                        var p0 = contPoints[i - 1];
                        var p1 = contPoints[i];
                        p.DrawLine(p0.x, p0.y, p1.x, p1.y);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        void DrawE(PixelFarm.Drawing.Painter painter)
        {
            PathWriter ps = new PathWriter();

            painter.Clear(PixelFarm.Drawing.Color.White);
            painter.StrokeColor = PixelFarm.Drawing.Color.Red;


            //p.Line(10, 10, 50, 10);
            //p.Line(50, 10, 50, 50);
            //p.Line(50, 50, 10, 50);
            //p.Line(50, 10, 10, 10);

            ps.Clear();
            //ps.MoveTo(10, 10);
            //ps.LineTo(50, 10);
            //ps.LineTo(50, 50);

            //ps.MoveTo(10, 10);
            //ps.LineTo(50, 10);
            //ps.LineTo(10, 20);

            ps.MoveTo(150, 10);
            ps.LineTo(110, 10);
            ps.LineTo(150, 20);

            //ps.MoveTo(50, 50);
            //ps.LineTo(40, 50);
            //ps.LineTo(80, 70);


            //ps.CloseFigure();

            //p.Fill(ps.Vxs, PixelFarm.Drawing.Color.Black);
            VertexStore output = new VertexStore();
            StrokeGen2  gen2   = new StrokeGen2();

            gen2.LineCapStyle    = LineCap.Butt;
            gen2.LineJoinStyle   = LineJoin.Miter;
            gen2.HalfStrokeWidth = 7;//
            gen2.Generate(ps.Vxs, output);
            //-----------------------------------------------------

            painter.Fill(output, PixelFarm.Drawing.Color.Red);
            painter.StrokeWidth = 1f;
            painter.Draw(ps.Vxs, PixelFarm.Drawing.Color.Black);
        }
Ejemplo n.º 5
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            if (myvxs == null)
            {
                var transform = Affine.NewMatix(
                    AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                    AffinePlan.Scale(spriteScale, spriteScale),
                    AffinePlan.Rotate(angle + Math.PI),
                    AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                    AffinePlan.Translate(Width / 2, Height / 2)
                    );
                //create vertextStore again from original path
                myvxs = new VertexStore();

                transform.TransformToVxs(lionShape.Vxs, myvxs);

                if (AutoFlipY)
                {
                    //flip the lion
                    PixelFarm.Agg.Transform.Affine aff = PixelFarm.Agg.Transform.Affine.NewMatix(
                        PixelFarm.Agg.Transform.AffinePlan.Scale(-1, -1),
                        PixelFarm.Agg.Transform.AffinePlan.Translate(0, 600));
                    //
                    var v2 = new VertexStore();
                    myvxs = transform.TransformToVxs(myvxs, v2);
                }
            }
            //---------------------------------------------------------------------------------------------
            {
                int             j        = lionShape.NumPaths;
                int[]           pathList = lionShape.PathIndexList;
                Drawing.Color[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;
                for (int i = 0; i < j; ++i)
                {
                    p.FillColor = colors[i];
                    p.Fill(new VertexStoreSnap(myvxs, pathList[i]));
                }
            }
            //test
            if (SharpenRadius > 0)
            {
                //p.DoFilter(new RectInt(0, p.Height, p.Width, 0), 2);
                //PixelFarm.Agg.Imaging.SharpenFilterARGB.Sharpen()
            }
        }
Ejemplo n.º 6
0
        public void RenderChar(char testChar, HintTechnique hint)
        {
            builder.SetHintTechnique(hint);
#if DEBUG
            GlyphBoneJoint.dbugTotalId        = 0;//reset
            builder.dbugAlwaysDoCurveAnalysis = true;
#endif
            _infoView.Clear();
            _latestHint = hint;
            _testChar   = testChar;
            //----------------------------------------------------
            //
            builder.Build(testChar, _sizeInPoint);
            var txToVxs1 = new GlyphTranslatorToVxs();
            builder.GlyphDynamicEdgeOffset = this.GlyphEdgeOffset;

            builder.ReadShapes(txToVxs1);

#if DEBUG
            var ps = txToVxs1.dbugGetPathWriter();
            _infoView.ShowOrgBorderInfo(ps.Vxs);
#endif
            PixelFarm.Drawing.VertexStore vxs = new PixelFarm.Drawing.VertexStore();

            txToVxs1.WriteOutput(vxs);
            //----------------------------------------------------

            //----------------------------------------------------
            painter.UseSubPixelLcdEffect = this.UseLcdTechnique;
            //5. use PixelFarm's Agg to render to bitmap...
            //5.1 clear background
            painter.Clear(PixelFarm.Drawing.Color.White);

            RectD bounds = new RectD();
            BoundingRect.GetBoundingRect(new PixelFarm.Drawing.VertexStoreSnap(vxs), ref bounds);
            //----------------------------------------------------
            float scale = _typeface.CalculateScaleToPixelFromPointSize(_sizeInPoint);
            _pxscale = scale;
            this._infoView.PxScale = scale;


            var   left2   = 0;
            int   floor_1 = (int)left2;
            float diff    = left2 - floor_1;
            //----------------------------------------------------
            if (OffsetMinorX)
            {
                MinorOffsetInfo = left2.ToString() + " =>" + floor_1 + ",diff=" + diff;
            }
            else
            {
                MinorOffsetInfo = left2.ToString();
            }


            //5. use PixelFarm's Agg to render to bitmap...
            //5.1 clear background
            painter.Clear(PixelFarm.Drawing.Color.White);

            if (FillBackGround)
            {
                //5.2
                painter.FillColor = PixelFarm.Drawing.Color.Black;

                float xpos = 5;// - diff;
                if (OffsetMinorX)
                {
                    xpos -= diff;
                }

                painter.SetOrigin(xpos, 10);
                painter.Fill(vxs);
            }
            if (DrawBorder)
            {
                //5.4
                painter.StrokeColor = PixelFarm.Drawing.Color.Green;
                //user can specific border width here...
                //5.5
                painter.Draw(vxs);
                //--------------
                int    markOnVertexNo = _infoView.DebugMarkVertexCommand;
                double x, y;
                vxs.GetVertex(markOnVertexNo, out x, out y);
                painter.FillRect(x, y, 4, 4, PixelFarm.Drawing.Color.Red);
                //--------------
                _infoView.ShowFlatternBorderInfo(vxs);
                //--------------
            }
#if DEBUG
            builder.dbugAlwaysDoCurveAnalysis = false;
#endif

            if (ShowTess)
            {
                RenderTessTesult();
            }

            //if (DrawDynamicOutline)
            //{
            //    GlyphDynamicOutline dynamicOutline = builder.LatestGlyphFitOutline;
            //    WalkDynamicOutline(painter, dynamicOutline, scale, DrawRegenerateOutline);

            //}
        }
Ejemplo n.º 7
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            p.RenderQuality = RenderQuality.Fast;
            Brush prevBrush = p.CurrentBrush;
            Brush selectedBrush;

            p.Clear(Color.White);

            switch (SelectedBrushKind)
            {
            default: throw new NotSupportedException();

            case BrushKind.SolidBrush:
                selectedBrush = _solidBrush;
                break;

            case BrushKind.LinearGradient:
                selectedBrush = _linearGrBrush;
                break;

            case BrushKind.CircularGradient:
                selectedBrush = _circularGrBrush;
                break;

            case BrushKind.PolygonGradient:
                selectedBrush = _polygonGradientBrush;
                break;
            }

            //
            p.CurrentBrush = selectedBrush;

            //special set for our GLPainter
            bool glPainter2MaskColor = false;

            DrawingGL.GLPainter glPainter = p as DrawingGL.GLPainter;
            if (glPainter != null)
            {
                glPainter2MaskColor        = glPainter.UseTwoColorsMask;
                glPainter.UseTwoColorsMask = EnableGLPainterTwoColorsMask;
            }

            //p.FillRect(0, 100, 500, 500);
            //p.FillRect(0, 200, 200, 50);

            if (UseClipRegion)
            {
                //fill vxs region1
                p.FillRegion(_triangleVxs);
                //fill vxs region2
                if (UseOffset)
                {
                    float prev_ox = p.OriginX;
                    float prev_oy = p.OriginY;
                    p.SetOrigin(100, 120);
                    p.FillRegion(_triangleVxs);
                    p.SetOrigin(prev_ox, prev_oy);//restore
                }
                else
                {
                    p.FillRegion(_triangleVxs2);
                }
            }
            else
            {
                p.Fill(_triangleVxs);
                if (UseOffset)
                {
                    float prev_ox = p.OriginX;
                    float prev_oy = p.OriginY;
                    p.SetOrigin(100, 120);
                    p.Fill(_triangleVxs);
                    p.SetOrigin(prev_ox, prev_oy);//restore
                }
                else
                {
                    p.Fill(_triangleVxs2);
                }
            }


            //-------------

            p.CurrentBrush = prevBrush;

            if (glPainter != null)
            {
                //restore
                glPainter.UseTwoColorsMask = glPainter2MaskColor;
            }
        }