Exemplo n.º 1
0
        public WpfDrawingContext(bool isFragment, WpfDrawingSettings settings)
        {
            var sysParam = typeof(SystemParameters);

            var dpiXProperty = sysParam.GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
            var dpiYProperty = sysParam.GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static);

            _dpiX = (int)dpiXProperty.GetValue(null, null);
            _dpiY = (int)dpiYProperty.GetValue(null, null);

            if (settings == null)
            {
                settings = new WpfDrawingSettings();
            }
            _quickBounds   = Rect.Empty;
            _isFragment    = isFragment;
            _settings      = settings;
            _drawStack     = new Stack <DrawingGroup>();
            _paintContexts = new Dictionary <string, WpfSvgPaintContext>(StringComparer.Ordinal);
            _baseUrls      = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            _registeredIds = settings[RegisteredIdKey] as HashSet <string>;
            if (_registeredIds == null)
            {
                _registeredIds            = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                settings[RegisteredIdKey] = _registeredIds;
            }

            var visitors = settings.Visitors;

            if (visitors != null)
            {
                WpfLinkVisitor linkVisitor = visitors.LinkVisitor;
                if (linkVisitor != null)
                {
                    _linkVisitor = linkVisitor;
                }
                WpfFontFamilyVisitor fontFamilyVisitor = visitors.FontFamilyVisitor;
                if (fontFamilyVisitor != null)
                {
                    _fontFamilyVisitor = fontFamilyVisitor;
                }
                WpfEmbeddedImageVisitor imageVisitor = visitors.ImageVisitor;
                if (imageVisitor != null)
                {
                    _imageVisitor = imageVisitor;
                }
                WpfIDVisitor idVisitor = visitors.IDVisitor;
                if (idVisitor != null)
                {
                    _idVisitor = idVisitor;
                }
                WpfClassVisitor classVisitor = visitors.ClassVisitor;
                if (classVisitor != null)
                {
                    _classVisitor = classVisitor;
                }
            }
        }
Exemplo n.º 2
0
        public void Initialize(WpfLinkVisitor linkVisitor, WpfFontFamilyVisitor fontFamilyVisitor,
                               WpfEmbeddedImageVisitor imageVisitor)
        {
            //TODO: Depreciate this operation as we have more visitors...
            if (linkVisitor != null)
            {
                _linkVisitor = linkVisitor;
            }
            if (fontFamilyVisitor != null)
            {
                _fontFamilyVisitor = fontFamilyVisitor;
            }
            if (imageVisitor != null)
            {
                _imageVisitor = imageVisitor;
            }

            _rootDrawing = new DrawingGroup();

            this.Push(_rootDrawing);


            if (_idVisitor != null && !_idVisitor.IsInitialized)
            {
                _idVisitor.Initialize(this);
            }
            if (_linkVisitor != null && !_linkVisitor.IsInitialized)
            {
                _linkVisitor.Initialize(this);
            }
            if (_classVisitor != null && !_classVisitor.IsInitialized)
            {
                _classVisitor.Initialize(this);
            }
            if (_fontFamilyVisitor != null && !_fontFamilyVisitor.IsInitialized)
            {
                _fontFamilyVisitor.Initialize(this);
            }
            if (_imageVisitor != null && !_imageVisitor.IsInitialized)
            {
                _imageVisitor.Initialize(this);
            }
            if (_linkVisitor != null && _linkVisitor.Aggregates)
            {
                _linkDrawing = new DrawingGroup();

                string groupId = _linkVisitor.AggregatedLayerName;
                if (!string.IsNullOrWhiteSpace(groupId))
                {
                    Runtime.SvgObject.SetName(_linkDrawing, groupId);
                }

                _linkVisitor.Initialize(_linkDrawing, this);
            }
        }
