상속: ISvgLength
예제 #1
0
        private double CalcPatternUnit(SvgLength length, SvgLengthDirection dir, Rect bounds)
        {
            if (_patternElement.PatternUnits.AnimVal.Equals(SvgUnitType.UserSpaceOnUse))
            {
                return length.Value;
            }
            else
            {
                double calcValue = length.ValueInSpecifiedUnits;
                if (dir == SvgLengthDirection.Horizontal)
                {
                    calcValue *= bounds.Width;
                }
                else
                {
                    calcValue *= bounds.Height;
                }
                if (length.UnitType == SvgLengthType.Percentage)
                {
                    calcValue /= 100F;
                }

                return calcValue;
            }
        }
예제 #2
0
 public void TestExValues()
 {
     length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "10ex");
     Assert.AreEqual(SvgLengthType.Exs, length.UnitType);
     Assert.AreEqual(10, length.ValueInSpecifiedUnits);
     Assert.AreEqual("10ex", length.ValueAsString);
 }
예제 #3
0
 public void TestCmValues()
 {
     length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "10cm");
     Assert.AreEqual(10 / 2.54 * 96, length.Value);
     Assert.AreEqual(SvgLengthType.Cm, length.UnitType);
     Assert.AreEqual(10, length.ValueInSpecifiedUnits);
     Assert.AreEqual("10cm", length.ValueAsString);
 }
예제 #4
0
        public override void CacheRenderingRegion(ISvgRenderer renderer)
        {
            base.CacheRenderingRegion(renderer);

            if (renderingNode != null)
            {
                if (renderingNode.ScreenRegion != RectangleF.Empty)
                {
                    return;
                }

                //TODO this is still fairly experimental, a margin of 20 gives us some overlap for leeway
                //TODO in general, overlap is necessary to handle strokes, which are not covered in bbox, but are
                //TODO for rendering purposes (same with markers)
                string strokeWidth = this.GetPropertyValue("stroke-width");
                if (strokeWidth.Length == 0)
                {
                    strokeWidth = "1px";
                }
                SvgLength strokeWidthLength = new SvgLength(this, "stroke-width", SvgLengthDirection.Viewport, strokeWidth);
                renderingNode.ScreenRegion = GetBRect((float)strokeWidthLength.Value);
            }
        }
예제 #5
0
        public override void CssInvalidate()
        {
            base.CssInvalidate();

            string strokeWidth = this.GetPropertyValue("stroke-width");

            if (strokeWidth.Length == 0)
            {
                strokeWidth = "1px";
            }
            SvgLength strokeWidthLength = new SvgLength(this, "stroke-width", SvgLengthDirection.Viewport, strokeWidth);

            if (renderingNode != null)
            {
                // Quick-cache
                renderingNode.ScreenRegion = GetBRect((float)strokeWidthLength.Value);
                OwnerDocument.Window.Renderer.InvalidateRect(renderingNode.ScreenRegion);
            }
            else
            {
                OwnerDocument.Window.Renderer.InvalidateRect(GetBRect((float)strokeWidthLength.Value));
            }
        }
예제 #6
0
        private double getViewportProp(string propertyName, string inValue, double calcParentVP, 
            double defaultValue, SvgLengthDirection dir)
        {
            double ret;
            inValue = inValue.Trim();

            if (inValue.Length > 0)
            {
                if (inValue.EndsWith("%"))
                {
                    double perc = SvgNumber.ParseNumber(inValue.Substring(0, inValue.Length - 1)) / 100;
                    ret = calcParentVP * perc;
                }
                else
                {
                    ret = new SvgLength(this, propertyName, dir, inValue, String.Empty).Value;
                }
            }
            else ret = defaultValue;

            return ret;
        }
 public SvgAnimatedLength(SvgElement ownerElement, string propertyName,
                          SvgLengthDirection direction, string strValue, string defaultValue)
 {
     baseVal = new SvgLength(ownerElement, propertyName, direction,
                             strValue, defaultValue);
 }
