Beispiel #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            //----------------------
            //1. test gdi+ font path
            char  testChar = 'b';
            float fontSize = 20;

            using (Graphics g = this.pictureBox1.CreateGraphics())
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.Clear(System.Drawing.Color.White);
                //convert Agg vxs to bitmap
                int bmpW = 500;
                int bmpH = 500;
                using (Bitmap bufferBmp = new Bitmap(bmpW, bmpH))
                {
                    ActualImage      actualImage = new ActualImage(bmpW, bmpH);
                    AggRenderSurface gfx         = new AggRenderSurface(actualImage);
                    var vxs = new PixelFarm.Drawing.VertexStore();
                    //vxs.AddMoveTo(0, 0);
                    ////vxs.AddP3c(100, 0);
                    ////vxs.AddP3c(100,150);
                    ////vxs.AddLineTo(0,0);
                    //vxs.AddLineTo(0, 0);
                    //vxs.AddP3c(100, 0);
                    ////vxs.AddLineTo(100, 0);
                    ////vxs.AddLineTo(100, 150);
                    //vxs.AddP3c(100, 150);
                    //vxs.AddLineTo(0, 150);
                    //vxs.AddCloseFigure();

                    //PixelFarm.Agg.VertexSource.CurveFlattener cflat = new PixelFarm.Agg.VertexSource.CurveFlattener();
                    //vxs = cflat.MakeVxs(vxs);

                    gfx.Render(vxs, PixelFarm.Drawing.Color.Black);
                    //test subpixel rendering


                    vxs = vxs.TranslateToNewVxs(15, 0, new PixelFarm.Drawing.VertexStore());
                    gfx.UseSubPixelRendering = true;
                    gfx.Render(vxs, PixelFarm.Drawing.Color.Black);
                    PixelFarm.Agg.Imaging.BitmapHelper.CopyToGdiPlusBitmapSameSize(
                        actualImage, //src from actual img buffer
                        bufferBmp    //dest to buffer bmp
                        );
                    //-----------------------------------------
                    bufferBmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    g.DrawImage(bufferBmp, new System.Drawing.Point(0, 30));
                }
            }
        }
Beispiel #2
0
 public static void WriteRoundRect(PixelFarm.Drawing.VertexStore inputVxs,
                                   RectangleF rect, float nwRadius, float neRadius, float seRadius, float swRadius)
 {
     //  NW-----NE
     //  |       |
     //  |       |
     //  SW-----SE
     using (Tools.BorrowRoundedRect(out PixelFarm.CpuBlit.VertexProcessing.RoundedRect roundRect))
     {
         //TODO: review here again
         roundRect.SetRect(rect.Left, rect.Bottom, rect.Right, rect.Top);
         roundRect.SetRadius(swRadius, seRadius, neRadius, nwRadius);
         roundRect.MakeVxs(inputVxs);
     }
 }
Beispiel #3
0
        /// <summary>
        /// check if this is a simple rect
        /// </summary>
        /// <param name="vxs"></param>
        /// <returns></returns>
        public static bool EvaluateRectClip(VertexStore vxs, out RectangleF clipRect)
        {
            float x0 = 0, y0 = 0;
            float x1 = 0, y1 = 0;
            float x2 = 0, y2 = 0;
            float x3 = 0, y3 = 0;
            float x4 = 0, y4 = 0;

            clipRect = new RectangleF();

            int sideCount = 0;

            int j = vxs.Count;

            for (int i = 0; i < j; ++i)
            {
                VertexCmd cmd = vxs.GetVertex(i, out double x, out double y);
                switch (cmd)
                {
                default: return(false);

                case VertexCmd.NoMore:
                    if (i > 6)
                    {
                        return(false);
                    }
                    break;

                case VertexCmd.Close:
                    if (i > 5)
                    {
                        return(false);
                    }
                    break;

                case VertexCmd.LineTo:
                {
                    switch (i)
                    {
                    case 1:
                        x1 = (float)x;
                        y1 = (float)y;
                        sideCount++;
                        break;

                    case 2:
                        x2 = (float)x;
                        y2 = (float)y;
                        sideCount++;
                        break;

                    case 3:
                        x3 = (float)x;
                        y3 = (float)y;
                        sideCount++;
                        break;

                    case 4:
                        x4 = (float)x;
                        y4 = (float)y;
                        sideCount++;
                        break;
                    }
                }
                break;

                case VertexCmd.MoveTo:
                {
                    if (i == 0)
                    {
                        x0 = (float)x;
                        y0 = (float)y;
                    }
                    else
                    {
                        return(false);
                    }
                }
                break;
                }
            }

            if (sideCount == 4)
            {
                RectSide s0 = FindRectSide(x0, y0, x1, y1);
                if (s0 == RectSide.None)
                {
                    return(false);
                }
                //
                RectSide s1 = FindRectSide(x1, y1, x2, y2);
                if (s1 == RectSide.None || s0 == s1)
                {
                    return(false);
                }
                //
                RectSide s2 = FindRectSide(x2, y2, x3, y3);
                if (s2 == RectSide.None || s1 == s2)
                {
                    return(false);
                }
                //
                RectSide s3 = FindRectSide(x3, y3, x4, y4);
                if (s3 == RectSide.None || s2 == s3)
                {
                    return(false);
                }
                //
                if (x4 == x0 && y4 == y0)
                {
                    if (s0 == RectSide.Horizontal)
                    {
                        clipRect = new RectangleF(x0, y0, x1 - x0, y3 - y0);
                    }
                    else
                    {
                        clipRect = new RectangleF(x0, y0, x3 - x0, y3 - y0);
                    }

                    return(true);
                }
            }
            return(false);
        }
