3 * Copyright (C) 2007 Google (Evan Stade)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include "gdiplus_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
35 GpStatus WINGDIPAPI GdipCreateStringFormat(INT attr, LANGID lang,
36 GpStringFormat **format)
38 TRACE("(%i, %x, %p)\n", attr, lang, format);
41 return InvalidParameter;
43 *format = GdipAlloc(sizeof(GpStringFormat));
44 if(!*format) return OutOfMemory;
46 (*format)->attr = attr;
47 (*format)->lang = lang;
48 (*format)->digitlang = LANG_NEUTRAL;
49 (*format)->trimming = StringTrimmingCharacter;
50 (*format)->digitsub = StringDigitSubstituteUser;
51 (*format)->character_ranges = NULL;
52 (*format)->range_count = 0;
54 (*format)->tabcount = 0;
55 (*format)->firsttab = 0.0;
56 (*format)->tabs = NULL;
58 TRACE("<-- %p\n", *format);
63 GpStatus WINGDIPAPI GdipDeleteStringFormat(GpStringFormat *format)
66 return InvalidParameter;
68 GdipFree(format->character_ranges);
69 GdipFree(format->tabs);
75 GpStatus WINGDIPAPI GdipStringFormatGetGenericDefault(GpStringFormat **format)
80 return InvalidParameter;
82 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, format);
86 (*format)->align = StringAlignmentNear;
87 (*format)->vertalign = StringAlignmentNear;
92 GpStatus WINGDIPAPI GdipGetStringFormatAlign(GpStringFormat *format,
93 StringAlignment *align)
96 return InvalidParameter;
98 *align = format->align;
103 GpStatus WINGDIPAPI GdipGetStringFormatDigitSubstitution(GDIPCONST GpStringFormat *format,
104 LANGID *language, StringDigitSubstitute *substitute)
107 return InvalidParameter;
109 if(language) *language = format->digitlang;
110 if(substitute) *substitute = format->digitsub;
115 GpStatus WINGDIPAPI GdipGetStringFormatFlags(GDIPCONST GpStringFormat* format,
118 if (!(format && flags))
119 return InvalidParameter;
121 *flags = format->attr;
126 GpStatus WINGDIPAPI GdipGetStringFormatHotkeyPrefix(GDIPCONST GpStringFormat
130 return InvalidParameter;
132 *hkpx = (INT)format->hkprefix;
137 GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat *format,
138 StringAlignment *align)
140 if(!format || !align)
141 return InvalidParameter;
143 *align = format->vertalign;
148 GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(
149 GDIPCONST GpStringFormat *format, INT *count)
151 if (!(format && count))
152 return InvalidParameter;
154 TRACE("%p %p\n", format, count);
156 *count = format->range_count;
161 GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *format,
164 if(!format || !count)
165 return InvalidParameter;
167 *count = format->tabcount;
172 GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat *format, INT count,
173 REAL *firsttab, REAL *tabs)
175 if(!format || !firsttab || !tabs)
176 return InvalidParameter;
178 /* native simply crashes on count < 0 */
180 memcpy(tabs, format->tabs, sizeof(REAL)*count);
182 *firsttab = format->firsttab;
187 GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format,
188 StringTrimming *trimming)
190 if(!format || !trimming)
191 return InvalidParameter;
193 *trimming = format->trimming;
198 GpStatus WINGDIPAPI GdipSetStringFormatAlign(GpStringFormat *format,
199 StringAlignment align)
201 TRACE("(%p, %i)\n", format, align);
204 return InvalidParameter;
206 format->align = align;
211 /*FIXME: digit substitution actually not implemented, get/set only */
212 GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat *format,
213 LANGID language, StringDigitSubstitute substitute)
215 TRACE("(%p, %x, %i)\n", format, language, substitute);
218 return InvalidParameter;
220 format->digitlang = language;
221 format->digitsub = substitute;
226 GpStatus WINGDIPAPI GdipSetStringFormatHotkeyPrefix(GpStringFormat *format,
229 TRACE("(%p, %i)\n", format, hkpx);
231 if(!format || hkpx < 0 || hkpx > 2)
232 return InvalidParameter;
234 format->hkprefix = (HotkeyPrefix) hkpx;
239 GpStatus WINGDIPAPI GdipSetStringFormatLineAlign(GpStringFormat *format,
240 StringAlignment align)
242 TRACE("(%p, %i)\n", format, align);
245 return InvalidParameter;
247 format->vertalign = align;
252 GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(
253 GpStringFormat *format, INT rangeCount, GDIPCONST CharacterRange *ranges)
255 CharacterRange *new_ranges;
257 if (!(format && ranges))
258 return InvalidParameter;
260 TRACE("%p, %d, %p\n", format, rangeCount, ranges);
262 new_ranges = GdipAlloc(rangeCount * sizeof(CharacterRange));
266 GdipFree(format->character_ranges);
267 format->character_ranges = new_ranges;
268 memcpy(format->character_ranges, ranges, sizeof(CharacterRange) * rangeCount);
269 format->range_count = rangeCount;
274 GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat *format, REAL firsttab,
275 INT count, GDIPCONST REAL *tabs)
277 TRACE("(%p, %0.2f, %i, %p)\n", format, firsttab, count, tabs);
280 return InvalidParameter;
283 if(firsttab < 0.0) return NotImplemented;
284 /* first time allocation */
285 if(format->tabcount == 0){
286 format->tabs = GdipAlloc(sizeof(REAL)*count);
291 if((format->tabcount < count) && (format->tabcount > 0)){
293 ptr = HeapReAlloc(GetProcessHeap(), 0, format->tabs, sizeof(REAL)*count);
298 format->firsttab = firsttab;
299 format->tabcount = count;
300 memcpy(format->tabs, tabs, sizeof(REAL)*count);
306 GpStatus WINGDIPAPI GdipSetStringFormatTrimming(GpStringFormat *format,
307 StringTrimming trimming)
309 TRACE("(%p, %i)\n", format, trimming);
312 return InvalidParameter;
314 format->trimming = trimming;
319 GpStatus WINGDIPAPI GdipSetStringFormatFlags(GpStringFormat *format, INT flags)
321 TRACE("(%p, %x)\n", format, flags);
324 return InvalidParameter;
326 format->attr = flags;
331 GpStatus WINGDIPAPI GdipCloneStringFormat(GDIPCONST GpStringFormat *format, GpStringFormat **newFormat)
333 if(!format || !newFormat)
334 return InvalidParameter;
336 *newFormat = GdipAlloc(sizeof(GpStringFormat));
337 if(!*newFormat) return OutOfMemory;
339 **newFormat = *format;
341 if(format->tabcount > 0){
342 (*newFormat)->tabs = GdipAlloc(sizeof(REAL) * format->tabcount);
343 if(!(*newFormat)->tabs){
344 GdipFree(*newFormat);
347 memcpy((*newFormat)->tabs, format->tabs, sizeof(REAL) * format->tabcount);
350 (*newFormat)->tabs = NULL;
352 if(format->range_count > 0){
353 (*newFormat)->character_ranges = GdipAlloc(sizeof(CharacterRange) * format->range_count);
354 if(!(*newFormat)->character_ranges){
355 GdipFree((*newFormat)->tabs);
356 GdipFree(*newFormat);
359 memcpy((*newFormat)->character_ranges, format->character_ranges,
360 sizeof(CharacterRange) * format->range_count);
363 (*newFormat)->character_ranges = NULL;
365 TRACE("%p %p\n",format,newFormat);
370 GpStatus WINGDIPAPI GdipStringFormatGetGenericTypographic(GpStringFormat **format)
375 return InvalidParameter;
377 stat = GdipCreateStringFormat(StringFormatFlagsNoFitBlackBox |
378 StringFormatFlagsLineLimit |
379 StringFormatFlagsNoClip, LANG_NEUTRAL, format);
383 (*format)->digitlang = LANG_NEUTRAL;
384 (*format)->digitsub = StringDigitSubstituteUser;
385 (*format)->trimming = StringTrimmingNone;
386 (*format)->hkprefix = HotkeyPrefixNone;
387 (*format)->align = StringAlignmentNear;
388 (*format)->vertalign = StringAlignmentNear;