コード例 #1
0
        public void DrawPath(
            IElement element,
            IFrameContext context,
            Paths.Path path,
            Fill fill,
            Stroke strokeStyle
            )
        {
            if (path == null || path.Segments.Length == 0)
            {
                return;
            }


            var fillBrush   = CreateBrush(element, context, fill.Brush, fill.Opacity);
            var strokeBrush = strokeStyle.Width > 0
                ? CreateBrush(element, context, strokeStyle.Brush, strokeStyle.Opacity)
                : null;
            var geometry = PathBuilder.Create(_dc, path);

            if (fillBrush != null)
            {
                Target.FillGeometry(geometry, fillBrush);
            }

            if (strokeBrush != null)
            {
                Target.DrawGeometry(
                    geometry,
                    strokeBrush,
                    strokeStyle.Width,
                    GetStrokeStyle(strokeStyle)
                    );
            }
        }
コード例 #2
0
        public static D2D1.Geometry Create(D2D1.RenderTarget target, Paths.Path path,
                                           D2D1.FillMode fillMode = D2D1.FillMode.Winding)
        {
            var segments   = path.Segments;
            var length     = segments.Length;
            var geometries = length > 1 ? new D2D1.Geometry[segments.Length] : null;
            var i          = 0;

            foreach (var segment in path.Segments)
            {
                var geometry = new D2D1.PathGeometry(target.Factory);
                using (var sink = geometry.Open())
                {
                    sink.SetSegmentFlags(D2D1.PathSegment.None);
                    foreach (var x in segment.Commands)
                    {
                        x.Visit(sink, Visitor);
                    }
                    sink.Close();
                }

                if (length == 1)
                {
                    return(geometry);
                }
                geometries[i++] = geometry;
            }

            try
            {
                return(new D2D1.GeometryGroup(target.Factory, fillMode, geometries));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }