src/win32/gdi.cpp in rays-0.1.3 vs src/win32/gdi.cpp in rays-0.1.4

- old
+ new

@@ -264,40 +264,49 @@ static bool calc_size ( coord* width, coord* height, HDC hdc, const char* str) { - if ((!width && !height) || !hdc || !str) return false; + if (!width || !height || !hdc || !str) return false; + bool empty = *str == '\0'; + if (empty) str = " "; + RECT rect = {0, 0, 0, 0}; - BOOL ret = DrawTextA( - hdc, str, (int) strlen(str), &rect, + int ret = DrawTextA( + hdc, str, -1, &rect, DT_EXPANDTABS | DT_NOPREFIX | DT_CALCRECT); - if (!ret) return false; - if (width) *width = rect.right - rect.left; - if (height) *height = rect.bottom - rect.top; - + *width = empty ? 0 : rect.right - rect.left; + *height = rect.bottom - rect.top; return true; } bool Font::get_extent ( coord* width, coord* height, const char* str, HDC hdc) { - if (!*this || (!width && !height) || !str) + if (!*this || (!width && !height)) return false; + if (width) *width = 0; + if (height) *height = 0; + DC dc = hdc ? DC(hdc) : screen_dc(); if (!dc) return false; + coord w = 0, h = 0; + Font old = dc.font(); dc.set_font(*this); - bool ret = calc_size(width, height, dc.handle(), str); + bool ret = calc_size(&w, &h, dc.handle(), str); dc.set_font(old); + if (width) *width = w; + if (height) *height = h; + return ret; } String Font::name () const @@ -425,22 +434,22 @@ struct DCState { HPEN hpen; - Pen pen; + Pen pen; HBRUSH hbrush; - Brush brush; + Brush brush; HFONT hfont; - Font font; + Font font; HBITMAP hbitmap; - Bitmap bitmap; + Bitmap bitmap; COLORREF textcolor, backcolor; int backmode;