Nikolay Sivov : gdiplus: Implemented Gdip[Get/Set] StringFormatTabStops with tests.
Alexandre Julliard
julliard at winehq.org
Wed Jul 30 08:36:02 CDT 2008
Module: wine
Branch: master
Commit: f44034a7d4d4b773e175261b2c13c3b6e99ede18
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f44034a7d4d4b773e175261b2c13c3b6e99ede18
Author: Nikolay Sivov <bunglehead at gmail.com>
Date: Wed Jul 30 15:06:50 2008 +0400
gdiplus: Implemented Gdip[Get/Set]StringFormatTabStops with tests.
---
dlls/gdiplus/gdiplus.spec | 4 +-
dlls/gdiplus/stringformat.c | 45 +++++++++++++++++++++
dlls/gdiplus/tests/stringformat.c | 80 +++++++++++++++++++++++++++++++++++++
include/gdiplusflat.h | 2 +
4 files changed, 129 insertions(+), 2 deletions(-)
diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index e645f06..661cb8f 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -393,7 +393,7 @@
@ stdcall GdipGetStringFormatLineAlign(ptr ptr)
@ stdcall GdipGetStringFormatMeasurableCharacterRangeCount(ptr ptr)
@ stdcall GdipGetStringFormatTabStopCount(ptr ptr)
-@ stub GdipGetStringFormatTabStops
+@ stdcall GdipGetStringFormatTabStops(ptr long ptr ptr)
@ stdcall GdipGetStringFormatTrimming(ptr ptr)
@ stub GdipGetTextContrast
@ stdcall GdipGetTextRenderingHint(ptr ptr)
@@ -591,7 +591,7 @@
@ stdcall GdipSetStringFormatHotkeyPrefix(ptr long)
@ stdcall GdipSetStringFormatLineAlign(ptr long)
@ stdcall GdipSetStringFormatMeasurableCharacterRanges(ptr long ptr)
-@ stub GdipSetStringFormatTabStops
+@ stdcall GdipSetStringFormatTabStops(ptr long long ptr)
@ stdcall GdipSetStringFormatTrimming(ptr long)
@ stub GdipSetTextContrast
@ stdcall GdipSetTextRenderingHint(ptr long)
diff --git a/dlls/gdiplus/stringformat.c b/dlls/gdiplus/stringformat.c
index 2c37d81..2f8a290 100644
--- a/dlls/gdiplus/stringformat.c
+++ b/dlls/gdiplus/stringformat.c
@@ -153,6 +153,21 @@ GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *fo
return Ok;
}
+GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat *format, INT count,
+ REAL *firsttab, REAL *tabs)
+{
+ if(!format || !firsttab || !tabs)
+ return InvalidParameter;
+
+ /* native simply crashes on count < 0 */
+ if(count != 0)
+ memcpy(tabs, format->tabs, sizeof(REAL)*count);
+
+ *firsttab = format->firsttab;
+
+ return Ok;
+}
+
GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format,
StringTrimming *trimming)
{
@@ -221,6 +236,36 @@ GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(GpStringFormat*
return NotImplemented;
}
+GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat *format, REAL firsttab,
+ INT count, GDIPCONST REAL *tabs)
+{
+ if(!format || !tabs)
+ return InvalidParameter;
+
+ if(count > 0){
+ if(firsttab < 0.0) return NotImplemented;
+ /* first time allocation */
+ if(format->tabcount == 0){
+ format->tabs = GdipAlloc(sizeof(REAL)*count);
+ if(!format->tabs)
+ return OutOfMemory;
+ }
+ /* reallocation */
+ if((format->tabcount < count) && (format->tabcount > 0)){
+ REAL *ptr;
+ ptr = HeapReAlloc(GetProcessHeap(), 0, format->tabs, sizeof(REAL)*count);
+ if(!ptr)
+ return OutOfMemory;
+ format->tabs = ptr;
+ }
+ format->firsttab = firsttab;
+ format->tabcount = count;
+ memcpy(format->tabs, tabs, sizeof(REAL)*count);
+ }
+
+ return Ok;
+}
+
GpStatus WINGDIPAPI GdipSetStringFormatTrimming(GpStringFormat *format,
StringTrimming trimming)
{
diff --git a/dlls/gdiplus/tests/stringformat.c b/dlls/gdiplus/tests/stringformat.c
index 376173c..3294304 100644
--- a/dlls/gdiplus/tests/stringformat.c
+++ b/dlls/gdiplus/tests/stringformat.c
@@ -23,6 +23,7 @@
#include "wine/test.h"
#define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
+#define expectf(expected, got) ok(got == expected, "Expected %.2f, got %.2f\n", expected, got)
static void test_constructor(void)
{
@@ -171,11 +172,14 @@ static void test_getgenerictypographic(void)
expect(Ok, stat);
}
+static REAL tabstops[] = {0.0, 10.0, 2.0};
static void test_tabstops(void)
{
GpStringFormat *format;
GpStatus stat;
INT count;
+ REAL tabs[3];
+ REAL firsttab;
stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
expect(Ok, stat);
@@ -188,10 +192,86 @@ static void test_tabstops(void)
stat = GdipGetStringFormatTabStopCount(format, NULL);
expect(InvalidParameter, stat);
+ stat = GdipSetStringFormatTabStops(NULL, 0.0, 0, NULL);
+ expect(InvalidParameter, stat);
+ stat = GdipSetStringFormatTabStops(format, 0.0, 0, NULL);
+ expect(InvalidParameter, stat);
+ stat = GdipSetStringFormatTabStops(NULL, 0.0, 0, tabstops);
+ expect(InvalidParameter, stat);
+
+ stat = GdipGetStringFormatTabStops(NULL, 0, NULL, NULL);
+ expect(InvalidParameter, stat);
+ stat = GdipGetStringFormatTabStops(format, 0, NULL, NULL);
+ expect(InvalidParameter, stat);
+ stat = GdipGetStringFormatTabStops(NULL, 0, &firsttab, NULL);
+ expect(InvalidParameter, stat);
+ stat = GdipGetStringFormatTabStops(NULL, 0, NULL, tabs);
+ expect(InvalidParameter, stat);
+ stat = GdipGetStringFormatTabStops(format, 0, &firsttab, NULL);
+ expect(InvalidParameter, stat);
+ stat = GdipGetStringFormatTabStops(format, 0, NULL, tabs);
+ expect(InvalidParameter, stat);
+
/* not NULL */
stat = GdipGetStringFormatTabStopCount(format, &count);
expect(Ok, stat);
expect(0, count);
+ /* negative tabcount */
+ stat = GdipSetStringFormatTabStops(format, 0.0, -1, tabstops);
+ expect(Ok, stat);
+ count = -1;
+ stat = GdipGetStringFormatTabStopCount(format, &count);
+ expect(Ok, stat);
+ expect(0, count);
+
+ stat = GdipSetStringFormatTabStops(format, -10.0, 0, tabstops);
+ expect(Ok, stat);
+ stat = GdipSetStringFormatTabStops(format, -10.0, 1, tabstops);
+ expect(NotImplemented, stat);
+
+ firsttab = -1.0;
+ tabs[0] = tabs[1] = tabs[2] = -1.0;
+ stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
+ expect(Ok, stat);
+ expectf(-1.0, tabs[0]);
+ expectf(-1.0, tabs[1]);
+ expectf(-1.0, tabs[2]);
+ expectf(0.0, firsttab);
+
+ stat = GdipSetStringFormatTabStops(format, +0.0, 3, tabstops);
+ expect(Ok, stat);
+ count = 0;
+ stat = GdipGetStringFormatTabStopCount(format, &count);
+ expect(Ok, stat);
+ expect(3, count);
+
+ firsttab = -1.0;
+ tabs[0] = tabs[1] = tabs[2] = -1.0;
+ stat = GdipGetStringFormatTabStops(format, 3, &firsttab, tabs);
+ expect(Ok, stat);
+ expectf(0.0, tabs[0]);
+ expectf(10.0, tabs[1]);
+ expectf(2.0, tabs[2]);
+ expectf(0.0, firsttab);
+
+ stat = GdipSetStringFormatTabStops(format, 10.0, 3, tabstops);
+ expect(Ok, stat);
+ firsttab = -1.0;
+ tabs[0] = tabs[1] = tabs[2] = -1.0;
+ stat = GdipGetStringFormatTabStops(format, 0, &firsttab, tabs);
+ expect(Ok, stat);
+ expectf(-1.0, tabs[0]);
+ expectf(-1.0, tabs[1]);
+ expectf(-1.0, tabs[2]);
+ expectf(10.0, firsttab);
+
+ /* zero tabcount, after valid setting to 3 */
+ stat = GdipSetStringFormatTabStops(format, 0.0, 0, tabstops);
+ expect(Ok, stat);
+ count = 0;
+ stat = GdipGetStringFormatTabStopCount(format, &count);
+ expect(Ok, stat);
+ expect(3, count);
stat = GdipDeleteStringFormat(format);
expect(Ok, stat);
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index 9d1e9f1..f5705a7 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -445,6 +445,7 @@ GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat*,StringAlignment
GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(
GDIPCONST GpStringFormat*, INT*);
GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat*,INT*);
+GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat*,INT,REAL*,REAL*);
GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat*,StringTrimming*);
GpStatus WINGDIPAPI GdipSetStringFormatAlign(GpStringFormat*,StringAlignment);
GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat*,LANGID,StringDigitSubstitute);
@@ -452,6 +453,7 @@ GpStatus WINGDIPAPI GdipSetStringFormatHotkeyPrefix(GpStringFormat*,INT);
GpStatus WINGDIPAPI GdipSetStringFormatLineAlign(GpStringFormat*,StringAlignment);
GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(
GpStringFormat*, INT, GDIPCONST CharacterRange*);
+GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat*,REAL,INT,GDIPCONST REAL*);
GpStatus WINGDIPAPI GdipSetStringFormatTrimming(GpStringFormat*,StringTrimming);
GpStatus WINGDIPAPI GdipCloneStringFormat(GDIPCONST GpStringFormat*,GpStringFormat**);
More information about the wine-cvs
mailing list