コード例 #1
0
ファイル: GRender.cs プロジェクト: w1146869587/SharpSVG
 public static async System.Threading.Tasks.Task Render(IElement element, IFrameContext context, RendererDirect2D render)
 {
     using (TransformHelper.Create(render, element, context))
         using (LayerHelper.Create(render, element, context))
             foreach (var child in element.Children)
             {
                 await render.GetRenderer(child.ElementType)(child, context, render);
             }
 }
コード例 #2
0
 public static Task Render(IElement element, IFrameContext context, RendererDirect2D render)
 {
     using (TransformHelper.Create(render, element, context))
         using (LayerHelper.Create(render, element, context))
         {
             render.DrawPolyline(
                 element,
                 context,
                 element.GetPoints(),
                 element.GetFill(context),
                 element.GetStroke(context)
                 );
             return(Task.CompletedTask);
         }
 }
コード例 #3
0
ファイル: LineRender.cs プロジェクト: w1146869587/SharpSVG
 public static Task Render(IElement element, IFrameContext context, RendererDirect2D render)
 {
     using (TransformHelper.Create(render, element, context))
         using (LayerHelper.Create(render, element, context))
         {
             render.DrawLine(
                 element,
                 context,
                 element.GetX1Y1(context),
                 element.GetX2Y2(context),
                 element.GetStroke(context)
                 );
         }
     return(Task.CompletedTask);
 }
コード例 #4
0
 public static Task Render(IElement element, IFrameContext context, RendererDirect2D render)
 {
     using (TransformHelper.Create(render, element, context))
         using (LayerHelper.Create(render, element, context))
         {
             render.DrawBarcode(
                 element,
                 context,
                 element.GetBounds(context),
                 element.GetFill(context),
                 element.GetStroke(context),
                 element.Attributes.GetValue <string>("value"));
             return(Task.CompletedTask);
         }
 }
コード例 #5
0
        public static Task Render(IElement element, IFrameContext context, RendererDirect2D render)
        {
            if (TransformHelper.IsHidden(element))
            {
                return(Task.CompletedTask);
            }

            using (TransformHelper.Create(render, element, context))
                using (LayerHelper.Create(render, element, context))
                {
                    var font      = element.GetFont(context);
                    var fill      = element.GetFill(context);
                    var fillBrush = render.CreateBrush(element, context, fill.Brush, fill.Opacity);

                    if (fillBrush == null)
                    {
                        return(Task.CompletedTask);
                    }

                    foreach (var text in element.Children.OfType <ITextContent>())
                    {
                        using (var textLayout = render.CreateTextLayout(font, text.Content, 999999))
                        {
                            var frameSize = context.Size;
                            var textSize  = new PxSize(textLayout.Metrics.WidthIncludingTrailingWhitespace, textLayout.Metrics.Height);
                            var scale     = CalcScale(frameSize, textSize);

                            var matrix = PxMatrix.Translation(
                                scale,
                                scale,
                                (frameSize.Width - (scale * textSize.Width)) / 2f,
                                (frameSize.Height - (scale * textSize.Height)) / 2f
                                );

                            using (TransformHelper.Create(render, matrix))
                            {
                                render.Target.DrawTextLayout(
                                    new DXM.RawVector2(0, 0),
                                    textLayout,
                                    fillBrush,
                                    D2D1.DrawTextOptions.EnableColorFont
                                    );
                            }
                        }
                    }
                    return(Task.CompletedTask);
                }
        }
コード例 #6
0
        private static void Render(this D2D1.Bitmap bitmap, IElement element, IFrameContext context, RendererDirect2D render)
        {
            var size     = element.GetSize(context, context.Size);
            var viewPort = bitmap.Size.FromDx().AsRectangle();

            using (TransformHelper.CreatePosition(render, element, context))
                using (LayerHelper.Create(render, element, context, size))
                    using (TransformHelper.Create(render, element.GetPreserveAspectRatio().CalcMatrix(size, viewPort)))
                    {
                        render.Target.DrawBitmap(
                            bitmap,
                            new DXM.RawRectangleF(0, 0, bitmap.Size.Width, bitmap.Size.Height),
                            element.GetOpacity(),
                            D2D1.BitmapInterpolationMode.NearestNeighbor
                            );
                    }
        }
コード例 #7
0
ファイル: SvgRender.cs プロジェクト: w1146869587/SharpSVG
        public static async Task Render(IElement element, IFrameContext context, RendererDirect2D render)
        {
            var size     = element.GetSize(context, context.Size);
            var viewPort = element.GetViewBox()?.AsRectangle() ?? size.AsRectangle();

            var newContext = context.Create(viewPort.Size);

            using (element.IsRootElement ? null : TransformHelper.CreatePosition(render, element, context))
                using (LayerHelper.Create(render, element, context, size))
                    using (TransformHelper.Create(render, element.GetPreserveAspectRatio().CalcMatrix(size, viewPort)))
                    {
                        foreach (var child in element.Children)
                        {
                            await render.GetRenderer(child.ElementType)(child, newContext, render);
                        }
                    }
        }
