Exemplo n.º 1
0
        public static async Task Render(IElement element, IFrameContext context, RendererDirect2D render)
        {
            var href = element.GetHref();

            if (href == null)
            {
                return;
            }
            var fragment = (href.Scheme == "internal")
        ? element.OwnerDocument?.GetElementById(href.Fragment.Substring(1))
        : await LoadExternal(href, render, element.OwnerDocument.BaseUri);

            if (fragment == null)
            {
                return;
            }

            try
            {
                fragment.SetParentOverride(element);
                using (TransformHelper.CreatePosition(render, element, context))
                    await render.GetRenderer(fragment.ElementType)(
                        fragment,
                        context.Create(element.GetSize(context, context.Size)),
                        render
                        );
            }
            finally
            {
                fragment.SetParentOverride(null);
            }
        }
Exemplo n.º 2
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
                            );
                    }
        }
Exemplo n.º 3
0
        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);
                        }
                    }
        }
Exemplo n.º 4
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);
                        }
        }