[GDI+: 2/5] added Pens implementation, test
Evan Stade
estade at gmail.com
Fri Jun 8 15:46:27 CDT 2007
Hi,
Changelog:
*added pen implementation
*added just enough memory and startup implementation to support pens
*defined some types
*added pen test
dlls/gdiplus/Makefile.in | 5 +-
dlls/gdiplus/gdiplus.c | 54 +++++++++++++++++++++++
dlls/gdiplus/gdiplus.spec | 12 +++--
dlls/gdiplus/gdiplus_private.h | 53 +++++++++++++++++++++++
dlls/gdiplus/pen.c | 72 +++++++++++++++++++++++++++++++
dlls/gdiplus/tests/Makefile.in | 13 ++++++
dlls/gdiplus/tests/pen.c | 92 ++++++++++++++++++++++++++++++++++++++++
7 files changed, 292 insertions(+), 9 deletions(-)
-Evan Stade
-------------- next part --------------
diff --git a/dlls/gdiplus/Makefile.in b/dlls/gdiplus/Makefile.in
index f1d5040..3f57760 100644
--- a/dlls/gdiplus/Makefile.in
+++ b/dlls/gdiplus/Makefile.in
@@ -4,10 +4,11 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = gdiplus.dll
IMPORTLIB = libgdiplus.$(IMPLIBEXT)
-IMPORTS = gdi32 advapi32 kernel32 ntdll
+IMPORTS = gdi32 advapi32 kernel32 ntdll user32
C_SRCS = \
- gdiplus.c
+ gdiplus.c \
+ pen.c
@MAKE_DLL_RULES@
diff --git a/dlls/gdiplus/gdiplus.c b/dlls/gdiplus/gdiplus.c
index 367fab5..3ec257a 100644
--- a/dlls/gdiplus/gdiplus.c
+++ b/dlls/gdiplus/gdiplus.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Evan Stade
+ * Copyright (C) 2007 Google (Evan Stade)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -22,6 +22,9 @@ #include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wine/debug.h"
+#include "wingdi.h"
+#include "gdiplus.h"
+#include "gdiplus_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
@@ -43,3 +46,52 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWO
}
return TRUE;
}
+
+Status WINAPI GdiplusStartup(ULONG_PTR *token, const GdiplusStartupInput *input,
+ GdiplusStartupOutput *output)
+{
+ if(!token)
+ return InvalidParameter;
+
+ if(input->GdiplusVersion != 1) {
+ return UnsupportedGdiplusVersion;
+ } else if ((input->DebugEventCallback) ||
+ (input->SuppressBackgroundThread) || (input->SuppressExternalCodecs)){
+ FIXME("Unimplemented for non-default GdiplusStartupInput");
+ return NotImplemented;
+ } else if(output) {
+ FIXME("Unimplemented for non-null GdiplusStartupOutput");
+ return NotImplemented;
+ }
+
+ return Ok;
+}
+
+void WINAPI GdiplusShutdown(ULONG_PTR token)
+{
+ /* FIXME: no object tracking */
+}
+
+void* WINGDIPAPI GdipAlloc(size_t size)
+{
+ return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
+}
+
+void WINGDIPAPI GdipFree(void* ptr)
+{
+ HeapFree(GetProcessHeap(), 0, ptr);
+}
+
+COLORREF ARGB2COLORREF(ARGB color)
+{
+ /*
+ Packing of these color structures:
+ COLORREF: 00bbggrr
+ ARGB: aarrggbb
+ FIXME:doesn't handle alpha channel
+ */
+ return (COLORREF)
+ ((color & 0x0000ff) << 16) +
+ (color & 0x00ff00) +
+ ((color & 0xff0000) >> 16);
+}
diff --git a/dlls/gdiplus/gdiplus.spec b/dlls/gdiplus/gdiplus.spec
index 863be69..2bb3ba9 100644
--- a/dlls/gdiplus/gdiplus.spec
+++ b/dlls/gdiplus/gdiplus.spec
@@ -31,7 +31,7 @@
@ stub GdipAddPathRectanglesI
@ stub GdipAddPathString
@ stub GdipAddPathStringI
-@ stub GdipAlloc
+@ stdcall GdipAlloc(long)
@ stub GdipBeginContainer2
@ stub GdipBeginContainer
@ stub GdipBeginContainerI
@@ -111,7 +111,7 @@
@ stub GdipCreatePathGradientFromPath
@ stub GdipCreatePathGradientI
@ stub GdipCreatePathIter
-@ stub GdipCreatePen1
+@ stdcall GdipCreatePen1(long long long ptr)
@ stub GdipCreatePen2
@ stub GdipCreateRegion
@ stub GdipCreateRegionHrgn
@@ -136,7 +136,7 @@
@ stub GdipDeleteMatrix
@ stub GdipDeletePath
@ stub GdipDeletePathIter
-@ stub GdipDeletePen
+@ stdcall GdipDeletePen(ptr)
@ stub GdipDeletePrivateFontCollection
@ stub GdipDeleteRegion
@ stub GdipDeleteStringFormat
@@ -222,7 +222,7 @@
@ stub GdipFillRegion
@ stub GdipFlattenPath
@ stub GdipFlush
-@ stub GdipFree
+@ stdcall GdipFree(ptr)
@ stub GdipGetAdjustableArrowCapFillState
@ stub GdipGetAdjustableArrowCapHeight
@ stub GdipGetAdjustableArrowCapMiddleInset
@@ -605,5 +605,5 @@
@ stub GdipWindingModeOutline
@ stub GdiplusNotificationHook
@ stub GdiplusNotificationUnhook
-@ stub GdiplusShutdown
-@ stub GdiplusStartup
+@ stdcall GdiplusShutdown(ptr)
+@ stdcall GdiplusStartup(ptr ptr ptr)
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
new file mode 100644
index 0000000..269097f
--- /dev/null
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2007 Google (Evan Stade)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef __WINE_GP_PRIVATE_H_
+#define __WINE_GP_PRIVATE_H_
+
+#include "windef.h"
+#include "winbase.h"
+#include "gdiplus.h"
+
+#define GP_DEFAULT_PENSTYLE (PS_GEOMETRIC | PS_ENDCAP_FLAT)
+
+COLORREF ARGB2COLORREF(ARGB color);
+
+struct GpPen{
+ UINT style;
+ COLORREF color;
+ GpUnit unit;
+ REAL width;
+ HPEN gdipen;
+};
+
+struct GpGraphics{
+ HDC hdc;
+ HWND hwnd;
+};
+
+struct GpBrush{
+ HBRUSH gdibrush;
+ GpBrushType bt;
+ COLORREF color;
+};
+
+struct GpSolidFill{
+ GpBrush brush;
+};
+
+#endif
diff --git a/dlls/gdiplus/pen.c b/dlls/gdiplus/pen.c
new file mode 100644
index 0000000..9354646
--- /dev/null
+++ b/dlls/gdiplus/pen.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2007 Google (Evan Stade)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#include "gdiplus.h"
+#include "gdiplus_private.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
+
+GpStatus WINGDIPAPI GdipCreatePen1(ARGB color, FLOAT width, GpUnit unit,
+ GpPen **pen)
+{
+ LOGBRUSH lb;
+ GpPen *gp_pen;
+
+ gp_pen = (GpPen*) GdipAlloc(sizeof(GpPen));
+ if(!pen) return OutOfMemory;
+
+ gp_pen->style = GP_DEFAULT_PENSTYLE;
+ gp_pen->color = ARGB2COLORREF(color);
+ gp_pen->width = width;
+ gp_pen->unit = unit;
+
+ /* FIXME: Currently only solid lines supported. */
+ lb.lbStyle = BS_SOLID;
+ lb.lbColor = gp_pen->color;
+ lb.lbHatch = 0;
+
+ if((gp_pen->unit == UnitWorld) || (gp_pen->unit == UnitPixel)) {
+ gp_pen->gdipen = ExtCreatePen(gp_pen->style, (INT) gp_pen->width, &lb,
+ 0, NULL);
+ } else {
+ FIXME("UnitWorld, UnitPixel only supported units");
+ return NotImplemented;
+ }
+
+ if(!gp_pen)
+ return GenericError;
+
+ *pen = gp_pen;
+
+ return Ok;
+}
+
+GpStatus WINGDIPAPI GdipDeletePen(GpPen *pen)
+{
+ if(!pen) return InvalidParameter;
+ DeleteObject(pen->gdipen);
+ GdipFree(pen);
+
+ return Ok;
+}
diff --git a/dlls/gdiplus/tests/Makefile.in b/dlls/gdiplus/tests/Makefile.in
new file mode 100644
index 0000000..14bc936
--- /dev/null
+++ b/dlls/gdiplus/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR = @srcdir@
+VPATH = @srcdir@
+TESTDLL = gdiplus.dll
+IMPORTS = user32 gdi32 kernel32 gdiplus
+
+CTESTS = \
+ pen.c
+
+ at MAKE_TEST_RULES@
+
+ at DEPENDENCIES@ # everything below this line is overwritten by make depend
diff --git a/dlls/gdiplus/tests/pen.c b/dlls/gdiplus/tests/pen.c
new file mode 100644
index 0000000..c5f7482
--- /dev/null
+++ b/dlls/gdiplus/tests/pen.c
@@ -0,0 +1,92 @@
+/*
+ * Unit test suite for pens
+ *
+ * Copyright (C) 2007 Google (Evan Stade)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+
+#include "windef.h"
+#include "gdiplus.h"
+#include "wine/test.h"
+
+#define expect(expected, got) ok(got == expected, "Expected %.8x, got %.8x\n", expected, got)
+
+static void test_startup(void)
+{
+ GpPen *pen;
+ Status status;
+ GdiplusStartupInput gdiplusStartupInput;
+ ULONG_PTR gdiplusToken;
+
+ gdiplusStartupInput.GdiplusVersion = 1;
+ gdiplusStartupInput.DebugEventCallback = NULL;
+ gdiplusStartupInput.SuppressBackgroundThread = 0;
+ gdiplusStartupInput.SuppressExternalCodecs = 0;
+
+ status = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
+ expect(Ok, status);
+ GdiplusShutdown(gdiplusToken);
+
+ gdiplusStartupInput.GdiplusVersion = 2;
+
+ status = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
+ expect(UnsupportedGdiplusVersion, status);
+ GdiplusShutdown(gdiplusToken);
+
+ status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
+
+ todo_wine
+ expect(GdiplusNotInitialized, status);
+
+ GdipDeletePen(pen);
+}
+
+static void test_constructor_destructor(void)
+{
+ GpStatus status;
+ GpPen *pen = NULL;
+
+ status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
+ expect(Ok, status);
+ ok(pen != NULL, "Expected pen to be initialized");
+
+ status = GdipDeletePen(NULL);
+ expect(InvalidParameter, status);
+
+ status = GdipDeletePen(pen);
+ expect(Ok, status);
+}
+
+START_TEST(pen)
+{
+ GdiplusStartupInput gdiplusStartupInput;
+ ULONG_PTR gdiplusToken;
+
+ test_startup();
+
+ gdiplusStartupInput.GdiplusVersion = 1;
+ gdiplusStartupInput.DebugEventCallback = NULL;
+ gdiplusStartupInput.SuppressBackgroundThread = 0;
+ gdiplusStartupInput.SuppressExternalCodecs = 0;
+
+ GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
+
+ test_constructor_destructor();
+
+ GdiplusShutdown(gdiplusToken);
+}
--
1.4.1
More information about the wine-patches
mailing list