1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
File: HITextUtils.h
Contains: Text utilities provided by HIToolbox.
Version: QuickTime 7.3
Copyright: (c) 2007 (c)2002 by Apple Computer, Inc., all rights reserved.
Bugs?: For bug reports, consult the following page on
the World Wide Web:
http://developer.apple.com/bugreporter/
*/
#ifndef __HITEXTUTILS__
#define __HITEXTUTILS__
#ifndef __MACTYPES__
#include <MacTypes.h>
#endif
#ifndef __COREFOUNDATION__
#include <CoreFoundation.h>
#endif
#ifndef __TEXTCOMMON__
#include <TextCommon.h>
#endif
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_IMPORT
#pragma import on
#endif
/*
* GetTextAndEncodingFromCFString()
*
* Summary:
* Converts the contents of a CFString to the one- or two-byte
* encoding that most accurately represents the original Unicode
* characters in the string.
*
* Discussion:
* Because the Macintosh toolbox has had, until Carbon, little
* support for Unicode, you may often find that your applications
* need to translate a CFString (containing Unicode characters) back
* to a one- or two-byte encoding of the string in order to draw,
* measure, or otherwise use the text in the string.
* GetTextAndEncodingFromCFString is a utility that may be helpful
* to do this, in some circumstances. The Carbon toolbox uses this
* API itself when translating CFStrings to Pascal strings.
* GetTextAndEncodingFromCFString attempts to convert the Unicode
* characters in the string to the closest non-Unicode
* representation of the string. For example, a string containing
* only Unicode characters that are present in the MacRoman one-byte
* encoding will be translated to MacRoman, and
* kTextEncodingMacRoman will be returned as the encoding of the
* text. A string containing Unicode characters that are present in
* the MacJapanese two-byte encoding will be translated to
* MacJapanese (Shift-JIS), and kTextEncodingMacJapanese will be
* returned as the encoding of the text.
* GetTextAndEncodingFromCFString is designed to be used for simple
* strings which contain only text from a single language. It is not
* designed to translate strings with multiple runs of text from
* different languages, and will only return the first run of such a
* string; for example, if you pass it a string containing a run of
* Roman characters followed by a run of Japanese characters, it
* will only return the Roman characters in the output buffer. For
* more complex text translation, you should call the Unicode
* converter directly (see ConvertFromUnicodeToTextRun, which
* GetTextAndEncodingFromCFString uses internally).
*
* Parameters:
*
* inString:
* The string to convert.
*
* outText:
* The output buffer in which to place the converted text.
*
* inTextMaxLength:
* The length in bytes of the input buffer.
*
* outTextLength:
* On exit, contains the length in bytes of the text that was
* placed into the output buffer.
*
* outEncoding:
* On exit, contains the encoding of the text that was placed into
* the output buffer.
*
* Availability:
* Non-Carbon CFM: not available
* CarbonLib: in CarbonLib 1.2.5 and later
* Mac OS X: in version 10.0 and later
*/
EXTERN_API( OSStatus )
GetTextAndEncodingFromCFString(
CFStringRef inString,
BytePtr outText,
ByteCount inTextMaxLength,
ByteCount * outTextLength,
TextEncoding * outEncoding); /* can be NULL */
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#endif /* __HITEXTUTILS__ */
|