Commit 44e98392 authored by Evan Stade's avatar Evan Stade Committed by Alexandre Julliard

gdiplus: Handle empty layout rectangle in GdipMeasureString.

parent d4107db6
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <math.h> #include <math.h>
#include <limits.h>
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
...@@ -1716,6 +1717,10 @@ GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix ...@@ -1716,6 +1717,10 @@ GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix
return Ok; return Ok;
} }
/* Find the smallest rectangle that bounds the text when it is printed in rect
* according to the format options listed in format. If rect has 0 width and
* height, then just find the smallest rectangle that bounds the text when it's
* printed at location (rect->X, rect-Y). */
GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds, GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
...@@ -1723,7 +1728,8 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, ...@@ -1723,7 +1728,8 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
{ {
HFONT oldfont; HFONT oldfont;
WCHAR* stringdup; WCHAR* stringdup;
INT sum = 0, height = 0, fit, fitcpy, max_width = 0, i, j, lret, nwidth; INT sum = 0, height = 0, fit, fitcpy, max_width = 0, i, j, lret, nwidth,
nheight;
SIZE size; SIZE size;
if(!graphics || !string || !font || !rect) if(!graphics || !string || !font || !rect)
...@@ -1744,6 +1750,10 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, ...@@ -1744,6 +1750,10 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw)); oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
nwidth = roundr(rect->Width); nwidth = roundr(rect->Width);
nheight = roundr(rect->Height);
if((nwidth == 0) && (nheight == 0))
nwidth = nheight = INT_MAX;
for(i = 0, j = 0; i < length; i++){ for(i = 0, j = 0; i < length; i++){
if(!isprintW(string[i]) && (string[i] != '\n')) if(!isprintW(string[i]) && (string[i] != '\n'))
...@@ -1796,7 +1806,7 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, ...@@ -1796,7 +1806,7 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
height += size.cy; height += size.cy;
max_width = max(max_width, size.cx); max_width = max(max_width, size.cx);
if(height > roundr(rect->Height)) if(height > nheight)
break; break;
/* Stop if this was a linewrap (but not if it was a linebreak). */ /* Stop if this was a linewrap (but not if it was a linebreak). */
...@@ -1807,7 +1817,7 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, ...@@ -1807,7 +1817,7 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
bounds->X = rect->X; bounds->X = rect->X;
bounds->Y = rect->Y; bounds->Y = rect->Y;
bounds->Width = (REAL)max_width; bounds->Width = (REAL)max_width;
bounds->Height = min((REAL)height, rect->Height); bounds->Height = (REAL) min(height, nheight);
DeleteObject(SelectObject(graphics->hdc, oldfont)); DeleteObject(SelectObject(graphics->hdc, oldfont));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment