Пример #1
0
        void DrawWithLineProfile(OutlineAARasterizer rasterizer)
        {
            SvgRenderVx renderVx  = lionShape.GetRenderVx();
            int         num_paths = renderVx.SvgVxCount;

            var renderState = new TempRenderState();

            renderState.strokeColor = PixelFarm.Drawing.Color.Black;
            renderState.strokeWidth = 1;
            renderState.fillColor   = PixelFarm.Drawing.Color.Black;
            renderState.affineTx    = null;


            for (int i = 0; i < num_paths; ++i)
            {
                SvgPart vx = renderVx.GetInnerVx(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:
                {
                    //temp
                    rasterizer.RenderVertexSnap(
                        new PixelFarm.Drawing.VertexStoreSnap(vx.GetVxs(), 0),
                        new Drawing.Color(255, 0, 0));
                }
                break;
                    //{

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

                    //        VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                    //        if (vx.HasStrokeColor)
                    //        {
                    //            //has speciic stroke color
                    //            p.StrokeWidth = vx.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)
                    //        {
                    //            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;
                }
            }
        }
Пример #2
0
        public void Render(Painter p)
        {
            //
            if (HasBitmapSnapshot)
            {
                p.DrawImage(_backimg, X, Y);
                return;
            }

            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);
        }