opennurbs_internal_unicode_cp.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_INTERNAL_UNICODE_CP_INC_)
18 #define OPENNURBS_INTERNAL_UNICODE_CP_INC_
19 
20 #if !defined(ON_COMPILING_OPENNURBS)
21 // This check is included in all opennurbs source .c and .cpp files to insure
22 // ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
23 // When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
24 // and the opennurbs .h files alter what is declared and how it is declared.
25 #error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
26 #endif
27 
28 #if !defined(ON_RUNTIME_WIN)
29 #error Do not use for Windows builds.
30 #endif
31 
32 #if !defined(ON_RUNTIME_WIN)
33 // When we do not have access to Windows code page tools,
34 // we have to add in code to get convert Windows and Apple
35 // multibyte encodings to UNICODE encodings.
36 //
37 // In practice, the primary use of the double byte code page support
38 // is in parsing rich text (RTF) in ON_TextContent classes created
39 // on computers with Eastern European and Asian locales as the default
40 // locale.
41 //
42 // Many Western European and Americas locales are handled by the
43 // single byte code pages 1252 and 10000. Code pages for other
44 // locales will be added as needed because embedding the large
45 // double byte tables makes the resulting libraries large.
46 //
47 // At this time opennurbs does not ship the
48 // code page N to UNICODE translation tables as separate files
49 // that can be loaded on demand because of the added installation
50 // and runtime lookup complexities.
51 //
52 // When possible, Rhino and opennurbs replace code page
53 // encodings with UNICODE in RTF. All runtimes strings
54 // use UNICODE UTF-8, UTF-16, or UTF-32 encodings.
55 // Whenever posssible, the UNICODE encoding is used
56 // to retrieve glyph information from fonts.
57 #define ON_DOUBLE_BYTE_CODE_PAGE_SUPPORT
58 #endif
59 
60 #if defined(ON_DOUBLE_BYTE_CODE_PAGE_SUPPORT)
61 
62 /////////////////////////////////////////////////////////
63 //
64 // Code page 932
65 //
66 
67 bool ON_IsPotentialWindowsCodePage932SingleByteEncoding(
68  ON__UINT32 x
69 );
70 
71 bool ON_IsPotentialWindowsCodePage932DoubleByteEncoding(
72  ON__UINT32 lead_byte,
73  ON__UINT32 trailing_byte
74 );
75 
76 /*
77 Description:
78  Convert a Windows code page 932 encoded value to a UNICODE code point.
79  This code page is often used for Japanese glpyhs.
80 
81 Parameters:
82  code_page_932_character_value - [in]
83  Valid values are 0 to 0xFDFE with some exceptions in that range.
84  unicode_code_point - [out]
85  ON_UnicodeCodePoint::ON_ReplacementCharacter is returned when code_page_932_character_value is not valid.
86 
87 Returns:
88  1: if code_page_932_character_value and the corresponding UNICODE code point is returned in *unicode_code_point.
89  0: otherwise and *unicode_code_point = ON_UnicodeCodePoint::ON_ReplacementCharacter.
90 
91 Remarks:
92  Windows code page 932: https://msdn.microsoft.com/en-us/library/cc194887.aspx
93  Conversions to Unicode are based on the Unicode.org mapping of Shift JIS
94  ftp://ftp.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/JIS/SHIFTJIS.TXT
95 */
96 #if defined(ON_COMPILER_MSC) && defined(NDEBUG)
97  // Work around Release build optimization bug in Visual Studio 2017.
98 __declspec(noinline)
99 #endif
100 int ON_MapWindowsCodePage932ToUnicode(
101  ON__UINT32 code_page_932_character_value,
102  ON__UINT32* unicode_code_point
103 );
104 
105 /////////////////////////////////////////////////////////
106 //
107 // Code page 949
108 //
109 
110 bool ON_IsPotentialWindowsCodePage949SingleByteEncoding(
111  ON__UINT32 x
112 );
113 
114 bool ON_IsPotentialWindowsCodePage949DoubleByteEncoding(
115  ON__UINT32 lead_byte,
116  ON__UINT32 trailing_byte
117 );
118 
119 /*
120 Description:
121  Convert a Windows code page 949 encoded value to a UNICODE code point.
122  This code page is often used for Korean glpyhs.
123 
124 Parameters:
125  code_page_949_character_value - [in]
126  Valid values are 0 to 0xFDFE with some exceptions in that range.
127  unicode_code_point - [out]
128  ON_UnicodeCodePoint::ON_ReplacementCharacter is returned when code_page_949_character_value is not valid.
129 
130 Returns:
131  1: if code_page_949_character_value and the corresponding UNICODE code point is returned in *unicode_code_point.
132  0: otherwise and *unicode_code_point = ON_UnicodeCodePoint::ON_ReplacementCharacter.
133 
134 Remarks:
135  Windows code page 949: https://msdn.microsoft.com/en-us/library/cc194941.aspx
136  Conversions to Unicode are based on the Unicode.org mapping of Windows-949
137  ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP949.TXT
138 */
139 #if defined(ON_COMPILER_MSC) && defined(NDEBUG)
140  // Work around Release build optimization bug in Visual Studio 2017.
141 __declspec(noinline)
142 #endif
143 int ON_MapWindowsCodePage949ToUnicode(
144  ON__UINT32 code_page_949_character_value,
145  ON__UINT32* unicode_code_point
146 );
147 
148 
149 #endif
150 
151 #endif