zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
 
 
 
#ifndef _OD_CHARMAPPER_H_
#define _OD_CHARMAPPER_H_
 
#include "TD_PackPush.h"
 
#include "OdCodePage.h"
#include "OdError.h"
#include "OdArray.h"
 
class OdStreamBuf;
class OdString;
typedef OdArray <char, OdMemoryAllocator<char> > OdAnsiCharArray;
typedef OdArray<OdChar, OdMemoryAllocator<OdChar> > OdCharArray;
 
 
/** \details
    This class implements character mapping.
    Library: TD_Root
    <group Other_Classes>
*/
class FIRSTDLL_EXPORT OdCharMapper
{
  static OdString m_MapFile;
private:
    OdCharMapper();
public:
//    static OdResult initialize(OdStreamBuf* pIo);
 
  /** \details
    Initializes this CharMapper object from the specified mapping file.
    \param filename [in]  File name.
    \remarks
    Returns eOk if successful, or an appropriate error code if not.
  */
  static OdResult initialize(const OdString& filename);
 
  /** \details
    Maps the specified Unicode character to the specified code page.
    \param sourceChar [in]  Unicode source character.
    \param codepageId [in]  Object ID of the code page.
    \param codepageChar [out]  Receives the code page character.
    \param bTryToUseSystemCP [in]   Try to use default ANSI code page and OEM  code page in case conversion with codepageId is not OK
    \remarks
    Returns eOk if successful, or an appropriate error code if not.
  */
  static OdResult unicodeToCodepage(OdChar sourceChar,
    OdCodePageId codepageId,
    OdChar& codepageChar,
    bool bTryToUseSystemCP = true );
 
  /** \details
  Maps the specified Unicode character to the specified code page using IMLangFontLink2 interface.
  \param sourceChar [in]  Unicode source character.
  \param codepageId [in]  Object ID of the code page.
  \param codepageChar [out]  Receives the code page character.
  \remarks
  Returns eOk if successful, or an appropriate error code if not.
  */
  static OdResult unicodeToCodepage2(OdChar sourceChar,
    OdCodePageId codepageId,
    OdChar& codepageChar);
 
  /** \details
    Maps the specified code page character to Unicode.
    \param sourceChar [in]  Code page source character.
    \param codepageId [in]  Object ID of the code page.
    \param unicodeChar [out]  Receives the Unicode character.
    \remarks
    Returns eOk if successful, or an appropriate error code if not.
  */
  static OdResult codepageToUnicode(OdChar sourceChar,
    OdCodePageId codepageId,
    OdChar& unicodeChar);
 
  /** \details
    Returns true if and only if the specified byte is one of the leading bytes of the specified code page.
    \param testByte [in]  Byte to test.
    \param codepageId [in]  Object ID of the code page.
  */
  static bool isLeadByte(OdUInt8 testByte, OdCodePageId codepageId);
 
  /** \details
    Returns the code page with the specified description.
    \param description [in]  Description.  
    \param codepageId [out]  Receives the object ID of the code page.  
    \remarks
    Returns eOk if successful, or an appropriate error code if not.
  */
  static OdResult codepageDescToId(const OdString& description, OdCodePageId& codepageId);
 
  /** \details
    Returns the description for the specified code page.
    \param description [out]  Receives the description.  
    \param codepageId [in]  Object ID of the code page.
    \remarks
    Returns eOk if successful, or an appropriate error code if not.
  */
  static OdResult codepageIdToDesc(OdCodePageId codepageId, OdString& description);
 
  /** \details
    Returns the number of valid code pages for this CharMapper object.
  */
  static OdUInt32 numValidCodepages();
 
  /** \details
    Returns the code page corresponding to the specified ANSI code page.
    \param ansiCodePage [in]  ANSI code page.
  */
  static OdCodePageId ansiCpToAcadCp(OdUInt32 ansiCodePage);
 
  /** \details
    Returns the ANSI code page corresponding to the specified code page.
    \param acadCodePageId [in]  code page.
  */
  static OdUInt32 acadCpToAnsiCp(OdCodePageId acadCodePageId);
 
  /** \details
    Returns the code page corresponding to the specified ANSI character set.
    \param ansiCharacterSet [in]  Character Set.
  */
   static OdCodePageId getCodepageByCharset(OdUInt16 ansiCharacterSet);
 
   static OdUInt16 getReorderCharsetByChar(OdChar ch);
 
   /** \details
   Returns true if and only if the specified code page supports conversion.
   \param codepageId [in]  Object ID of the code page.
   */
   static bool isConversionSupported(OdCodePageId codepageId);
 
   static void wideCharToMultiByte(OdCodePageId codePage, const OdChar* srcBuf, int srcSize, OdAnsiCharArray& dstBuf);
   // Returns number of characters (! not dstBuf length)
   static void multiByteToWideChar(OdCodePageId codePage, const char* srcBuf, int srcSize, OdCharArray& dstBuf);
 
