Mercurial > projects > dwt-win
diff dwt/graphics/GC.d @ 25:d6fa61ac6912
GC
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 27 Jan 2008 23:17:22 +0100 |
parents | 7b3e88548661 |
children | 9a64a7781bab |
line wrap: on
line diff
--- a/dwt/graphics/GC.d Sun Jan 27 20:29:00 2008 +0100 +++ b/dwt/graphics/GC.d Sun Jan 27 23:17:22 2008 +0100 @@ -54,6 +54,7 @@ import dwt.graphics.Transform; import dwt.graphics.LineAttributes; +import dwt.dwthelper.utils; import tango.text.convert.Format; /** @@ -1479,22 +1480,22 @@ if (isDib) { /* Palette-based DIBSECTION */ if (OS.IsWinCE) { - byte[] pBits = new byte[1]; - OS.MoveMemory(pBits, bm.bmBits, 1); + byte* pBits = cast(byte*)bm.bmBits; + //OS.MoveMemory(pBits, bm.bmBits, 1); byte oldValue = pBits[0]; int mask = (0xFF << (8 - bm.bmBitsPixel)) & 0x00FF; pBits[0] = cast(byte)((srcImage.transparentPixel << (8 - bm.bmBitsPixel)) | (pBits[0] & ~mask)); - OS.MoveMemory(bm.bmBits, pBits, 1); + //OS.MoveMemory(bm.bmBits, pBits, 1); int color = OS.GetPixel(srcHdc, 0, 0); pBits[0] = oldValue; - OS.MoveMemory(bm.bmBits, pBits, 1); + //OS.MoveMemory(bm.bmBits, pBits, 1); transBlue = (color & 0xFF0000) >> 16; transGreen = (color & 0xFF00) >> 8; transRed = color & 0xFF; } else { int maxColors = 1 << bm.bmBitsPixel; byte[] oldColors = new byte[maxColors * 4]; - OS.GetDIBColorTable(srcHdc, 0, maxColors, oldColors); + OS.GetDIBColorTable(srcHdc, 0, maxColors, cast(RGBQUAD*)oldColors.ptr); int offset = srcImage.transparentPixel * 4; bool fixPalette = false; for (int i = 0; i < oldColors.length; i += 4) { @@ -1511,7 +1512,7 @@ newColors[offset] = cast(byte)transBlue; newColors[offset+1] = cast(byte)transGreen; newColors[offset+2] = cast(byte)transRed; - OS.SetDIBColorTable(srcHdc, 0, maxColors, newColors); + OS.SetDIBColorTable(srcHdc, 0, maxColors, cast(RGBQUAD*)newColors.ptr); originalColors = oldColors; } else { transBlue = oldColors[offset] & 0xFF; @@ -1523,14 +1524,14 @@ /* Palette-based bitmap */ int numColors = 1 << bm.bmBitsPixel; /* Set the few fields necessary to get the RGB data out */ - BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER(); + BITMAPINFOHEADER bmiHeader; bmiHeader.biSize = BITMAPINFOHEADER.sizeof; bmiHeader.biPlanes = bm.bmPlanes; bmiHeader.biBitCount = bm.bmBitsPixel; byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4]; - OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof); + bmi[] = (cast(byte*)&bmiHeader)[ 0 .. BITMAPINFOHEADER.sizeof ]; if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); - OS.GetDIBits(srcHdc, srcImage.handle, 0, 0, 0, bmi, OS.DIB_RGB_COLORS); + OS.GetDIBits(srcHdc, srcImage.handle, 0, 0, null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS); int offset = BITMAPINFOHEADER.sizeof + 4 * srcImage.transparentPixel; transRed = bmi[offset + 2] & 0xFF; transGreen = bmi[offset + 1] & 0xFF; @@ -1559,7 +1560,7 @@ } int transparentColor = transBlue << 16 | transGreen << 8 | transRed; - if (OS.IsWinCE) { + static if (OS.IsWinCE) { /* * Note in WinCE. TransparentImage uses the first entry of a palette * based image when there are multiple entries that have the same @@ -1577,7 +1578,7 @@ auto oldMaskBitmap = OS.SelectObject(maskHdc, maskBitmap); OS.SetBkColor(srcHdc, transparentColor); OS.BitBlt(maskHdc, 0, 0, imgWidth, imgHeight, srcHdc, 0, 0, OS.SRCCOPY); - if (originalColors !is null) OS.SetDIBColorTable(srcHdc, 0, 1 << bm.bmBitsPixel, originalColors); + if (originalColors !is null) OS.SetDIBColorTable(srcHdc, 0, 1 << bm.bmBitsPixel, cast(RGBQUAD*)originalColors.ptr); if (OS.GetDeviceCaps(handle, OS.TECHNOLOGY) is OS.DT_RASPRINTER) { /* Most printers do not support BitBlt(), draw the source bitmap transparently using clipping */ @@ -1666,9 +1667,9 @@ } if (OS.IsWinCE) { int [] points = [x1, y1, x2, y2]; - OS.Polyline (handle, points, points.length / 2); + OS.Polyline (handle, cast(POINT*)points.ptr, points.length / 2); } else { - OS.MoveToEx (handle, x1, y1, 0); + OS.MoveToEx (handle, x1, y1, null); OS.LineTo (handle, x2, y2); } if (data.lineWidth <= 1) { @@ -1810,7 +1811,7 @@ } } } - OS.Polygon(handle, pointArray, pointArray.length / 2); + OS.Polygon(handle, cast(POINT*)pointArray.ptr, pointArray.length / 2); if ((data.style & DWT.MIRRORED) !is 0) { if (data.lineWidth !is 0 && data.lineWidth % 2 is 0) { for (int i = 0; i < pointArray.length; i+=2) { @@ -1844,7 +1845,7 @@ auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); - Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, pointArray, pointArray.length / 2); + Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2); Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } @@ -1855,7 +1856,7 @@ } } } - OS.Polyline(handle, pointArray, pointArray.length / 2); + OS.Polyline(handle, cast(POINT*)pointArray.ptr, pointArray.length / 2); int length_ = pointArray.length; if (length_ >= 2) { if (data.lineWidth <= 1) { @@ -1904,7 +1905,7 @@ if (data.lineWidth > 1) { if ((data.lineWidth % 2) is 1) x++; } else { - if (data.hPen !is null && OS.GetObject(data.hPen, 0, 0) !is LOGPEN.sizeof) { + if (data.hPen !is null && OS.GetObject(data.hPen, 0, null) !is LOGPEN.sizeof) { x++; } } @@ -2007,7 +2008,7 @@ } } -void drawRoundRectangleGdip (int gdipGraphics, int pen, int x, int y, int width, int height, int arcWidth, int arcHeight) { +void drawRoundRectangleGdip (Gdip.Graphics* gdipGraphics, Gdip.Pen* pen, int x, int y, int width, int height, int arcWidth, int arcHeight) { int nx = x; int ny = y; int nw = width; @@ -2101,33 +2102,34 @@ if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); // TCHAR buffer = new TCHAR (getCodePage(), string, false); - int length_ = string.length; + wchar[] wstr = StrToWCHARs( string ); + int length_ = wstr.length; if (length_ is 0) return; - char[] buffer = new char [length_]; - string.getChars(0, length_, buffer, 0); + wchar* buffer = wstr.ptr; auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { checkGC(FONT | FOREGROUND | (isTransparent ? 0 : BACKGROUND)); - PointF pt = new PointF(); - int format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); + Gdip.PointF pt; + auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces; if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; Gdip.StringFormat_SetFormatFlags(format, formatFlags); if (!isTransparent) { - RectF bounds = new RectF(); - Gdip.Graphics_MeasureString(gdipGraphics, buffer, length_, data.gdipFont, pt, format, bounds); - Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.round(bounds.Width), Math.round(bounds.Height)); + Gdip.RectF bounds; + Gdip.Graphics_MeasureString(gdipGraphics, buffer, length_, data.gdipFont, pt, format, &bounds); + Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.rndint(bounds.Width), Math.rndint(bounds.Height)); } - int gstate = 0, brush = getFgBrush(); + int gstate = 0; + auto brush = getFgBrush(); if ((data.style & DWT.MIRRORED) !is 0) { switch (Gdip.Brush_GetType(brush)) { case Gdip.BrushTypeLinearGradient: - Gdip.LinearGradientBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend); - Gdip.LinearGradientBrush_TranslateTransform(brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); + Gdip.LinearGradientBrush_ScaleTransform(cast(Gdip.LinearGradientBrush*)brush, -1, 1, Gdip.MatrixOrderPrepend); + Gdip.LinearGradientBrush_TranslateTransform(cast(Gdip.LinearGradientBrush*)brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); break; case Gdip.BrushTypeTextureFill: - Gdip.TextureBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend); - Gdip.TextureBrush_TranslateTransform(brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); + Gdip.TextureBrush_ScaleTransform(cast(Gdip.TextureBrush*)brush, -1, 1, Gdip.MatrixOrderPrepend); + Gdip.TextureBrush_TranslateTransform(cast(Gdip.TextureBrush*)brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); break; } gstate = Gdip.Graphics_Save(gdipGraphics); @@ -2140,10 +2142,10 @@ if ((data.style & DWT.MIRRORED) !is 0) { switch (Gdip.Brush_GetType(brush)) { case Gdip.BrushTypeLinearGradient: - Gdip.LinearGradientBrush_ResetTransform(brush); + Gdip.LinearGradientBrush_ResetTransform(cast(Gdip.LinearGradientBrush*)brush); break; case Gdip.BrushTypeTextureFill: - Gdip.TextureBrush_ResetTransform(brush); + Gdip.TextureBrush_ResetTransform(cast(Gdip.TextureBrush*)brush); break; } Gdip.Graphics_Restore(gdipGraphics, gstate); @@ -2160,14 +2162,14 @@ } checkGC(FONT | FOREGROUND_TEXT | BACKGROUND_TEXT); int oldBkMode = OS.SetBkMode(handle, isTransparent ? OS.TRANSPARENT : OS.OPAQUE); - RECT rect = null; - SIZE size = null; + RECT rect; + SIZE size; + bool sizeValid = false; int flags = 0; if ((data.style & DWT.MIRRORED) !is 0) { if (!isTransparent) { - size = new SIZE(); - OS.GetTextExtentPoint32W(handle, buffer, length_, size); - rect = new RECT (); + sizeValid = true; + OS.GetTextExtentPoint32W(handle, buffer, length_, &size); rect.left = x; rect.right = x + size.cx; rect.top = y; @@ -2177,19 +2179,18 @@ x--; } if (rop2 !is OS.R2_XORPEN) { - OS.ExtTextOutW(handle, x, y, flags, rect, buffer, length_, null); + OS.ExtTextOutW(handle, x, y, flags, &rect, buffer, length_, null); } else { int foreground = OS.GetTextColor(handle); if (isTransparent) { - if (size is null) { - size = new SIZE(); - OS.GetTextExtentPoint32W(handle, buffer, length_, size); + if (!sizeValid) { + OS.GetTextExtentPoint32W(handle, buffer, length_, &size); } int width = size.cx, height = size.cy; - int hBitmap = OS.CreateCompatibleBitmap(handle, width, height); + auto hBitmap = OS.CreateCompatibleBitmap(handle, width, height); if (hBitmap is null) DWT.error(DWT.ERROR_NO_HANDLES); - int memDC = OS.CreateCompatibleDC(handle); - int hOldBitmap = OS.SelectObject(memDC, hBitmap); + auto memDC = OS.CreateCompatibleDC(handle); + auto hOldBitmap = OS.SelectObject(memDC, hBitmap); OS.PatBlt(memDC, 0, 0, width, height, OS.BLACKNESS); OS.SetBkMode(memDC, OS.TRANSPARENT); OS.SetTextColor(memDC, foreground); @@ -2200,9 +2201,9 @@ OS.DeleteDC(memDC); OS.DeleteObject(hBitmap); } else { - int background = OS.GetBkColor(handle); + auto background = OS.GetBkColor(handle); OS.SetTextColor(handle, foreground ^ background); - OS.ExtTextOutW(handle, x, y, flags, rect, buffer, length_, null); + OS.ExtTextOutW(handle, x, y, flags, &rect, buffer, length_, null); OS.SetTextColor(handle, foreground); } } @@ -2298,34 +2299,35 @@ auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { checkGC(FONT | FOREGROUND | ((flags & DWT.DRAW_TRANSPARENT) !is 0 ? 0 : BACKGROUND)); - int length_ = string.length; - char[] buffer = new char [length_]; - string.getChars(0, length_, buffer, 0); - PointF pt = new PointF(); - int format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); + wchar[] wstr = StrToWCHARs( string ); + int length_ = wstr.length; + wchar* buffer = wstr.ptr; + Gdip.PointF pt; + auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces; if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; Gdip.StringFormat_SetFormatFlags(format, formatFlags); - float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [measureSpace(data.gdipFont, format) * 8] : new float[1]; - Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); + float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [ cast(float) measureSpace(data.gdipFont, format) * 8] : new float[1]; + Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr); int hotkeyPrefix = (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone; if ((flags & DWT.DRAW_MNEMONIC) !is 0 && (data.uiState & OS.UISF_HIDEACCEL) !is 0) hotkeyPrefix = Gdip.HotkeyPrefixHide; Gdip.StringFormat_SetHotkeyPrefix(format, hotkeyPrefix); if ((flags & DWT.DRAW_TRANSPARENT) is 0) { - RectF bounds = new RectF(); - Gdip.Graphics_MeasureString(gdipGraphics, buffer, length_, data.gdipFont, pt, format, bounds); - Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.round(bounds.Width), Math.round(bounds.Height)); + Gdip.RectF bounds; + Gdip.Graphics_MeasureString(gdipGraphics, buffer, length_, data.gdipFont, pt, format, &bounds); + Gdip.Graphics_FillRectangle(gdipGraphics, data.gdipBrush, x, y, Math.rndint(bounds.Width), Math.rndint(bounds.Height)); } - int gstate = 0, brush = getFgBrush(); + int gstate = 0; + auto brush = getFgBrush(); if ((data.style & DWT.MIRRORED) !is 0) { switch (Gdip.Brush_GetType(brush)) { case Gdip.BrushTypeLinearGradient: - Gdip.LinearGradientBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend); - Gdip.LinearGradientBrush_TranslateTransform(brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); + Gdip.LinearGradientBrush_ScaleTransform(cast(Gdip.LinearGradientBrush*)brush, -1, 1, Gdip.MatrixOrderPrepend); + Gdip.LinearGradientBrush_TranslateTransform(cast(Gdip.LinearGradientBrush*)brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); break; case Gdip.BrushTypeTextureFill: - Gdip.TextureBrush_ScaleTransform(brush, -1, 1, Gdip.MatrixOrderPrepend); - Gdip.TextureBrush_TranslateTransform(brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); + Gdip.TextureBrush_ScaleTransform(cast(Gdip.TextureBrush*)brush, -1, 1, Gdip.MatrixOrderPrepend); + Gdip.TextureBrush_TranslateTransform(cast(Gdip.TextureBrush*)brush, - 2 * x, 0, Gdip.MatrixOrderPrepend); break; } gstate = Gdip.Graphics_Save(gdipGraphics); @@ -2338,10 +2340,10 @@ if ((data.style & DWT.MIRRORED) !is 0) { switch (Gdip.Brush_GetType(brush)) { case Gdip.BrushTypeLinearGradient: - Gdip.LinearGradientBrush_ResetTransform(brush); + Gdip.LinearGradientBrush_ResetTransform(cast(Gdip.LinearGradientBrush*)brush); break; case Gdip.BrushTypeTextureFill: - Gdip.TextureBrush_ResetTransform(brush); + Gdip.TextureBrush_ResetTransform(cast(Gdip.TextureBrush*)brush); break; } Gdip.Graphics_Restore(gdipGraphics, gstate); @@ -2349,10 +2351,11 @@ Gdip.StringFormat_delete(format); return; } - TCHAR buffer = new TCHAR(getCodePage(), string, false); - int length_ = buffer.length(); + TCHAR[] wstr = StrToTCHARs( string ); + TCHAR* buffer = wstr.ptr; + int length_ = wstr.length; if (length_ is 0) return; - RECT rect = new RECT(); + RECT rect; /* * Feature in Windows. For some reason DrawText(), the maximum * value for the bottom and right coordinates for the RECT that @@ -2364,7 +2367,7 @@ * larger limit on the other Windows platforms. */ int limit = OS.IsWin95 ? 0x7FFF : 0x6FFFFFF; - OS.SetRect(rect, x, y, limit, limit); + OS.SetRect(&rect, x, y, limit, limit); int uFormat = OS.DT_LEFT; if ((flags & DWT.DRAW_DELIMITER) is 0) uFormat |= OS.DT_SINGLELINE; if ((flags & DWT.DRAW_TAB) !is 0) uFormat |= OS.DT_EXPANDTABS; @@ -2382,23 +2385,23 @@ checkGC(FONT | FOREGROUND_TEXT | BACKGROUND_TEXT); int oldBkMode = OS.SetBkMode(handle, (flags & DWT.DRAW_TRANSPARENT) !is 0 ? OS.TRANSPARENT : OS.OPAQUE); if (rop2 !is OS.R2_XORPEN) { - OS.DrawText(handle, buffer, length_, rect, uFormat); + OS.DrawText(handle, buffer, length_, &rect, uFormat); } else { int foreground = OS.GetTextColor(handle); if ((flags & DWT.DRAW_TRANSPARENT) !is 0) { - OS.DrawText(handle, buffer, buffer.length(), rect, uFormat | OS.DT_CALCRECT); + OS.DrawText(handle, buffer, length_, &rect, uFormat | OS.DT_CALCRECT); int width = rect.right - rect.left; int height = rect.bottom - rect.top; auto hBitmap = OS.CreateCompatibleBitmap(handle, width, height); if (hBitmap is null) DWT.error(DWT.ERROR_NO_HANDLES); - int memDC = OS.CreateCompatibleDC(handle); - int hOldBitmap = OS.SelectObject(memDC, hBitmap); + auto memDC = OS.CreateCompatibleDC(handle); + auto hOldBitmap = OS.SelectObject(memDC, hBitmap); OS.PatBlt(memDC, 0, 0, width, height, OS.BLACKNESS); OS.SetBkMode(memDC, OS.TRANSPARENT); OS.SetTextColor(memDC, foreground); OS.SelectObject(memDC, OS.GetCurrentObject(handle, OS.OBJ_FONT)); - OS.SetRect(rect, 0, 0, 0x7FFF, 0x7FFF); - OS.DrawText(memDC, buffer, length_, rect, uFormat); + OS.SetRect(&rect, 0, 0, 0x7FFF, 0x7FFF); + OS.DrawText(memDC, buffer, length_, &rect, uFormat); OS.BitBlt(handle, x, y, width, height, memDC, 0, 0, OS.SRCINVERT); OS.SelectObject(memDC, hOldBitmap); OS.DeleteDC(memDC); @@ -2406,7 +2409,7 @@ } else { int background = OS.GetBkColor(handle); OS.SetTextColor(handle, foreground ^ background); - OS.DrawText(handle, buffer, length_, rect, uFormat); + OS.DrawText(handle, buffer, length_, &rect, uFormat); OS.SetTextColor(handle, foreground); } } @@ -2513,7 +2516,7 @@ points[0] = points[points.length - 2] = cteX >> 1; points[1] = points[points.length - 1] = cteY >> 1; } - OS.Polygon(handle, points, points.length / 2); + OS.Polygon(handle, cast(POINT*)points.ptr, points.length / 2); } else { int x1, y1, x2, y2,tmp; bool isNegative; @@ -2585,13 +2588,13 @@ fromRGB = backgroundRGB; toRGB = foregroundRGB; } - if (fromRGB.equals(toRGB)) { + if (fromRGB ==/*eq*/ toRGB) { fillRectangle(x, y, width, height); return; } if (data.gdipGraphics !is null) { initGdip(); - PointF p1= new PointF(), p2 = new PointF(); + Gdip.PointF p1, p2; p1.X = x; p1.Y = y; if (vertical) { @@ -2607,8 +2610,8 @@ rgb = ((toRGB.red & 0xFF) << 16) | ((toRGB.green & 0xFF) << 8) | (toRGB.blue & 0xFF); auto toGpColor = Gdip.Color_new(data.alpha << 24 | rgb); if (toGpColor is null) DWT.error(DWT.ERROR_NO_HANDLES); - int brush = Gdip.LinearGradientBrush_new(p1, p2, fromGpColor, toGpColor); - Gdip.Graphics_FillRectangle(data.gdipGraphics, brush, x, y, width, height); + auto brush = Gdip.LinearGradientBrush_new(p1, p2, fromGpColor, toGpColor); + Gdip.Graphics_FillRectangle(data.gdipGraphics, cast(Gdip.Brush*)brush, x, y, width, height); Gdip.LinearGradientBrush_delete(brush); Gdip.Color_delete(fromGpColor); Gdip.Color_delete(toGpColor); @@ -2634,31 +2637,30 @@ final auto hHeap = OS.GetProcessHeap(); final auto pMesh = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, GRADIENT_RECT.sizeof + TRIVERTEX.sizeof * 2); if (pMesh is null) DWT.error(DWT.ERROR_NO_HANDLES); - final int pVertex = pMesh + GRADIENT_RECT.sizeof; + auto pVertex = cast(TRIVERTEX*)( pMesh + GRADIENT_RECT.sizeof ); - GRADIENT_RECT gradientRect = new GRADIENT_RECT(); + GRADIENT_RECT gradientRect; gradientRect.UpperLeft = 0; gradientRect.LowerRight = 1; - OS.MoveMemory(pMesh, gradientRect, GRADIENT_RECT.sizeof); + *cast(GRADIENT_RECT*)pMesh = gradientRect; - TRIVERTEX trivertex = new TRIVERTEX(); + TRIVERTEX* trivertex = pVertex; trivertex.x = x; trivertex.y = y; trivertex.Red = cast(short)((fromRGB.red << 8) | fromRGB.red); trivertex.Green = cast(short)((fromRGB.green << 8) | fromRGB.green); trivertex.Blue = cast(short)((fromRGB.blue << 8) | fromRGB.blue); - trivertex.Alpha = -1; - OS.MoveMemory(pVertex, trivertex, TRIVERTEX.sizeof); + trivertex.Alpha = ushort.max; + trivertex = pVertex+1; trivertex.x = x + width; trivertex.y = y + height; trivertex.Red = cast(short)((toRGB.red << 8) | toRGB.red); trivertex.Green = cast(short)((toRGB.green << 8) | toRGB.green); trivertex.Blue = cast(short)((toRGB.blue << 8) | toRGB.blue); - trivertex.Alpha = -1; - OS.MoveMemory(pVertex + TRIVERTEX.sizeof, trivertex, TRIVERTEX.sizeof); + trivertex.Alpha = ushort.max; - bool success = OS.GradientFill(handle, pVertex, 2, pMesh, 1, vertical ? OS.GRADIENT_FILL_RECT_V : OS.GRADIENT_FILL_RECT_H); + bool success = cast(bool)OS.GradientFill(handle, pVertex, 2, pMesh, 1, vertical ? OS.GRADIENT_FILL_RECT_V : OS.GRADIENT_FILL_RECT_H); OS.HeapFree(hHeap, 0, pMesh); if (success) return; } @@ -2764,7 +2766,7 @@ pointArray[i]--; } } - OS.Polygon(handle, pointArray, pointArray.length / 2); + OS.Polygon(handle, cast(POINT*)pointArray.ptr, pointArray.length / 2); if ((data.style & DWT.MIRRORED) !is 0) { for (int i = 0; i < pointArray.length; i+=2) { pointArray[i]++; @@ -2853,7 +2855,7 @@ OS.RoundRect(handle, x,y,x+width+1,y+height+1,arcWidth, arcHeight); } -void fillRoundRectangleGdip (int gdipGraphics, int brush, int x, int y, int width, int height, int arcWidth, int arcHeight) { +void fillRoundRectangleGdip (Gdip.Graphics* gdipGraphics, Gdip.Brush* brush, int x, int y, int width, int height, int arcWidth, int arcHeight) { int nx = x; int ny = y; int nw = width; @@ -2907,7 +2909,7 @@ * underline HDC. This is done by calling GetHDC() * followed by ReleaseHDC(). */ - int hdc = Gdip.Graphics_GetHDC(data.gdipGraphics); + auto hdc = Gdip.Graphics_GetHDC(data.gdipGraphics); Gdip.Graphics_ReleaseHDC(data.gdipGraphics, hdc); } } @@ -2930,19 +2932,21 @@ public int getAdvanceWidth(char ch) { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); checkGC(FONT); - if (OS.IsWinCE) { - SIZE size = new SIZE(); - OS.GetTextExtentPoint32W(handle, [ch], 1, size); + static if (OS.IsWinCE) { + SIZE size; + OS.GetTextExtentPoint32W(handle, [ch], 1, &size); return size.cx; } int tch = ch; if (ch > 0x7F) { - TCHAR buffer = new TCHAR(getCodePage(), ch, false); - tch = buffer.tcharAt(0); + char[1] str; + str[0] = ch; + TCHAR[] buffer = StrToTCHARs( str ); + tch = buffer[0]; } - int[] width = new int[1]; - OS.GetCharWidth(handle, tch, tch, width); - return width[0]; + int width; + OS.GetCharWidth(handle, tch, tch, &width); + return width; } /** @@ -3076,15 +3080,17 @@ checkGC(FONT); /* GetCharABCWidths only succeeds on truetype fonts */ - if (!OS.IsWinCE) { + static if (!OS.IsWinCE) { int tch = ch; if (ch > 0x7F) { - TCHAR buffer = new TCHAR(getCodePage(), ch, false); - tch = buffer.tcharAt (0); + char[1] str; + str[0] = ch; + TCHAR[] buffer = StrToTCHARs( str ); + tch = buffer[0]; } - int[] width = new int[3]; - if (OS.GetCharABCWidths(handle, tch, tch, width)) { - return width[1]; + ABC abc; + if (OS.GetCharABCWidths(handle, tch, tch, &abc)) { + return abc.abcA; } } @@ -3092,7 +3098,9 @@ TEXTMETRIC lptm; OS.GetTextMetrics(handle, &lptm); SIZE size; - OS.GetTextExtentPoint32W(handle, [ch], 1, &size); + char[1] str; + str[0] = ch; + OS.GetTextExtentPoint32W(handle, StrToWCHARz( str ), 1, &size); return size.cx - lptm.tmOverhang; } @@ -3112,14 +3120,14 @@ if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { - Rect rect = new Rect(); + Gdip.Rect rect; Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); Gdip.Graphics_GetVisibleClipBounds(gdipGraphics, rect); Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); return new Rectangle(rect.X, rect.Y, rect.Width, rect.Height); } - RECT rect = new RECT(); - OS.GetClipBox(handle, rect); + RECT rect; + OS.GetClipBox(handle, &rect); return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); } @@ -3143,62 +3151,62 @@ if (region.isDisposed()) DWT.error (DWT.ERROR_INVALID_ARGUMENT); auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { - int rgn = Gdip.Region_new(); + auto rgn = Gdip.Region_new(); Gdip.Graphics_GetClip(data.gdipGraphics, rgn); if (Gdip.Region_IsInfinite(rgn, gdipGraphics)) { - Rect rect = new Rect(); + Gdip.Rect rect; Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeNone); Gdip.Graphics_GetVisibleClipBounds(gdipGraphics, rect); Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); OS.SetRectRgn(region.handle, rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height); } else { - int matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); - int identity = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); + auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); + auto identity_ = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); Gdip.Graphics_GetTransform(gdipGraphics, matrix); - Gdip.Graphics_SetTransform(gdipGraphics, identity); - int hRgn = Gdip.Region_GetHRGN(rgn, data.gdipGraphics); + Gdip.Graphics_SetTransform(gdipGraphics, identity_); + auto hRgn = Gdip.Region_GetHRGN(rgn, data.gdipGraphics); Gdip.Graphics_SetTransform(gdipGraphics, matrix); - Gdip.Matrix_delete(identity); + Gdip.Matrix_delete(identity_); Gdip.Matrix_delete(matrix); - OS.CombineRgn(region.handle, hRgn, 0, OS.RGN_COPY); + OS.CombineRgn(region.handle, hRgn, null, OS.RGN_COPY); OS.DeleteObject(hRgn); } Gdip.Region_delete(rgn); return; } - POINT pt = new POINT (); - if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, pt); + POINT pt; + static if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, &pt); int result = OS.GetClipRgn (handle, region.handle); if (result !is 1) { - RECT rect = new RECT(); - OS.GetClipBox(handle, rect); + RECT rect; + OS.GetClipBox(handle, &rect); OS.SetRectRgn(region.handle, rect.left, rect.top, rect.right, rect.bottom); } else { OS.OffsetRgn (region.handle, pt.x, pt.y); } - if (!OS.IsWinCE) { - int metaRgn = OS.CreateRectRgn (0, 0, 0, 0); - if (OS.GetMetaRgn (handle, metaRgn) !is null) { + static if (!OS.IsWinCE) { + auto metaRgn = OS.CreateRectRgn (0, 0, 0, 0); + if (OS.GetMetaRgn (handle, metaRgn) !is 0) { OS.OffsetRgn (metaRgn, pt.x, pt.y); OS.CombineRgn (region.handle, metaRgn, region.handle, OS.RGN_AND); } OS.DeleteObject(metaRgn); - int hwnd = data.hwnd; + auto hwnd = data.hwnd; if (hwnd !is null && data.ps !is null) { - int sysRgn = OS.CreateRectRgn (0, 0, 0, 0); + auto sysRgn = OS.CreateRectRgn (0, 0, 0, 0); if (OS.GetRandomRgn (handle, sysRgn, OS.SYSRGN) is 1) { if (OS.WIN32_VERSION >= OS.VERSION(4, 10)) { if ((OS.GetLayout(handle) & OS.LAYOUT_RTL) !is 0) { int nBytes = OS.GetRegionData (sysRgn, 0, null); int [] lpRgnData = new int [nBytes / 4]; - OS.GetRegionData (sysRgn, nBytes, lpRgnData); - int newSysRgn = OS.ExtCreateRegion([-1, 0, 0, 1, 0, 0], nBytes, lpRgnData); + OS.GetRegionData (sysRgn, nBytes, cast(RGNDATA*)lpRgnData.ptr); + auto newSysRgn = OS.ExtCreateRegion( cast(XFORM*) [-1, 0, 0, 1, 0, 0].ptr, nBytes, cast(RGNDATA*)lpRgnData.ptr); OS.DeleteObject(sysRgn); sysRgn = newSysRgn; } } if (OS.IsWinNT) { - OS.MapWindowPoints(0, hwnd, pt, 1); + OS.MapWindowPoints(null, hwnd, &pt, 1); OS.OffsetRgn(sysRgn, pt.x, pt.y); } OS.CombineRgn (region.handle, sysRgn, region.handle, OS.RGN_AND); @@ -3210,14 +3218,14 @@ int getCodePage () { if (OS.IsUnicode) return OS.CP_ACP; - int[] lpCs = new int[8]; - int cs = OS.GetTextCharset(handle); - OS.TranslateCharsetInfo(cs, lpCs, OS.TCI_SRCCHARSET); - return lpCs[1]; + CHARSETINFO csi; + auto cs = OS.GetTextCharset(handle); + OS.TranslateCharsetInfo( cast(DWORD*)cs, &csi, OS.TCI_SRCCHARSET); + return csi.ciACP; } -int getFgBrush() { - return data.foregroundPattern !is null ? data.foregroundPattern.handle : data.gdipFgBrush; +Gdip.Brush* getFgBrush() { + return data.foregroundPattern !is null ? data.foregroundPattern.handle : cast(Gdip.Brush*)data.gdipFgBrush; } /** @@ -3552,10 +3560,10 @@ auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { Gdip.Graphics_GetTransform(gdipGraphics, transform.handle); - int identity = identity(); - Gdip.Matrix_Invert(identity); - Gdip.Matrix_Multiply(transform.handle, identity, Gdip.MatrixOrderAppend); - Gdip.Matrix_delete(identity); + auto identity_ = identity(); + Gdip.Matrix_Invert(identity_); + Gdip.Matrix_Multiply(transform.handle, identity_, Gdip.MatrixOrderAppend); + Gdip.Matrix_delete(identity_); } else { transform.setElements(1, 0, 0, 1, 0, 0); } @@ -3598,14 +3606,14 @@ * cannot be reset. The fix is to clear the clipping before * the GDI+ graphics is created and reset it afterwards. */ - int hRgn = OS.CreateRectRgn(0, 0, 0, 0); - int result = OS.GetClipRgn(handle, hRgn); - if (!OS.IsWinCE) { - POINT pt = new POINT (); - OS.GetWindowOrgEx (handle, pt); + auto hRgn = OS.CreateRectRgn(0, 0, 0, 0); + auto result = OS.GetClipRgn(handle, hRgn); + static if (!OS.IsWinCE) { + POINT pt; + OS.GetWindowOrgEx (handle, &pt); OS.OffsetRgn (hRgn, pt.x, pt.y); } - OS.SelectClipRgn(handle, 0); + OS.SelectClipRgn(handle, null); /* * Bug in GDI+. GDI+ does not work when the HDC layout is RTL. There @@ -3623,7 +3631,7 @@ Gdip.Graphics_SetPageUnit(gdipGraphics, Gdip.UnitPixel); Gdip.Graphics_SetPixelOffsetMode(gdipGraphics, Gdip.PixelOffsetModeHalf); if ((data.style & DWT.MIRRORED) !is 0) { - int matrix = identity(); + auto matrix = identity(); Gdip.Graphics_SetTransform(gdipGraphics, matrix); Gdip.Matrix_delete(matrix); } @@ -3642,34 +3650,34 @@ } } -int identity() { +Gdip.Matrix* identity() { if ((data.style & DWT.MIRRORED) !is 0) { int width = 0; Image image = data.image; if (image !is null) { - BITMAP bm = new BITMAP(); - OS.GetObject(image.handle, BITMAP.sizeof, bm); + BITMAP bm; + OS.GetObject(image.handle, BITMAP.sizeof, &bm); width = bm.bmWidth; } else if (data.hwnd !is null) { - RECT rect = new RECT(); - OS.GetClientRect(data.hwnd, rect); + RECT rect; + OS.GetClientRect(data.hwnd, &rect); width = rect.right - rect.left; } - POINT pt = new POINT (); - if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, pt); + POINT pt; + if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, &pt); return Gdip.Matrix_new(-1, 0, 0, 1, width + 2 * pt.x, 0); } return Gdip.Matrix_new(1, 0, 0, 1, 0, 0); } void init(Drawable drawable, GCData data, HDC hDC) { - int foreground = data.foreground; + auto foreground = data.foreground; if (foreground !is -1) { data.state &= ~(FOREGROUND | FOREGROUND_TEXT | PEN); } else { data.foreground = OS.GetTextColor(hDC); } - int background = data.background; + auto background = data.background; if (background !is -1) { data.state &= ~(BACKGROUND | BACKGROUND_TEXT | BRUSH); } else { @@ -3692,7 +3700,7 @@ data.hNullBitmap = OS.SelectObject(hDC, image.handle); image.memGC = this; } - int layout = data.layout; + auto layout = data.layout; if (layout !is -1) { if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) { int flags = OS.GetLayout(hDC); @@ -3722,8 +3730,8 @@ * * @see #equals */ -public int hashCode () { - return handle; +public override hash_t toHash () { + return cast(hash_t)handle; } /** @@ -3742,8 +3750,8 @@ */ public bool isClipped() { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); - int region = OS.CreateRectRgn(0, 0, 0, 0); - int result = OS.GetClipRgn(handle, region); + auto region = OS.CreateRectRgn(0, 0, 0, 0); + auto result = OS.GetClipRgn(handle, region); OS.DeleteObject(region); return result > 0; } @@ -3762,10 +3770,10 @@ return handle is null; } -float measureSpace(int font, int format) { - PointF pt = new PointF(); - RectF bounds = new RectF(); - Gdip.Graphics_MeasureString(data.gdipGraphics, (" "w).ptr, 1, font, pt, format, bounds); +float measureSpace(Gdip.Font* font, Gdip.StringFormat* format) { + Gdip.PointF pt; + Gdip.RectF bounds; + Gdip.Graphics_MeasureString(data.gdipGraphics, (" "w).ptr, 1, font, pt, format, &bounds); return bounds.Width; } @@ -3823,7 +3831,7 @@ data.alpha = 0xFF; data.backgroundPattern = data.foregroundPattern = null; data.state = 0; - setClipping(0); + setClipping( cast(HRGN) null); if ((data.style & DWT.MIRRORED) !is 0) { OS.SetLayout(handle, OS.GetLayout(handle) | OS.LAYOUT_RTL); } @@ -3965,22 +3973,21 @@ data.state &= ~BACKGROUND; } -void setClipping(int clipRgn) { - int hRgn = clipRgn; +void setClipping(HRGN clipRgn) { + auto hRgn = clipRgn; auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { if (hRgn !is null) { - int region = Gdip.Region_new(hRgn); + auto region = Gdip.Region_new(hRgn); Gdip.Graphics_SetClip(gdipGraphics, region, Gdip.CombineModeReplace); Gdip.Region_delete(region); } else { Gdip.Graphics_ResetClip(gdipGraphics); } } else { - POINT pt = null; + POINT pt; if (hRgn !is null && !OS.IsWinCE) { - pt = new POINT(); - OS.GetWindowOrgEx(handle, pt); + OS.GetWindowOrgEx(handle, &pt); OS.OffsetRgn(hRgn, -pt.x, -pt.y); } OS.SelectClipRgn(handle, hRgn); @@ -4009,7 +4016,7 @@ */ public void setClipping (int x, int y, int width, int height) { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); - int hRgn = OS.CreateRectRgn(x, y, x + width, y + height); + auto hRgn = OS.CreateRectRgn(x, y, x + width, y + height); setClipping(hRgn); OS.DeleteObject(hRgn); } @@ -4043,7 +4050,7 @@ public void setClipping (Path path) { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (path !is null && path.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); - setClipping(0); + setClipping(cast(HRGN)null); if (path !is null) { initGdip(); int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; @@ -4068,7 +4075,7 @@ public void setClipping (Rectangle rect) { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (rect is null) { - setClipping(0); + setClipping(cast(HRGN)null); } else { setClipping(rect.x, rect.y, rect.width, rect.height); } @@ -4093,7 +4100,7 @@ public void setClipping (Region region) { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (region !is null && region.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); - setClipping(region !is null ? region.handle : 0); + setClipping(region !is null ? region.handle : cast(HRGN)null); } /** @@ -4592,9 +4599,9 @@ textMode = Gdip.TextRenderingHintSingleBitPerPixelGridFit; break; case DWT.ON: - int[] type = new int[1]; - OS.SystemParametersInfo(OS.SPI_GETFONTSMOOTHINGTYPE, 0, type, 0); - if (type[0] is OS.FE_FONTSMOOTHINGCLEARTYPE) { + int type; + OS.SystemParametersInfo(OS.SPI_GETFONTSMOOTHINGTYPE, 0, &type, 0); + if (type is OS.FE_FONTSMOOTHINGCLEARTYPE) { textMode = Gdip.TextRenderingHintClearTypeGridFit; } else { textMode = Gdip.TextRenderingHintAntiAliasGridFit; @@ -4638,12 +4645,12 @@ if (transform !is null && transform.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); if (data.gdipGraphics is null && transform is null) return; initGdip(); - int identity = identity(); + auto identity_ = identity(); if (transform !is null) { - Gdip.Matrix_Multiply(identity, transform.handle, Gdip.MatrixOrderPrepend); + Gdip.Matrix_Multiply(identity_, transform.handle, Gdip.MatrixOrderPrepend); } - Gdip.Graphics_SetTransform(data.gdipGraphics, identity); - Gdip.Matrix_delete(identity); + Gdip.Graphics_SetTransform(data.gdipGraphics, identity_); + Gdip.Matrix_delete(identity_); data.state &= ~DRAW_OFFSET; } @@ -4672,22 +4679,23 @@ checkGC(FONT); int length_ = string.length; if (data.gdipGraphics !is null) { - PointF pt = new PointF(); - RectF bounds = new RectF(); - char[] buffer; + Gdip.PointF pt; + Gdip.RectF bounds; + wchar* buffer; if (length_ !is 0) { - buffer = new char [length_]; - string.getChars(0, length_, buffer, 0); + wchar[] wstr = StrToWCHARs( string ); + buffer = wstr.ptr; + length_ = wstr.length; } else { - buffer = (" "w).dup; + buffer = (" "w).ptr; } - int format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); + auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces; if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; Gdip.StringFormat_SetFormatFlags(format, formatFlags); - Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, buffer.length, data.gdipFont, pt, format, bounds); + Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length_, data.gdipFont, pt, format, &bounds); Gdip.StringFormat_delete(format); - return new Point(length_ is 0 ? 0 : Math.round(bounds.Width), Math.round(bounds.Height)); + return new Point(length_ is 0 ? 0 : Math.rndint(bounds.Width), Math.rndint(bounds.Height)); } SIZE size; if (length_ is 0) { @@ -4696,8 +4704,9 @@ return new Point(0, size.cy); } else { // TCHAR buffer = new TCHAR (getCodePage(), string, false); - char[] buffer = new char [length_]; - string.getChars(0, length_, buffer, 0); + wchar[] wstr = StrToWCHARs( string ); + wchar* buffer = wstr.ptr; + length_ = wstr.length; OS.GetTextExtentPoint32W(handle, buffer, length_, &size); return new Point(size.cx, size.cy); } @@ -4762,40 +4771,43 @@ if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); checkGC(FONT); if (data.gdipGraphics !is null) { - PointF pt = new PointF(); - RectF bounds = new RectF(); - char[] buffer; + Gdip.PointF pt; + Gdip.RectF bounds; + wchar* buffer; int length_ = string.length; if (length_ !is 0) { - buffer = new char [length_]; - string.getChars(0, length_, buffer, 0); + wchar[] wstr = StrToWCHARs( string ); + buffer = wstr.ptr; + length_ = wstr.length; } else { buffer = (" "w).ptr; } - int format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); + auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces; if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; Gdip.StringFormat_SetFormatFlags(format, formatFlags); float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [measureSpace(data.gdipFont, format) * 8] : new float[1]; - Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); + Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr); Gdip.StringFormat_SetHotkeyPrefix(format, (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone); - Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, buffer.length, data.gdipFont, pt, format, bounds); + Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length_, data.gdipFont, pt, format, &bounds); Gdip.StringFormat_delete(format); - return new Point(length_ is 0 ? 0 : Math.round(bounds.Width), Math.round(bounds.Height)); + return new Point(length_ is 0 ? 0 : Math.rndint(bounds.Width), Math.rndint(bounds.Height)); } if (string.length is 0) { - SIZE size = new SIZE(); + SIZE size; // OS.GetTextExtentPoint32(handle, SPACE, SPACE.length(), size); - OS.GetTextExtentPoint32W(handle, (" "w).ptr, 1, size); + OS.GetTextExtentPoint32W(handle, (" "w).ptr, 1, &size); return new Point(0, size.cy); } - RECT rect = new RECT(); - TCHAR buffer = new TCHAR(getCodePage(), string, false); + RECT rect; + auto wstr = StrToTCHARs( string ); + TCHAR* buffer = wstr.ptr; + int length_ = wstr.length; int uFormat = OS.DT_LEFT | OS.DT_CALCRECT; if ((flags & DWT.DRAW_DELIMITER) is 0) uFormat |= OS.DT_SINGLELINE; if ((flags & DWT.DRAW_TAB) !is 0) uFormat |= OS.DT_EXPANDTABS; if ((flags & DWT.DRAW_MNEMONIC) is 0) uFormat |= OS.DT_NOPREFIX; - OS.DrawText(handle, buffer, buffer.length(), rect, uFormat); + OS.DrawText(handle, buffer, length_, &rect, uFormat); return new Point(rect.right, rect.bottom); }