CFx SDK Documentation  2020SP3
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 
FIRSTDLL_EXPORT
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
OdResult
OdResult
Definition: OdResult.h:29
OdCharMapper::getCheckSumUnicode
static double getCheckSumUnicode(OdString str)
OdString
Definition: OdString.h:95
OdCharMapper::unicodeToUtf8
static void unicodeToUtf8(const OdChar *srcBuf, int srcSize, OdAnsiCharArray &dstBuf)
OdCharMapper::getCodepageByCharset
static OdCodePageId getCodepageByCharset(OdUInt16 ansiCharacterSet)
OdUInt8
unsigned char OdUInt8
Definition: OdPlatformSettings.h:759
OdCharMapper::addBigFontWithIndex
static OdResult addBigFontWithIndex(const OdString &bigFont, OdInt32 cpIndex)
OdCharMapper::addBigFonts
static OdResult addBigFonts(OdStreamBuf *io)
KOREAN_WANSUNG_CP_INDEX
@ KOREAN_WANSUNG_CP_INDEX
Definition: OdCharMapper.h:296
OdCodePageId
OdCodePageId
Definition: OdCodePage.h:31
OdAsianCpIndex
OdAsianCpIndex
Definition: OdCharMapper.h:293
OdArray
Definition: OdArray.h:591
OdCodePage.h
TD_PackPop.h
odToCodepoint
T1 odToCodepoint(T1 chr, T2 chr2)
Definition: OdCharMapper.h:276
OdUInt16
unsigned short OdUInt16
Definition: OdPlatformSettings.h:760
OdCharMapper::getCheckSumAnsi
static double getCheckSumAnsi(OdAnsiString str)
odIsCodepoint
bool odIsCodepoint(T chr)
Definition: OdCharMapper.h:282
OdCharMapper::numValidCodepages
static OdUInt32 numValidCodepages()
OdUInt32
unsigned int OdUInt32
Definition: OdPlatformSettings.h:783
OdAnsiCharArray
OdArray< char, OdMemoryAllocator< char > > OdAnsiCharArray
Definition: OdCharMapper.h:37
JAPANESE_CP_INDEX
@ JAPANESE_CP_INDEX
Definition: OdCharMapper.h:294
OdCharMapper::getCpIndexByBigFont
static OdInt32 getCpIndexByBigFont(const OdString &bigFont)
odToLeadSurrogate
T odToLeadSurrogate(T chr)
Definition: OdCharMapper.h:285
OdArray.h
OdCharMapper::unicodeToCodepage
static OdResult unicodeToCodepage(OdChar sourceChar, OdCodePageId codepageId, OdChar &codepageChar, bool bTryToUseSystemCP=true)
OdCharArray
OdArray< OdChar, OdMemoryAllocator< OdChar > > OdCharArray
Definition: OdCharMapper.h:39
OdCharMapper::codepageIdToDesc
static OdResult codepageIdToDesc(OdCodePageId codepageId, OdString &description)
OdCharMapper::acadCpToAnsiCp
static OdUInt32 acadCpToAnsiCp(OdCodePageId acadCodePageId)
OdInt32
int OdInt32
Definition: OdPlatformSettings.h:782
OdCharMapper::initialize
static OdResult initialize(const OdString &filename)
OdChar
wchar_t OdChar
Definition: OdPlatformSettings.h:745
OdCharMapper::unicodeToCodepage2
static OdResult unicodeToCodepage2(OdChar sourceChar, OdCodePageId codepageId, OdChar &codepageChar)
OdCharMapper::codepageDescToId
static OdResult codepageDescToId(const OdString &description, OdCodePageId &codepageId)
odToTailSurrogate
T odToTailSurrogate(T chr)
Definition: OdCharMapper.h:288
OdCharMapper::isConversionSupported
static bool isConversionSupported(OdCodePageId codepageId)
OdCharMapper::isLeadByte
static bool isLeadByte(OdUInt8 testByte, OdCodePageId codepageId)
OdCharMapper::getCpByBigFont
static OdCodePageId getCpByBigFont(const OdString &bigFont)
OdCharMapper::utf8ToUnicode
static void utf8ToUnicode(const char *srcBuf, int srcSize, OdCharArray &dstBuf)
OdCharMapper::codepageToUnicode
static OdResult codepageToUnicode(OdChar sourceChar, OdCodePageId codepageId, OdChar &unicodeChar)
TD_PackPush.h
odIsTailSurrogate
bool odIsTailSurrogate(T chr)
Definition: OdCharMapper.h:273
odToCodeValue
OdUInt32 odToCodeValue(T chr, T chr2)
Definition: OdCharMapper.h:279
OdCharMapper::convertCIFcoding
static OdString convertCIFcoding(const OdString &strText)
OdStreamBuf
Definition: OdStreamBuf.h:67
OdCharMapper::getReorderCharsetByChar
static OdUInt16 getReorderCharsetByChar(OdChar ch)
OdCharMapper
Definition: OdCharMapper.h:48
odIsLeadSurrogate
bool odIsLeadSurrogate(T chr)
Definition: OdCharMapper.h:270
OdCharMapper::ansiCpToAcadCp
static OdCodePageId ansiCpToAcadCp(OdUInt32 ansiCodePage)
OdCharMapper::wideCharToMultiByte
static void wideCharToMultiByte(OdCodePageId codePage, const OdChar *srcBuf, int srcSize, OdAnsiCharArray &dstBuf)
OdCharMapper::addBigFontWithCodepage
static OdResult addBigFontWithCodepage(const OdString &bigFont, OdCodePageId codePageId)
OdError.h
OdCharMapper::multiByteToWideChar
static void multiByteToWideChar(OdCodePageId codePage, const char *srcBuf, int srcSize, OdCharArray &dstBuf)
KOREAN_JOHAB_CP_INDEX
@ KOREAN_JOHAB_CP_INDEX
Definition: OdCharMapper.h:297
TRADITIONAL_CHINESE_CP_INDEX
@ TRADITIONAL_CHINESE_CP_INDEX
Definition: OdCharMapper.h:295
SIMPLIFIED_CHINESE_CP_INDEX
@ SIMPLIFIED_CHINESE_CP_INDEX
Definition: OdCharMapper.h:298