2 * @file gdiplusstringformat.h
3 * @copy 2012 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 /* Created by Markus Koenig <markus@stber-koenig.de> */
25 #ifndef __GDIPLUS_STRINGFORMAT_H
26 #define __GDIPLUS_STRINGFORMAT_H
27 #pragma GCC system_header
31 * GDI+ StringFormat class
35 #error "A C++ compiler is required to include gdiplusstringformat.h."
38 class StringFormat: public GdiplusBase
40 friend class Graphics;
41 friend class GraphicsPath;
44 static const StringFormat* GenericDefault();
45 static const StringFormat* GenericTypographic();
47 StringFormat(INT formatFlags = 0, LANGID language = LANG_NEUTRAL):
48 nativeStringFormat(NULL), lastStatus(Ok)
50 lastStatus = DllExports::GdipCreateStringFormat(
51 formatFlags, language, &nativeStringFormat);
53 StringFormat(const StringFormat *format):
54 nativeStringFormat(NULL), lastStatus(Ok)
56 lastStatus = DllExports::GdipCloneStringFormat(
57 format ? format->nativeStringFormat : NULL,
62 DllExports::GdipDeleteStringFormat(nativeStringFormat);
64 StringFormat* Clone() const
66 GpStringFormat *cloneStringFormat = NULL;
67 Status status = updateStatus(DllExports::GdipCloneStringFormat(
68 nativeStringFormat, &cloneStringFormat));
70 StringFormat *result = new StringFormat(
71 cloneStringFormat, lastStatus);
73 DllExports::GdipDeleteStringFormat(cloneStringFormat);
74 lastStatus = OutOfMemory;
82 StringAlignment GetAlignment() const
84 StringAlignment result = StringAlignmentNear;
85 updateStatus(DllExports::GdipGetStringFormatAlign(
86 nativeStringFormat, &result));
89 LANGID GetDigitSubstitutionLanguage() const
92 StringDigitSubstitute method;
93 updateStatus(DllExports::GdipGetStringFormatDigitSubstitution(
94 nativeStringFormat, &result, &method));
97 StringDigitSubstitute GetDigitSubstitutionMethod() const
100 StringDigitSubstitute result = StringDigitSubstituteUser;
101 updateStatus(DllExports::GdipGetStringFormatDigitSubstitution(
102 nativeStringFormat, &language, &result));
105 INT GetFormatFlags() const
108 updateStatus(DllExports::GdipGetStringFormatFlags(
109 nativeStringFormat, &result));
112 HotkeyPrefix GetHotkeyPrefix() const
114 HotkeyPrefix result = HotkeyPrefixNone;
115 updateStatus(DllExports::GdipGetStringFormatHotkeyPrefix(
116 nativeStringFormat, (INT*) &result));
119 Status GetLastStatus() const
121 Status result = lastStatus;
125 StringAlignment GetLineAlignment() const
127 StringAlignment result = StringAlignmentNear;
128 updateStatus(DllExports::GdipGetStringFormatLineAlign(
129 nativeStringFormat, &result));
132 INT GetMeasurableCharacterRangeCount() const
135 updateStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(
136 nativeStringFormat, &result));
139 INT GetTabStopCount() const
142 updateStatus(DllExports::GdipGetStringFormatTabStopCount(
143 nativeStringFormat, &result));
146 Status GetTabStops(INT count, REAL *firstTabOffset, REAL *tabStops)
148 return updateStatus(DllExports::GdipGetStringFormatTabStops(
149 nativeStringFormat, count,
150 firstTabOffset, tabStops));
152 StringTrimming GetTrimming() const
154 StringTrimming result = StringTrimmingNone;
155 updateStatus(DllExports::GdipGetStringFormatTrimming(
156 nativeStringFormat, &result));
159 Status SetAlignment(StringAlignment align)
161 return updateStatus(DllExports::GdipSetStringFormatAlign(
162 nativeStringFormat, align));
164 Status SetDigitSubstitution(LANGID language,
165 StringDigitSubstitute substitute)
167 return updateStatus(DllExports::GdipSetStringFormatDigitSubstitution(
168 nativeStringFormat, language, substitute));
170 Status SetFormatFlags(INT flags)
172 return updateStatus(DllExports::GdipSetStringFormatFlags(
173 nativeStringFormat, flags));
175 Status SetHotkeyPrefix(HotkeyPrefix hotkeyPrefix)
177 return updateStatus(DllExports::GdipSetStringFormatHotkeyPrefix(
178 nativeStringFormat, (INT) hotkeyPrefix));
180 Status SetLineAlignment(StringAlignment align)
182 return updateStatus(DllExports::GdipSetStringFormatLineAlign(
183 nativeStringFormat, align));
185 Status SetMeasurableCharacterRanges(INT rangeCount,
186 const CharacterRange *ranges)
188 return updateStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(
189 nativeStringFormat, rangeCount, ranges));
191 Status SetTabStops(REAL firstTabOffset, INT count, const REAL *tabStops)
193 return updateStatus(DllExports::GdipSetStringFormatTabStops(
194 nativeStringFormat, firstTabOffset,
197 Status SetTrimming(StringTrimming trimming)
199 return updateStatus(DllExports::GdipSetStringFormatTrimming(
200 nativeStringFormat, trimming));
204 StringFormat(GpStringFormat *stringFormat, Status status):
205 nativeStringFormat(stringFormat), lastStatus(status) {}
206 StringFormat(const StringFormat&);
207 StringFormat& operator=(const StringFormat&);
209 Status updateStatus(Status newStatus) const
211 if (newStatus != Ok) lastStatus = newStatus;
215 GpStringFormat *nativeStringFormat;
216 mutable Status lastStatus;
220 // FIXME: do StringFormat::GenericDefault() et al. need to be thread safe?
221 // FIXME: maybe put this in gdiplus.c?
223 extern "C" void *_GdipStringFormatCachedGenericDefault;
224 extern "C" void *_GdipStringFormatCachedGenericTypographic;
226 __inline__ const StringFormat* StringFormat::GenericDefault()
228 if (!_GdipStringFormatCachedGenericDefault) {
229 GpStringFormat *nativeStringFormat = 0;
230 Status status = DllExports::GdipStringFormatGetGenericDefault(
231 &nativeStringFormat);
232 if (status == Ok && nativeStringFormat) {
233 _GdipStringFormatCachedGenericDefault = (void*)
234 new StringFormat(nativeStringFormat, Ok);
237 return (StringFormat*) _GdipStringFormatCachedGenericDefault;
240 __inline__ const StringFormat* StringFormat::GenericTypographic()
242 if (!_GdipStringFormatCachedGenericTypographic) {
243 GpStringFormat *nativeStringFormat = 0;
244 Status status = DllExports::GdipStringFormatGetGenericTypographic(
245 &nativeStringFormat);
246 if (status == Ok && nativeStringFormat) {
247 _GdipStringFormatCachedGenericTypographic = (void*)
248 new StringFormat(nativeStringFormat, Ok);
251 return (StringFormat*) _GdipStringFormatCachedGenericTypographic;
256 #endif /* __GDIPLUS_STRINGFORMAT_H */