コード例 #1
0
ファイル: SVGTextParser.cs プロジェクト: znsoft/TUSA
        public static void Parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, string text)
        {
            float?X        = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X);
            float?Y        = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y);
            float?size     = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_SIZE);
            Paint pPaint   = pSVGPaint.getPaint();
            float fontsize = pPaint.TextSize;

            if (size != null)
            {
                fontsize        = (float)size;
                pPaint          = new Paint();// pPaint);
                pPaint.TextSize = fontsize;
            }
            if (X != null && Y != null)
            {
                bool fill = pSVGPaint.setFill(pSVGProperties);

                bool stroke = pSVGPaint.setStroke(pSVGProperties);
                // ширина текста
                float width = pPaint.MeasureText(text);

                pCanvas.DrawText(text, X.Value, Y.Value, pPaint);

                if (fill || stroke)
                {
                    pSVGPaint.ensureComputedBoundsInclude(X.Value + width, Y.Value + pPaint.TextSize);
                }
            }
        }
コード例 #2
0
        public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint)
        {
            var points = pSVGProperties.GetStringAttribute(SVGConstants.ATTRIBUTE_POINTS).ParseFloats();

            if (points != null)
            {
                if (points.Length >= 2)
                {
                    Path path = SVGPolylineParser.parse(points);
                    path.Close();

                    bool fill = pSVGPaint.setFill(pSVGProperties);
                    if (fill)
                    {
                        pCanvas.DrawPath(path, pSVGPaint.getPaint());
                    }

                    bool stroke = pSVGPaint.setStroke(pSVGProperties);
                    if (stroke)
                    {
                        pCanvas.DrawPath(path, pSVGPaint.getPaint());
                    }

                    if (fill || stroke)
                    {
                        pSVGPaint.ensureComputedBoundsInclude(path);
                    }
                }
            }
        }
コード例 #3
0
ファイル: SVGCircleParser.cs プロジェクト: znsoft/TUSA
        public static void Parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint)
        {
            float?centerX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_X);
            float?centerY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_Y);
            float?radius  = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS);

            if (centerX != null && centerY != null && radius != null)
            {
                bool fill = pSVGPaint.setFill(pSVGProperties);
                if (fill)
                {
                    pCanvas.DrawCircle(centerX.Value, centerY.Value, radius.Value, pSVGPaint.getPaint());
                }

                bool stroke = pSVGPaint.setStroke(pSVGProperties);
                if (stroke)
                {
                    pCanvas.DrawCircle(centerX.Value, centerY.Value, radius.Value, pSVGPaint.getPaint());
                }

                if (fill || stroke)
                {
                    pSVGPaint.ensureComputedBoundsInclude(centerX.Value - radius.Value, centerY.Value - radius.Value);
                    pSVGPaint.ensureComputedBoundsInclude(centerX.Value + radius.Value, centerY.Value + radius.Value);
                }
            }
        }
コード例 #4
0
ファイル: SVGEllipseParser.cs プロジェクト: jdluzen/xamsvg
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
			float? centerX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_X);
			float? centerY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_Y);
			float? radiusX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
			float? radiusY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);
			if (centerX != null && centerY != null && radiusX != null && radiusY != null) {
				pRect.Set(centerX.Value - radiusX.Value,
				          centerY.Value - radiusY.Value,
				          centerX.Value + radiusX.Value,
				          centerY.Value + radiusY.Value);

				bool fill = pSVGPaint.setFill(pSVGProperties);
				if (fill) {
					pCanvas.DrawOval(pRect, pSVGPaint.getPaint());
				}

				bool stroke = pSVGPaint.setStroke(pSVGProperties);
				if (stroke) {
					pCanvas.DrawOval(pRect, pSVGPaint.getPaint());
				}

				if(fill || stroke) {
					pSVGPaint.ensureComputedBoundsInclude(centerX.Value - radiusX.Value, centerY.Value - radiusY.Value);
					pSVGPaint.ensureComputedBoundsInclude(centerX.Value + radiusX.Value, centerY.Value + radiusY.Value);
				}
			}
		}
コード例 #5
0
ファイル: SVGLineParser.cs プロジェクト: jdluzen/xamsvg
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint) {
			float x1 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X1, 0f);
			float x2 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X2, 0f);
			float y1 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y1, 0f);
			float y2 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y2, 0f);
			if (pSVGPaint.setStroke(pSVGProperties)) {
				pSVGPaint.ensureComputedBoundsInclude(x1, y1);
				pSVGPaint.ensureComputedBoundsInclude(x2, y2);
				pCanvas.DrawLine(x1, y1, x2, y2, pSVGPaint.getPaint());
			}
		}