   // This is actually CESU-8 encoding used in DXF (http://www.unicode.org/reports/tr26/)
   static void utf8ToUnicode(const char* srcBuf, int srcSize, OdCharArray& dstBuf);
   static void unicodeToUtf8(const OdChar* srcBuf, int srcSize, OdAnsiCharArray& dstBuf);
 
   /** \details
     Adds the bigFont to map.
     \param bigFont [in]  big font file name.  
     \param cpIndex [in]  code page index.
     
     \remarks
     cpIndex must be one of the following:
     
     <table>
     Value    Description
     1        CP_ANSI_932
     2        CP_ANSI_950
     3        CP_ANSI_949
     5        CP_ANSI_936
     </table>
 
     Returns eOk if successful, or an appropriate error code if not.
   */
   static OdResult addBigFontWithIndex(const OdString& bigFont, OdInt32 cpIndex);
 
   /** \details
     Adds the bigFont to map.
     \param bigFont [in]  big font file name.  
     \param codePageId [in]  CodePage ID.
 
     \remarks
     codePageId must be one of the following:
     
     @untitled table
     CP_ANSI_932
     CP_ANSI_950
     CP_ANSI_949
     CP_ANSI_936
 
     Returns eOk if successful, or an appropriate error code if not.
   */
   static OdResult addBigFontWithCodepage(const OdString& bigFont, OdCodePageId codePageId);
 
   /** \details
     Adds the bigfont list from io stream to map.
     \param io [in]  stream with next format.
 
     Anything after a '#' character is a comment (and ignored)
     The ';' character is used to separate the file name from the code page index
  
     <BIGFONTFILENAME.SHX>;<CODE PAGE INDEX>
   
     There should be no leading or trailing spaces for the filename
    
     JAPANESE_CODEPAGE_INDEX = 1,
     TRADITIONAL_CHINESE_CODEPAGE_INDEX = 2,
     KOREAN_CODEPAGE_INDEX = 3,
     KOREAN_JOHAB_CODEPAGE_INDEX = 4,
     SIMPLIFIED_CHINESE_CODEPAGE_INDEX = 5
    
     Returns eOk if successful, or an appropriate error code if not.
   */
   static OdResult addBigFonts(OdStreamBuf* io);
 
   /** \details
     Returns the OdCodePageId.
     \remarks
     getCpByBigFont returns one of the following:
     
     @untitled table
     CP_ANSI_932
     CP_ANSI_950
     CP_ANSI_949
     CP_ANSI_936
     \param bigFont [in]  big font file name.  
   */
 
   static OdCodePageId getCpByBigFont(const OdString& bigFont);
   /** \details
     Returns the code page index.
     \remarks
     getCpIndexByBigFont returns one of the following:
     
     <table>
     Value     Description
     1         CP_ANSI_932
     2         CP_ANSI_950
     3         CP_ANSI_949
     5         CP_ANSI_936
     \param bigFont [in]  big font file name.  
     </table>
   */
   static OdInt32 getCpIndexByBigFont(const OdString& bigFont);
 
   /** \details
     Returns the check sum for an ANSI string.
     \param str [in]  String for calculating check sum.  
   */
   static double getCheckSumAnsi(OdAnsiString str);
 
   /** \details
     Returns the check sum for a unicode string.
     \param str [in]  String for calculating check sum.  
   */
   static double getCheckSumUnicode(OdString str);
 
   static OdString convertCIFcoding(const OdString& strText);
};
 
// Surrogate pairs support
template<class T> inline bool odIsLeadSurrogate(T chr) {
  return (chr >= 0xD800 && chr <= 0xDFFF);
}
template<class T> inline bool odIsTailSurrogate(T chr) {
  return (chr >= 0xDC00 && chr <= 0xDFFF);
}
template<class T1, class T2> inline T1 odToCodepoint(T1 chr, T2 chr2) {
  return (chr << 10) + chr2 + (0x10000 - (0xD800 << 10) - 0xDC00);
}
template<class T> inline OdUInt32 odToCodeValue(T chr, T chr2) {
  return ((OdUInt32)chr << 10) + chr2 + (0x10000 - (0xD800 << 10) - 0xDC00);
}
template<class T> inline bool odIsCodepoint(T chr) {
  return (chr >= 0x10000 && chr <= 0x10FFFF);
}
template<class T> inline T odToLeadSurrogate(T chr) {
  return ((0xD800 - (0x10000 >> 10)) + (chr >> 10));
}
template<class T> inline T odToTailSurrogate(T chr) {
  return (0xDC00 + (chr & 0x3FF));
}
 
enum OdAsianCpIndex
{
  JAPANESE_CP_INDEX = 1,              // 932
  TRADITIONAL_CHINESE_CP_INDEX = 2,   // 950
  KOREAN_WANSUNG_CP_INDEX = 3,        // 949
  KOREAN_JOHAB_CP_INDEX = 4,          // 1361
  SIMPLIFIED_CHINESE_CP_INDEX = 5     // 936
};
 
/** \details
  Returns the specified text converted from one code page to another.
  \param source [in]  Source text.
  \param sourceId [in]  Object ID of source code page.
  \param destId [in]  Object ID of destination code page.
*/
 
#include "TD_PackPop.h"
 
#endif