protected override void Initialize(SvgElement element)
        {
            base.Initialize(element);

            _isMeasuring  = false;
            _isGroupAdded = false;
            _isTextPath   = false;
            _textWidth    = 0;
            _drawGroup    = null;

            _textElement = element as SvgTextBaseElement;
            if (_textElement == null)
            {
                throw new InvalidOperationException();
            }

            if (_textContext == null)
            {
                _textContext = new WpfTextContext(_textElement, this);
            }
            else
            {
                _textContext.SetElement(_textElement);
            }

            if (_horzRenderer == null)
            {
                _horzRenderer = new WpfHorzTextRenderer(_textElement, this);
            }
            else
            {
                _horzRenderer.Uninitialize();
                _horzRenderer.SetElement(_textElement);
            }
            if (_vertRenderer == null)
            {
                _vertRenderer = new WpfVertTextRenderer(_textElement, this);
            }
            else
            {
                _vertRenderer.Uninitialize();
                _vertRenderer.SetElement(_textElement);
            }
            if (_pathRenderer == null)
            {
                _pathRenderer = new WpfPathTextRenderer(_textElement, this);
            }
            else
            {
                _pathRenderer.Uninitialize();
                _pathRenderer.SetElement(_textElement);
            }
        }
        public WpfTextRendering(SvgElement element)
            : base(element)
        {
            _textElement = element as SvgTextElement;
            if (_textElement == null)
            {
                throw new InvalidOperationException();
            }

            _horzRenderer = new WpfHorzTextRenderer(_textElement, this);
            _vertRenderer = new WpfVertTextRenderer(_textElement, this);
            _pathRenderer = new WpfPathTextRenderer(_textElement, this);
        }
Ejemplo n.º 3
0
        public WpfTextRendering(SvgElement element)
            : base(element)
        {
            _textElement = element as SvgTextBaseElement;
            if (_textElement != null)
            {
                _textContext = new WpfTextContext(_textElement, this);

                _horzRenderer = new WpfHorzTextRenderer(_textElement, this);
                _vertRenderer = new WpfVertTextRenderer(_textElement, this);
                _pathRenderer = new WpfPathTextRenderer(_textElement, this);
            }
        }
        public override void AfterRender(WpfDrawingRenderer renderer)
        {
            if (_horzRenderer != null)
            {
                _horzRenderer.Uninitialize();
                _horzRenderer = null;
            }
            if (_vertRenderer != null)
            {
                _vertRenderer.Uninitialize();
                _vertRenderer = null;
            }
            if (_pathRenderer != null)
            {
                _pathRenderer.Uninitialize();
                _pathRenderer = null;
            }

            if (_drawContext != null)
            {
                _drawContext.Close();
                _drawContext = null;
            }

            WpfDrawingContext context = renderer.Context;

            // TODO-PAUL: Testing this for validity...
            // Remove the GuidelineSet from the groups added by the FormattedText to reduced the
            // size of output XAML...
            if (_drawGroup != null)
            {
                ResetGuidelineSet(_drawGroup);
            }

            if (context.IncludeRuntime)
            {
                if (_drawGroup != null)
                {
                    // Add the element/object type...
                    SvgObject.SetType(_drawGroup, SvgObjectType.Text);

                    // Add title for tooltips, if any...
                    SvgTitleElement titleElement = _svgElement.SelectSingleNode("title") as SvgTitleElement;
                    if (titleElement != null)
                    {
                        string titleValue = titleElement.InnerText;
                        if (!string.IsNullOrWhiteSpace(titleValue))
                        {
                            SvgObject.SetTitle(_drawGroup, titleValue);
                        }
                    }
                }
            }

            if (!_isGroupAdded)
            {
                if (_drawGroup != null)
                {
                    if (_isTextPath || _drawGroup.Transform != null || _drawGroup.ClipGeometry != null)
                    {
                        DrawingGroup curGroup = _context.Peek();
                        Debug.Assert(curGroup != null);
                        if (curGroup != null)
                        {
                            curGroup.Children.Add(_drawGroup);
                        }
                    }
                    else if (_drawGroup.Children.Count != 0)
                    {
                        DrawingGroup firstGroup = _drawGroup.Children[0] as DrawingGroup;
                        if (firstGroup != null && firstGroup.Children.Count != 0)
                        {
                            //Drawing firstDrawing = firstGroup.Children[0];

                            DrawingGroup curGroup = _context.Peek();
                            Debug.Assert(curGroup != null);
                            if (curGroup != null)
                            {
                                curGroup.Children.Add(_drawGroup);
                            }
                        }
                    }
                }
            }
            else
            {
                if (_drawGroup != null)
                {
                    DrawingGroup currentGroup = context.Peek();

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

                    context.Pop();
                }
            }

            _context   = null;
            _drawGroup = null;

            base.AfterRender(renderer);
        }