/// <summary> /// Creates a new TextStyle that is a copy of the current instance. /// </summary> /// <param name="newName">TextStyle name of the copy.</param> /// <returns>A new TextStyle that is a copy of this instance.</returns> public override TableObject Clone(string newName) { ShapeStyle copy = new ShapeStyle(newName, this.shapeFile, this.size, this.widthFactor, this.obliqueAngle); foreach (XData data in this.XData.Values) { copy.XData.Add((XData)data.Clone()); } return(copy); }
/// <summary> /// Initializes a new instance of the <c>LinetypeShapeSegment</c> class. /// </summary> /// <param name="name">Shape name of the linetype segment.</param> /// <param name="style">File where the shape of the linetype segment is defined.</param> /// <param name="length">Dash, dot, or space length of the linetype segment.</param> /// <param name="offset">Shift of the shape along the line.</param> /// <param name="rotationType">Type of rotation defined by the rotation value.</param> /// <param name="rotation">Rotation of the shape.</param> /// <param name="scale">Scale of the shape.</param> /// <remarks> /// The shape must be defined in the .shx shape definitions file.<br /> /// The DXF instead of saving the shape name, as the Shape entity or the shape linetype segments definition in a .lin file, /// it stores the shape number. Therefore when saving a DXF file the shape number will be obtained reading the .shp file.<br /> /// It is required that the equivalent .shp file to be also present in the same folder or one of the support folders defined in the DxfDocument. /// </remarks> public LinetypeShapeSegment(string name, ShapeStyle style, double length, Vector2 offset, LinetypeSegmentRotationType rotationType, double rotation, double scale) : base(LinetypeSegmentType.Shape, length) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name), "The linetype shape name should be at least one character long."); } this.name = name; this.style = style ?? throw new ArgumentNullException(nameof(style)); this.offset = offset; this.rotationType = rotationType; this.rotation = MathHelper.NormalizeAngle(rotation); this.scale = scale; }
/// <summary> /// Initializes a new instance of the <c>LinetypeShapeSegment</c> class. /// </summary> /// <param name="name">Shape name of the linetype segment.</param> /// <param name="style">File where the shape of the linetype segment is defined.</param> /// <param name="length">Dash, dot, or space length of the linetype segment.</param> /// <param name="offset">Shift of the shape along the line.</param> /// <param name="rotationType">Type of rotation defined by the rotation value.</param> /// <param name="rotation">Rotation of the shape.</param> /// <param name="scale">Scale of the shape.</param> /// <remarks> /// The shape must be defined in the .shx shape definitions file.<br /> /// The dxf instead of saving the shape name, as the Shape entity or the shape linetype segments definition in a .lin file, /// it stores the shape number. Therefore when saving a dxf file the shape number will be obtained reading the .shp file.<br /> /// It is required that the equivalent .shp file to be also present in the same folder or one of the support folders defined in the DxfDocument. /// </remarks> public LinetypeShapeSegment(string name, ShapeStyle style, double length, Vector2 offset, LinetypeSegmentRotationType rotationType, double rotation, double scale) : base(LinetypeSegmentType.Shape, length) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name", "The linetype shape name should be at least one character long."); } this.name = name; if (style == null) { throw new ArgumentNullException("style"); } this.style = style; this.offset = offset; this.rotationType = rotationType; this.rotation = MathHelper.NormalizeAngle(rotation); if (scale <= 0) { throw new ArgumentOutOfRangeException("scale", scale, "The LinetypeShepeSegment scale must be greater than zero."); } this.scale = scale; }
/// <summary> /// Initializes a new instance of the <c>LinetypeShapeSegment</c> class. /// </summary> /// <param name="name">Shape name of the linetype segment.</param> /// <param name="style">File where the shape of the linetype segment is defined.</param> /// <param name="length">Dash, dot, or space length of the linetype segment.</param> /// <remarks> /// The shape must be defined in the .shx shape definitions file.<br /> /// The DXF instead of saving the shape name, as the Shape entity or the shape linetype segments definition in a .lin file, /// it stores the shape number. Therefore when saving a DXF file the shape number will be obtained reading the .shp file.<br /> /// It is required that the equivalent .shp file to be also present in the same folder or one of the support folders defined in the DxfDocument. /// </remarks> public LinetypeShapeSegment(string name, ShapeStyle style, double length) : this(name, style, length, Vector2.Zero, LinetypeSegmentRotationType.Relative, 0.0, 1.0) { }
private static LinetypeSegment ReadLineTypeComplexSegment(string data, double length) { // the data is enclosed in brackets if (data[0] != '[' || data[data.Length - 1] != ']') { return(null); } // the first data item in a complex linetype definition segment // can be a shape name or a text string, the last always is enclosed in "" LinetypeSegmentType type = data[1] != '"' ? LinetypeSegmentType.Shape : LinetypeSegmentType.Text; data = data.Substring(1, data.Length - 2); string name; string style; Vector2 position = Vector2.Zero; LinetypeSegmentRotationType rotationType = LinetypeSegmentRotationType.Relative; double rotation = 0.0; double scale = 0.1; string[] tokens = data.Split(','); // at least two items must be present the shape name and file if (tokens.Length < 2) { return(null); } name = tokens[0].Trim('"'); style = tokens[1]; for (int i = 2; i < tokens.Length; i++) { string value = tokens[i].Remove(0, 2); if (tokens[i].StartsWith("X=", StringComparison.InvariantCultureIgnoreCase)) { double x; if (double.TryParse(value, out x)) { position.X = x; } } else if (tokens[i].StartsWith("Y=", StringComparison.InvariantCultureIgnoreCase)) { double y; if (double.TryParse(value, out y)) { position.Y = y; } } else if (tokens[i].StartsWith("S=", StringComparison.InvariantCultureIgnoreCase)) { double s; if (double.TryParse(value, out s)) { scale = s; } if (scale <= 0.0) { scale = 0.1; } } else if (tokens[i].StartsWith("R=", StringComparison.InvariantCultureIgnoreCase)) { rotationType = LinetypeSegmentRotationType.Relative; rotation = ReadRotation(value); } else if (tokens[i].StartsWith("Q=", StringComparison.InvariantCultureIgnoreCase)) { rotationType = LinetypeSegmentRotationType.Absolute; rotation = ReadRotation(value); } else if (tokens[i].StartsWith("U=", StringComparison.InvariantCultureIgnoreCase)) { rotationType = LinetypeSegmentRotationType.Upright; rotation = ReadRotation(value); } } if (type == LinetypeSegmentType.Text) { TextStyle textStyle = new TextStyle(style); return(new LinetypeTextSegment(name, textStyle, length, position, rotationType, rotation, scale)); } if (type == LinetypeSegmentType.Shape) { ShapeStyle shapeStyle = new ShapeStyle(style); return(new LinetypeShapeSegment(name, shapeStyle, length, position, rotationType, rotation, scale)); } return(null); }
private static LinetypeSegment ReadLineTypeComplexSegment(string[] data, double length) { // the data is enclosed in brackets Debug.Assert(data[0][0] == '[' || data[data.Length - 1][data[data.Length - 1].Length - 1] == ']', "The data is enclosed in brackets."); // the first data item in a complex linetype definition segment // can be a shape name or a text string, the last always is enclosed in "" LinetypeSegmentType type = data[0][1] == '"' ? LinetypeSegmentType.Text : LinetypeSegmentType.Shape; // remove the start and end brackets data[0] = data[0].Remove(0, 1); data[data.Length - 1] = data[data.Length - 1].Remove(data[data.Length - 1].Length - 1, 1); Vector2 position = Vector2.Zero; LinetypeSegmentRotationType rotationType = LinetypeSegmentRotationType.Relative; double rotation = 0.0; double scale = 0.1; // at least two items must be present the shape name and file if (data.Length < 2) { return(null); } string name = data[0].Trim('"'); string style = data[1]; for (int i = 2; i < data.Length; i++) { string value = data[i].Remove(0, 2); if (data[i].StartsWith("X=", StringComparison.InvariantCultureIgnoreCase)) { position.X = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture); } else if (data[i].StartsWith("Y=", StringComparison.InvariantCultureIgnoreCase)) { position.Y = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture); } else if (data[i].StartsWith("S=", StringComparison.InvariantCultureIgnoreCase)) { scale = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture); if (scale <= 0.0) { scale = 0.1; } } else if (data[i].StartsWith("A=", StringComparison.InvariantCultureIgnoreCase)) { rotationType = LinetypeSegmentRotationType.Absolute; rotation = ReadRotation(value); } else if (data[i].StartsWith("R=", StringComparison.InvariantCultureIgnoreCase)) { rotationType = LinetypeSegmentRotationType.Relative; rotation = ReadRotation(value); } else if (data[i].StartsWith("U=", StringComparison.InvariantCultureIgnoreCase)) { rotationType = LinetypeSegmentRotationType.Upright; rotation = ReadRotation(value); } } if (type == LinetypeSegmentType.Text) { // complex text linetype segments only holds the name of the style TextStyle textStyle = new TextStyle(style, "simplex.shx"); return(new LinetypeTextSegment(name, textStyle, length, position, rotationType, rotation, scale)); } if (type == LinetypeSegmentType.Shape) { ShapeStyle shapeStyle = new ShapeStyle(style); return(new LinetypeShapeSegment(name, shapeStyle, length, position, rotationType, rotation, scale)); } return(null); }