Beispiel #4
0
 public static void AddNoMore(this VertexStore vxs)
 {
     vxs.AddVertex(0, 0, VertexCmd.NoMore);
 }
Beispiel #5
0
 public VertexStoreSnap(VertexStore vxs)
 {
     this.vxs     = vxs;
     this.startAt = 0;
 }
Beispiel #6
0
 public abstract void Draw(VertexStore vxs);
        public static VertexStore ScaleToNewVxs(this VertexStore src, double sx, double sy, VertexStore outputVxs)
        {
            //TODO: review here
            Affine aff = Affine.NewScaling(sx, sy);

            return(aff.TransformToVxs(src, outputVxs));
        }
Beispiel #8
0
        /// <summary>
        /// copy data from 'another' append to this vxs,we DO NOT store 'another' vxs inside this
        /// </summary>
        /// <param name="another"></param>
        public void AppendVertexStore(VertexStore another)
        {
            //append data from another
            if (_allocated_vertices_count < _vertices_count + another._vertices_count)
            {
                //alloc a new one
                int new_alloc = _vertices_count + another._vertices_count;

                _allocated_vertices_count = new_alloc;
                _vertices_count           = new_alloc;               //new

                var new_coord_xy = new double[(new_alloc + 1) << 1]; //*2
                var new_cmds     = new byte[(new_alloc + 1)];
                //copy org

                //A.1
                System.Array.Copy(
                    _coord_xy,             //src_arr
                    0,                     //src_index
                    new_coord_xy,          //dst
                    0,                     //dst index
                    _vertices_count << 1); //len


                //A.2
                System.Array.Copy(
                    _cmds,            //src_arr
                    0,                //src_index
                    new_cmds,         //dst
                    0,                //dst index
                    _vertices_count); //len


                //B.1
                System.Array.Copy(
                    another._coord_xy,    //src
                    0,                    //srcIndex
                    new_coord_xy,         //dst
                    _vertices_count << 1, //dst index
                        another._vertices_count << 1);
                //**

                //B.2
                System.Array.Copy(
                    another._cmds,   //src
                    0,               //srcIndex
                    new_cmds,        //dst
                    _vertices_count, //dst index
                    another._vertices_count);

                _coord_xy        = new_coord_xy;
                _cmds            = new_cmds;
                _vertices_count += another._vertices_count;
            }
            else
            {
                System.Array.Copy(
                    another._coord_xy,    //src
                    0,                    //src index
                    _coord_xy,            //dst
                    _vertices_count << 1, //*2 //
                        another._vertices_count << 1);



                //B.2
                System.Array.Copy(
                    another._cmds,   //src
                    0,               //src index
                    _cmds,           //dst
                    _vertices_count, //dst index
                    another._vertices_count);

                _vertices_count += another._vertices_count;
            }
        }
Beispiel #9
0
 /// <summary>
 /// copy from src to the new one
 /// </summary>
 /// <param name="src"></param>
 /// <returns></returns>
 public static VertexStore CreateCopy(VertexStore src)
 {
     return(new VertexStore(src, false));
 }
        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);
        }
 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);
 }
 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);
 }
Beispiel #13
0
 public void Release(ref VertexStore vxs)
 {
     vxs.Clear();
     _stack.Push(vxs);
     vxs = null;
 }
Beispiel #14
0
 public VertexStoreSnap(VertexStore vxs, int startAt)
 {
     this.vxs     = vxs;
     this.startAt = startAt;
 }
Beispiel #15
0
 public abstract void Fill(VertexStore vxs);
Beispiel #16
0
 /// <summary>
 /// add 3rd curve point (for C4 curve)
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public static void AddP3c(this VertexStore vxs, double x, double y)
 {
     vxs.AddVertex(x, y, VertexCmd.P3c);
 }
