CFx SDK Documentation  2023 SP0
OdCharMapper.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 
26 
27 #ifndef _OD_CHARMAPPER_H_
28 #define _OD_CHARMAPPER_H_
29 
30 #include "TD_PackPush.h"
31 
32 #include "OdCodePage.h"
33 #include "OdError.h"
34 #include "OdArray.h"
35 
36 class OdStreamBuf;
37 class OdString;
40 
41 
48 {
49  static OdString m_MapFile;
50 private:
51  OdCharMapper();
52 public:
53 // static OdResult initialize(OdStreamBuf* pIo);
54 
61  static OdResult initialize(const OdString& filename);
62 
72  static OdResult unicodeToCodepage(OdChar sourceChar,
73  OdCodePageId codepageId,
74  OdChar& codepageChar,
75  bool bTryToUseSystemCP = true );
76 
85  static OdResult unicodeToCodepage2(OdChar sourceChar,
86  OdCodePageId codepageId,
87  OdChar& codepageChar);
88 
97  static OdResult codepageToUnicode(OdChar sourceChar,
98  OdCodePageId codepageId,
99  OdChar& unicodeChar);
100 
106  static bool isLeadByte(OdUInt8 testByte, OdCodePageId codepageId);
107 
115  static OdResult codepageDescToId(const OdString& description, OdCodePageId& codepageId);
116 
124  static OdResult codepageIdToDesc(OdCodePageId codepageId, OdString& description);
125 
130 
135  static OdCodePageId ansiCpToAcadCp(OdUInt32 ansiCodePage);
136 
141  static OdUInt32 acadCpToAnsiCp(OdCodePageId acadCodePageId);
142 
147  static OdCodePageId getCodepageByCharset(OdUInt16 ansiCharacterSet);
148 
150 
155  static bool isConversionSupported(OdCodePageId codepageId);
156 
157  static void wideCharToMultiByte(OdCodePageId codePage, const OdChar* srcBuf, int srcSize, OdAnsiCharArray& dstBuf);
158  // Returns number of characters (! not dstBuf length)
159  static void multiByteToWideChar(OdCodePageId codePage, const char* srcBuf, int srcSize, OdCharArray& dstBuf);
160 
161  // This is actually CESU-8 encoding used in DXF (http://www.unicode.org/reports/tr26/)
162  static void utf8ToUnicode(const char* srcBuf, int srcSize, OdCharArray& dstBuf);
163  static void unicodeToUtf8(const OdChar* srcBuf, int srcSize, OdAnsiCharArray& dstBuf);
164 
183  static OdResult addBigFontWithIndex(const OdString& bigFont, OdInt32 cpIndex);
184 
201  static OdResult addBigFontWithCodepage(const OdString& bigFont, OdCodePageId codePageId);
202 
223 
237  static OdCodePageId getCpByBigFont(const OdString& bigFont);
252  static OdInt32 getCpIndexByBigFont(const OdString& bigFont);
253 
258  static double getCheckSumAnsi(OdAnsiString str);
259 
264  static double getCheckSumUnicode(OdString str);
265 
266  static OdString convertCIFcoding(const OdString& strText);
267 };
268 
269 // Surrogate pairs support
270 template<class T> inline bool odIsLeadSurrogate(T chr) {
271  return (chr >= 0xD800 && chr <= 0xDFFF);
272 }
273 template<class T> inline bool odIsTailSurrogate(T chr) {
274  return (chr >= 0xDC00 && chr <= 0xDFFF);
275 }
276 template<class T1, class T2> inline T1 odToCodepoint(T1 chr, T2 chr2) {
277  return (chr << 10) + chr2 + (0x10000 - (0xD800 << 10) - 0xDC00);
278 }
279 template<class T> inline OdUInt32 odToCodeValue(T chr, T chr2) {
280  return ((OdUInt32)chr << 10) + chr2 + (0x10000 - (0xD800 << 10) - 0xDC00);
281 }
282 template<class T> inline bool odIsCodepoint(T chr) {
283  return (chr >= 0x10000 && chr <= 0x10FFFF);
284 }
285 template<class T> inline T odToLeadSurrogate(T chr) {
286  return ((0xD800 - (0x10000 >> 10)) + (chr >> 10));
287 }
288 template<class T> inline T odToTailSurrogate(T chr) {
289  return (0xDC00 + (chr & 0x3FF));
290 }
291 
293 {
294  JAPANESE_CP_INDEX = 1, // 932
298  SIMPLIFIED_CHINESE_CP_INDEX = 5 // 936
299 };
300 
308 #include "TD_PackPop.h"
309 
310 #endif
311 
T odToLeadSurrogate(T chr)
Definition: OdCharMapper.h:285
T1 odToCodepoint(T1 chr, T2 chr2)
Definition: OdCharMapper.h:276
OdArray< char, OdMemoryAllocator< char > > OdAnsiCharArray
Definition: OdCharMapper.h:37
OdAsianCpIndex
Definition: OdCharMapper.h:293
@ TRADITIONAL_CHINESE_CP_INDEX
Definition: OdCharMapper.h:295
@ KOREAN_WANSUNG_CP_INDEX
Definition: OdCharMapper.h:296
@ KOREAN_JOHAB_CP_INDEX
Definition: OdCharMapper.h:297
@ SIMPLIFIED_CHINESE_CP_INDEX
Definition: OdCharMapper.h:298
@ JAPANESE_CP_INDEX
Definition: OdCharMapper.h:294
bool odIsLeadSurrogate(T chr)
Definition: OdCharMapper.h:270
OdArray< OdChar, OdMemoryAllocator< OdChar > > OdCharArray
Definition: OdCharMapper.h:39
bool odIsTailSurrogate(T chr)
Definition: OdCharMapper.h:273
T odToTailSurrogate(T chr)
Definition: OdCharMapper.h:288
OdUInt32 odToCodeValue(T chr, T chr2)
Definition: OdCharMapper.h:279
bool odIsCodepoint(T chr)
Definition: OdCharMapper.h:282
OdCodePageId
Definition: OdCodePage.h:31
unsigned int OdUInt32
unsigned short OdUInt16
int OdInt32
unsigned char OdUInt8
wchar_t OdChar
OdResult
Definition: OdResult.h:29
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
static OdUInt16 getReorderCharsetByChar(OdChar ch)
static void unicodeToUtf8(const OdChar *srcBuf, int srcSize, OdAnsiCharArray &dstBuf)
static OdCodePageId ansiCpToAcadCp(OdUInt32 ansiCodePage)
static OdResult unicodeToCodepage(OdChar sourceChar, OdCodePageId codepageId, OdChar &codepageChar, bool bTryToUseSystemCP=true)
static bool isLeadByte(OdUInt8 testByte, OdCodePageId codepageId)
static void multiByteToWideChar(OdCodePageId codePage, const char *srcBuf, int srcSize, OdCharArray &dstBuf)
static OdResult codepageDescToId(const OdString &description, OdCodePageId &codepageId)
static double getCheckSumAnsi(OdAnsiString str)
static OdResult addBigFonts(OdStreamBuf *io)
static OdCodePageId getCpByBigFont(const OdString &bigFont)
static OdString convertCIFcoding(const OdString &strText)
static void wideCharToMultiByte(OdCodePageId codePage, const OdChar *srcBuf, int srcSize, OdAnsiCharArray &dstBuf)
static OdUInt32 numValidCodepages()
static OdResult initialize(const OdString &filename)
static OdCodePageId getCodepageByCharset(OdUInt16 ansiCharacterSet)
static bool isConversionSupported(OdCodePageId codepageId)
static OdResult codepageIdToDesc(OdCodePageId codepageId, OdString &description)
static OdResult unicodeToCodepage2(OdChar sourceChar, OdCodePageId codepageId, OdChar &codepageChar)
static OdInt32 getCpIndexByBigFont(const OdString &bigFont)
static double getCheckSumUnicode(OdString str)
static OdResult addBigFontWithCodepage(const OdString &bigFont, OdCodePageId codePageId)
static OdUInt32 acadCpToAnsiCp(OdCodePageId acadCodePageId)
static OdResult addBigFontWithIndex(const OdString &bigFont, OdInt32 cpIndex)
static void utf8ToUnicode(const char *srcBuf, int srcSize, OdCharArray &dstBuf)
static OdResult codepageToUnicode(OdChar sourceChar, OdCodePageId codepageId, OdChar &unicodeChar)