1 /******************************************************************************
2 **  libDXFrw - Library to read/write DXF files (ascii & binary)              **
3 **                                                                           **
4 **  Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com               **
5 **                                                                           **
6 **  This library is free software, licensed under the terms of the GNU       **
7 **  General Public License as published by the Free Software Foundation,     **
8 **  either version 2 of the License, or (at your option) any later version.  **
9 **  You should have received a copy of the GNU General Public License        **
10 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.    **
11 ******************************************************************************/
12 
13 #ifndef DWGUTIL_H
14 #define DWGUTIL_H
15 
16 #include "../drw_base.h"
17 
18 namespace DRW
19 {
20   std::string toHexStr( int n );
21 }
22 
23 class dwgRSCodec
24 {
25   public:
dwgRSCodec()26     dwgRSCodec() {}
27 
28     static void decode239I( duint8 *in, duint8 *out, duint32 blk );
29     static void decode251I( duint8 *in, duint8 *out, duint32 blk );
30 };
31 
32 class dwgCompressor
33 {
34   public:
dwgCompressor()35     dwgCompressor()
36       : bufC( nullptr )
37       , bufD( nullptr )
38       , sizeC( 0 )
39       , sizeD( 0 )
40       , pos( 0 )
41       , rpos( 0 )
42     {}
43 
44     void decompress18( duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize );
45     static void decrypt18Hdr( duint8 *buf, duint32 size, duint32 offset );
46 //  static void decrypt18Data(duint8 *buf, duint32 size, duint32 offset);
47     static void decompress21( duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize );
48 
49   private:
50     duint32 litLength18();
51     static duint32 litLength21( duint8 *cbuf, duint8 oc, duint32 *si );
52     static void copyCompBytes21( duint8 *cbuf, duint8 *dbuf, duint32 l, duint32 si, duint32 di );
53     static void readInstructions21( duint8 *cbuf, duint32 *si, duint8 *oc, duint32 *so, duint32 *l );
54 
55     duint32 longCompressionOffset();
56     duint32 long20CompressionOffset();
57     duint32 twoByteOffset( duint32 *ll );
58 
59     duint8 *bufC = nullptr;
60     duint8 *bufD = nullptr;
61     duint32 sizeC;
62     duint32 sizeD;
63     duint32 pos;
64     duint32 rpos;
65 
66 };
67 
68 class secEnum
69 {
70   public:
71     enum DWGSection
72     {
73       UNKNOWNS,        //!< UNKNOWN section.
74       FILEHEADER,      //!< File Header (in R3-R15
75       HEADER,          //!< AcDb:Header
76       CLASSES,         //!< AcDb:Classes
77       SUMMARYINFO,     //!< AcDb:SummaryInfo
78       PREVIEW,         //!< AcDb:Preview
79       VBAPROY,         //!< AcDb:VBAProject
80       APPINFO,         //!< AcDb:AppInfo
81       FILEDEP,         //!< AcDb:FileDepList
82       REVHISTORY,      //!< AcDb:RevHistory
83       SECURITY,        //!< AcDb:Security
84       OBJECTS,         //!< AcDb:AcDbObjects
85       OBJFREESPACE,    //!< AcDb:ObjFreeSpace
86       TEMPLATE,        //!< AcDb:Template
87       HANDLES,         //!< AcDb:Handles
88       PROTOTYPE,       //!< AcDb:AcDsPrototype_1b
89       AUXHEADER,       //!< AcDb:AuxHeader, in (R13-R15) second file header
90       SIGNATURE,       //!< AcDb:Signature
91       APPINFOHISTORY,  //!< AcDb:AppInfoHistory (in ac1021 may be a renamed section?
92       EXTEDATA,        //!< Extended Entity Data
93       PROXYGRAPHICS    //!< PROXY ENTITY GRAPHICS
94     };
95 
secEnum()96     secEnum() {}
97 
98     static DWGSection getEnum( std::string nameSec );
99 };
100 
101 #endif // DWGUTIL_H
102