[PATCH] Test case for Bug 50

Pedro Araujo Chaves Jr. inckie at gmail.com
Fri Feb 2 08:34:31 CST 2007


Attached is the test case I wrote to validate my patch for Bug #50.
The patch itself will be attached in a following message.

Test description:

This test is based on the results of my traces of Lotus Notes R5: in
order to get a long string linewrapped and justified, it first uses
GetTextExtent32() to get the word sequences that fit in a single line
(the paragraph extents); then it calls SetTextJustification() to
disable justification and then again GetTextExtent32(),  in order to
compare this width to the width of the container and get the total
extra space — which should be divided as evenly as possible among the
break characters found in the extent, which is done with a new call to
SetTextJustification() with breakExtra and breakCount. That way, as
expected, a subsequent call to TabbedTextOut() (which in turn calls
ExtTextOutW()) will result in that the text will be rendered
justified, that is, with its break characters widened so that its
width is equal to that of the client area.

The test suceeds if all the extents, except for the last one, which is
likely to be too short to reach the opposite margin, are output with
the same width as the client area.

Note: perhaps it would be better to output the text to a proper
window, but the screen itself should do.

About me: my name is Pedro Araújo and I work for Banco do Brasil; I
was assigned the task of improving the execution under Wine of
applications used by the bank employees — Lotus Notes R5, in the case
of this patch.

Regards,
Pedro Araújo.
-------------- next part --------------
From 4dae39acd90b5c67975af4d1c253eeae8b99f56d Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Pedro_Ara=C3=BAjo_Chaves_J=C3=BAnior?= <pedrojr at pulchra.(none)>
Date: Fri, 2 Feb 2007 12:14:46 -0200
Subject: [PATCH] Test case for Bug 50.
---
 dlls/gdi32/tests/font.c |  115 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index e18bffe..5ac30a2 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -732,6 +732,120 @@ #endif
     ReleaseDC(0, hdc);
 }
 
+void testJustification(HDC hdc, PSTR str, RECT *clientArea)
+{
+    INT         x, y,
+                breakCount,
+                outputWidth = 0,
+                areaWidth = clientArea->right - clientArea->left,
+                nErrors = 0, e;
+    BOOL        lastExtent = FALSE;
+    PSTR        pFirstChar, pLastChar;
+    SIZE        size;
+    TEXTMETRICA tm;
+    struct err
+    {
+        char extent[100];
+        int  width;
+    } error[10];
+
+    GetTextMetricsA(hdc, &tm);
+    y = clientArea->top;
+    do {
+        breakCount = 0;
+        while (*str == tm.tmBreakChar) str++; /* skip leading break chars */
+        pFirstChar = str;
+
+        do {
+            pLastChar = str;
+
+            /* if not at the end of the string, ... */
+            if (*str == '\0') break;
+            /* ... add the next word to the current extent */
+            while (*str != '\0' && *str++ != tm.tmBreakChar);
+            breakCount++;
+            SetTextJustification(hdc, 0, 0);
+            GetTextExtentPoint32(hdc, pFirstChar, str - pFirstChar - 1, &size);
+        } while ((int) size.cx < areaWidth);
+
+        /* ignore trailing break chars */
+        breakCount--;
+        while (*(pLastChar - 1) == tm.tmBreakChar)
+        {
+            pLastChar--;
+            breakCount--;
+        }
+
+        if (*str == '\0' || breakCount <= 0) pLastChar = str;
+
+        SetTextJustification(hdc, 0, 0);
+        GetTextExtentPoint32(hdc, pFirstChar, pLastChar - pFirstChar, &size);
+
+        /* do not justify the last extent */
+        if (*str != '\0' && breakCount > 0)
+            SetTextJustification(
+                    hdc, areaWidth - size.cx, breakCount);
+        else lastExtent = TRUE;
+
+        x = clientArea->left;
+
+        outputWidth = LOWORD(TabbedTextOut(
+                             hdc, x, y, pFirstChar, pLastChar - pFirstChar,
+                             0, NULL, 0));
+        if (!lastExtent && (outputWidth != areaWidth))
+        {
+            memset(error[nErrors].extent, 0, 100);
+            memcpy(error[nErrors].extent, pFirstChar, pLastChar - pFirstChar);
+            error[nErrors].width = outputWidth;
+            nErrors++;
+        }
+
+        y += size.cy;
+        str = pLastChar;
+    } while (*str && y < clientArea->bottom);
+
+    for (e = 0; e < nErrors; e++)
+    {
+todo_wine
+{
+        ok(error[e].width == areaWidth,
+            "The output text (\"%s\") width should be %d, not %d.\n",
+            error[e].extent, areaWidth, error[e].width);
+}
+    }
+}
+
+void test_SetTextJustification()
+{
+    HDC hdc = GetDC(0);
+    RECT clientArea = {0, 0, 400, 400};
+    LOGFONTA lf;
+    HFONT hfont;
+    static char testText[] =
+            "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
+            "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
+            "enim ad minim veniam, quis nostrud exercitation ullamco laboris "
+            "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in "
+            "reprehenderit in voluptate velit esse cillum dolore eu fugiat "
+            "nulla pariatur. Excepteur sint occaecat cupidatat non proident, "
+            "sunt in culpa qui officia deserunt mollit anim id est laborum.";
+
+    memset(&lf, 0, sizeof lf);
+    lf.lfCharSet = ANSI_CHARSET;
+    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+    lf.lfWeight = FW_DONTCARE;
+    lf.lfHeight = 20;
+    lf.lfQuality = DEFAULT_QUALITY;
+    lstrcpyA(lf.lfFaceName, "Times New Roman");
+    hfont = create_font("Times New Roman", &lf);
+    SelectObject(hdc, hfont);
+
+    testJustification(hdc, testText, &clientArea);
+
+    DeleteObject(hfont);
+    ReleaseDC(0, hdc);
+}
+
 START_TEST(font)
 {
     test_logfont();
@@ -742,4 +856,5 @@ START_TEST(font)
     test_text_extents();
     test_GetGlyphIndices();
     test_GetKerningPairs();
+    test_SetTextJustification();
 }
-- 
1.4.1


More information about the wine-patches mailing list