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); } } }
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); } } } }
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); } } }
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); } } }
/** * Uppercase rules are absolute positions, lowercase are relative. * Types of path rules: * <p/> * <ol> * <li>M/m - (x y)+ - Move to (without drawing) * <li>Z/z - (no params) - Close path (back to starting point) * <li>L/l - (x y)+ - Line to * <li>H/h - x+ - Horizontal ine to * <li>V/v - y+ - Vertical line to * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from previous C/S is the x1, y1 of this bezier) * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection" of last one w.r.t. to current point) * <li>A/a - ... - Arc to</li> * </ol> * <p/> * Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, (ie. begin with a - sign) */ Path parse(SVGProperties pSVGProperties) { String pathString = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_PATHDATA); if(pathString == null) { return null; } this.mString = pathString.Trim(); this.mLastX = 0; this.mLastY = 0; this.mLastCubicBezierX2 = 0; this.mLastCubicBezierY2 = 0; this.mCommand = null; this.mCommandParameters.Clear(); this.mPath = new Path(); if(this.mString.Length == 0) { return this.mPath; } String fillrule = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILLRULE); if(fillrule != null) { if(SVGConstants.ATTRIBUTE_FILLRULE_VALUE_EVENODD.Equals(fillrule)) { this.mPath.SetFillType(Path.FillType.EvenOdd); } else { this.mPath.SetFillType(Path.FillType.Winding); } /* * TODO Check against: * http://www.w3.org/TR/SVG/images/painting/fillrule-nonzero.svg / http://www.w3.org/TR/SVG/images/painting/fillrule-nonzero.png * http://www.w3.org/TR/SVG/images/painting/fillrule-evenodd.svg / http://www.w3.org/TR/SVG/images/painting/fillrule-evenodd.png */ } this.mCurrentChar = this.mString[0]; this.mPosition = 0; this.mLength = this.mString.Length; while (this.mPosition < this.mLength) { try { this.skipWhitespace(); if (char.IsLetter(this.mCurrentChar) && (this.mCurrentChar != 'e') && (this.mCurrentChar != 'E')) { this.processCommand(); this.mCommand = this.mCurrentChar; this.mCommandStart = this.mPosition; this.advance(); } else { float parameter = this.nextFloat(); this.mCommandParameters.Enqueue(parameter); } } catch(Exception t) { throw new ArgumentException("Error parsing: '" + this.mString.Substring(this.mCommandStart, this.mPosition) + "'. Command: '" + this.mCommand + "'. Parameters: '" + this.mCommandParameters.Count + "'.", t); } } this.processCommand(); return this.mPath; }
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()); } }
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); } }
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); } }
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); } } } }
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); } }
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); } }
/** * Uppercase rules are absolute positions, lowercase are relative. * Types of path rules: * <p/> * <ol> * <li>M/m - (x y)+ - Move to (without drawing) * <li>Z/z - (no params) - Close path (back to starting point) * <li>L/l - (x y)+ - Line to * <li>H/h - x+ - Horizontal ine to * <li>V/v - y+ - Vertical line to * <li>C/c - (x1 y1 x2 y2 x y)+ - Cubic bezier to * <li>S/s - (x2 y2 x y)+ - Smooth cubic bezier to (shorthand that assumes the x2, y2 from previous C/S is the x1, y1 of this bezier) * <li>Q/q - (x1 y1 x y)+ - Quadratic bezier to * <li>T/t - (x y)+ - Smooth quadratic bezier to (assumes previous control point is "reflection" of last one w.r.t. to current point) * <li>A/a - ... - Arc to</li> * </ol> * <p/> * Numbers are separate by whitespace, comma or nothing at all (!) if they are self-delimiting, (ie. begin with a - sign) */ Path parse(SVGProperties pSVGProperties) { String pathString = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_PATHDATA); if (pathString == null) { return(null); } this.mString = pathString.Trim(); this.mLastX = 0; this.mLastY = 0; this.mLastCubicBezierX2 = 0; this.mLastCubicBezierY2 = 0; this.mCommand = null; this.mCommandParameters.Clear(); this.mPath = new Path(); if (this.mString.Length == 0) { return(this.mPath); } String fillrule = pSVGProperties.getStringProperty(SVGConstants.ATTRIBUTE_FILLRULE); if (fillrule != null) { if (SVGConstants.ATTRIBUTE_FILLRULE_VALUE_EVENODD.Equals(fillrule)) { this.mPath.SetFillType(Path.FillType.EvenOdd); } else { this.mPath.SetFillType(Path.FillType.Winding); } /* * TODO Check against: * http://www.w3.org/TR/SVG/images/painting/fillrule-nonzero.svg / http://www.w3.org/TR/SVG/images/painting/fillrule-nonzero.png * http://www.w3.org/TR/SVG/images/painting/fillrule-evenodd.svg / http://www.w3.org/TR/SVG/images/painting/fillrule-evenodd.png */ } this.mCurrentChar = this.mString[0]; this.mPosition = 0; this.mLength = this.mString.Length; while (this.mPosition < this.mLength) { try { this.skipWhitespace(); if (char.IsLetter(this.mCurrentChar) && (this.mCurrentChar != 'e') && (this.mCurrentChar != 'E')) { this.processCommand(); this.mCommand = this.mCurrentChar; this.mCommandStart = this.mPosition; this.advance(); } else { float parameter = this.nextFloat(); this.mCommandParameters.Enqueue(parameter); } } catch (Exception t) { throw new ArgumentException("Error parsing: '" + this.mString.Substring(this.mCommandStart, this.mPosition) + "'. Command: '" + this.mCommand + "'. Parameters: '" + this.mCommandParameters.Count + "'.", t); } } this.processCommand(); return(this.mPath); }