コード例 #6
0
ファイル: SVGRectParser.cs プロジェクト: jdluzen/xamsvg
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
			float x = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X, 0f);
			float y = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y, 0f);
			float width = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_WIDTH, 0f);
			float height = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_HEIGHT, 0f);

			pRect.Set(x, y, x + width, y + height);

			float? rX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
			float? rY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);

			bool rXSpecified = rX != null && rX >= 0;
			bool rYSpecified = rY != null && rY >= 0;

			bool rounded = rXSpecified || rYSpecified;
			float rx;
			float ry;
			if(rXSpecified && rYSpecified) {
				rx = Math.Min(rX.Value, width * 0.5f);
				ry = Math.Min(rY.Value, height * 0.5f);
			} else if(rXSpecified) {
				ry = rx = Math.Min(rX.Value, width * 0.5f);
			} else if(rYSpecified) {
				rx = ry = Math.Min(rY.Value, height * 0.5f);
			} else {
				rx = 0;
				ry = 0;
			}

			bool fill = pSVGPaint.setFill(pSVGProperties);
			if (fill) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			bool stroke = pSVGPaint.setStroke(pSVGProperties);
			if (stroke) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			if(fill || stroke) {
				pSVGPaint.ensureComputedBoundsInclude(x, y, width, height);
			}
		}
コード例 #7
0
ファイル: SVGLineParser.cs プロジェクト: znsoft/TUSA
        public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint)
        {
            float x1 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X1, 0f);
            float x2 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X2, 0f);
            float y1 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y1, 0f);
            float y2 = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y2, 0f);

            if (pSVGPaint.setStroke(pSVGProperties))
            {
                pSVGPaint.ensureComputedBoundsInclude(x1, y1);
                pSVGPaint.ensureComputedBoundsInclude(x2, y2);
                pCanvas.DrawLine(x1, y1, x2, y2, pSVGPaint.getPaint());
            }
        }
コード例 #8
0
ファイル: SVGPathParser.cs プロジェクト: jdluzen/xamsvg
		public void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint) {
			Path path = this.parse(pSVGProperties);

			bool fill = pSVGPaint.setFill(pSVGProperties);
			if (fill) {
				pCanvas.DrawPath(path, pSVGPaint.getPaint());
			}

			bool stroke = pSVGPaint.setStroke(pSVGProperties);
			if (stroke) {
				pCanvas.DrawPath(path, pSVGPaint.getPaint());
			}

			if(fill || stroke) {
				pSVGPaint.ensureComputedBoundsInclude(path);
			}
		}
コード例 #9
0
ファイル: SVGPolylineParser.cs プロジェクト: jdluzen/xamsvg
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint) {
			var points = pSVGProperties.GetStringAttribute(SVGConstants.ATTRIBUTE_POINTS).ParseFloats ();
			if (points != null) {
				if (points.Length >= 2) {
					Path path = SVGPolylineParser.parse(points);

					bool fill = pSVGPaint.setFill(pSVGProperties);
					if (fill) {
						pCanvas.DrawPath(path, pSVGPaint.getPaint());
					}

					bool stroke = pSVGPaint.setStroke(pSVGProperties);
					if (stroke) {
						pCanvas.DrawPath(path, pSVGPaint.getPaint());
					}

					if(fill || stroke) {
						pSVGPaint.ensureComputedBoundsInclude(path);
					}
				}
			}
		}
コード例 #10
0
ファイル: SVGPathParser.cs プロジェクト: znsoft/TUSA
        public void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint)
        {
            Path path = this.parse(pSVGProperties);

            bool fill = pSVGPaint.setFill(pSVGProperties);

            if (fill)
            {
                pCanvas.DrawPath(path, pSVGPaint.getPaint());
            }

            bool stroke = pSVGPaint.setStroke(pSVGProperties);

            if (stroke)
            {
                pCanvas.DrawPath(path, pSVGPaint.getPaint());
            }

            if (fill || stroke)
            {
                pSVGPaint.ensureComputedBoundsInclude(path);
            }
        }
コード例 #11
0
        public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect)
        {
            float x      = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X, 0f);
            float y      = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y, 0f);
            float width  = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_WIDTH, 0f);
            float height = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_HEIGHT, 0f);

            pRect.Set(x, y, x + width, y + height);

            float?rX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
            float?rY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);

            bool rXSpecified = rX != null && rX >= 0;
            bool rYSpecified = rY != null && rY >= 0;

            bool  rounded = rXSpecified || rYSpecified;
            float rx;
            float ry;

            if (rXSpecified && rYSpecified)
            {
                rx = Math.Min(rX.Value, width * 0.5f);
                ry = Math.Min(rY.Value, height * 0.5f);
            }
            else if (rXSpecified)
            {
                ry = rx = Math.Min(rX.Value, width * 0.5f);
            }
            else if (rYSpecified)
            {
                rx = ry = Math.Min(rY.Value, height * 0.5f);
            }
            else
            {
                rx = 0;
                ry = 0;
            }

            bool fill = pSVGPaint.setFill(pSVGProperties);

            if (fill)
            {
                if (rounded)
                {
                    pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
                }
                else
                {
                    pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
                }
            }

            bool stroke = pSVGPaint.setStroke(pSVGProperties);

            if (stroke)
            {
                if (rounded)
                {
                    pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
                }
                else
                {
                    pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
                }
            }

            if (fill || stroke)
            {
                pSVGPaint.ensureComputedBoundsInclude(x, y, width, height);
            }
        }