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

            for (int i = 0; i < count; ++i)
            {
                cmd = src.GetVertex(i, out double x, out double y);
                x  += dx;
                y  += dy;
                outputVxs.AddVertex(x, y, cmd);
            }
            return(outputVxs);
        }
Esempio n. 2
0
        public static void FlipY(VertexStore vxs, double y1, double y2)
        {
            int    i;
            double x, y;
            int    count = vxs.Count;

            for (i = 0; i < count; ++i)
            {
                VertexCmd flags = vxs.GetVertex(i, out x, out y);
                if (VertexHelper.IsVertextCommand(flags))
                {
                    vxs.ReplaceVertex(i, x, y2 - y + y1);
                }
            }
        }
Esempio n. 3
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);

            //}
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 public VertexCmd GetNextVertex(out double x, out double y)
 {
     return(vxs.GetVertex(currentIterIndex++, out x, out y));
 }
Esempio n. 6
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));
            }
        }