TransformToVxs() public method

we do NOT store vxs, return original outputVxs
public TransformToVxs ( VertexStore src, VertexStore outputVxs ) : VertexStore
src VertexStore
outputVxs VertexStore
return VertexStore
Example #1
0
        public static SvgPart TransformToNew(SvgPart originalSvgVx, PixelFarm.Agg.Transform.Affine tx)
        {
            SvgPart newSx = new SvgPart(originalSvgVx.Kind);

            if (originalSvgVx._vxs != null)
            {
                VertexStore vxs = new VertexStore();
                tx.TransformToVxs(originalSvgVx._vxs, vxs);
                newSx._vxs = vxs;
            }

            if (originalSvgVx.HasFillColor)
            {
                newSx._fillColor = originalSvgVx._fillColor;
            }
            if (originalSvgVx.HasStrokeColor)
            {
                newSx.StrokeColor = originalSvgVx.StrokeColor;
            }
            if (originalSvgVx.HasStrokeWidth)
            {
                newSx.StrokeWidth = originalSvgVx.StrokeWidth;
            }
            return(newSx);
        }
Example #2
0
        public void Render(Painter p)
        {
            //
            if (HasBitmapSnapshot)
            {
                p.DrawImage(_backimg, X, Y);
                return;
            }

            PixelFarm.Agg.Transform.Affine currentTx = null;

            var renderState = new TempRenderState();

            renderState.strokeColor = p.StrokeColor;
            renderState.strokeWidth = (float)p.StrokeWidth;
            renderState.fillColor   = p.FillColor;
            renderState.affineTx    = currentTx;

            //------------------
            VertexStore tempVxs = p.GetTempVxsStore();

            int j = _vxList.Length;

            for (int i = 0; i < j; ++i)
            {
                SvgPart vx = _vxList[i];
                switch (vx.Kind)
                {
                case SvgRenderVxKind.BeginGroup:
                {
                    //1. save current state before enter new state
                    p.StackPushUserObject(renderState);

                    //2. enter new px context
                    if (vx.HasFillColor)
                    {
                        p.FillColor = renderState.fillColor = vx.FillColor;
                    }
                    if (vx.HasStrokeColor)
                    {
                        p.StrokeColor = renderState.strokeColor = vx.StrokeColor;
                    }
                    if (vx.HasStrokeWidth)
                    {
                        p.StrokeWidth = renderState.strokeWidth = vx.StrokeWidth;
                    }
                    if (vx.AffineTx != null)
                    {
                        //apply this to current tx
                        if (currentTx != null)
                        {
                            currentTx = currentTx * vx.AffineTx;
                        }
                        else
                        {
                            currentTx = vx.AffineTx;
                        }
                        renderState.affineTx = currentTx;
                    }
                }
                break;

                case SvgRenderVxKind.EndGroup:
                {
                    //restore to prev state
                    renderState   = (TempRenderState)p.StackPopUserObject();
                    p.FillColor   = renderState.fillColor;
                    p.StrokeColor = renderState.strokeColor;
                    p.StrokeWidth = renderState.strokeWidth;
                    currentTx     = renderState.affineTx;
                }
                break;

                case SvgRenderVxKind.Path:
                {
                    VertexStore vxs = vx.GetVxs();
                    if (vx.HasFillColor)
                    {
                        //has specific fill color
                        if (vx.FillColor.A > 0)
                        {
                            if (currentTx == null)
                            {
                                p.Fill(vxs, vx.FillColor);
                            }
                            else
                            {
                                //have some tx
                                tempVxs.Clear();
                                currentTx.TransformToVxs(vxs, tempVxs);
                                p.Fill(tempVxs, vx.FillColor);
                            }
                        }
                    }
                    else
                    {
                        if (p.FillColor.A > 0)
                        {
                            if (currentTx == null)
                            {
                                p.Fill(vxs);
                            }
                            else
                            {
                                //have some tx
                                tempVxs.Clear();
                                currentTx.TransformToVxs(vxs, tempVxs);
                                p.Fill(tempVxs);
                            }
                        }
                    }

                    if (p.StrokeWidth > 0)
                    {
                        //check if we have a stroke version of this render vx
                        //if not then request a new one
                        if (vx.HasStrokeColor)
                        {
                            //has specific stroke color
                            p.StrokeWidth = vx.StrokeWidth;
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);

                            if (currentTx == null)
                            {
                                p.Fill(strokeVxs, vx.StrokeColor);
                            }
                            else
                            {
                                //have some tx
                                tempVxs.Clear();
                                currentTx.TransformToVxs(strokeVxs, tempVxs);
                                p.Fill(tempVxs, vx.StrokeColor);
                            }
                        }
                        else if (p.StrokeColor.A > 0)
                        {
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                            if (currentTx == null)
                            {
                                p.Fill(strokeVxs, p.StrokeColor);
                            }
                            else
                            {
                                tempVxs.Clear();
                                currentTx.TransformToVxs(strokeVxs, tempVxs);
                                p.Fill(tempVxs, p.StrokeColor);
                            }
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        if (vx.HasStrokeColor)
                        {
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                            p.Fill(strokeVxs);
                        }
                        else if (p.StrokeColor.A > 0)
                        {
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                            p.Fill(strokeVxs, p.StrokeColor);
                        }
                    }
                }
                break;
                }
            }


            p.ReleaseTempVxsStore(tempVxs);
        }