/// <summary> /// Initializes a new instance of the <c>Text</c> class. /// </summary> public Text() : base(DxfObjectCode.Text) { this.value = string.Empty; this.basePoint = Vector3f.Zero; this.alignment = TextAlignment.BaselineLeft; this.layer = Layer.Default; this.color = AciColor.ByLayer; this.lineType = LineType.ByLayer; this.normal = Vector3f.UnitZ; this.style = TextStyle.Default; this.rotation = 0.0f; this.height = 0.0f; this.widthFactor = 1.0f; this.obliqueAngle = 0.0f; }
private TextStyle GetTextStyle(string name) { if (this.textStyles.ContainsKey(name)) { return this.textStyles[name]; } //just in case the text style has not been defined in the table section var textStyle = new TextStyle(name, "Arial"); this.textStyles.Add(textStyle.Name, textStyle); return textStyle; }
/// <summary> /// Intitializes a new instance of the <c>AttributeDefiniton</c> class. /// </summary> /// <param name="id">Attribute identifier, the parameter <c>id</c> string cannot contain spaces.</param> public AttributeDefinition(string id) : base(DxfObjectCode.AttributeDefinition) { if (id.Contains(" ")) throw new ArgumentException("The id string cannot contain spaces", "id"); this.id = id; this.flags = AttributeFlags.Visible; this.text = string.Empty; this.value = null; this.basePoint = Vector3f.Zero; this.layer = Layer.Default; this.color = AciColor.ByLayer; this.lineType = LineType.ByLayer; this.style = TextStyle.Default; this.alignment = TextAlignment.BaselineLeft; this.height = this.style.Height == 0 ? 1.0f : this.style.Height; this.widthFactor = this.style.WidthFactor; this.rotation = 0.0f; this.normal = Vector3f.UnitZ; }
private static void WriteDxfFile() { DxfDocument dxf = new DxfDocument(); //arc Arc arc = new Arc(new Vector3f(10, 10, 0), 10, 45, 135); arc.Layer = new Layer("arc"); arc.Layer.Color.Index = 1; dxf.AddEntity(arc); //xData sample XData xdata = new XData(new ApplicationRegistry("SharpDxf")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with SharpDxf")); xdata.XDataRecord.Add(XDataRecord.OpenControlString); xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0)); xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0)); xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0)); xdata.XDataRecord.Add(XDataRecord.CloseControlString); XData xdata2 = new XData(new ApplicationRegistry("other application")); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with SharpDxf")); xdata2.XDataRecord.Add(XDataRecord.OpenControlString); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record")); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5)); xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Long, 350)); xdata2.XDataRecord.Add(XDataRecord.CloseControlString); //circle Vector3f extrusion = new Vector3f(1, 1, 1); Vector3f centerWCS = new Vector3f(1, 1, 1); Vector3d centerOCS = MathHelper.Transform((Vector3d) centerWCS, (Vector3d)extrusion, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object); Circle circle = new Circle((Vector3f) centerOCS, 5); circle.Layer = new Layer("circle with spaces"); circle.Layer.Color=AciColor.Yellow; circle.LineType = LineType.Dashed; circle.Normal = extrusion; circle.XData=new Dictionary<ApplicationRegistry, XData> { {xdata.ApplicationRegistry, xdata}, {xdata2.ApplicationRegistry, xdata2} }; dxf.AddEntity(circle); //points Point point1 = new Point(new Vector3f(-3, -3, 0)); point1.Layer = new Layer("point"); point1.Color = new AciColor(30); Point point2 = new Point(new Vector3f(1, 1, 1)); point2.Layer = point1.Layer; point2.Layer.Color.Index = 9; point2.Normal = new Vector3f(1, 1, 1); dxf.AddEntity(point1); dxf.AddEntity(point2); //3dface Face3d face3D = new Face3d(new Vector3f(-5, -5, 5), new Vector3f(5, -5, 5), new Vector3f(5, 5, 5), new Vector3f(-5, 5, 5)); face3D.Layer = new Layer("3dface"); face3D.Layer.Color.Index = 3; dxf.AddEntity(face3D); //polyline PolylineVertex polyVertex; List<PolylineVertex> polyVertexes = new List<PolylineVertex>(); polyVertex = new PolylineVertex(new Vector2f(-50, -50)); polyVertex.BeginThickness = 2; polyVertexes.Add(polyVertex); polyVertex = new PolylineVertex(new Vector2f(50, -50)); polyVertex.BeginThickness = 1; polyVertexes.Add(polyVertex); polyVertex = new PolylineVertex(new Vector2f(50, 50)); polyVertex.Bulge = 1; polyVertexes.Add(polyVertex); polyVertex = new PolylineVertex(new Vector2f(-50, 50)); polyVertexes.Add(polyVertex); Polyline polyline2d = new Polyline(polyVertexes, true); polyline2d.Layer = new Layer("polyline2d"); polyline2d.Layer.Color.Index = 5; polyline2d.Normal = new Vector3f(1, 1, 1); polyline2d.Elevation = 100.0f; dxf.AddEntity(polyline2d); //lightweight polyline LightWeightPolylineVertex lwVertex; List<LightWeightPolylineVertex> lwVertexes = new List<LightWeightPolylineVertex>(); lwVertex = new LightWeightPolylineVertex(new Vector2f(-25, -25)); lwVertex.BeginThickness = 2; lwVertexes.Add(lwVertex); lwVertex = new LightWeightPolylineVertex(new Vector2f(25, -25)); lwVertex.BeginThickness = 1; lwVertexes.Add(lwVertex); lwVertex = new LightWeightPolylineVertex(new Vector2f(25, 25)); lwVertex.Bulge = 1; lwVertexes.Add(lwVertex); lwVertex = new LightWeightPolylineVertex(new Vector2f(-25, 25)); lwVertexes.Add(lwVertex); LightWeightPolyline lwPolyline = new LightWeightPolyline(lwVertexes, true); lwPolyline.Layer = new Layer("lwpolyline"); lwPolyline.Layer.Color.Index = 5; lwPolyline.Normal = new Vector3f(1, 1, 1); lwPolyline.Elevation = 100.0f; dxf.AddEntity(lwPolyline); //line Line line = new Line(new Vector3f(0, 0, 0), new Vector3f(10, 10, 10)); line.Layer = new Layer("line"); line.Layer.Color.Index = 6; dxf.AddEntity(line); //3d polyline Polyline3dVertex vertex; List<Polyline3dVertex> vertexes = new List<Polyline3dVertex>(); vertex = new Polyline3dVertex(new Vector3f(-50, -50, 0)); vertexes.Add(vertex); vertex = new Polyline3dVertex(new Vector3f(50, -50, 10)); vertexes.Add(vertex); vertex = new Polyline3dVertex(new Vector3f(50, 50, 25)); vertexes.Add(vertex); vertex = new Polyline3dVertex(new Vector3f(-50, 50, 50)); vertexes.Add(vertex); Polyline3d polyline = new Polyline3d(vertexes, true); polyline.Layer = new Layer("polyline3d"); polyline.Layer.Color.Index = 24; dxf.AddEntity(polyline); //block definition Block block = new Block("TestBlock"); block.Entities.Add(new Line(new Vector3f(-5, -5, 5), new Vector3f(5, 5, 5))); block.Entities.Add(new Line(new Vector3f(5, -5, 5), new Vector3f(-5, 5, 5))); //insert Insert insert = new Insert(block, new Vector3f(5, 5, 5)); insert.Layer = new Layer("insert"); insert.Layer.Color.Index = 4; dxf.AddEntity(insert); //text TextStyle style=new TextStyle("True type font","Arial.ttf"); Text text = new Text("Hello world!", Vector3f.Zero, 10.0f,style); text.Layer = new Layer("text"); text.Layer.Color.Index = 8; text.Alignment = TextAlignment.TopRight; dxf.AddEntity(text); dxf.Save("AutoCad2007.dxf", DxfVersion.AutoCad2007); dxf.Save("AutoCad2004.dxf", DxfVersion.AutoCad2004); dxf.Save("AutoCad2000.dxf", DxfVersion.AutoCad2000); dxf.Save("AutoCad12.dxf", DxfVersion.AutoCad12); }
/// <summary> /// Initializes a new instance of the <c>Text</c> class. /// </summary> /// <param name="text">Text string.</param> /// <param name="basePoint">Text base <see cref="Vector3f">point</see>.</param> /// <param name="height">Text height.</param> /// <param name="style">Text <see cref="TextStyle">style</see>.</param> public Text(string text, Vector3f basePoint, float height, TextStyle style) : base(DxfObjectCode.Text) { this.value = text; this.basePoint = basePoint; this.alignment = TextAlignment.BaselineLeft; this.layer = Layer.Default; this.color = AciColor.ByLayer; this.lineType = LineType.ByLayer; this.normal = Vector3f.UnitZ; this.style = style; this.height = height; this.widthFactor = style.WidthFactor; this.obliqueAngle = style.ObliqueAngle; this.rotation = 0.0f; }
/// <summary> /// Determines if a specified text style exists in the table. /// </summary> /// <param name="textStyle">Text style to locate.</param> /// <returns>True if the specified text style exists or false in any other case.</returns> public bool ContainsTextStyle(TextStyle textStyle) { return this.textStyles.ContainsKey(textStyle.Name); }
/// <summary> /// Writes a new text style to the table section. /// </summary> /// <param name="style">TextStyle.</param> public void WriteTextStyle(TextStyle style) { if (this.activeTable != StringCode.TextStyleTable) { throw new InvalidDxfTableException(this.activeTable, this.file); } this.WriteCodePair(0, style.CodeName); this.WriteCodePair(5, style.Handle); this.WriteCodePair(100, SubclassMarker.TableRecord); this.WriteCodePair(100, SubclassMarker.TextStyle); this.WriteCodePair(2, style); this.WriteCodePair(3, style.Font); if (style.IsVertical) { this.WriteCodePair(70, 4); } else { this.WriteCodePair(70, 0); } if (style.IsBackward && style.IsUpsideDown) { this.WriteCodePair(71, 6); } else if (style.IsBackward) { this.WriteCodePair(71, 2); } else if (style.IsUpsideDown) { this.WriteCodePair(71, 4); } else { this.WriteCodePair(71, 0); } this.WriteCodePair(40, style.Height); this.WriteCodePair(41, style.WidthFactor); this.WriteCodePair(42, style.Height); this.WriteCodePair(50, style.ObliqueAngle); }