예제 #8
0
        public void PaintMarker(GdiGraphicsRenderer renderer, GdiGraphicsWrapper gr, 
            SvgMarkerPosition markerPos, SvgStyleableElement refElement)
        {
            ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement;
            SvgMarkerElement markerElm     = (SvgMarkerElement) element;

            SvgPointF[] vertexPositions = markerHostElm.MarkerPositions;
            int start;
            int len;

            // Choose which part of the position array to use
            switch (markerPos)
            {
                case SvgMarkerPosition.Start:
                    start = 0;
                    len = 1;
                    break;
                case SvgMarkerPosition.Mid:
                    start = 1;
                    len = vertexPositions.Length - 2;
                    break;
                default:
                    // == MarkerPosition.End
                    start = vertexPositions.Length-1;
                    len = 1;
                    break;
            }

            for (int i = start; i < start+len; i++)
            {
                SvgPointF point = vertexPositions[i];

                GdiGraphicsContainer gc = gr.BeginContainer();

                gr.TranslateTransform(point.X, point.Y);

                if (markerElm.OrientType.AnimVal.Equals(SvgMarkerOrient.Angle))
                {
                    gr.RotateTransform((float)markerElm.OrientAngle.AnimVal.Value);
                }
                else
                {
                    double angle;

                    switch(markerPos)
                    {
                        case SvgMarkerPosition.Start:
                            angle = markerHostElm.GetStartAngle(i + 1);
                            break;
                        case SvgMarkerPosition.Mid:
                            //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2;
                            angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1));
                            break;
                        default:
                            angle = markerHostElm.GetEndAngle(i);
                            break;
                    }
                    gr.RotateTransform((float)angle);
                }

                if (markerElm.MarkerUnits.AnimVal.Equals(SvgMarkerUnit.StrokeWidth))
                {
                    SvgLength strokeWidthLength = new SvgLength(refElement,
                        "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1");
                    float strokeWidth = (float)strokeWidthLength.Value;
                    gr.ScaleTransform(strokeWidth, strokeWidth);
                }

                SvgPreserveAspectRatio spar =
                    (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal;
                double[] translateAndScale = spar.FitToViewBox((SvgRect)markerElm.ViewBox.AnimVal,
                    new SvgRect(0, 0, markerElm.MarkerWidth.AnimVal.Value,
                        markerElm.MarkerHeight.AnimVal.Value));

                gr.TranslateTransform(-(float)(markerElm.RefX.AnimVal.Value * translateAndScale[2]),
                    -(float)(markerElm.RefY.AnimVal.Value * translateAndScale[3]));

                gr.ScaleTransform((float)translateAndScale[2], (float)translateAndScale[3]);

                Clip(gr);

                renderer.RenderChildren(markerElm);

                gr.EndContainer(gc);
            }
        }
        public override void CacheRenderingRegion(ISvgRenderer renderer)
        {
            base.CacheRenderingRegion(renderer);

              if (renderingNode != null)
              {
            if (renderingNode.ScreenRegion != RectangleF.Empty)
              return;

            //TODO this is still fairly experimental, a margin of 20 gives us some overlap for leeway
            //TODO in general, overlap is necessary to handle strokes, which are not covered in bbox, but are
            //TODO for rendering purposes (same with markers)
            string strokeWidth = this.GetPropertyValue("stroke-width");
            if(strokeWidth.Length == 0) strokeWidth = "1px";
            SvgLength strokeWidthLength = new SvgLength(this, "stroke-width", SvgLengthDirection.Viewport, strokeWidth);
            renderingNode.ScreenRegion = GetBRect((float)strokeWidthLength.Value);
              }
        }
