1 | /**************************************************************************\
|
---|
2 | *
|
---|
3 | * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
|
---|
4 | *
|
---|
5 | * Module Name:
|
---|
6 | *
|
---|
7 | * GdiplusStringFormat.h
|
---|
8 | *
|
---|
9 | * Abstract:
|
---|
10 | *
|
---|
11 | * GDI+ StringFormat class
|
---|
12 | *
|
---|
13 | \**************************************************************************/
|
---|
14 |
|
---|
15 | #ifndef _GDIPLUSSTRINGFORMAT_H
|
---|
16 | #define _GDIPLUSSTRINGFORMAT_H
|
---|
17 |
|
---|
18 | class StringFormat : public GdiplusBase
|
---|
19 | {
|
---|
20 | public:
|
---|
21 | friend class Graphics;
|
---|
22 | friend class GraphicsPath;
|
---|
23 |
|
---|
24 |
|
---|
25 | StringFormat(
|
---|
26 | IN INT formatFlags = 0,
|
---|
27 | IN LANGID language = LANG_NEUTRAL
|
---|
28 | )
|
---|
29 | {
|
---|
30 | nativeFormat = NULL;
|
---|
31 | lastError = DllExports::GdipCreateStringFormat(
|
---|
32 | formatFlags,
|
---|
33 | language,
|
---|
34 | &nativeFormat
|
---|
35 | );
|
---|
36 | }
|
---|
37 |
|
---|
38 | static const StringFormat *GenericDefault();
|
---|
39 | static const StringFormat *GenericTypographic();
|
---|
40 |
|
---|
41 | StringFormat(
|
---|
42 | IN const StringFormat *format
|
---|
43 | )
|
---|
44 | {
|
---|
45 | nativeFormat = NULL;
|
---|
46 | lastError = DllExports::GdipCloneStringFormat(
|
---|
47 | format ? format->nativeFormat : NULL,
|
---|
48 | &nativeFormat
|
---|
49 | );
|
---|
50 | }
|
---|
51 |
|
---|
52 | StringFormat *Clone() const
|
---|
53 | {
|
---|
54 | GpStringFormat *clonedStringFormat = NULL;
|
---|
55 |
|
---|
56 | lastError = DllExports::GdipCloneStringFormat(
|
---|
57 | nativeFormat,
|
---|
58 | &clonedStringFormat
|
---|
59 | );
|
---|
60 |
|
---|
61 | if (lastError == Ok)
|
---|
62 | return new StringFormat(clonedStringFormat, lastError);
|
---|
63 | else
|
---|
64 | return NULL;
|
---|
65 | }
|
---|
66 |
|
---|
67 | ~StringFormat()
|
---|
68 | {
|
---|
69 | DllExports::GdipDeleteStringFormat(nativeFormat);
|
---|
70 | }
|
---|
71 |
|
---|
72 | Status SetFormatFlags(IN INT flags)
|
---|
73 | {
|
---|
74 | return SetStatus(DllExports::GdipSetStringFormatFlags(
|
---|
75 | nativeFormat,
|
---|
76 | flags
|
---|
77 | ));
|
---|
78 | }
|
---|
79 |
|
---|
80 | INT GetFormatFlags() const
|
---|
81 | {
|
---|
82 | INT flags;
|
---|
83 | SetStatus(DllExports::GdipGetStringFormatFlags(nativeFormat, &flags));
|
---|
84 | return flags;
|
---|
85 | }
|
---|
86 |
|
---|
87 | Status SetAlignment(IN StringAlignment align)
|
---|
88 | {
|
---|
89 | return SetStatus(DllExports::GdipSetStringFormatAlign(
|
---|
90 | nativeFormat,
|
---|
91 | align
|
---|
92 | ));
|
---|
93 | }
|
---|
94 |
|
---|
95 | StringAlignment GetAlignment() const
|
---|
96 | {
|
---|
97 | StringAlignment alignment;
|
---|
98 | SetStatus(DllExports::GdipGetStringFormatAlign(
|
---|
99 | nativeFormat,
|
---|
100 | &alignment
|
---|
101 | ));
|
---|
102 | return alignment;
|
---|
103 | }
|
---|
104 |
|
---|
105 | Status SetLineAlignment(IN StringAlignment align)
|
---|
106 | {
|
---|
107 | return SetStatus(DllExports::GdipSetStringFormatLineAlign(
|
---|
108 | nativeFormat,
|
---|
109 | align
|
---|
110 | ));
|
---|
111 | }
|
---|
112 |
|
---|
113 | StringAlignment GetLineAlignment() const
|
---|
114 | {
|
---|
115 | StringAlignment alignment;
|
---|
116 | SetStatus(DllExports::GdipGetStringFormatLineAlign(
|
---|
117 | nativeFormat,
|
---|
118 | &alignment
|
---|
119 | ));
|
---|
120 | return alignment;
|
---|
121 | }
|
---|
122 |
|
---|
123 | Status SetHotkeyPrefix(IN HotkeyPrefix hotkeyPrefix)
|
---|
124 | {
|
---|
125 | return SetStatus(DllExports::GdipSetStringFormatHotkeyPrefix(
|
---|
126 | nativeFormat,
|
---|
127 | (INT)hotkeyPrefix
|
---|
128 | ));
|
---|
129 | }
|
---|
130 |
|
---|
131 | HotkeyPrefix GetHotkeyPrefix() const
|
---|
132 | {
|
---|
133 | HotkeyPrefix hotkeyPrefix;
|
---|
134 | SetStatus(DllExports::GdipGetStringFormatHotkeyPrefix(
|
---|
135 | nativeFormat,
|
---|
136 | (INT*)&hotkeyPrefix
|
---|
137 | ));
|
---|
138 | return hotkeyPrefix;
|
---|
139 | }
|
---|
140 |
|
---|
141 | Status SetTabStops(
|
---|
142 | IN REAL firstTabOffset,
|
---|
143 | IN INT count,
|
---|
144 | IN const REAL *tabStops
|
---|
145 | )
|
---|
146 | {
|
---|
147 | return SetStatus(DllExports::GdipSetStringFormatTabStops(
|
---|
148 | nativeFormat,
|
---|
149 | firstTabOffset,
|
---|
150 | count,
|
---|
151 | tabStops
|
---|
152 | ));
|
---|
153 | }
|
---|
154 |
|
---|
155 | INT GetTabStopCount() const
|
---|
156 | {
|
---|
157 | INT count;
|
---|
158 | SetStatus(DllExports::GdipGetStringFormatTabStopCount(nativeFormat, &count));
|
---|
159 | return count;
|
---|
160 | }
|
---|
161 |
|
---|
162 | Status GetTabStops(
|
---|
163 | IN INT count,
|
---|
164 | OUT REAL *firstTabOffset,
|
---|
165 | OUT REAL *tabStops
|
---|
166 | ) const
|
---|
167 | {
|
---|
168 | return SetStatus(DllExports::GdipGetStringFormatTabStops(
|
---|
169 | nativeFormat,
|
---|
170 | count,
|
---|
171 | firstTabOffset,
|
---|
172 | tabStops
|
---|
173 | ));
|
---|
174 | }
|
---|
175 |
|
---|
176 | Status SetDigitSubstitution(
|
---|
177 | IN LANGID language,
|
---|
178 | IN StringDigitSubstitute substitute
|
---|
179 | )
|
---|
180 | {
|
---|
181 | return SetStatus(DllExports::GdipSetStringFormatDigitSubstitution(
|
---|
182 | nativeFormat,
|
---|
183 | language,
|
---|
184 | substitute
|
---|
185 | ));
|
---|
186 | }
|
---|
187 |
|
---|
188 | LANGID GetDigitSubstitutionLanguage(
|
---|
189 | ) const
|
---|
190 | {
|
---|
191 | LANGID language;
|
---|
192 | SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
|
---|
193 | nativeFormat,
|
---|
194 | &language,
|
---|
195 | NULL
|
---|
196 | ));
|
---|
197 | return language;
|
---|
198 | }
|
---|
199 |
|
---|
200 | StringDigitSubstitute GetDigitSubstitutionMethod(
|
---|
201 | ) const
|
---|
202 | {
|
---|
203 | StringDigitSubstitute substitute;
|
---|
204 | SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
|
---|
205 | nativeFormat,
|
---|
206 | NULL,
|
---|
207 | &substitute
|
---|
208 | ));
|
---|
209 | return substitute;
|
---|
210 | }
|
---|
211 |
|
---|
212 | Status SetTrimming(IN StringTrimming trimming)
|
---|
213 | {
|
---|
214 | return SetStatus(DllExports::GdipSetStringFormatTrimming(
|
---|
215 | nativeFormat,
|
---|
216 | trimming
|
---|
217 | ));
|
---|
218 | }
|
---|
219 |
|
---|
220 | StringTrimming GetTrimming() const
|
---|
221 | {
|
---|
222 | StringTrimming trimming;
|
---|
223 | SetStatus(DllExports::GdipGetStringFormatTrimming(
|
---|
224 | nativeFormat,
|
---|
225 | &trimming
|
---|
226 | ));
|
---|
227 | return trimming;
|
---|
228 | }
|
---|
229 |
|
---|
230 | Status SetMeasurableCharacterRanges(
|
---|
231 | IN INT rangeCount,
|
---|
232 | IN const CharacterRange *ranges
|
---|
233 | )
|
---|
234 | {
|
---|
235 | return SetStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(
|
---|
236 | nativeFormat,
|
---|
237 | rangeCount,
|
---|
238 | ranges
|
---|
239 | ));
|
---|
240 | }
|
---|
241 |
|
---|
242 | INT GetMeasurableCharacterRangeCount()
|
---|
243 | {
|
---|
244 | INT count;
|
---|
245 | SetStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(
|
---|
246 | nativeFormat,
|
---|
247 | &count
|
---|
248 | ));
|
---|
249 | return count;
|
---|
250 | }
|
---|
251 |
|
---|
252 | Status GetLastStatus() const
|
---|
253 | {
|
---|
254 | Status lastStatus = lastError;
|
---|
255 | lastError = Ok;
|
---|
256 |
|
---|
257 | return lastStatus;
|
---|
258 | }
|
---|
259 |
|
---|
260 | protected:
|
---|
261 |
|
---|
262 | Status SetStatus(GpStatus newStatus) const
|
---|
263 | {
|
---|
264 | if (newStatus == Ok)
|
---|
265 | {
|
---|
266 | return Ok;
|
---|
267 | }
|
---|
268 | else
|
---|
269 | {
|
---|
270 | return lastError = newStatus;
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | StringFormat(const StringFormat &source)
|
---|
275 | {
|
---|
276 | nativeFormat = NULL;
|
---|
277 | lastError = DllExports::GdipCloneStringFormat(
|
---|
278 | source.nativeFormat,
|
---|
279 | &nativeFormat
|
---|
280 | );
|
---|
281 | }
|
---|
282 |
|
---|
283 | StringFormat& operator=(const StringFormat &source)
|
---|
284 | {
|
---|
285 | DllExports::GdipDeleteStringFormat(nativeFormat);
|
---|
286 | lastError = DllExports::GdipCloneStringFormat(
|
---|
287 | source.nativeFormat,
|
---|
288 | &nativeFormat
|
---|
289 | );
|
---|
290 | return *this;
|
---|
291 | }
|
---|
292 |
|
---|
293 | StringFormat(GpStringFormat * clonedStringFormat, Status status)
|
---|
294 | {
|
---|
295 | lastError = status;
|
---|
296 | nativeFormat = clonedStringFormat;
|
---|
297 |
|
---|
298 | }
|
---|
299 |
|
---|
300 | GpStringFormat *nativeFormat;
|
---|
301 | mutable Status lastError;
|
---|
302 | };
|
---|
303 |
|
---|
304 | static BYTE GenericTypographicStringFormatBuffer[sizeof(StringFormat)] = {0};
|
---|
305 | static BYTE GenericDefaultStringFormatBuffer[sizeof(StringFormat)] = {0};
|
---|
306 |
|
---|
307 | inline const StringFormat *StringFormat::GenericDefault()
|
---|
308 | {
|
---|
309 | StringFormat * genericDefaultStringFormat =
|
---|
310 | (StringFormat*)GenericDefaultStringFormatBuffer;
|
---|
311 |
|
---|
312 | genericDefaultStringFormat->lastError =
|
---|
313 | DllExports::GdipStringFormatGetGenericDefault(
|
---|
314 | &(genericDefaultStringFormat->nativeFormat)
|
---|
315 | );
|
---|
316 |
|
---|
317 | return genericDefaultStringFormat;
|
---|
318 | }
|
---|
319 |
|
---|
320 | inline const StringFormat *StringFormat::GenericTypographic()
|
---|
321 | {
|
---|
322 | StringFormat * genericTypographicStringFormat =
|
---|
323 | (StringFormat*)GenericTypographicStringFormatBuffer;
|
---|
324 |
|
---|
325 | genericTypographicStringFormat->lastError =
|
---|
326 | DllExports::GdipStringFormatGetGenericTypographic(
|
---|
327 | &genericTypographicStringFormat->nativeFormat
|
---|
328 | );
|
---|
329 |
|
---|
330 | return genericTypographicStringFormat;
|
---|
331 | }
|
---|
332 |
|
---|
333 | #endif // !_GDIPLUSSTRINGFORMAT_H
|
---|