1 {
2 File: HIToolbox/HITextUtils.h
3
4 Contains: Text utilities provided by HIToolbox.
5
6 Version: HIToolbox-624~3
7
8 Copyright: � 2002-2008 by Apple Computer, Inc., all rights reserved.
9
10 Bugs?: For bug reports, consult the following page on
11 the World Wide Web:
12
13 http://bugs.freepascal.org
14
15 }
16 { Pascal Translation: Peter N Lewis, <peter@stairways.com.au>, August 2005 }
17 { Pascal Translation Updated: Jonas Maebe, <jonas@freepascal.org>, October 2009 }
18 { Pascal Translation Updated: Jonas Maebe, <jonas@freepascal.org>, October 2012 }
19 {
20 Modified for use with Free Pascal
21 Version 308
22 Please report any bugs to <gpc@microbizz.nl>
23 }
24
25 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
26 {$mode macpas}
27 {$modeswitch cblocks}
28 {$packenum 1}
29 {$macro on}
30 {$inline on}
31 {$calling mwpascal}
32
33 unit HITextUtils;
34 interface
35 {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
36 {$setc GAP_INTERFACES_VERSION := $0308}
37
38 {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
39 {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
40 {$endc}
41
42 {$ifc defined CPUPOWERPC and defined CPUI386}
43 {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
44 {$endc}
45 {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
46 {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
47 {$endc}
48
49 {$ifc not defined __ppc__ and defined CPUPOWERPC32}
50 {$setc __ppc__ := 1}
51 {$elsec}
52 {$setc __ppc__ := 0}
53 {$endc}
54 {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
55 {$setc __ppc64__ := 1}
56 {$elsec}
57 {$setc __ppc64__ := 0}
58 {$endc}
59 {$ifc not defined __i386__ and defined CPUI386}
60 {$setc __i386__ := 1}
61 {$elsec}
62 {$setc __i386__ := 0}
63 {$endc}
64 {$ifc not defined __x86_64__ and defined CPUX86_64}
65 {$setc __x86_64__ := 1}
66 {$elsec}
67 {$setc __x86_64__ := 0}
68 {$endc}
69 {$ifc not defined __arm__ and defined CPUARM}
70 {$setc __arm__ := 1}
71 {$elsec}
72 {$setc __arm__ := 0}
73 {$endc}
74 {$ifc not defined __arm64__ and defined CPUAARCH64}
75 {$setc __arm64__ := 1}
76 {$elsec}
77 {$setc __arm64__ := 0}
78 {$endc}
79
80 {$ifc defined cpu64}
81 {$setc __LP64__ := 1}
82 {$elsec}
83 {$setc __LP64__ := 0}
84 {$endc}
85
86
87 {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
88 {$error Conflicting definitions for __ppc__ and __i386__}
89 {$endc}
90
91 {$ifc defined __ppc__ and __ppc__}
92 {$setc TARGET_CPU_PPC := TRUE}
93 {$setc TARGET_CPU_PPC64 := FALSE}
94 {$setc TARGET_CPU_X86 := FALSE}
95 {$setc TARGET_CPU_X86_64 := FALSE}
96 {$setc TARGET_CPU_ARM := FALSE}
97 {$setc TARGET_CPU_ARM64 := FALSE}
98 {$setc TARGET_OS_MAC := TRUE}
99 {$setc TARGET_OS_IPHONE := FALSE}
100 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
101 {$setc TARGET_OS_EMBEDDED := FALSE}
102 {$elifc defined __ppc64__ and __ppc64__}
103 {$setc TARGET_CPU_PPC := FALSE}
104 {$setc TARGET_CPU_PPC64 := TRUE}
105 {$setc TARGET_CPU_X86 := FALSE}
106 {$setc TARGET_CPU_X86_64 := FALSE}
107 {$setc TARGET_CPU_ARM := FALSE}
108 {$setc TARGET_CPU_ARM64 := FALSE}
109 {$setc TARGET_OS_MAC := TRUE}
110 {$setc TARGET_OS_IPHONE := FALSE}
111 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
112 {$setc TARGET_OS_EMBEDDED := FALSE}
113 {$elifc defined __i386__ and __i386__}
114 {$setc TARGET_CPU_PPC := FALSE}
115 {$setc TARGET_CPU_PPC64 := FALSE}
116 {$setc TARGET_CPU_X86 := TRUE}
117 {$setc TARGET_CPU_X86_64 := FALSE}
118 {$setc TARGET_CPU_ARM := FALSE}
119 {$setc TARGET_CPU_ARM64 := FALSE}
120 {$ifc defined iphonesim}
121 {$setc TARGET_OS_MAC := FALSE}
122 {$setc TARGET_OS_IPHONE := TRUE}
123 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
124 {$elsec}
125 {$setc TARGET_OS_MAC := TRUE}
126 {$setc TARGET_OS_IPHONE := FALSE}
127 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
128 {$endc}
129 {$setc TARGET_OS_EMBEDDED := FALSE}
130 {$elifc defined __x86_64__ and __x86_64__}
131 {$setc TARGET_CPU_PPC := FALSE}
132 {$setc TARGET_CPU_PPC64 := FALSE}
133 {$setc TARGET_CPU_X86 := FALSE}
134 {$setc TARGET_CPU_X86_64 := TRUE}
135 {$setc TARGET_CPU_ARM := FALSE}
136 {$setc TARGET_CPU_ARM64 := FALSE}
137 {$ifc defined iphonesim}
138 {$setc TARGET_OS_MAC := FALSE}
139 {$setc TARGET_OS_IPHONE := TRUE}
140 {$setc TARGET_IPHONE_SIMULATOR := TRUE}
141 {$elsec}
142 {$setc TARGET_OS_MAC := TRUE}
143 {$setc TARGET_OS_IPHONE := FALSE}
144 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
145 {$endc}
146 {$setc TARGET_OS_EMBEDDED := FALSE}
147 {$elifc defined __arm__ and __arm__}
148 {$setc TARGET_CPU_PPC := FALSE}
149 {$setc TARGET_CPU_PPC64 := FALSE}
150 {$setc TARGET_CPU_X86 := FALSE}
151 {$setc TARGET_CPU_X86_64 := FALSE}
152 {$setc TARGET_CPU_ARM := TRUE}
153 {$setc TARGET_CPU_ARM64 := FALSE}
154 {$setc TARGET_OS_MAC := FALSE}
155 {$setc TARGET_OS_IPHONE := TRUE}
156 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
157 {$setc TARGET_OS_EMBEDDED := TRUE}
158 {$elifc defined __arm64__ and __arm64__}
159 {$setc TARGET_CPU_PPC := FALSE}
160 {$setc TARGET_CPU_PPC64 := FALSE}
161 {$setc TARGET_CPU_X86 := FALSE}
162 {$setc TARGET_CPU_X86_64 := FALSE}
163 {$setc TARGET_CPU_ARM := FALSE}
164 {$setc TARGET_CPU_ARM64 := TRUE}
165 {$ifc defined ios}
166 {$setc TARGET_OS_MAC := FALSE}
167 {$setc TARGET_OS_IPHONE := TRUE}
168 {$setc TARGET_OS_EMBEDDED := TRUE}
169 {$elsec}
170 {$setc TARGET_OS_MAC := TRUE}
171 {$setc TARGET_OS_IPHONE := FALSE}
172 {$setc TARGET_OS_EMBEDDED := FALSE}
173 {$endc}
174 {$setc TARGET_IPHONE_SIMULATOR := FALSE}
175 {$elsec}
176 {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
177 {$endc}
178
179 {$ifc defined __LP64__ and __LP64__ }
180 {$setc TARGET_CPU_64 := TRUE}
181 {$elsec}
182 {$setc TARGET_CPU_64 := FALSE}
183 {$endc}
184
185 {$ifc defined FPC_BIG_ENDIAN}
186 {$setc TARGET_RT_BIG_ENDIAN := TRUE}
187 {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
188 {$elifc defined FPC_LITTLE_ENDIAN}
189 {$setc TARGET_RT_BIG_ENDIAN := FALSE}
190 {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
191 {$elsec}
192 {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
193 {$endc}
194 {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
195 {$setc CALL_NOT_IN_CARBON := FALSE}
196 {$setc OLDROUTINENAMES := FALSE}
197 {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
198 {$setc OPAQUE_UPP_TYPES := TRUE}
199 {$setc OTCARBONAPPLICATION := TRUE}
200 {$setc OTKERNEL := FALSE}
201 {$setc PM_USE_SESSION_APIS := TRUE}
202 {$setc TARGET_API_MAC_CARBON := TRUE}
203 {$setc TARGET_API_MAC_OS8 := FALSE}
204 {$setc TARGET_API_MAC_OSX := TRUE}
205 {$setc TARGET_CARBON := TRUE}
206 {$setc TARGET_CPU_68K := FALSE}
207 {$setc TARGET_CPU_MIPS := FALSE}
208 {$setc TARGET_CPU_SPARC := FALSE}
209 {$setc TARGET_OS_UNIX := FALSE}
210 {$setc TARGET_OS_WIN32 := FALSE}
211 {$setc TARGET_RT_MAC_68881 := FALSE}
212 {$setc TARGET_RT_MAC_CFM := FALSE}
213 {$setc TARGET_RT_MAC_MACHO := TRUE}
214 {$setc TYPED_FUNCTION_POINTERS := TRUE}
215 {$setc TYPE_BOOL := FALSE}
216 {$setc TYPE_EXTENDED := FALSE}
217 {$setc TYPE_LONGLONG := TRUE}
218 uses MacTypes, TextCommon, CFBase;
219 {$endc} {not MACOSALLINCLUDE}
220
221
222 {$ifc TARGET_OS_MAC}
223
224 {$ALIGN POWER}
225
226
227 {$ifc not TARGET_CPU_64}
228 {
229 * GetTextAndEncodingFromCFString()
230 *
231 * Summary:
232 * Converts the contents of a CFString to the one- or two-byte
233 * encoding that most accurately represents the original Unicode
234 * characters in the string.
235 *
236 * Discussion:
237 * Because the Macintosh toolbox has had, until Carbon, little
238 * support for Unicode, you may often find that your applications
239 * need to translate a CFString (containing Unicode characters) back
240 * to a one- or two-byte encoding of the string in order to draw,
241 * measure, or otherwise use the text in the string.
242 * GetTextAndEncodingFromCFString is a utility that may be helpful
243 * to do this, in some circumstances. The Carbon toolbox uses this
244 * API itself when translating CFStrings to Pascal strings.
245 * GetTextAndEncodingFromCFString attempts to convert the Unicode
246 * characters in the string to the closest non-Unicode
247 * representation of the string. For example, a string containing
248 * only Unicode characters that are present in the MacRoman one-byte
249 * encoding will be translated to MacRoman, and
250 * kTextEncodingMacRoman will be returned as the encoding of the
251 * text. A string containing Unicode characters that are present in
252 * the MacJapanese two-byte encoding will be translated to
253 * MacJapanese (Shift-JIS), and kTextEncodingMacJapanese will be
254 * returned as the encoding of the text.
255 * GetTextAndEncodingFromCFString is designed to be used for simple
256 * strings which contain only text from a single language. It is not
257 * designed to translate strings with multiple runs of text from
258 * different languages, and will only return the first run of such a
259 * string; for example, if you pass it a string containing a run of
260 * Roman characters followed by a run of Japanese characters, it
261 * will only return the Roman characters in the output buffer. For
262 * more complex text translation, you should call the Unicode
263 * converter directly (see ConvertFromUnicodeToTextRun, which
264 * GetTextAndEncodingFromCFString uses internally).
265 *
266 * Mac OS X threading:
267 * Not thread safe
268 *
269 * Parameters:
270 *
271 * inString:
272 * The string to convert.
273 *
274 * outText:
275 * The output buffer in which to place the converted text.
276 *
277 * inTextMaxLength:
278 * The length in bytes of the input buffer.
279 *
280 * outTextLength:
281 * On exit, contains the length in bytes of the text that was
282 * placed into the output buffer.
283 *
284 * outEncoding:
285 * On exit, contains the encoding of the text that was placed into
286 * the output buffer.
287 *
288 * Availability:
289 * Mac OS X: in version 10.0 and later in Carbon.framework [32-bit only]
290 * CarbonLib: in CarbonLib 1.2.5 and later
291 * Non-Carbon CFM: not available
292 }
GetTextAndEncodingFromCFStringnull293 function GetTextAndEncodingFromCFString( inString: CFStringRef; outText: BytePtr; inTextMaxLength: ByteCount; var outTextLength: ByteCount; outEncoding: TextEncodingPtr { can be NULL } ): OSStatus; external name '_GetTextAndEncodingFromCFString';
294 (* AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER *)
295
296
297 {$endc} {not TARGET_CPU_64}
298
299 {$endc} {TARGET_OS_MAC}
300 {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
301
302 end.
303 {$endc} {not MACOSALLINCLUDE}
304