# HG changeset patch # User Frank Benoit # Date 1201472982 -3600 # Node ID fa34113bf4be4bbbf815b484391f405952f782e4 # Parent d6fa61ac6912660bd694fb7e9996f556929e4210 Path diff -r d6fa61ac6912 -r fa34113bf4be dwt/graphics/Path.d --- a/dwt/graphics/Path.d Sun Jan 27 23:17:22 2008 +0100 +++ b/dwt/graphics/Path.d Sun Jan 27 23:29:42 2008 +0100 @@ -7,26 +7,29 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit *******************************************************************************/ module dwt.graphics.Path; import dwt.internal.gdip.Gdip; -//PORTING_TYPE -class Path{ - Gdip.GraphicsPath* handle; - bool isDisposed(); -} - -/++ import dwt.DWT; import dwt.DWTError; import dwt.DWTException; import dwt.internal.gdip.Gdip; -import dwt.internal.gdip.PointF; -import dwt.internal.gdip.RectF; import dwt.internal.win32.OS; +import dwt.graphics.Resource; +import dwt.graphics.Device; +import dwt.graphics.Font; +import dwt.graphics.GC; +import dwt.graphics.GCData; +import dwt.graphics.PathData; + +import dwt.dwthelper.System; +import tango.text.convert.Format; + /** * Instances of this class represent paths through the two-dimensional * coordinate system. Paths do not have to be continuous, and can be @@ -44,7 +47,7 @@ * * @since 3.1 */ -public class Path extends Resource { +public class Path : Resource { /** * the OS resource for the Path @@ -56,9 +59,9 @@ * platforms and should never be accessed from application code. *

