Exemplo n.º 1
0
 private void InvalidateAndUpdate(RectangleF rect)
 {
     if (_svgRenderer != null)
     {
         _svgRenderer.InvalidateRect(SvgConvert.ToRect(rect));
         InvalidateAndRender();
     }
 }
Exemplo n.º 2
0
        private SvgRectF GetElementBounds(SvgTransformableElement element, float margin)
        {
            SvgRenderingHint hint = element.RenderingHint;

            if (hint == SvgRenderingHint.Shape || hint == SvgRenderingHint.Text)
            {
                GraphicsPath gp = GdiRendering.CreatePath(element);
                if (gp == null)
                {
                    return(SvgRectF.Empty);
                }
                ISvgMatrix svgMatrix = element.GetScreenCTM();
                if (svgMatrix == null)
                {
                    return(SvgRectF.Empty);
                }

                Matrix matrix = new Matrix((float)svgMatrix.A, (float)svgMatrix.B, (float)svgMatrix.C,
                                           (float)svgMatrix.D, (float)svgMatrix.E, (float)svgMatrix.F);
                SvgRectF bounds = SvgConvert.ToRect(gp.GetBounds(matrix));
                bounds = SvgRectF.Inflate(bounds, margin, margin);

                return(bounds);
            }

            SvgUseElement useElement = element as SvgUseElement;

            if (useElement != null)
            {
                SvgTransformableElement refEl = useElement.ReferencedElement as SvgTransformableElement;
                if (refEl == null)
                {
                    return(SvgRectF.Empty);
                }

                XmlElement refElParent = (XmlElement)refEl.ParentNode;
                element.OwnerDocument.Static = true;
                useElement.CopyToReferencedElement(refEl);
                element.AppendChild(refEl);

                SvgRectF bbox = this.GetElementBounds(refEl, margin);

                element.RemoveChild(refEl);
                useElement.RestoreReferencedElement(refEl);
                refElParent.AppendChild(refEl);
                element.OwnerDocument.Static = false;

                return(bbox);
            }

            SvgRectF union = SvgRectF.Empty;
            SvgTransformableElement transformChild;

            foreach (XmlNode childNode in element.ChildNodes)
            {
                if (childNode is SvgDefsElement)
                {
                    continue;
                }
                if (childNode is ISvgTransformable)
                {
                    transformChild = (SvgTransformableElement)childNode;
                    SvgRectF bbox = this.GetElementBounds(transformChild, margin);
                    if (bbox != SvgRectF.Empty)
                    {
                        if (union == SvgRectF.Empty)
                        {
                            union = bbox;
                        }
                        else
                        {
                            union = SvgRectF.Union(union, bbox);
                        }
                    }
                }
            }

            return(union);
        }