예제 #10
0
        public void RenderMarker0(WpfDrawingRenderer renderer, WpfDrawingContext gr, 
            SvgMarkerPosition markerPos, SvgStyleableElement refElement)
        {
            //PathGeometry g;
            //g.GetPointAtFractionLength(

            ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement;
            SvgMarkerElement markerElm = (SvgMarkerElement)_svgElement;

            SvgPointF[] vertexPositions = markerHostElm.MarkerPositions;
            int start;
            int len;

            // Choose which part of the position array to use
            switch (markerPos)
            {
                case SvgMarkerPosition.Start:
                    start = 0;
                    len = 1;
                    break;
                case SvgMarkerPosition.Mid:
                    start = 1;
                    len = vertexPositions.Length - 2;
                    break;
                default:
                    // == MarkerPosition.End
                    start = vertexPositions.Length - 1;
                    len = 1;
                    break;
            }

            for (int i = start; i < start + len; i++)
            {
                SvgPointF point = vertexPositions[i];

                Matrix m = GetTransformMatrix(_svgElement);

                //GraphicsContainer gc = gr.BeginContainer();

                this.BeforeRender(renderer);

                //gr.TranslateTransform(point.X, point.Y);

                //PAUL:
                //m.Translate(point.X, point.Y);

                if (markerElm.OrientType.AnimVal.Equals(SvgMarkerOrient.Angle))
                {
                    m.Rotate(markerElm.OrientAngle.AnimVal.Value);
                    //gr.RotateTransform((double)markerElm.OrientAngle.AnimVal.Value);
                }
                else
                {
                    double angle;

                    switch (markerPos)
                    {
                        case SvgMarkerPosition.Start:
                            angle = markerHostElm.GetStartAngle(i + 1);
                            break;
                        case SvgMarkerPosition.Mid:
                            //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2;
                            angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1));
                            break;
                        default:
                            angle = markerHostElm.GetEndAngle(i);
                            break;
                    }
                    //gr.RotateTransform(angle);
                    m.Rotate(angle);
                }

                if (markerElm.MarkerUnits.AnimVal.Equals(SvgMarkerUnit.StrokeWidth))
                {
                    string propValue = refElement.GetPropertyValue("stroke-width");
                    if (propValue.Length == 0)
                        propValue = "1";

                    SvgLength strokeWidthLength = new SvgLength("stroke-width", propValue, refElement, SvgLengthDirection.Viewport);
                    double strokeWidth = strokeWidthLength.Value;
                    //gr.ScaleTransform(strokeWidth, strokeWidth);
                    m.Scale(strokeWidth, strokeWidth);
                }

                SvgPreserveAspectRatio spar = (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal;
                double[] translateAndScale = spar.FitToViewBox(
                    (SvgRect)markerElm.ViewBox.AnimVal, new SvgRect(0, 0,
                        markerElm.MarkerWidth.AnimVal.Value, markerElm.MarkerHeight.AnimVal.Value));

                //PAUL:
                //m.Translate(-(double)markerElm.RefX.AnimVal.Value * translateAndScale[2], -(double)markerElm.RefY.AnimVal.Value * translateAndScale[3]);

                //PAUL:
                m.Scale(translateAndScale[2], translateAndScale[3]);
                m.Translate(point.X, point.Y);

                //Matrix oldTransform = TransformMatrix;
                //TransformMatrix = m;
                //try
                //{
                //newTransform.Append(m);
                //TransformGroup tg = new TransformGroup();

                //renderer.Canvas.re

                //gr.TranslateTransform(
                //    -(double)markerElm.RefX.AnimVal.Value * translateAndScale[2],
                //    -(double)markerElm.RefY.AnimVal.Value * translateAndScale[3]
                //    );

                //gr.ScaleTransform(translateAndScale[2], translateAndScale[3]);

                renderer.RenderChildren(markerElm);
            //                markerElm.RenderChildren(renderer);
                //}
                //finally
                //{
                //    TransformMatrix = oldTransform;
                //}
                //    //gr.EndContainer(gc);

                _matrix = m;
                this.Render(renderer);

                //gr.EndContainer(gc);

                this.AfterRender(renderer);
            }
        }