Exemplo n.º 3
0
        public WpfDrawingContext(bool isFragment, WpfDrawingSettings settings)
        {
            if (settings == null)
            {
                settings = new WpfDrawingSettings();
            }
            _quickBounds   = Rect.Empty;
            _isFragment    = isFragment;
            _settings      = settings;
            _drawStack     = new Stack <DrawingGroup>();
            _paintContexts = new Dictionary <string, WpfSvgPaintContext>(StringComparer.Ordinal);

            _registeredIds = settings[RegisteredIdKey] as HashSet <string>;
            if (_registeredIds == null)
            {
                _registeredIds            = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
                settings[RegisteredIdKey] = _registeredIds;
            }

            var visitors = settings.Visitors;

            if (visitors != null)
            {
                WpfLinkVisitor linkVisitor = visitors.LinkVisitor;
                if (linkVisitor != null)
                {
                    _linkVisitor = linkVisitor;
                }
                WpfFontFamilyVisitor fontFamilyVisitor = visitors.FontFamilyVisitor;
                if (fontFamilyVisitor != null)
                {
                    _fontFamilyVisitor = fontFamilyVisitor;
                }
                WpfEmbeddedImageVisitor imageVisitor = visitors.ImageVisitor;
                if (imageVisitor != null)
                {
                    _imageVisitor = imageVisitor;
                }
                WpfIDVisitor idVisitor = visitors.IDVisitor;
                if (idVisitor != null)
                {
                    _idVisitor = idVisitor;
                }
                WpfClassVisitor classVisitor = visitors.ClassVisitor;
                if (classVisitor != null)
                {
                    _classVisitor = classVisitor;
                }
            }
        }
        public void Initialize(WpfLinkVisitor linkVisitor, WpfFontFamilyVisitor fontFamilyVisitor,
                               WpfEmbeddedImageVisitor imageVisitor)
        {
            _linkVisitor       = linkVisitor;
            _fontFamilyVisitor = fontFamilyVisitor;
            _imageVisitor      = imageVisitor;

            _rootDrawing = new DrawingGroup();

            this.Push(_rootDrawing);

            if (_linkVisitor != null && _linkVisitor.Aggregates)
            {
                _linkDrawing = new DrawingGroup();

                string groupId = _linkVisitor.AggregatedLayerName;
                if (!string.IsNullOrWhiteSpace(groupId))
                {
                    Runtime.SvgObject.SetName(_linkDrawing, groupId);
                }

                linkVisitor.Initialize(_linkDrawing, this);
            }
        }
Exemplo n.º 5
0
        public void Initialize(WpfLinkVisitor linkVisitor, WpfFontFamilyVisitor fontFamilyVisitor,
                               WpfEmbeddedImageVisitor imageVisitor)
        {
            _linkVisitor       = linkVisitor;
            _fontFamilyVisitor = fontFamilyVisitor;
            _imageVisitor      = imageVisitor;

            _rootDrawing = new DrawingGroup();

            this.Push(_rootDrawing);

            if (_linkVisitor != null && _linkVisitor.Aggregates)
            {
                _linkDrawing = new DrawingGroup();

                string groupId = _linkVisitor.AggregatedLayerName;
                if (!string.IsNullOrWhiteSpace(groupId))
                {
                    _linkDrawing.SetValue(FrameworkElement.NameProperty, groupId);
                }

                linkVisitor.Initialize(_linkDrawing, this);
            }
        }
Exemplo n.º 6
0
        public override void Render(WpfDrawingRenderer renderer)
        {
            _isAggregated = false;

            if (_isLayer)
            {
                base.Render(renderer);

                return;
            }

            WpfDrawingContext context = renderer.Context;

            Geometry  clipGeom  = this.ClipGeometry;
            Transform transform = this.Transform;

            float opacityValue = -1;

            SvgAElement element = (SvgAElement)_svgElement;
            string      opacity = element.GetPropertyValue("opacity");

            if (string.IsNullOrWhiteSpace(opacity))
            {
                opacity = element.GetPropertyValue("opacity");
            }
            if (opacity != null && opacity.Length > 0)
            {
                opacityValue = (float)SvgNumber.ParseNumber(opacity);
                opacityValue = Math.Min(opacityValue, 1);
                opacityValue = Math.Max(opacityValue, 0);
            }

            WpfLinkVisitor linkVisitor = context.LinkVisitor;

            if (linkVisitor != null || clipGeom != null || transform != null || opacityValue >= 0)
            {
                _drawGroup = new DrawingGroup();

                string elementId = this.GetElementName();
                if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId))
                {
                    _drawGroup.SetValue(FrameworkElement.NameProperty, elementId);

                    context.RegisterId(elementId);

                    if (context.IncludeRuntime)
                    {
                        SvgObject.SetId(_drawGroup, elementId);
                    }
                }

                string elementClass = this.GetElementClass();
                if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime)
                {
                    SvgObject.SetClass(_drawGroup, elementClass);
                }

                DrawingGroup currentGroup = context.Peek();

                if (currentGroup == null)
                {
                    throw new InvalidOperationException("An existing group is expected.");
                }

                if (linkVisitor != null && linkVisitor.Aggregates && context.Links != null)
                {
                    if (!linkVisitor.Exists(elementId))
                    {
                        context.Links.Children.Add(_drawGroup);
                    }
                }
                else
                {
                    currentGroup.Children.Add(_drawGroup);
                }

                context.Push(_drawGroup);

                if (clipGeom != null)
                {
                    _drawGroup.ClipGeometry = clipGeom;
                }

                if (transform != null)
                {
                    _drawGroup.Transform = transform;
                }

                if (opacityValue >= 0)
                {
                    _drawGroup.Opacity = opacityValue;
                }

                string sVisibility = element.GetPropertyValue("visibility");
                string sDisplay    = element.GetPropertyValue("display");
                if (string.Equals(sVisibility, "hidden") || string.Equals(sDisplay, "none"))
                {
                    opacityValue       = 0;
                    _drawGroup.Opacity = 0;
                }

                if (linkVisitor != null)
                {
                    linkVisitor.Visit(_drawGroup, element, context, opacityValue);

                    _isAggregated = linkVisitor.IsAggregate;
                }
            }

            base.Render(renderer);
        }