Beispiel #17
0
 //TODO: remove paint series,
 public abstract void PaintSeries(VertexStore vxs, Color[] colors, int[] pathIndexs, int numPath);
Beispiel #18
0
 public static void AddMoveTo(this VertexStore vxs, double x0, double y0)
 {
     vxs.AddVertex(x0, y0, VertexCmd.MoveTo);
 }
        /// <summary>
        /// copy + translate vertext data from src to outputVxs
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="outputVxs"></param>
        /// <returns></returns>
        public static VertexStore TranslateToNewVxs(this VertexStore src, double dx, double dy, VertexStore outputVxs)
        {
            int       count = src.Count;
            VertexCmd cmd;
            double    x, y;

            for (int i = 0; i < count; ++i)
            {
                cmd = src.GetVertex(i, out x, out y);
                x  += dx;
                y  += dy;
                outputVxs.AddVertex(x, y, cmd);
            }
            return(outputVxs);
        }
Beispiel #20
0
 public static void AddLineTo(this VertexStore vxs, double x1, double y1)
 {
     vxs.AddVertex(x1, y1, VertexCmd.LineTo);
 }
Beispiel #21
0
 /// <summary>
 /// we DO NOT store vxs
 /// </summary>
 /// <param name="vxs"></param>
 public abstract void SetClipRgn(VertexStore vxs);
Beispiel #22
0
 public static void AddCloseFigure(this VertexStore vxs)
 {
     vxs.AddVertex(0, 0, VertexCmd.Close);
 }
Beispiel #23
0
        public FigureContainer Build(PixelFarm.Drawing.VertexStore vxs)
        {
            //vxs must be flatten vxs.

            double prevX       = 0;
            double prevY       = 0;
            double prevMoveToX = 0;
            double prevMoveToY = 0;

            _xylist.Clear();
            _figs.Clear();
            //TODO: reivew here
            //about how to reuse this list
            //result...


            int       index = 0;
            VertexCmd cmd;

            double x, y;

            while ((cmd = vxs.GetVertex(index++, out x, out y)) != VertexCmd.NoMore)
            {
                switch (cmd)
                {
                case PixelFarm.CpuBlit.VertexCmd.MoveTo:

                    prevMoveToX = prevX = x;
                    prevMoveToY = prevY = y;
                    _xylist.Add((float)x);
                    _xylist.Add((float)y);
                    break;

                case PixelFarm.CpuBlit.VertexCmd.LineTo:
                    _xylist.Add((float)x);
                    _xylist.Add((float)y);
                    prevX = x;
                    prevY = y;
                    break;

                case PixelFarm.CpuBlit.VertexCmd.Close:
                {
                    //don't add
                    //_xylist.Add((float)prevMoveToX);
                    //_xylist.Add((float)prevMoveToY);

                    prevX = prevMoveToX;
                    prevY = prevMoveToY;
                    //-----------
                    Figure newfig = new Figure(_xylist.ToArray());
                    newfig.IsClosedFigure = true;

                    _figs.Add(newfig);
                    //-----------
                    _xylist.Clear();         //clear temp list
                }
                break;

                case PixelFarm.CpuBlit.VertexCmd.NoMore:
                    goto EXIT_LOOP;

                default:
                    throw new System.NotSupportedException();
                }
            }
EXIT_LOOP:

            if (_figs.Count == 0)
            {
                Figure newfig = new Figure(_xylist.ToArray());
                newfig.IsClosedFigure = false;
                return(new FigureContainer(newfig));
            }
            //
            if (_xylist.Count > 1)
            {
                prevX = prevMoveToX;
                prevY = prevMoveToY;
                //
                Figure newfig = new Figure(_xylist.ToArray());
                newfig.IsClosedFigure = true; //?
                _figs.Add(newfig);
            }

            if (_figs.Count == 1)
            {
                Figure fig = _figs[0];
                _figs.Clear();
                return(new FigureContainer(fig));
            }
            else
            {
                MultiFigures multiFig = new MultiFigures(_figs.ToArray());
                _figs.Clear();
                return(new FigureContainer(multiFig));
            }
        }
Beispiel #24
0
 public static void AddCloseFigure(this VertexStore vxs, double x, double y)
 {
     vxs.AddVertex(x, y, VertexCmd.Close);
 }
Beispiel #25
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);

            //}
        }
Beispiel #26
0
 internal VertexSnapIter(VertexStoreSnap vsnap)
 {
     this.vxs = VertexStoreSnap.GetInternalVxs(vsnap);
     this.currentIterIndex = vsnap.StartAt;
 }