Beispiel #1
0
        /// <summary>
        /// Creates a new instance of the XPath class.
        /// </summary>
        /// <param name="geometry"></param>
        /// <param name="isStroked"></param>
        /// <param name="isFilled"></param>
        /// <returns></returns>
        public XPath Path(
            XPathGeometry geometry,
            bool isStroked = true,
            bool isFilled  = false)
        {
            var path = XPath.Create(
                "",
                Context.Editor.Project.CurrentStyleLibrary.CurrentStyle,
                geometry,
                isStroked,
                isFilled);

            Context.Editor.AddWithHistory(path);
            return(path);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="path"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, XPath path, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            var _gfx = gfx as Graphics;

            var gp = path.Geometry.ToGraphicsPath(dx, dy, _scaleToPage);

            if (path.IsFilled && path.IsStroked)
            {
                var brush = ToSolidBrush(path.Style.Fill);
                var pen   = ToPen(path.Style, _scaleToPage);
                _gfx.FillPath(
                    brush,
                    gp);
                _gfx.DrawPath(
                    pen,
                    gp);
                brush.Dispose();
                pen.Dispose();
            }
            else if (path.IsFilled && !path.IsStroked)
            {
                var brush = ToSolidBrush(path.Style.Fill);
                _gfx.FillPath(
                    brush,
                    gp);
                brush.Dispose();
            }
            else if (!path.IsFilled && path.IsStroked)
            {
                var pen = ToPen(path.Style, _scaleToPage);
                _gfx.DrawPath(
                    pen,
                    gp);
                pen.Dispose();
            }
        }
Beispiel #3
0
        private void InitializeWorkingPath(XPoint start)
        {
            _geometry = XPathGeometry.Create(
                new List<XPathFigure>(),
                _editor.Project.Options.DefaultFillRule);

            _geometry.BeginFigure(
                start,
                _editor.Project.Options.DefaultIsFilled,
                _editor.Project.Options.DefaultIsClosed);

            _path = XPath.Create(
                "Path",
                _editor.Project.CurrentStyleLibrary.CurrentStyle,
                _geometry,
                _editor.Project.Options.DefaultIsStroked,
                _editor.Project.Options.DefaultIsFilled);

            _editor.Project.CurrentContainer.WorkingLayer.Shapes = _editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_path);

            _previousPathTool = _editor.CurrentPathTool;
            _isInitialized = true;
        }
Beispiel #4
0
 private void DeInitializeWorkingPath()
 {
     _isInitialized = false;
     _geometry = null;
     _path = null;
 }
Beispiel #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="path"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, XPath path, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _gfx = gfx as Graphics;

            var gp = path.Geometry.ToGraphicsPath(dx, dy, _scaleToPage);

            if (path.IsFilled && path.IsStroked)
            {
                var brush = ToSolidBrush(path.Style.Fill);
                var pen = ToPen(path.Style, _scaleToPage);
                _gfx.FillPath(
                    brush,
                    gp);
                _gfx.DrawPath(
                    pen,
                    gp);
                brush.Dispose();
                pen.Dispose();
            }
            else if (path.IsFilled && !path.IsStroked)
            {
                var brush = ToSolidBrush(path.Style.Fill);
                _gfx.FillPath(
                    brush,
                    gp);
                brush.Dispose();
            }
            else if (!path.IsFilled && path.IsStroked)
            {
                var pen = ToPen(path.Style, _scaleToPage);
                _gfx.DrawPath(
                    pen,
                    gp);
                pen.Dispose();
            }
        }
Beispiel #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="path"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XPath path, double dx, double dy, ImmutableArray<Property> db, Record r)
        {
            if (path.Geometry == null)
                return;

            var _dc = dc as DrawingContext;

            var style = path.Style;
            if (style == null)
                return;

            double thickness = style.Thickness / _state.Zoom;
            double half = thickness / 2.0;

            Tuple<Brush, Pen> cache = null;
            Brush fill;
            Pen stroke;
            if (_enableStyleCache
                && _styleCache.TryGetValue(style, out cache))
            {
                fill = cache.Item1;
                stroke = cache.Item2;
            }
            else
            {
                fill = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                if (_enableStyleCache)
                    _styleCache.Add(style, Tuple.Create(fill, stroke));
            }

            Tuple<XPathGeometry, StreamGeometry, ShapeStyle> pcache = null;
            StreamGeometry sg;

            if (_enablePathCache
                && _pathCache.TryGetValue(path, out pcache)
                && pcache.Item1 == path.Geometry
                && pcache.Item3 == style)
            {
                sg = pcache.Item2;
                _dc.DrawGeometry(path.IsFilled ? fill : null, path.IsStroked ? stroke : null, sg);
            }
            else
            {
                sg = path.Geometry.ToStreamGeometry();

                if (_enablePathCache)
                {
                    var tuple = Tuple.Create(path.Geometry, sg, style);
                    if (_pathCache.ContainsKey(path))
                    {
                        _pathCache[path] = tuple;
                    }
                    else
                    {
                        _pathCache.Add(path, tuple);
                    }
                }

                _dc.DrawGeometry(path.IsFilled ? fill : null, path.IsStroked ? stroke : null, sg);
            }
        }
Beispiel #7
0
        public void Draw(object ds, XPath path, double dx, double dy, ImmutableArray<Property> db, Record r)
        {
            var _ds = ds as CanvasDrawingSession;

            double thickness = path.Style.Thickness / _state.Zoom;
            var brush = ToColor(path.Style.Fill);
            var pen = ToColor(path.Style.Stroke);
            var ss = CreateStrokeStyle(path.Style);

            var g = path.Geometry.ToCanvasGeometry(_ds);

            if (path.IsFilled)
            {
                _ds.FillGeometry(g, (float)dx, (float)dy, brush);
            }

            if (path.IsStroked)
            {
                _ds.DrawGeometry(g, (float)dx, (float)dy, pen, (float)thickness, ss);
            }

            g.Dispose();
            ss.Dispose();
        }
Beispiel #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="path"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XPath path, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            if (!path.IsFilled && !path.IsStroked)
                return;

            var _dc = dc as DrawingContext;

            var g = path.Geometry.ToGeometry();

            var brush = ToSolidBrush(path.Style.Fill);
            var pen = ToPen(path.Style, _scaleToPage);
            _dc.DrawGeometry(
                path.IsFilled ? brush : null,
                path.IsStroked ? pen : null,
                g);

            // TODO: g.Dispose();
            // TODO: brush.Dispose();
            // TODO: pen.Dispose();
        }