[1/4] gdiplus: GdipGetStringFormatTabStopCount implementation with tests

Nikolay Sivov bunglehead at gmail.com
Wed Jul 30 06:06:39 CDT 2008


Changelog:
    - data members for StringFormat tabstops added
    - constructor/copy constructor/destructor modified
    - GdipGetStringFormatTabStopCount implementation
    - existing tests expanded with tab count check, added new for GdipGetStringFormatTabStopCount
---
 dlls/gdiplus/gdiplus.spec         |    2 +-
 dlls/gdiplus/gdiplus_private.h    |    3 +++
 dlls/gdiplus/stringformat.c       |   28 +++++++++++++++++++++++++++-
 dlls/gdiplus/tests/stringformat.c |   30 ++++++++++++++++++++++++++++++
 include/gdiplusflat.h             |    1 +
 5 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 0579ebe..e645f06 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -392,7 +392,7 @@
 @ stdcall GdipGetStringFormatHotkeyPrefix(ptr ptr)
 @ stdcall GdipGetStringFormatLineAlign(ptr ptr)
 @ stdcall GdipGetStringFormatMeasurableCharacterRangeCount(ptr ptr)
-@ stub GdipGetStringFormatTabStopCount
+@ stdcall GdipGetStringFormatTabStopCount(ptr ptr)
 @ stub GdipGetStringFormatTabStops
 @ stdcall GdipGetStringFormatTrimming(ptr ptr)
 @ stub GdipGetTextContrast
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index cb5f821..b445a58 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -194,6 +194,9 @@ struct GpStringFormat{
     HotkeyPrefix hkprefix;
     StringAlignment vertalign;
     StringDigitSubstitute digitsub;
+    INT tabcount;
+    REAL firsttab;
+    REAL *tabs;
 };
 
 struct GpFontCollection{
diff --git a/dlls/gdiplus/stringformat.c b/dlls/gdiplus/stringformat.c
index 1be075b..2c37d81 100644
--- a/dlls/gdiplus/stringformat.c
+++ b/dlls/gdiplus/stringformat.c
@@ -46,6 +46,10 @@ GpStatus WINGDIPAPI GdipCreateStringFormat(INT attr, LANGID lang,
     (*format)->digitlang = LANG_NEUTRAL;
     (*format)->trimming = StringTrimmingCharacter;
     (*format)->digitsub = StringDigitSubstituteUser;
+    /* tabstops */
+    (*format)->tabcount = 0;
+    (*format)->firsttab = 0.0;
+    (*format)->tabs = NULL;
 
     return Ok;
 }
@@ -55,6 +59,7 @@ GpStatus WINGDIPAPI GdipDeleteStringFormat(GpStringFormat *format)
     if(!format)
         return InvalidParameter;
 
+    GdipFree(format->tabs);
     GdipFree(format);
 
     return Ok;
@@ -137,6 +142,17 @@ GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(
     return NotImplemented;
 }
 
+GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *format,
+    INT *count)
+{
+    if(!format || !count)
+        return InvalidParameter;
+
+    *count = format->tabcount;
+
+    return Ok;
+}
+
 GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format,
     StringTrimming *trimming)
 {
@@ -233,12 +249,22 @@ GpStatus WINGDIPAPI GdipCloneStringFormat(GDIPCONST GpStringFormat *format, GpSt
 
     **newFormat = *format;
 
+    if(format->tabcount > 0){
+        (*newFormat)->tabs = GdipAlloc(sizeof(REAL) * format->tabcount);
+        if(!(*newFormat)->tabs){
+            GdipFree(*newFormat);
+            return OutOfMemory;
+        }
+        memcpy((*newFormat)->tabs, format->tabs, sizeof(REAL) * format->tabcount);
+    }
+    else
+        (*newFormat)->tabs = NULL;
+
     TRACE("%p %p\n",format,newFormat);
 
     return Ok;
 }
 
-/*FIXME: add zero tab stops number */
 GpStatus WINGDIPAPI GdipStringFormatGetGenericTypographic(GpStringFormat **format)
 {
     GpStatus stat;
diff --git a/dlls/gdiplus/tests/stringformat.c b/dlls/gdiplus/tests/stringformat.c
index ae93104..451cdf3 100644
--- a/dlls/gdiplus/tests/stringformat.c
+++ b/dlls/gdiplus/tests/stringformat.c
@@ -140,6 +140,7 @@ static void test_getgenerictypographic(void)
     StringTrimming trimming;
     StringDigitSubstitute digitsub;
     LANGID digitlang;
+    INT tabcount;
 
     /* NULL arg */
     stat = GdipStringFormatGetGenericTypographic(NULL);
@@ -154,6 +155,7 @@ static void test_getgenerictypographic(void)
     GdipGetStringFormatHotkeyPrefix(format, &n);
     GdipGetStringFormatTrimming(format, &trimming);
     GdipGetStringFormatDigitSubstitution(format, &digitlang, &digitsub);
+    GdipGetStringFormatTabStopCount(format, &tabcount);
 
     expect((StringFormatFlagsNoFitBlackBox |StringFormatFlagsLineLimit | StringFormatFlagsNoClip),
             flags);
@@ -163,11 +165,38 @@ static void test_getgenerictypographic(void)
     expect(StringTrimmingNone, trimming);
     expect(StringDigitSubstituteUser, digitsub);
     expect(LANG_NEUTRAL, digitlang);
+    expect(0, tabcount);
 
     stat = GdipDeleteStringFormat(format);
     expect(Ok, stat);
 }
 
+static void test_tabstops(void)
+{
+    GpStringFormat *format;
+    GpStatus stat;
+    INT count;
+    
+    stat = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
+    expect(Ok, stat);
+
+    /* NULL */
+    stat = GdipGetStringFormatTabStopCount(NULL, NULL);
+    expect(InvalidParameter, stat);
+    stat = GdipGetStringFormatTabStopCount(NULL, &count);
+    expect(InvalidParameter, stat);
+    stat = GdipGetStringFormatTabStopCount(format, NULL);
+    expect(InvalidParameter, stat);
+
+    /* not NULL */
+    stat = GdipGetStringFormatTabStopCount(format, &count);
+    expect(Ok, stat);
+    expect(0, count);
+
+    stat = GdipDeleteStringFormat(format);
+    expect(Ok, stat);    
+}
+
 START_TEST(stringformat)
 {
     struct GdiplusStartupInput gdiplusStartupInput;
@@ -184,6 +213,7 @@ START_TEST(stringformat)
     test_characterrange();
     test_digitsubstitution();
     test_getgenerictypographic();
+    test_tabstops();
 
     GdiplusShutdown(gdiplusToken);
 }
diff --git a/include/gdiplusflat.h b/include/gdiplusflat.h
index 963c9c6..9d1e9f1 100644
--- a/include/gdiplusflat.h
+++ b/include/gdiplusflat.h
@@ -444,6 +444,7 @@ GpStatus WINGDIPAPI GdipGetStringFormatHotkeyPrefix(GDIPCONST GpStringFormat*,IN
 GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat*,StringAlignment*);
 GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(
         GDIPCONST GpStringFormat*, INT*);
+GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat*,INT*);
 GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat*,StringTrimming*);
 GpStatus WINGDIPAPI GdipSetStringFormatAlign(GpStringFormat*,StringAlignment);
 GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat*,LANGID,StringDigitSubstitute);
-- 
1.4.4.4






More information about the wine-patches mailing list