• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 14083457468

26 Mar 2025 12:37PM UTC coverage: 76.338% (+0.2%) from 76.127%
14083457468

Pull #211

github

web-flow
Merge 48899a8f3 into c902191a1
Pull Request #211: Cad to svg

5534 of 7958 branches covered (69.54%)

Branch coverage included in aggregate %.

247 of 293 new or added lines in 7 files covered. (84.3%)

22 existing lines in 2 files now uncovered.

21914 of 27998 relevant lines covered (78.27%)

74980.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

36.67
/src/ACadSharp/IO/SvgWriter.cs
1
using ACadSharp.Entities;
2
using ACadSharp.IO.SVG;
3
using ACadSharp.Objects;
4
using ACadSharp.Tables;
5
using CSMath;
6
using System;
7
using System.IO;
8
using System.Xml;
9

10
namespace ACadSharp.IO
11
{
12
        public class SvgWriter : CadWriterBase<SvgConfiguration>
13
        {
14
                private SvgXmlWriter _writer;
15

16
                /// <summary>
17
                /// Initialize an instance of <see cref="SvgWriter"/> with a default document as a reference.
18
                /// </summary>
19
                /// <param name="stream"></param>
NEW
20
                public SvgWriter(Stream stream) : base(stream, null)
×
NEW
21
                {
×
NEW
22
                }
×
23

24
                /// <summary>
25
                /// Initialize an instance of <see cref="SvgWriter"/> with a default document as a reference.
26
                /// </summary>
27
                /// <param name="filename"></param>
28
                public SvgWriter(string filename)
NEW
29
                        : this(File.Create(filename))
×
NEW
30
                {
×
NEW
31
                }
×
32

33
                /// <summary>
34
                /// 
35
                /// </summary>
36
                /// <param name="filename"></param>
37
                /// <param name="document">Document to export from.</param>
38
                public SvgWriter(string filename, CadDocument document)
39
                        : this(File.Create(filename), document)
1✔
40
                {
1✔
41
                }
1✔
42

43
                public SvgWriter(Stream stream, CadDocument document) : base(stream, document)
1✔
44
                {
1✔
45
                }
1✔
46

47
                /// <inheritdoc/>
48
                /// <remarks>
49
                /// <see cref="SvgWriter"/> will draw all the content in the model space.<br/>
50
                /// The writer must be initialized with a none null <see cref="CadDocument"/>.
51
                /// </remarks>
52
                public override void Write()
53
                {
1✔
54
                        this.Write(this._document.ModelSpace);
1✔
55
                }
1✔
56

57
                public void Write(BlockRecord record)
58
                {
1✔
59
                        this.createWriter();
1✔
60

61
                        this._writer.WriteBlock(record);
1✔
62
                }
1✔
63

64
                public void Write(Layout layout)
NEW
65
                {
×
NEW
66
                        throw new NotImplementedException();
×
67
                }
68

69
                public void WriteEntity(Entity entity)
NEW
70
                {
×
NEW
71
                        this.createWriter();
×
72

NEW
73
                        this._writer.WriteStartDocument();
×
74

NEW
75
                        this._writer.WriteStartElement("svg");
×
NEW
76
                        this._writer.WriteAttributeString("xmlns", "http://www.w3.org/2000/svg");
×
77

NEW
78
                        BoundingBox box = entity.GetBoundingBox();
×
NEW
79
                        this._writer.WriteAttributeString("width", box.Max.X);
×
NEW
80
                        this._writer.WriteAttributeString("height", box.Max.Y);
×
NEW
81
                        this._writer.WriteAttributeString(" transform", "scale(1,-1)");
×
82

NEW
83
                        switch (entity)
×
84
                        {
85
                                case Line line:
NEW
86
                                        this.writeLine(line);
×
NEW
87
                                        break;
×
88
                                default:
NEW
89
                                        throw new NotImplementedException($"Entity {entity.SubclassMarker} is not implemented.");
×
90
                        }
91

NEW
92
                        this._writer.WriteEndElement();
×
93

NEW
94
                        this._writer.WriteEndDocument();
×
95

NEW
96
                        this._writer.Close();
×
NEW
97
                }
×
98

99
                private void createWriter()
100
                {
1✔
101
                        StreamWriter textWriter = new StreamWriter(this._stream);
1✔
102
                        this._writer = new SvgXmlWriter(this._stream, this._encoding, this.Configuration);
1✔
103
                        this._writer.Formatting = Formatting.Indented;
1✔
104
                        this._writer.OnNotification += this.triggerNotification;
1✔
105
                }
1✔
106

107
                private void writeEntityStyle(Entity entity)
NEW
108
                {
×
NEW
109
                        this._writer.WriteAttributeString("style", $"stroke:rgb({entity.Color.R},{entity.Color.G},{entity.Color.B})");
×
NEW
110
                }
×
111

112
                private void writeLine(Line line)
NEW
113
                {
×
NEW
114
                        this._writer.WriteStartElement("line");
×
115

NEW
116
                        this.writeEntityStyle(line);
×
117

NEW
118
                        this._writer.WriteAttributeString("x1", line.StartPoint.X);
×
NEW
119
                        this._writer.WriteAttributeString("y1", line.StartPoint.Y);
×
NEW
120
                        this._writer.WriteAttributeString("x2", line.EndPoint.X);
×
NEW
121
                        this._writer.WriteAttributeString("y2", line.EndPoint.Y);
×
NEW
122
                }
×
123

124
                /// <inheritdoc/>
125
                public override void Dispose()
126
                {
1✔
127
                        this._stream.Dispose();
1✔
128
                }
1✔
129
        }
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc