Inheritance: SvgElement
コード例 #1
0
        public void EnsureServer(SvgElement styleOwner)
        {
            if (!_serverLoaded && styleOwner != null)
            {
                if (DeferredId == "currentColor")
                {
                    var colorElement = (from e in styleOwner.ParentsAndSelf.OfType <SvgElement>()
                                        where e.Color != None && e.Color != NotSet && e.Color != Inherit
                                        select e).FirstOrDefault();
                    _concreteServer = colorElement?.Color;
                }
                else
                {
                    _concreteServer = styleOwner.OwnerDocument.IdManager.GetElementById(DeferredId) as SvgPaintServer;

                    _fallbackServer = FallbackServer;
                    if (_fallbackServer == null)
                    {
                        _fallbackServer = None;
                    }
                    else if (!(_fallbackServer is SvgColourServer ||
                               (_fallbackServer is SvgDeferredPaintServer && string.Equals(((SvgDeferredPaintServer)_fallbackServer).DeferredId, "currentColor"))))
                    {
                        _fallbackServer = Inherit;
                    }
                }
                _serverLoaded = true;
            }
        }
コード例 #2
0
        /// <summary>
        /// Renders the fill of the <see cref="SvgVisualElement"/> to the specified <see cref="ISvgRenderer"/>
        /// </summary>
        /// <param name="renderer">The <see cref="ISvgRenderer"/> object to render to.</param>
        /// <param name="fill"></param>
        protected internal virtual bool RenderFill(ISvgRenderer renderer, SvgPaintServer fill = null)
        {
            fill = fill ?? Fill;

            if (fill != null && fill != SvgPaintServer.None)
            {
                renderer.FillPath(Path(renderer), fill.GetColor(this, renderer, FixOpacityValue(FillOpacity), false));
                return(true);
            }

            return(false);
        }
コード例 #3
0
        public static T TryGet <T>(SvgPaintServer server, SvgElement parent) where T : SvgPaintServer
        {
            if (!(server is SvgDeferredPaintServer))
            {
                return(server as T);
            }

            var deferred = (SvgDeferredPaintServer)server;

            deferred.EnsureServer(parent);
            return((deferred._concreteServer ?? deferred._fallbackServer) as T);
        }
コード例 #4
0
        /// <summary>
        /// Common code for rendering a marker once the orientation angle has been calculated
        /// </summary>
        /// <param name="fAngle"></param>
        /// <param name="pRenderer"></param>
        /// <param name="pOwner"></param>
        /// <param name="pMarkerPoint"></param>
        private void RenderPart2(float fAngle, ISvgRenderer pRenderer, SvgVisualElement pOwner, PointF pMarkerPoint)
        {
            using (var pRenderPen = CreatePen(pOwner, pRenderer))
            {
                using (var markerPath = GetClone(pOwner))
                {
                    using (var transMatrix = new Matrix())
                    {
                        transMatrix.Translate(pMarkerPoint.X, pMarkerPoint.Y);
                        if (Orient.IsAuto)
                        {
                            transMatrix.Rotate(fAngle);
                        }
                        else
                        {
                            transMatrix.Rotate(Orient.Angle);
                        }
                        switch (MarkerUnits)
                        {
                        case SvgMarkerUnits.strokeWidth:
                            transMatrix.Translate(AdjustForViewBoxWidth(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this) *
                                                                        pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)),
                                                  AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) *
                                                                         pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this)));
                            break;

                        case SvgMarkerUnits.userSpaceOnUse:
                            transMatrix.Translate(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this),
                                                  -RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this));
                            break;
                        }
                        markerPath.Transform(transMatrix);
                        if (pRenderPen != null)
                        {
                            pRenderer.DrawPath(pRenderPen, markerPath);
                        }

                        SvgPaintServer pFill     = this.Children.First().Fill;
                        SvgFillRule    pFillRule = FillRule;                                                            // TODO: What do we use the fill rule for?
                        float          fOpacity  = FillOpacity;

                        if (pFill != null)
                        {
                            using (var pBrush = pFill.GetBrush(this, pRenderer, fOpacity))
                            {
                                pRenderer.FillPath(pBrush, markerPath);
                            }
                        }
                    }
                }
            }
        }
