コード例 #1
0
        private static D2D1.Geometry CreateGeometry(D2D1.RenderTarget target, FontManager fontManager, IElement element,
                                                    IFrameContext context, ClipPathUnits clipPathUnits, IElement targetElement)
        {
            var geom = CreateGeometryInternal(target, fontManager, element, context, clipPathUnits, targetElement);

            if (geom == null)
            {
                return(null);
            }
            var rt = element.GetTransform();

            if (rt == null)
            {
                return(geom);
            }

            return(new D2D1.TransformedGeometry(
                       target.Factory,
                       geom,
                       rt.ToDx(element, context)
                       ));
        }
コード例 #2
0
        private static D2D1.Geometry CreateGeometryInternal(D2D1.RenderTarget target, FontManager fontManager, IElement element, IFrameContext context, ClipPathUnits clipPathUnits, IElement targetElement)
        {
            if (clipPathUnits == ClipPathUnits.UserSpaceOnUse)
            {
                switch (element.ElementType)
                {
                case "rect":
                    return(new D2D1.RectangleGeometry(target.Factory, element.GetBounds(context).ToDx()));

                case "circle":
                    var r = element.GetRadius(context);
                    return(new D2D1.EllipseGeometry(target.Factory, new D2D1.Ellipse()
                    {
                        Point = element.GetCxCy(context).ToDx(),
                        RadiusX = r,
                        RadiusY = r
                    }));

                case "path":
                    return(PathBuilder.Create(target, element.GetPath(), D2D1.FillMode.Alternate));

                case "text":
                    var geom = new D2D1.PathGeometry(target.Factory);
                    using (var sink = geom.Open())
                    {
                        var font         = element.GetFont(context);
                        var fontFace     = fontManager.GetFontFace(font);
                        var glyphIndices = fontFace.GetGlyphIndices("Clip Test");
                        var xx           = new[] { 35f, 50f, 55f, 65f, 45f, 48f, 52f, 32f, 61f };
                        fontFace.GetGlyphRunOutline(
                            font.Size,
                            glyphIndices,
                            xx,
                            null,
                            glyphIndices.Length,
                            false,
                            false,
                            sink);

                        sink.Close();

                        return(new D2D1.TransformedGeometry(
                                   target.Factory,
                                   geom,
                                   Matrix3x2.Translation(0, font.Size)
                                   ));

                        //return geom;
                    }

                default:
                    return(null);
                }
            }
            else
            {
                var targetBounds = GetBounds(targetElement, context);

                switch (element.ElementType)
                {
                case "rect":
                    var rectBounds = element.GetBounds(context);
                    var w          = targetBounds.Width * rectBounds.Width;
                    var h          = targetBounds.Height * rectBounds.Height;
                    var x          = targetBounds.X + (targetBounds.Width * rectBounds.X);
                    var y          = targetBounds.Y + (targetBounds.Height * rectBounds.Y);
                    return(new D2D1.RectangleGeometry(
                               target.Factory,
                               new RawRectangleF(x, y, x + w, y + h)
                               ));

                case "circle":
                    var r    = element.GetRadius(context);
                    var cxCy = element.GetCxCy(context);
                    return(new D2D1.EllipseGeometry(target.Factory, new D2D1.Ellipse()
                    {
                        Point = new RawVector2(targetBounds.X + (cxCy.X * targetBounds.Width), targetBounds.Y + (cxCy.Y * targetBounds.Height)),
                        RadiusX = r * targetBounds.Width,
                        RadiusY = r * targetBounds.Width
                    }));

                case "path":
                    return(PathBuilder.Create(target, element.GetPath(), D2D1.FillMode.Alternate));

                default:
                    return(null);
                }
            }
        }
コード例 #3
0
ファイル: Clip.cs プロジェクト: w1146869587/SharpSVG
 public Clip(IEnumerable <IElement> children, string tag, ClipPathUnits clipPathUnits)
 {
     Tag           = tag;
     Children      = children.ToArray();
     ClipPathUnits = clipPathUnits;
 }