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

DomCR / ACadSharp / 14190822328

01 Apr 2025 08:24AM UTC coverage: 76.405% (+0.07%) from 76.336%
14190822328

Pull #563

github

web-flow
Merge f908d8369 into dc2a59405
Pull Request #563: Issue 558 dwg thumbnail support

5584 of 8016 branches covered (69.66%)

Branch coverage included in aggregate %.

63 of 108 new or added lines in 5 files covered. (58.33%)

1 existing line in 1 file now uncovered.

22074 of 28183 relevant lines covered (78.32%)

74501.98 hits per line

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

15.38
/src/ACadSharp/DwgPreview.cs
1
using CSUtilities.IO;
2

3
namespace ACadSharp
4
{
5
        /// <summary>
6
        /// Stores the thumbnail information to generate the preview for a CadDocument.
7
        /// </summary>
8
        public class DwgPreview
9
        {
10
                /// <summary>
11
                /// Type of media stored in the preview.
12
                /// </summary>
13
                public enum PreviewType
14
                {
15
                        Unknown = 0,
16
                        Bmp = 2,
17
                        Wmf = 3,
18
                        Png = 6,
19
                }
20

21
                /// <summary>
22
                /// Code that specifies the type of media stored in the preview.
23
                /// </summary>
NEW
24
                public PreviewType Code { get; }
×
25

26
                /// <summary>
27
                /// Header for the preview section.
28
                /// </summary>
29
                /// <remarks>
30
                /// Usually is formed by an empty array of 80 zeros.
31
                /// </remarks>
NEW
32
                public byte[] RawHeader { get; }
×
33

34
                /// <summary>
35
                /// Bytes conforming the thumbnail.
36
                /// </summary>
NEW
37
                public byte[] RawImage { get; }
×
38

39
                /// <summary>
40
                /// Default constructor with an unknown media type.
41
                /// </summary>
NEW
42
                public DwgPreview()
×
NEW
43
                {
×
NEW
44
                        this.Code = PreviewType.Unknown;
×
NEW
45
                        this.RawHeader = new byte[0];
×
NEW
46
                        this.RawImage = new byte[0];
×
NEW
47
                }
×
48

49
                /// <summary>
50
                /// Constructor to define a preview instance.
51
                /// </summary>
52
                /// <param name="code"></param>
53
                /// <param name="rawHeader"></param>
54
                /// <param name="rawImage"></param>
55
                public DwgPreview(PreviewType code, byte[] rawHeader, byte[] rawImage)
7✔
56
                {
7✔
57
                        this.Code = code;
7✔
58
                        this.RawHeader = rawHeader;
7✔
59
                        this.RawImage = rawImage;
7✔
60
                }
7✔
61

62
                /// <summary>
63
                /// Save the image into a file.
64
                /// </summary>
65
                /// <param name="path">Path where the image has to be stored.</param>
66
                /// <exception cref="System.NotSupportedException"></exception>
67
                public void Save(string path)
NEW
68
                {
×
69
                        bool writeHeader;
NEW
70
                        switch (this.Code)
×
71
                        {
72
                                case PreviewType.Bmp:
73
                                case PreviewType.Wmf:
74
                                case PreviewType.Png:
NEW
75
                                        writeHeader = false;
×
NEW
76
                                        break;
×
77
                                case PreviewType.Unknown:
78
                                default:
NEW
79
                                        throw new System.NotSupportedException($"Preview with code {this.Code} not supported.");
×
80
                        }
81

NEW
82
                        using (StreamIO sw = new StreamIO(path, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
×
NEW
83
                        {
×
NEW
84
                                if (writeHeader)
×
NEW
85
                                {
×
NEW
86
                                        sw.WriteBytes(this.RawHeader);
×
NEW
87
                                }
×
88

NEW
89
                                sw.WriteBytes(this.RawImage);
×
NEW
90
                        }
×
NEW
91
                }
×
92
        }
93
}
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