コード例 #8
0
ファイル: SymbolRender.cs プロジェクト: w1146869587/SharpSVG
        public static async Task Render(IElement element, IFrameContext context, RendererDirect2D render)
        {
            if (element.Parent.ElementType != "use")
            {
                return;
            }

            var size     = element.GetSize(context, context.Size);
            var viewPort = element.GetViewBox()?.AsRectangle() ?? size.AsRectangle();

            var newContext = context.Create(viewPort.Size);

            using (TransformHelper.Create(render, element.GetPreserveAspectRatio().CalcMatrix(size, viewPort)))
                foreach (var child in element.Children)
                {
                    await render.GetRenderer(child.ElementType)(child, newContext, render);
                }
        }
コード例 #9
0
        public static async Task Render(this IDocument doc, IElement element, IFrameContext context, RendererDirect2D render)
        {
            var root = doc.RootElement;

            if (root == null)
            {
                return;
            }

            var size       = element.GetSize(context, context.Size);
            var viewPort   = root.GetViewBox()?.AsRectangle() ?? size.AsRectangle();
            var newContext = context.Create(viewPort.Size);

            using (TransformHelper.CreatePosition(render, element, context))
                using (TransformHelper.Create(render, element.GetPreserveAspectRatio().CalcMatrix(size, viewPort)))
                    using (LayerHelper.Create(render, element, context, viewPort.Size))
                        foreach (var child in root.Children)
                        {
                            await render.GetRenderer(child.ElementType)(child, newContext, render);
                        }
        }
コード例 #10
0
        public static Task Render(IElement element, IFrameContext context, RendererDirect2D render)
        {
            if (TransformHelper.IsHidden(element))
            {
                return(Task.CompletedTask);
            }

            using (TransformHelper.Create(render, element, context))
                using (LayerHelper.Create(render, element, context))
                {
                    render.DrawEllipse(
                        element,
                        context,
                        element.GetCxCy(context),
                        element.GetRxRy(context),
                        element.GetFill(context),
                        element.GetStroke(context)
                        );
                    return(Task.CompletedTask);
                }
        }
コード例 #11
0
        public static Task Render(IElement element, IFrameContext context, RendererDirect2D render)
        {
            using (TransformHelper.Create(render, element, context))
                using (LayerHelper.Create(render, element, context))
                {
                    var x = 0f;
                    var y = 0f;

                    IBrush     brush         = null;
                    IBrush     sbrush        = null;
                    var        fillOpacity   = -1f;
                    D2D1.Brush fillBrush     = null;
                    D2D1.Brush strokeBrush   = null;
                    var        strokeOpacity = -1f;

                    foreach (var span in GetSpans(element, context))
                    {
                        if (span.X.HasValue)
                        {
                            x = span.X.Value;
                        }
                        if (span.Y.HasValue)
                        {
                            y = span.Y.Value;
                        }

                        var c       = span.Items.Count;
                        var layouts = new List <DW.TextLayout>(c);
                        var w       = 0f;
                        for (var i = 0; i < c; i++)
                        {
                            var ti = span.Items[i];

                            var l = render.CreateTextLayout(ti.Font, ti.Text, 9999999);
                            layouts.Add(l);
                            w += ti.Dx + l.Metrics.WidthIncludingTrailingWhitespace;
                        }

                        x -= span.TextAnchor == TextAnchor.Middle
                        ? w / 2
                        : span.TextAnchor == TextAnchor.End
                            ? w
                            : 0;

                        for (var i = 0; i < c; i++)
                        {
                            var ti = span.Items[i];
                            var l  = layouts[i];

                            if (brush != ti.Fill.Brush || !MathEx.NearEqual(fillOpacity, ti.Fill.Opacity))
                            {
                                fillBrush   = render.CreateBrush(element, context, ti.Fill.Brush, ti.Fill.Opacity);
                                brush       = ti.Fill.Brush;
                                fillOpacity = ti.Fill.Opacity;
                            }

                            if (sbrush != ti.Stroke.Brush || !MathEx.NearEqual(strokeOpacity, ti.Stroke.Opacity))
                            {
                                strokeBrush = render.CreateBrush(element, context, ti.Stroke.Brush, ti.Stroke.Opacity);
                                sbrush      = ti.Stroke.Brush;
                                fillOpacity = ti.Fill.Opacity;
                            }

                            x += ti.Dx;
                            y += ti.Dy;


                            if (fillBrush != null)
                            {
                                if (ti.Stroke.Brush != null)
                                {
                                    l.Draw(new CustomColorRenderer(render.Target, fillBrush, strokeBrush, ti.Stroke.Width), x,
                                           y - CalcBaselineOffset(l, ti.DominantBaseline));
                                }
                                else
                                {
                                    render.Target.DrawTextLayout(
                                        new DXM.RawVector2(x, y - CalcBaselineOffset(l, ti.DominantBaseline)),
                                        l,
                                        fillBrush,
                                        D2D1.DrawTextOptions.EnableColorFont
                                        );
                                }
                            }

                            x += l.Metrics.WidthIncludingTrailingWhitespace;

                            l.Dispose();
                        }
                    }

                    return(Task.CompletedTask);
                }
        }