コード例 #5
0
        public static T TryGet <T>(SvgPaintServer server, SvgElement parent) where T : SvgPaintServer
        {
            var deferred = server as SvgDeferredPaintServer;

            if (deferred == null)
            {
                return(server as T);
            }
            else
            {
                deferred.EnsureServer(parent);
                return(deferred._concreteServer as T);
            }
        }
コード例 #6
0
        /// <summary>
        /// Renders the stroke of the <see cref="SvgVisualElement"/> to the specified <see cref="ISvgRenderer"/>
        /// </summary>
        /// <param name="renderer">The <see cref="ISvgRenderer"/> object to render to.</param>
        /// <param name="stroke"></param>
        protected internal virtual bool RenderStroke(ISvgRenderer renderer, SvgPaintServer stroke = null)
        {
            stroke = stroke ?? Stroke;

            if (stroke != null && stroke != SvgPaintServer.None)
            {
                var strokeWidth = StrokeWidth.ToDeviceValue(renderer, UnitRenderingType.Other, this);

                renderer.DrawPath(Path(renderer), stroke.GetColor(this, renderer, FixOpacityValue(StrokeOpacity), true), strokeWidth);
                return(true);
            }

            return(false);
        }
コード例 #7
0
ファイル: SvgMarker.cs プロジェクト: asmboom/HtmlRenderer
        /// <summary>
        /// Common code for rendering a marker once the orientation angle has been calculated
        /// </summary>
        /// <param name="fAngle"></param>
        /// <param name="pRenderer"></param>
        /// <param name="pOwner"></param>
        /// <param name="pMarkerPoint"></param>
        private void RenderPart2(float fAngle, SvgRenderer pRenderer, SvgPath pOwner, PointF pMarkerPoint)
        {
            Pen pRenderPen = CreatePen(pOwner);

            GraphicsPath markerPath = GetClone(pOwner);

            Matrix transMatrix = new Matrix();

            transMatrix.Translate(pMarkerPoint.X, pMarkerPoint.Y);
            if (Orient.IsAuto)
            {
                transMatrix.Rotate(fAngle);
            }
            else
            {
                transMatrix.Rotate(Orient.Angle);
            }
            switch (MarkerUnits)
            {
            case SvgMarkerUnits.strokeWidth:
                transMatrix.Translate(AdjustForViewBoxWidth(-RefX * pOwner.StrokeWidth), AdjustForViewBoxHeight(-RefY * pOwner.StrokeWidth));
                break;

            case SvgMarkerUnits.userSpaceOnUse:
                transMatrix.Translate(-RefX, -RefY);
                break;
            }
            markerPath.Transform(transMatrix);
            pRenderer.DrawPath(pRenderPen, markerPath);

            SvgPaintServer pFill     = Fill;
            SvgFillRule    pFillRule = FillRule;                                                        // TODO: What do we use the fill rule for?
            float          fOpacity  = FillOpacity;

            if (pFill != null)
            {
                Brush pBrush = pFill.GetBrush(this, fOpacity);
                pRenderer.FillPath(pBrush, markerPath);
                pBrush.Dispose();
            }
            pRenderPen.Dispose();
            markerPath.Dispose();
            transMatrix.Dispose();
        }
コード例 #8
0
 public void EnsureServer(SvgElement styleOwner)
 {
     if (!_serverLoaded)
     {
         if (this.DeferredId == "currentColor" && styleOwner != null)
         {
             var colorElement = (from e in styleOwner.ParentsAndSelf.OfType <SvgElement>()
                                 where e.Color != SvgPaintServer.None && e.Color != SvgColorServer.NotSet &&
                                 e.Color != SvgColorServer.Inherit && e.Color != SvgColorServer.None
                                 select e).FirstOrDefault();
             _concreteServer = (colorElement == null ? SvgPaintServer.None : colorElement.Color);
         }
         else
         {
             _concreteServer = this.Document.IdManager.GetElementById(this.DeferredId) as SvgPaintServer;
         }
         _serverLoaded = true;
     }
 }
