public static string GetFriendlyValue(DiagramMarkShape value) { switch (value) { case DiagramMarkShape.None: return(Strings.DiagramMarkShapeNoneFriendlyValue); case DiagramMarkShape.Circle: return(Strings.DiagramMarkShapeCircleFriendlyValue); case DiagramMarkShape.Square: return(Strings.DiagramMarkShapeSquareFriendlyValue); case DiagramMarkShape.Diamond: return(Strings.DiagramMarkShapeDiamondFriendlyValue); case DiagramMarkShape.X: return(Strings.DiagramMarkShapeXFriendlyValue); } return(GetFriendlyValue((object)value)); }
public override string ToSvg() { string svg = ""; if (IsVisible()) { string prefix = DiagramStyle.GetMarkStylePrefix(Type); DiagramMarkShape shape = MarkStyle.MarkShape; double radius = MarkStyle.MarkRadiusRatio * 0.5 * Math.Min(Parent.Style.GridStringSpacing, Parent.Style.GridFretSpacing); double centerX = Parent.GridLeftEdge() + (Parent.Style.GridStringSpacing * (Position.String - 1)); double centerY = Parent.GridTopEdge() + (Parent.Style.GridFretSpacing / 2.0) + (Parent.Style.GridFretSpacing * (Position.Fret - 1)); // Draw shape string shapeStyle = Style.GetSvgStyle(DiagramMark._shapeStyleMap, prefix); if (MarkStyle.MarkBorderThickness > 0) { shapeStyle += Style.GetSvgStyle(DiagramMark._shapeStyleMapBorder, prefix); } switch (shape) { case DiagramMarkShape.Circle: svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.CIRCLE, shapeStyle, radius, centerX, centerY); break; case DiagramMarkShape.Square: svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.RECTANGLE, shapeStyle, radius * 2.0, radius * 2.0, centerX - radius, centerY - radius); break; case DiagramMarkShape.Diamond: string diamondPoints = ""; for (int i = 0; i < 4; i++) { double angle = (i * 90.0) * (Math.PI / 180.0); diamondPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1} ", centerX + (radius * Math.Cos(angle)), centerY + (radius * Math.Sin(angle))); } svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.POLYGON, shapeStyle, diamondPoints); break; case DiagramMarkShape.X: string xPoints = ""; for (int i = 0; i < 4; i++) { double angle = (45.0 + (i * 90.0)); double rad0 = (angle - 45.0) * (Math.PI / 180.0); // Starting close point double len0 = Math.Sqrt(2 * Math.Pow(radius * Math.Sin(XThicknessAngle), 2)); xPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1} ", centerX + (len0 * Math.Cos(rad0)), centerY + (len0 * Math.Sin(rad0))); double rad1 = (angle * (Math.PI / 180.0)) - XThicknessAngle; // First far corner xPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1} ", centerX + (radius * Math.Cos(rad1)), centerY + (radius * Math.Sin(rad1))); double rad2 = (angle * (Math.PI / 180.0)) + XThicknessAngle; // Second far corner xPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1} ", centerX + (radius * Math.Cos(rad2)), centerY + (radius * Math.Sin(rad2))); } svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.POLYGON, shapeStyle, xPoints.Trim()); break; case DiagramMarkShape.None: default: break; } // Draw text if (!StringUtils.IsNullOrWhiteSpace(Text) && MarkStyle.MarkTextVisible) { double textSize = radius * 2.0 * MarkStyle.MarkTextSizeRatio; double textX = centerX; double textY = centerY; switch (MarkStyle.MarkTextAlignment) { case DiagramHorizontalAlignment.Left: textX += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * textSize * 0.5 : -1.0 * radius; // D <-> U : L <-> R textY += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * radius : textSize * 0.5; // L <-> R : U <-> D break; case DiagramHorizontalAlignment.Center: textX += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * textSize * 0.5 : 0; // D <-> U : L <-> R textY += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? 0 : textSize * 0.5; // L <-> R : U <-> D break; case DiagramHorizontalAlignment.Right: textX += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * textSize * 0.5 : radius; // D <-> U : L <-> R textY += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? radius : textSize * 0.5; // L <-> R : U <-> D break; } string textStyle = Style.GetSvgStyle(DiagramMark._textStyleMap, prefix); textStyle += string.Format(CultureInfo.InvariantCulture, "font-size:{0}pt;", textSize); string textFormat = (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? SvgConstants.ROTATED_TEXT : SvgConstants.TEXT; svg += string.Format(CultureInfo.InvariantCulture, textFormat, textStyle, textX, textY, Text); } } return(svg); }
public override string ToSvg() { string svg = ""; if (IsVisible()) { string prefix = DiagramStyle.GetMarkStylePrefix(Type); DiagramMarkShape shape = MarkStyle.MarkShape; double radius = MarkStyle.MarkRadiusRatio * 0.5 * Math.Min(Parent.Style.GridStringSpacing, Parent.Style.GridFretSpacing); double centerX = Parent.GridLeftEdge() + (Parent.Style.GridStringSpacing * (Position.String - 1)); double centerY = Parent.GridTopEdge() + (Parent.Style.GridFretSpacing / 2.0) + (Parent.Style.GridFretSpacing * (Position.Fret - 1)); // Draw shape string shapeStyle = Style.GetSvgStyle(DiagramMark._shapeStyleMap, prefix); if (MarkStyle.MarkBorderThickness > 0) { shapeStyle += Style.GetSvgStyle(DiagramMark._shapeStyleMapBorder, prefix); } switch (shape) { case DiagramMarkShape.Circle: svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.CIRCLE, shapeStyle, radius, centerX, centerY); break; case DiagramMarkShape.Square: svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.RECTANGLE, shapeStyle, radius * 2.0, radius * 2.0, centerX - radius, centerY - radius); break; case DiagramMarkShape.Diamond: string diamondPoints = ""; diamondPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1} ", centerX, centerY - radius); diamondPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1} ", centerX + radius, centerY); diamondPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1} ", centerX, centerY + radius); diamondPoints += string.Format(CultureInfo.InvariantCulture, "{0},{1}", centerX - radius, centerY); svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.POLYGON, shapeStyle, diamondPoints); break; case DiagramMarkShape.X: double xDelta = Math.Sqrt((radius * radius / 2.0)); svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.LINE, shapeStyle, centerX - xDelta, centerY - xDelta, centerX + xDelta, centerY + xDelta); svg += string.Format(CultureInfo.InvariantCulture, SvgConstants.LINE, shapeStyle, centerX - xDelta, centerY + xDelta, centerX + xDelta, centerY - xDelta); break; case DiagramMarkShape.None: default: break; } // Draw text if (!StringUtils.IsNullOrWhiteSpace(Text) && MarkStyle.MarkTextVisible) { double textSize = radius * 2.0 * MarkStyle.MarkTextSizeRatio; double textX = centerX; double textY = centerY; switch (MarkStyle.MarkTextAlignment) { case DiagramHorizontalAlignment.Left: textX += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * textSize * 0.5 : -1.0 * radius; // D <-> U : L <-> R textY += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * radius : textSize * 0.5; // L <-> R : U <-> D break; case DiagramHorizontalAlignment.Center: textX += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * textSize * 0.5 : 0; // D <-> U : L <-> R textY += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? 0 : textSize * 0.5; // L <-> R : U <-> D break; case DiagramHorizontalAlignment.Right: textX += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? -1.0 * textSize * 0.5 : radius; // D <-> U : L <-> R textY += (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? radius : textSize * 0.5; // L <-> R : U <-> D break; } string textStyle = Style.GetSvgStyle(DiagramMark._textStyleMap, prefix); textStyle += string.Format(CultureInfo.InvariantCulture, "font-size:{0}pt;", textSize); string textFormat = (Parent.Style.Orientation == DiagramOrientation.LeftRight) ? SvgConstants.ROTATED_TEXT : SvgConstants.TEXT; svg += string.Format(CultureInfo.InvariantCulture, textFormat, textStyle, textX, textY, Text); } } return(svg); }