예제 #11
0
        public void RenderMarker(WpfDrawingRenderer renderer, WpfDrawingContext gr,
            SvgMarkerPosition markerPos, SvgStyleableElement refElement)
        {
            ISharpMarkerHost markerHostElm = (ISharpMarkerHost)refElement;
            SvgMarkerElement markerElm = (SvgMarkerElement)_svgElement;

            SvgPointF[] vertexPositions = markerHostElm.MarkerPositions;
            int start;
            int len;

            // Choose which part of the position array to use
            switch (markerPos)
            {
                case SvgMarkerPosition.Start:
                    start = 0;
                    len = 1;
                    break;
                case SvgMarkerPosition.Mid:
                    start = 1;
                    len = vertexPositions.Length - 2;
                    break;
                default:
                    // == MarkerPosition.End
                    start = vertexPositions.Length - 1;
                    len = 1;
                    break;
            }

            for (int i = start; i < start + len; i++)
            {
                SvgPointF point = vertexPositions[i];

                //GdiGraphicsContainer gc = gr.BeginContainer();

                this.BeforeRender(renderer);

                //Matrix matrix = Matrix.Identity;

                Matrix matrix = GetTransformMatrix(_svgElement);

                if (markerElm.OrientType.AnimVal.Equals(SvgMarkerOrient.Angle))
                {
                    matrix.Rotate(markerElm.OrientAngle.AnimVal.Value);
                }
                else
                {
                    double angle = 0;

                    switch (markerPos)
                    {
                        case SvgMarkerPosition.Start:
                            angle = markerHostElm.GetStartAngle(i + 1);
                            break;
                        case SvgMarkerPosition.Mid:
                            //angle = (markerHostElm.GetEndAngle(i) + markerHostElm.GetStartAngle(i + 1)) / 2;
                            angle = SvgNumber.CalcAngleBisection(markerHostElm.GetEndAngle(i), markerHostElm.GetStartAngle(i + 1));
                            break;
                        default:
                            angle = markerHostElm.GetEndAngle(i);
                            break;
                    }
                    matrix.Rotate(angle);
                }

                if (markerElm.MarkerUnits.AnimVal.Equals(SvgMarkerUnit.StrokeWidth))
                {
                    SvgLength strokeWidthLength = new SvgLength(refElement,
                        "stroke-width", SvgLengthSource.Css, SvgLengthDirection.Viewport, "1");
                    double strokeWidth = strokeWidthLength.Value;
                    matrix.Scale(strokeWidth, strokeWidth);
                }

                SvgPreserveAspectRatio spar =
                    (SvgPreserveAspectRatio)markerElm.PreserveAspectRatio.AnimVal;
                double[] translateAndScale = spar.FitToViewBox((SvgRect)markerElm.ViewBox.AnimVal,
                    new SvgRect(0, 0, markerElm.MarkerWidth.AnimVal.Value,
                        markerElm.MarkerHeight.AnimVal.Value));

                matrix.Translate(-markerElm.RefX.AnimVal.Value * translateAndScale[2],
                    -markerElm.RefY.AnimVal.Value * translateAndScale[3]);

                matrix.Scale(translateAndScale[2], translateAndScale[3]);

                matrix.Translate(point.X, point.Y);

                _matrix = matrix;
                this.Render(renderer);

                //Clip(gr);

                renderer.RenderChildren(markerElm);

                //gr.EndContainer(gc);

                this.AfterRender(renderer);
            }
        }
예제 #12
0
        private double GetStrokeWidth()
        {
            string strokeWidth = _element.GetPropertyValue("stroke-width");
            if (strokeWidth.Length == 0) strokeWidth = "1px";

            SvgLength strokeWidthLength = new SvgLength(_element, "stroke-width",
                SvgLengthDirection.Viewport, strokeWidth);

            return strokeWidthLength.Value;
        }
예제 #13
0
 private double GetDashOffset(double strokeWidth)
 {
     string dashOffset = _element.GetPropertyValue("stroke-dashoffset");
     if (dashOffset.Length > 0)
     {
         //divide by strokeWidth to take care of the difference between Svg and GDI+
         SvgLength dashOffsetLength = new SvgLength(_element, "stroke-dashoffset",
             SvgLengthDirection.Viewport, dashOffset);
         return dashOffsetLength.Value;
     }
     else
     {
         return 0;
     }
 }
예제 #14
0
        public static double GetComputedFontSize(SvgTextContentElement element)
        {
            string str = element.GetPropertyValue("font-size");
            double fontSize = 12;
            if (str.EndsWith("%"))
            {
                // percentage of inherited value
            }
            else if (_decimalNumber.IsMatch(str))
            {
                // svg length
                fontSize = new SvgLength(element, "font-size",
                    SvgLengthDirection.Viewport, str, "10px").Value;
            }
            else if (str == "larger")
            {
            }
            else if (str == "smaller")
            {

            }
            else
            {
                // check for absolute value
            }

            return fontSize;
        }