コード例 #9
0
        /// <summary>
        /// Common code for rendering a marker once the orientation angle has been calculated
        /// </summary>
        /// <param name="fAngle"></param>
        /// <param name="pRenderer"></param>
        /// <param name="pOwner"></param>
        /// <param name="pMarkerPoint"></param>
        private void RenderPart2(float fAngle, ISvgRenderer pRenderer, SvgVisualElement pOwner, PointF pMarkerPoint)
        {
            using (var pRenderPen = CreatePen(pOwner, pRenderer))
            {
                using (var markerPath = GetClone(pOwner, pRenderer))
                {
                    using (var transMatrix = new Matrix())
                    {
                        transMatrix.Translate(pMarkerPoint.X, pMarkerPoint.Y);
                        if (Orient.IsAuto)
                        {
                            transMatrix.Rotate(fAngle);
                        }
                        else
                        {
                            transMatrix.Rotate(Orient.Angle);
                        }
                        switch (MarkerUnits)
                        {
                        case SvgMarkerUnits.StrokeWidth:
                            if (ViewBox.Width > 0 && ViewBox.Height > 0)
                            {
                                transMatrix.Scale(MarkerWidth, MarkerHeight);
                                var strokeWidth = pOwner.StrokeWidth.ToDeviceValue(pRenderer, UnitRenderingType.Other, this);
                                transMatrix.Translate(AdjustForViewBoxWidth(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this) *
                                                                            strokeWidth),
                                                      AdjustForViewBoxHeight(-RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this) *
                                                                             strokeWidth));
                            }
                            else
                            {
                                // SvgMarkerUnits.UserSpaceOnUse
                                // TODO: We know this isn't correct.
                                //        But use this until the TODOs from AdjustForViewBoxWidth and AdjustForViewBoxHeight are done.
                                //  MORE see Unit Test "MakerEndTest.TestArrowCodeCreation()"
                                transMatrix.Translate(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this),
                                                      -RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this));
                            }
                            break;

                        case SvgMarkerUnits.UserSpaceOnUse:
                            transMatrix.Translate(-RefX.ToDeviceValue(pRenderer, UnitRenderingType.Horizontal, this),
                                                  -RefY.ToDeviceValue(pRenderer, UnitRenderingType.Vertical, this));
                            break;
                        }

                        if (MarkerElement != null && MarkerElement.Transforms != null)
                        {
                            using (var matrix = MarkerElement.Transforms.GetMatrix())
                                transMatrix.Multiply(matrix);
                        }
                        markerPath.Transform(transMatrix);
                        if (pRenderPen != null)
                        {
                            pRenderer.DrawPath(pRenderPen, markerPath);
                        }

                        SvgPaintServer pFill     = this.Children.First().Fill;
                        SvgFillRule    pFillRule = FillRule; // TODO: What do we use the fill rule for?

                        if (pFill != null)
                        {
                            using (var pBrush = pFill.GetBrush(this, pRenderer, FixOpacityValue(FillOpacity)))
                            {
                                pRenderer.FillPath(pBrush, markerPath);
                            }
                        }
                    }
                }
            }
        }
コード例 #10
0
 public SvgFallbackPaintServer(SvgPaintServer primary, IEnumerable <SvgPaintServer> fallbacks) : this()
 {
     _fallbacks = fallbacks;
     _primary   = primary;
 }
コード例 #11
0
 /// <summary>
 /// Initializes new instance of <see cref="SvgDeferredPaintServer"/> class.
 /// </summary>
 /// <param name="id">&lt;FuncIRI&gt;, &lt;IRI&gt; or &quot;currentColor&quot;.</param>
 /// <param name="fallbackServer">&quot;none&quot;, &quot;currentColor&quot; or <see cref="SvgColourServer"/> server.</param>
 public SvgDeferredPaintServer(string id, SvgPaintServer fallbackServer)
 {
     DeferredId     = id;
     FallbackServer = fallbackServer;
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SvgGradientStop"/> class.
 /// </summary>
 /// <param name="offset">The offset.</param>
 /// <param name="colour">The colour.</param>
 public SvgGradientStop(SvgUnit offset, Color colour)
 {
     this._offset  = offset;
     this._colour  = new SvgColourServer(colour);
     this._opacity = 1.0f;
 }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SvgGradientStop"/> class.
 /// </summary>
 public SvgGradientStop()
 {
     this._offset  = new SvgUnit(0.0f);
     this._colour  = SvgColourServer.NotSet;
     this._opacity = 1.0f;
 }