0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Resource / Resource_Unicode.hxx
CommitLineData
42cf5bc1 1// Created on: 1996-09-26
2// Created by: Arnaud BOUZY
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _Resource_Unicode_HeaderFile
18#define _Resource_Unicode_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <Standard_CString.hxx>
25#include <Standard_Boolean.hxx>
26#include <Standard_PCharacter.hxx>
27#include <Standard_Integer.hxx>
28#include <Resource_FormatType.hxx>
29class TCollection_ExtendedString;
30
31
32//! This class provides functions used to convert a non-ASCII C string
33//! given in ANSI, EUC, GB or SJIS format, to a
34//! Unicode string of extended characters, and vice versa.
35class Resource_Unicode
36{
37public:
38
39 DEFINE_STANDARD_ALLOC
40
41
42 //! Converts non-ASCII CString <fromstr> in SJIS format
43 //! to Unicode ExtendedString <tostr>.
44 Standard_EXPORT static void ConvertSJISToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
45
46 //! Converts non-ASCII CString <fromstr> in EUC format
47 //! to Unicode ExtendedString <tostr>.
48 Standard_EXPORT static void ConvertEUCToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
49
50 //! Converts non-ASCII CString <fromstr> in GB format
51 //! to Unicode ExtendedString <tostr>.
52 Standard_EXPORT static void ConvertGBToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
53
31e026ba 54 //! Converts non-ASCII CString <fromstr> in GBK format
55 //! to Unicode ExtendedString <tostr>.
56 Standard_EXPORT static Standard_Boolean ConvertGBKToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
57
58 //! Converts non-ASCII CString <fromstr> in Big5 format
59 //! to Unicode ExtendedString <tostr>.
60 Standard_EXPORT static Standard_Boolean ConvertBig5ToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
61
42cf5bc1 62 //! Converts non-ASCII CString <fromstr> in ANSI format
63 //! to Unicode ExtendedString <tostr>.
64 Standard_EXPORT static void ConvertANSIToUnicode (const Standard_CString fromstr, TCollection_ExtendedString& tostr);
65
66 //! Converts Unicode ExtendedString <fromstr> to non-ASCII
67 //! CString <tostr> in SJIS format, limited to <maxsize>
68 //! characters. To translate the whole <fromstr>, use more
69 //! than twice the length of <fromstr>. Returns true if
70 //! <maxsize> has not been reached before end of conversion.
71 Standard_EXPORT static Standard_Boolean ConvertUnicodeToSJIS (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
72
73 //! Converts Unicode ExtendedString <fromstr> to non-ASCII
74 //! CString <tostr> in EUC format, limited to <maxsize>
75 //! characters. To translate the whole <fromstr>, use more
76 //! than twice the length of <fromstr>. Returns true if
77 //! <maxsize> has not been reached before end of conversion.
78 Standard_EXPORT static Standard_Boolean ConvertUnicodeToEUC (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
79
80 //! Converts Unicode ExtendedString <fromstr> to non-ASCII
81 //! CString <tostr> in GB format, limited to <maxsize>
82 //! characters. To translate the whole <fromstr>, use more
83 //! than twice the length of <fromstr>. Returns true if
84 //! <maxsize> has not been reached before end of conversion.
85 Standard_EXPORT static Standard_Boolean ConvertUnicodeToGB (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
86
87 //! Converts Unicode ExtendedString <fromstr> to non-ASCII
88 //! CString <tostr> in ANSI format, limited to <maxsize>
89 //! characters. To translate the whole <fromstr>, use more
90 //! than twice the length of <fromstr>. Returns true if
91 //! <maxsize> has not been reached before end of conversion.
92 Standard_EXPORT static Standard_Boolean ConvertUnicodeToANSI (const TCollection_ExtendedString& fromstr, Standard_PCharacter& tostr, const Standard_Integer maxsize);
93
94 //! Defines the current conversion format as typecode.
95 //! This conversion format will then be used by the
96 //! functions ConvertFormatToUnicode and
97 //! ConvertUnicodeToFormat to convert the strings.
98 Standard_EXPORT static void SetFormat (const Resource_FormatType typecode);
99
100 //! Returns the current conversion format (either
101 //! ANSI, EUC, GB or SJIS).
102 //! The current converting format must be defined in
103 //! advance with the SetFormat function.
104 Standard_EXPORT static Resource_FormatType GetFormat();
105
106 //! Reads converting format from resource "FormatType"
107 //! in Resource Manager "CharSet"
108 Standard_EXPORT static void ReadFormat();
109
e3249d8e 110 //! Converts the non-ASCII C string (as specified by GetFormat()) to the Unicode string of extended characters.
111 static void ConvertFormatToUnicode (const Standard_CString theFromStr,
112 TCollection_ExtendedString& theToStr)
113 {
114 return ConvertFormatToUnicode (Resource_Unicode::GetFormat(), theFromStr, theToStr);
115 }
116
117 //! Converts the non-ASCII C string in specified format to the Unicode string of extended characters.
118 //! @param theFormat [in] source encoding
119 //! @param theFromStr [in] text to convert
120 //! @param theToStr [out] destination string
121 Standard_EXPORT static void ConvertFormatToUnicode (const Resource_FormatType theFormat,
122 const Standard_CString theFromStr,
123 TCollection_ExtendedString& theToStr);
124
125 //! Converts the Unicode string of extended characters to the non-ASCII string according to specified format.
126 //! You need more than twice the length of the source string to complete the conversion.
127 //! The function returns true if conversion is complete, i.e. the maximum number of characters is not reached before the end of conversion.
128 //! @param theFormat [in] destination encoding
129 //! @param theFromStr [in] text to convert
130 //! @param theToStr [out] destination buffer
131 //! @param theMaxSize [in] destination buffer length
132 Standard_EXPORT static Standard_Boolean ConvertUnicodeToFormat (const Resource_FormatType theFormat,
133 const TCollection_ExtendedString& theFromStr,
134 Standard_PCharacter& theToStr,
135 const Standard_Integer theMaxSize);
136
137 //! Converts the Unicode string of extended characters to the non-ASCII string according to the format returned by the function GetFormat.
138 //! @param theFromStr [in] text to convert
139 //! @param theToStr [out] destination buffer
140 //! @param theMaxSize [in] destination buffer length
141 static Standard_Boolean ConvertUnicodeToFormat (const TCollection_ExtendedString& theFromStr,
142 Standard_PCharacter& theToStr,
143 const Standard_Integer theMaxSize)
144 {
145 return ConvertUnicodeToFormat (Resource_Unicode::GetFormat(), theFromStr, theToStr, theMaxSize);
146 }
42cf5bc1 147
42cf5bc1 148};
149
42cf5bc1 150#endif // _Resource_Unicode_HeaderFile