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

DomCR / ACadSharp / 17606836664

10 Sep 2025 07:42AM UTC coverage: 78.24% (+0.006%) from 78.234%
17606836664

Pull #780

github

web-flow
Merge c7ee00785 into 18bab4ea2
Pull Request #780: Refactor for linetype

6635 of 9211 branches covered (72.03%)

Branch coverage included in aggregate %.

93 of 101 new or added lines in 20 files covered. (92.08%)

3 existing lines in 2 files now uncovered.

25665 of 32072 relevant lines covered (80.02%)

104956.17 hits per line

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

89.18
/src/ACadSharp/CadUtils.cs
1
using CSUtilities.Text;
2
using System;
3
using System.Collections.Generic;
4
using System.Globalization;
5
using System.Linq;
6
using System.Text;
7

8
namespace ACadSharp
9
{
10
        internal static class CadUtils
11
        {
12
                private static Dictionary<string, CodePage> _dxfEncodingMap = new Dictionary<string, CodePage>
1✔
13
                {
1✔
14
                        {"gb2312"    ,CodePage.Gb2312},
1✔
15
                        {"kcs5601"   ,CodePage.Ksc5601},
1✔
16
                        {"ascii"     ,CodePage.Usascii},
1✔
17
                        {"big5"      ,CodePage.big5},
1✔
18
                        {"johab"     ,CodePage.Johab},
1✔
19
                        {"mac-roman" ,CodePage.Xmacromanian},
1✔
20
                        {"dos437"    ,CodePage.Ibm437},
1✔
21
                        {"dos850"    ,CodePage.Ibm850},
1✔
22
                        {"dos852"    ,CodePage.Ibm852},
1✔
23
                        {"dos737"    ,CodePage.Ibm737},
1✔
24
                        {"dos866"    ,CodePage.Cp866},
1✔
25
                        {"dos855"    ,CodePage.Ibm855},
1✔
26
                        {"dos857"    ,CodePage.Ibm857},
1✔
27
                        {"dos860"    ,CodePage.Ibm860},
1✔
28
                        {"dos861"    ,CodePage.Ibm861},
1✔
29
                        {"dos863"    ,CodePage.Ibm863},
1✔
30
                        {"dos864"    ,CodePage.Ibm864},
1✔
31
                        {"dos865"    ,CodePage.Ibm865},
1✔
32
                        {"dos869"    ,CodePage.Ibm869},
1✔
33
                        {"dos720"    ,CodePage.Dos720},
1✔
34
                        {"dos775"    ,CodePage.Ibm775},
1✔
35
                        {"dos932"    ,CodePage.Shift_jis},
1✔
36
                        {"dos950"    ,CodePage.big5},
1✔
37
                        {"ansi_874"  ,CodePage.Windows874},
1✔
38
                        {"ansi_932"  ,CodePage.Shift_jis},
1✔
39
                        {"ansi_936"  ,CodePage.Gb2312},
1✔
40
                        {"ansi_950"  ,CodePage.big5},
1✔
41
                        {"ansi_1250" ,CodePage.Windows1250},
1✔
42
                        {"ansi1250"  ,CodePage.Windows1250},
1✔
43
                        {"ansi_1251" ,CodePage.Windows1251},
1✔
44
                        {"ansi1251"  ,CodePage.Windows1251},
1✔
45
                        {"ansi_1252" ,CodePage.Windows1252},
1✔
46
                        {"ansi1252"  ,CodePage.Windows1252},
1✔
47
                        {"ansi_1253" ,CodePage.Windows1253},
1✔
48
                        {"ansi1253"  ,CodePage.Windows1253},
1✔
49
                        {"ansi_1254" ,CodePage.Windows1254},
1✔
50
                        {"ansi1254"  ,CodePage.Windows1254},
1✔
51
                        {"ansi_1255" ,CodePage.Windows1255},
1✔
52
                        {"ansi1255"  ,CodePage.Windows1255},
1✔
53
                        {"ansi_1256" ,CodePage.Windows1256},
1✔
54
                        {"ansi1256"  ,CodePage.Windows1256},
1✔
55
                        {"ansi_1257" ,CodePage.Windows1257},
1✔
56
                        {"ansi1257"  ,CodePage.Windows1257},
1✔
57
                        {"iso8859-1" ,CodePage.Iso88591},
1✔
58
                        {"iso88591"  ,CodePage.Iso88591},
1✔
59
                        {"iso8859-2" ,CodePage.Iso88592},
1✔
60
                        {"iso88592"  ,CodePage.Iso88592},
1✔
61
                        {"iso8859-3" ,CodePage.Iso88593},
1✔
62
                        {"iso88593"  ,CodePage.Iso88593},
1✔
63
                        {"iso8859-4" ,CodePage.Iso88594},
1✔
64
                        {"iso88594"  ,CodePage.Iso88594},
1✔
65
                        {"iso8859-5" ,CodePage.Iso88595},
1✔
66
                        {"iso88595"  ,CodePage.Iso88595},
1✔
67
                        {"iso8859-6" ,CodePage.Iso88596},
1✔
68
                        {"iso88596"  ,CodePage.Iso88596},
1✔
69
                        {"iso8859-7" ,CodePage.Iso88597},
1✔
70
                        {"iso88597"  ,CodePage.Iso88597},
1✔
71
                        {"iso8859-8" ,CodePage.Iso88598},
1✔
72
                        {"iso88598"  ,CodePage.Iso88598},
1✔
73
                        {"iso8859-9" ,CodePage.Iso88599},
1✔
74
                        {"iso88599"  ,CodePage.Iso88599},
1✔
75
                        {"iso8859-10",CodePage.Iso885910},
1✔
76
                        {"iso885910" ,CodePage.Iso885910},
1✔
77
                        {"iso8859-13",CodePage.Iso885913},
1✔
78
                        {"iso885913" ,CodePage.Iso885913},
1✔
79
                        {"iso885915" ,CodePage.Iso885915},
1✔
80
                        {"iso8859-15",CodePage.Iso885915},
1✔
81
                };
1✔
82

83
                private static readonly LineWeightType[] _indexedValue = new LineWeightType[]
1✔
84
                {
1✔
85
                                 LineWeightType.W0,
1✔
86
                                 LineWeightType.W5,
1✔
87
                                 LineWeightType.W9,
1✔
88
                                 LineWeightType.W13,
1✔
89
                                 LineWeightType.W15,
1✔
90
                                 LineWeightType.W18,
1✔
91
                                 LineWeightType.W20,
1✔
92
                                 LineWeightType.W25,
1✔
93
                                 LineWeightType.W30,
1✔
94
                                 LineWeightType.W35,
1✔
95
                                 LineWeightType.W40,
1✔
96
                                 LineWeightType.W50,
1✔
97
                                 LineWeightType.W53,
1✔
98
                                 LineWeightType.W60,
1✔
99
                                 LineWeightType.W70,
1✔
100
                                 LineWeightType.W80,
1✔
101
                                 LineWeightType.W90,
1✔
102
                                 LineWeightType.W100,
1✔
103
                                 LineWeightType.W106,
1✔
104
                                 LineWeightType.W120,
1✔
105
                                 LineWeightType.W140,
1✔
106
                                 LineWeightType.W158,
1✔
107
                                 LineWeightType.W200,
1✔
108
                                 LineWeightType.W211
1✔
109
                };
1✔
110

111
                private static readonly CodePage[] _pageCodes = new CodePage[]
1✔
112
                {
1✔
113
                        CodePage.Unknown,
1✔
114
                        CodePage.Usascii,
1✔
115
                        CodePage.Iso88591,
1✔
116
                        CodePage.Iso88592,
1✔
117
                        CodePage.Iso88593,
1✔
118
                        CodePage.Iso88594,
1✔
119
                        CodePage.Iso88595,
1✔
120
                        CodePage.Iso88596,
1✔
121
                        CodePage.Iso88597,
1✔
122
                        CodePage.Iso88598,
1✔
123
                        CodePage.Iso88599,
1✔
124
                        CodePage.Ibm437,
1✔
125
                        CodePage.Ibm850,
1✔
126
                        CodePage.Ibm852,
1✔
127
                        CodePage.Ibm855,
1✔
128
                        CodePage.Ibm857,
1✔
129
                        CodePage.Ibm860,
1✔
130
                        CodePage.Ibm861,
1✔
131
                        CodePage.Ibm863,
1✔
132
                        CodePage.Ibm864,
1✔
133
                        CodePage.Ibm865,
1✔
134
                        CodePage.Ibm869,
1✔
135
                        CodePage.Shift_jis,
1✔
136
                        CodePage.Macintosh,
1✔
137
                        CodePage.big5,
1✔
138
                        CodePage.Ksc5601,
1✔
139
                        CodePage.Johab,
1✔
140
                        CodePage.Cp866,
1✔
141
                        CodePage.Windows1250,
1✔
142
                        CodePage.Windows1251,
1✔
143
                        CodePage.Windows1252,
1✔
144
                        CodePage.Gb2312,
1✔
145
                        CodePage.Windows1253,
1✔
146
                        CodePage.Windows1254,
1✔
147
                        CodePage.Windows1255,
1✔
148
                        CodePage.Windows1256,
1✔
149
                        CodePage.Windows1257,
1✔
150
                        CodePage.Windows874,
1✔
151
                        CodePage.Shift_jis,
1✔
152
                        CodePage.Gb2312,
1✔
153
                        CodePage.Ksc5601,
1✔
154
                        CodePage.big5,
1✔
155
                        CodePage.Johab,
1✔
156
                        CodePage.Utf16,
1✔
157
                        CodePage.Windows1258
1✔
158
                };
1✔
159

160
                public static LineWeightType ToValue(byte b)
161
                {
48,824✔
162
                        switch (b)
48,824✔
163
                        {
164
                                case 28:
165
                                case 29:
166
                                        return LineWeightType.ByLayer;
36,698✔
167
                                case 30:
168
                                        return LineWeightType.ByBlock;
7,638✔
169
                                case 31:
170
                                        return LineWeightType.Default;
2,079✔
171
                                default:
172
                                        if (b < 0 || b >= _indexedValue.Length)
2,409!
173
                                        {
×
NEW
174
                                                return LineWeightType.Default;
×
175
                                        }
176
                                        return _indexedValue[b];
2,409✔
177
                        }
178
                }
48,824✔
179

180
                public static byte ToIndex(LineWeightType value)
181
                {
3,777✔
182
                        byte result = 0;
3,777✔
183
                        switch (value)
3,777!
184
                        {
185
                                case LineWeightType.Default:
186
                                        result = 31;
315✔
187
                                        break;
315✔
188
                                case LineWeightType.ByBlock:
189
                                        result = 30;
120✔
190
                                        break;
120✔
191
                                case LineWeightType.ByLayer:
192
                                        result = 29;
3,342✔
193
                                        break;
3,342✔
194
                                default:
195
                                        result = (byte)Array.IndexOf(_indexedValue, value);
×
196
                                        if (result < 0)
×
197
                                        {
×
198
                                                result = 31;
×
199
                                        }
×
200
                                        break;
×
201
                        }
202

203
                        return result;
3,777✔
204
                }
3,777✔
205

206
                public static CodePage GetCodePage(string value)
207
                {
937✔
208
                        if (_dxfEncodingMap.TryGetValue(value.ToLower(), out CodePage code))
937!
209
                        {
937✔
210
                                return code;
937✔
211
                        }
212
                        else
213
                        {
×
214
                                return CodePage.Unknown;
×
215
                        }
216
                }
937✔
217

218
                public static string GetCodePageName(CodePage value)
219
                {
161✔
220
                        return _dxfEncodingMap.FirstOrDefault(o => o.Value == value).Key;
5,313✔
221
                }
161✔
222

223
                public static CodePage GetCodePage(int value)
224
                {
172✔
225
                        return _pageCodes.ElementAtOrDefault(value);
172✔
226
                }
172✔
227

228
                public static int GetCodeIndex(CodePage code)
229
                {
250✔
230
                        return _pageCodes.ToList().IndexOf(code);
250✔
231
                }
250✔
232

233
                public static ACadVersion GetVersionFromName(string name)
234
                {
788✔
235
                        //Modify the format of the name
236
                        string vname = name.Replace('.', '_').ToUpper();
788✔
237

238
                        if (Enum.TryParse(vname, out ACadVersion version))
788!
239
                                return version;
788✔
240
                        else
241
                                return ACadVersion.Unknown;
×
242
                }
788✔
243

244
                public static string GetNameFromVersion(ACadVersion version)
245
                {
×
246
                        return version.ToString().Replace('_', '.');
×
247
                }
×
248

249
                public static double ToJulianCalendar(DateTime date)
250
                {
1,320✔
251
                        int year = date.Year;
1,320✔
252
                        int month = date.Month;
1,320✔
253
                        int day = date.Day;
1,320✔
254
                        double hour = date.Hour;
1,320✔
255
                        double minute = date.Minute;
1,320✔
256
                        double second = date.Second;
1,320✔
257
                        double millisecond = date.Millisecond;
1,320✔
258
                        double fraction = day + hour / 24.0 + minute / 1440.0 + (second + millisecond / 1000) / 86400.0;
1,320✔
259

260
                        if (month < 3)
1,320✔
261
                        {
31✔
262
                                year -= 1;
31✔
263
                                month += 12;
31✔
264
                        }
31✔
265

266
                        int a = year / 100;
1,320✔
267
                        int b = 2 - a + a / 4;
1,320✔
268
                        int c;
269
                        if (year < 0)
1,320!
270
                        {
×
271
                                c = (int)(365.25 * year - 0.75);
×
272
                        }
×
273
                        else
274
                        {
1,320✔
275
                                c = (int)(365.25 * year);
1,320✔
276
                        }
1,320✔
277

278
                        int d = (int)(30.6001 * (month + 1));
1,320✔
279
                        return b + c + d + 1720995 + fraction;
1,320✔
280
                }
1,320✔
281

282
                public static DateTime FromJulianCalendar(double date)
283
                {
1,096✔
284
                        if (date < 1721426 || date > 5373484)
1,096!
285
                        {
×
286
                                throw new ArgumentOutOfRangeException(nameof(date), "The valid values range from 1721426 and 5373484 that correspond to January 1, 1 and December 31, 9999 respectively.");
×
287
                        }
288

289
                        double julian = (int)date;
1,096✔
290
                        double fraction = date - julian;
1,096✔
291

292
                        int temp = (int)((julian - 1867216.25) / 36524.25);
1,096✔
293
                        julian = julian + 1 + temp - (int)(temp / 4.0);
1,096✔
294

295
                        int a = (int)julian + 1524;
1,096✔
296
                        int b = (int)((a - 122.1) / 365.25);
1,096✔
297
                        int c = (int)(365.25 * b);
1,096✔
298
                        int d = (int)((a - c) / 30.6001);
1,096✔
299

300
                        int months = d < 14 ? d - 1 : d - 13;
1,096✔
301
                        int years = months > 2 ? b - 4716 : b - 4715;
1,096✔
302
                        int days = a - c - (int)(30.6001 * d);
1,096✔
303

304
                        int hours = (int)(fraction * 24);
1,096✔
305
                        fraction -= hours / 24.0;
1,096✔
306
                        int minutes = (int)(fraction * 1440);
1,096✔
307
                        fraction -= minutes / 1440.0;
1,096✔
308

309
                        double decimalSeconds = fraction * 86400;
1,096✔
310
                        int seconds = (int)decimalSeconds;
1,096✔
311
                        int milliseconds = (int)((decimalSeconds - seconds) * 1000);
1,096✔
312

313
                        return new DateTime(years, months, days, hours, minutes, seconds, milliseconds);
1,096✔
314
                }
1,096✔
315

316
                public static TimeSpan EditingTime(double elapsed)
317
                {
576✔
318
                        int days = (int)elapsed;
576✔
319
                        double fraction = elapsed - days;
576✔
320

321
                        int hours = (int)(fraction * 24);
576✔
322
                        fraction -= hours / 24.0;
576✔
323

324
                        int minutes = (int)(fraction * 1440);
576✔
325
                        fraction -= minutes / 1440.0;
576✔
326

327
                        double decimalSeconds = fraction * 86400;
576✔
328
                        int seconds = (int)decimalSeconds;
576✔
329
                        int milliseconds = (int)((decimalSeconds - seconds) * 1000);
576✔
330

331
                        return new TimeSpan(days, hours, minutes, seconds, milliseconds);
576✔
332
                }
576✔
333

334
                public static void DateToJulian(DateTime date, out int jdate, out int miliseconds)
335
                {
1,754✔
336
                        if (date < new DateTime(1, 1, 1, 12, 0, 0))
1,754!
337
                        {
×
338
                                jdate = 0;
×
339
                                miliseconds = 0;
×
340
                                return;
×
341
                        }
342

343
                        date = date.AddHours(-12.0);
1,754✔
344
                        int day = (int)Math.Floor((14.0 - date.Month) / 12.0);
1,754✔
345
                        int year = date.Year + 4800 - day;
1,754✔
346
                        int month = date.Month;
1,754✔
347
                        jdate = date.Day + (int)System.Math.Floor((153.0 * (double)(month + 12 * day - 3) + 2.0) / 5.0) + 365 * year + (int)System.Math.Floor((double)year / 4.0) - (int)System.Math.Floor((double)year / 100.0) + (int)System.Math.Floor((double)year / 400.0) - 32045;
1,754✔
348
                        miliseconds = date.Millisecond + date.Second * 1000 + date.Minute * 60000 + date.Hour * 3600000;
1,754✔
349
                }
1,754✔
350
        }
351
}
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