예제 #15
0
 public void TestExToAbsValues()
 {
     length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "10ex");
     Assert.AreEqual(60, length.Value);
 }
        public override void CssInvalidate()
        {
            base.CssInvalidate();

              string strokeWidth = this.GetPropertyValue("stroke-width");
              if(strokeWidth.Length == 0) strokeWidth = "1px";
              SvgLength strokeWidthLength = new SvgLength(this, "stroke-width", SvgLengthDirection.Viewport, strokeWidth);

              if (renderingNode != null)
              {
            // Quick-cache
            renderingNode.ScreenRegion = GetBRect((float)strokeWidthLength.Value);
            OwnerDocument.Window.Renderer.InvalidateRect(renderingNode.ScreenRegion);
              }
              else
              {
            OwnerDocument.Window.Renderer.InvalidateRect(GetBRect((float)strokeWidthLength.Value));
              }
        }
예제 #17
0
        public void TestSettingValues()
        {
            length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "10px");
            Assert.AreEqual(10, length.Value);
            Assert.AreEqual(SvgLengthType.Px, length.UnitType);
            Assert.AreEqual(10, length.ValueInSpecifiedUnits);
            Assert.AreEqual("10px", length.ValueAsString);

            length.ValueAsString = "10cm";
            Assert.AreEqual(10, length.ValueInSpecifiedUnits);
            length.Value = 200;
            double valueInCm = 200 / 96D * 2.54D;
            Assert.AreEqual(200, length.Value);
            Assert.AreEqual(valueInCm, length.ValueInSpecifiedUnits);
            Assert.AreEqual(valueInCm.ToString(SvgNumber.Format)+"cm", length.ValueAsString);

            // change px value
            length.ValueAsString = "2px";
            Assert.AreEqual(2, length.Value);
            Assert.AreEqual(2, length.ValueInSpecifiedUnits);
            Assert.AreEqual("2px", length.ValueAsString);

            // set to a CM value
            length.NewValueSpecifiedUnits(SvgLengthType.Cm, 23);
            Assert.AreEqual(23, length.ValueInSpecifiedUnits);
            Assert.AreEqual(23 / 2.54D * 96, length.Value);
            Assert.AreEqual("23cm", length.ValueAsString);
            Assert.AreEqual(SvgLengthType.Cm, length.UnitType);

            length.ConvertToSpecifiedUnits(SvgLengthType.Mm);
            Assert.AreEqual(230, length.ValueInSpecifiedUnits);
            Assert.AreEqual("230mm", length.ValueAsString);
            Assert.AreEqual(SvgLengthType.Mm, length.UnitType);
        }
예제 #18
0
        public void TestScientificValues()
        {
            length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "2E3px");
            Assert.AreEqual(2000, length.Value);
            Assert.AreEqual(SvgLengthType.Px, length.UnitType);
            Assert.AreEqual(2000, length.ValueInSpecifiedUnits);
            Assert.AreEqual("2000px", length.ValueAsString);

            length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "1E-1px");
            Assert.IsTrue(Math.Abs(0.1D-length.Value)<0.0001, "Value");
            Assert.AreEqual(SvgLengthType.Px, length.UnitType);
            Assert.IsTrue(Math.Abs(0.1D-length.ValueInSpecifiedUnits)<0.0001, "ValueInSpecifiedUnits");
            //Assert.AreEqual("0.1px", length.ValueAsString);
        }
예제 #19
0
        public void TestPercentValues()
        {
            length = new SvgLength(elm, "test", SvgLengthDirection.Horizontal, "10%");
            Assert.AreEqual(20, length.Value);
            Assert.AreEqual(SvgLengthType.Percentage, length.UnitType);
            Assert.AreEqual(10, length.ValueInSpecifiedUnits);
            Assert.AreEqual("10%", length.ValueAsString);

            length = new SvgLength(elm, "test", SvgLengthDirection.Vertical, "20%");
            Assert.AreEqual(60, length.Value);

            length = new SvgLength(elm, "test", SvgLengthDirection.Viewport, "10%");
            Assert.AreEqual(Math.Sqrt(200*200+300*300)/Math.Sqrt(2) * 0.1D, length.Value);
        }
예제 #20
0
 public SvgAnimatedLength(SvgElement ownerElement, string propertyName, 
     SvgLengthDirection direction, string strValue, string defaultValue)
 {
     baseVal = new SvgLength(ownerElement, propertyName, direction,
         strValue, defaultValue);
 }