Exemplo n.º 7
0
        public override void Render(WpfDrawingRenderer renderer)
        {
            _isAggregated = false;

            if (_isLayer)
            {
                base.Render(renderer);

                return;
            }
            var comparer = StringComparison.OrdinalIgnoreCase;

            WpfDrawingContext context = renderer.Context;

            Geometry  clipGeom  = this.ClipGeometry;
            Transform transform = this.Transform;

            float opacityValue = -1;

            SvgAElement element = (SvgAElement)_svgElement;
            string      opacity = element.GetPropertyValue("opacity");

            if (string.IsNullOrWhiteSpace(opacity))
            {
                opacity = element.GetPropertyValue("opacity");
            }
            if (!string.IsNullOrWhiteSpace(opacity))
            {
                opacityValue = (float)SvgNumber.ParseNumber(opacity);
                opacityValue = Math.Min(opacityValue, 1);
                opacityValue = Math.Max(opacityValue, 0);
            }

            WpfLinkVisitor linkVisitor = context.LinkVisitor;

            if (linkVisitor != null || clipGeom != null || transform != null || (opacityValue >= 0 && opacityValue < 1))
            {
                _drawGroup = new DrawingGroup();

                string elementId = this.GetElementName();
                if (!string.IsNullOrWhiteSpace(elementId) && !context.IsRegisteredId(elementId))
                {
                    SvgObject.SetName(_drawGroup, elementId);

                    context.RegisterId(elementId);

                    if (context.IncludeRuntime)
                    {
                        SvgObject.SetId(_drawGroup, elementId);
                    }
                }

                string elementClass = this.GetElementClass();
                if (!string.IsNullOrWhiteSpace(elementClass) && context.IncludeRuntime)
                {
                    SvgObject.SetClass(_drawGroup, elementClass);
                }

                DrawingGroup currentGroup = context.Peek();

                if (currentGroup == null)
                {
                    throw new InvalidOperationException("An existing group is expected.");
                }

                if (linkVisitor != null && linkVisitor.Aggregates && context.Links != null)
                {
                    if (!linkVisitor.Exists(elementId))
                    {
                        context.Links.Children.Add(_drawGroup);
                    }
                }
                else
                {
                    currentGroup.Children.Add(_drawGroup);
                }

                context.Push(_drawGroup);

                if (clipGeom != null)
                {
                    _drawGroup.ClipGeometry = clipGeom;
                }

                if (transform != null)
                {
                    _drawGroup.Transform = transform;
                }

                if ((opacityValue >= 0 && opacityValue < 1))
                {
                    _drawGroup.Opacity = opacityValue;
                }

                string sVisibility = element.GetPropertyValue(CssConstants.PropVisibility);
                string sDisplay    = element.GetPropertyValue(CssConstants.PropDisplay);
                if (string.Equals(sVisibility, CssConstants.ValHidden, comparer) ||
                    string.Equals(sDisplay, CssConstants.ValNone, comparer))
                {
                    opacityValue       = 0;
                    _drawGroup.Opacity = 0;
                }

                if (linkVisitor != null)
                {
                    linkVisitor.Visit(_drawGroup, element, context, opacityValue);

                    _isAggregated = linkVisitor.IsAggregate;
                }
            }

            // Register this drawing with the Drawing-Document...
            this.Rendered(_drawGroup);

            base.Render(renderer);
        }