*/ - public int handle; + public Gdip.GraphicsPath* handle; - PointF currentPoint = new PointF(), startPoint = new PointF(); + Gdip.PointF currentPoint, startPoint; /** * Constructs a new empty Path. @@ -82,13 +85,13 @@ * * @see #dispose() */ -public Path (Device device) { +public this (Device device) { if (device is null) device = Device.getDevice(); if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); this.device = device; device.checkGDIP(); handle = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); - if (handle is 0) DWT.error(DWT.ERROR_NO_HANDLES); + if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); if (device.tracking) device.new_Object(this); } @@ -135,10 +138,10 @@ if (width is height) { Gdip.GraphicsPath_AddArc(handle, x, y, width, height, -startAngle, -arcAngle); } else { - int path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); - if (path is 0) DWT.error(DWT.ERROR_NO_HANDLES); - int matrix = Gdip.Matrix_new(width, 0, 0, height, x, y); - if (matrix is 0) DWT.error(DWT.ERROR_NO_HANDLES); + auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); + if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); + auto matrix = Gdip.Matrix_new(width, 0, 0, height, x, y); + if (matrix is null) DWT.error(DWT.ERROR_NO_HANDLES); Gdip.GraphicsPath_AddArc(path, 0, 0, 1, 1, -startAngle, -arcAngle); Gdip.GraphicsPath_Transform(path, matrix); Gdip.GraphicsPath_AddPath(handle, path, true); @@ -185,12 +188,12 @@ */ public void addRectangle(float x, float y, float width, float height) { if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); - RectF rect = new RectF(); + Gdip.RectF rect; rect.X = x; rect.Y = y; rect.Width = width; rect.Height = height; - Gdip.GraphicsPath_AddRectangle(handle, rect); + Gdip.GraphicsPath_AddRectangle(handle, &rect); currentPoint.X = x; currentPoint.Y = y; } @@ -212,23 +215,23 @@ *
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  • * */ -public void addString(String string, float x, float y, Font font) { +public void addString(char[] string, float x, float y, Font font) { if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (font is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); if (font.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); - int length = string.length(); - char[] buffer = new char[length]; - string.getChars(0, length, buffer, 0); - int hDC = device.internal_new_GC(null); - int gdipFont = GC.createGdipFont(hDC, font.handle); - PointF point = new PointF(); + wchar[] wstr = StrToWCHARs( string ); + wchar* buffer = wstr.ptr; + int length = wstr.length; + auto hDC = device.internal_new_GC(null); + auto gdipFont = GC.createGdipFont(hDC, font.handle); + Gdip.PointF point; point.X = x - (Gdip.Font_GetSize(gdipFont) / 6); point.Y = y; - int family = Gdip.FontFamily_new(); + auto family = Gdip.FontFamily_new(); Gdip.Font_GetFamily(gdipFont, family); int style = Gdip.Font_GetStyle(gdipFont); float size = Gdip.Font_GetSize(gdipFont); - Gdip.GraphicsPath_AddString(handle, buffer, length, family, style, size, point, 0); + Gdip.GraphicsPath_AddString(handle, buffer, length, family, style, size, point, null); Gdip.GraphicsPath_GetLastPoint(handle, currentPoint); Gdip.FontFamily_delete(family); Gdip.Font_delete(gdipFont); @@ -323,10 +326,10 @@ * they allocate. */ public void dispose() { - if (handle is 0) return; + if (handle is null) return; if (device.isDisposed()) return; Gdip.GraphicsPath_delete(handle); - handle = 0; + handle = null; if (device.tracking) device.dispose_Object(this); device = null; } @@ -350,8 +353,8 @@ if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (bounds is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); if (bounds.length < 4) DWT.error(DWT.ERROR_INVALID_ARGUMENT); - RectF rect = new RectF(); - Gdip.GraphicsPath_GetBounds(handle, rect, 0, 0); + Gdip.RectF rect; + Gdip.GraphicsPath_GetBounds(handle, rect, null, null); bounds[0] = rect.X; bounds[1] = rect.Y; bounds[2] = rect.Width; @@ -397,7 +400,7 @@ byte[] gdipTypes = new byte[count]; float[] points = new float[count * 2]; Gdip.GraphicsPath_GetPathTypes(handle, gdipTypes, count); - Gdip.GraphicsPath_GetPathPoints(handle, points, count); + Gdip.GraphicsPath_GetPathPoints(handle, points.ptr, count); byte[] types = new byte[count * 2]; int index = 0, typesIndex = 0; while (index < count) { @@ -465,7 +468,7 @@ * @return true when the Path is disposed, and false otherwise */ public bool isDisposed() { - return handle is 0; + return handle is null; } /** @@ -515,10 +518,9 @@ * * @return a string representation of the receiver */ -public String toString() { +public char[] toString() { if (isDisposed()) return "Path {*DISPOSED*}"; - return "Path {" + handle + "}"; + return Format( "Path {{{}}", handle ); } } -++/ \ No newline at end of file diff -r d6fa61ac6912 -r fa34113bf4be dwt/graphics/Pattern.d --- a/dwt/graphics/Pattern.d Sun Jan 27 23:17:22 2008 +0100 +++ b/dwt/graphics/Pattern.d Sun Jan 27 23:29:42 2008 +0100 @@ -7,6 +7,8 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Port to the D programming language: + * Frank Benoit *******************************************************************************/ module dwt.graphics.Pattern; diff -r d6fa61ac6912 -r fa34113bf4be dwt/internal/gdip/Gdip.d --- a/dwt/internal/gdip/Gdip.d Sun Jan 27 23:17:22 2008 +0100 +++ b/dwt/internal/gdip/Gdip.d Sun Jan 27 23:29:42 2008 +0100 @@ -393,6 +393,9 @@ int StringFormat_SetFormatFlags(StringFormat* format, int flags); int StringFormat_SetTabStops(StringFormat* format, float firstTabOffset, int count, float* tabStops); + FontFamily* FontFamily_new(); + void FontFamily_delete(FontFamily* family); + int FontFamily_GetFamilyName(FontFamily* family, wchar* name, wchar language); }