Move the test for no segments before the assertion for non-NULL segment

2000-02-14  Tor Lillqvist  <tml@iki.fi>

* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.

* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?

* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
This commit is contained in:
Tor Lillqvist 2000-02-13 23:19:23 +00:00 committed by Tor Lillqvist
parent 95a9052d56
commit 37cfb7d74b
11 changed files with 257 additions and 96 deletions

View File

@ -1,3 +1,16 @@
2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.
* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?
* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
2000-02-13 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkcursor-x11.c (gdk_cursor_new_from_pixmap): init
@ -23,12 +36,16 @@
* gdk/win32/gdkgc-win32.c: Factor out common code from
_gdk_win32_gc_new and gdk_win32_gc_set_values into
gdk_win32_gc_values_to_win32values.
gdk_win32_gc_values_to_win32values. Use correct colour for
SetBkColor() (Until now the code actually used a random colour in
the call to SetBkColor()... but that didn't show up as not many
GDI APIs use the background colour. Pattern (opaque stippled)
brushes do.)
* gdk/win32/gdkmain-win32.c (gdk_win32_last_error_string,
gdk_win32_api_failed): New functions for error logging.
* gdk/win32/gdkprivate-win32.h: Declare them, and a macro
* gdk/win32/gdkprivate-win32.h: Declare them, and define a macro
WIN32_API_FAILED to call them, passing function or file name and
line number.

View File

@ -1,3 +1,16 @@
2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.
* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?
* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
2000-02-13 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkcursor-x11.c (gdk_cursor_new_from_pixmap): init
@ -23,12 +36,16 @@
* gdk/win32/gdkgc-win32.c: Factor out common code from
_gdk_win32_gc_new and gdk_win32_gc_set_values into
gdk_win32_gc_values_to_win32values.
gdk_win32_gc_values_to_win32values. Use correct colour for
SetBkColor() (Until now the code actually used a random colour in
the call to SetBkColor()... but that didn't show up as not many
GDI APIs use the background colour. Pattern (opaque stippled)
brushes do.)
* gdk/win32/gdkmain-win32.c (gdk_win32_last_error_string,
gdk_win32_api_failed): New functions for error logging.
* gdk/win32/gdkprivate-win32.h: Declare them, and a macro
* gdk/win32/gdkprivate-win32.h: Declare them, and define a macro
WIN32_API_FAILED to call them, passing function or file name and
line number.

View File

@ -1,3 +1,16 @@
2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.
* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?
* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
2000-02-13 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkcursor-x11.c (gdk_cursor_new_from_pixmap): init
@ -23,12 +36,16 @@
* gdk/win32/gdkgc-win32.c: Factor out common code from
_gdk_win32_gc_new and gdk_win32_gc_set_values into
gdk_win32_gc_values_to_win32values.
gdk_win32_gc_values_to_win32values. Use correct colour for
SetBkColor() (Until now the code actually used a random colour in
the call to SetBkColor()... but that didn't show up as not many
GDI APIs use the background colour. Pattern (opaque stippled)
brushes do.)
* gdk/win32/gdkmain-win32.c (gdk_win32_last_error_string,
gdk_win32_api_failed): New functions for error logging.
* gdk/win32/gdkprivate-win32.h: Declare them, and a macro
* gdk/win32/gdkprivate-win32.h: Declare them, and define a macro
WIN32_API_FAILED to call them, passing function or file name and
line number.

View File

@ -1,3 +1,16 @@
2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.
* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?
* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
2000-02-13 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkcursor-x11.c (gdk_cursor_new_from_pixmap): init
@ -23,12 +36,16 @@
* gdk/win32/gdkgc-win32.c: Factor out common code from
_gdk_win32_gc_new and gdk_win32_gc_set_values into
gdk_win32_gc_values_to_win32values.
gdk_win32_gc_values_to_win32values. Use correct colour for
SetBkColor() (Until now the code actually used a random colour in
the call to SetBkColor()... but that didn't show up as not many
GDI APIs use the background colour. Pattern (opaque stippled)
brushes do.)
* gdk/win32/gdkmain-win32.c (gdk_win32_last_error_string,
gdk_win32_api_failed): New functions for error logging.
* gdk/win32/gdkprivate-win32.h: Declare them, and a macro
* gdk/win32/gdkprivate-win32.h: Declare them, and define a macro
WIN32_API_FAILED to call them, passing function or file name and
line number.

View File

@ -1,3 +1,16 @@
2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.
* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?
* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
2000-02-13 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkcursor-x11.c (gdk_cursor_new_from_pixmap): init
@ -23,12 +36,16 @@
* gdk/win32/gdkgc-win32.c: Factor out common code from
_gdk_win32_gc_new and gdk_win32_gc_set_values into
gdk_win32_gc_values_to_win32values.
gdk_win32_gc_values_to_win32values. Use correct colour for
SetBkColor() (Until now the code actually used a random colour in
the call to SetBkColor()... but that didn't show up as not many
GDI APIs use the background colour. Pattern (opaque stippled)
brushes do.)
* gdk/win32/gdkmain-win32.c (gdk_win32_last_error_string,
gdk_win32_api_failed): New functions for error logging.
* gdk/win32/gdkprivate-win32.h: Declare them, and a macro
* gdk/win32/gdkprivate-win32.h: Declare them, and define a macro
WIN32_API_FAILED to call them, passing function or file name and
line number.

View File

@ -1,3 +1,16 @@
2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.
* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?
* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
2000-02-13 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkcursor-x11.c (gdk_cursor_new_from_pixmap): init
@ -23,12 +36,16 @@
* gdk/win32/gdkgc-win32.c: Factor out common code from
_gdk_win32_gc_new and gdk_win32_gc_set_values into
gdk_win32_gc_values_to_win32values.
gdk_win32_gc_values_to_win32values. Use correct colour for
SetBkColor() (Until now the code actually used a random colour in
the call to SetBkColor()... but that didn't show up as not many
GDI APIs use the background colour. Pattern (opaque stippled)
brushes do.)
* gdk/win32/gdkmain-win32.c (gdk_win32_last_error_string,
gdk_win32_api_failed): New functions for error logging.
* gdk/win32/gdkprivate-win32.h: Declare them, and a macro
* gdk/win32/gdkprivate-win32.h: Declare them, and define a macro
WIN32_API_FAILED to call them, passing function or file name and
line number.

View File

@ -1,3 +1,16 @@
2000-02-14 Tor Lillqvist <tml@iki.fi>
* gdk/gdkdraw.c (gdk_draw_segments): Move the test for no segments
before the assertion for non-NULL segment list.
* gdk/win32/gdkgc-win32.c: (gdk_win32_gc_values_to_win32values):
Seems that pattern brushes *must* be 8x8 pixels! At least on my
machine, but it might be display driver dependent. Sigh, so make
sure the stipple is that size. Does Windows suck or what?
* gdk/win32/gdkdrawable-win32.c: Improve error handling in a few
places.
2000-02-13 Havoc Pennington <hp@pobox.com>
* gdk/x11/gdkcursor-x11.c (gdk_cursor_new_from_pixmap): init
@ -23,12 +36,16 @@
* gdk/win32/gdkgc-win32.c: Factor out common code from
_gdk_win32_gc_new and gdk_win32_gc_set_values into
gdk_win32_gc_values_to_win32values.
gdk_win32_gc_values_to_win32values. Use correct colour for
SetBkColor() (Until now the code actually used a random colour in
the call to SetBkColor()... but that didn't show up as not many
GDI APIs use the background colour. Pattern (opaque stippled)
brushes do.)
* gdk/win32/gdkmain-win32.c (gdk_win32_last_error_string,
gdk_win32_api_failed): New functions for error logging.
* gdk/win32/gdkprivate-win32.h: Declare them, and a macro
* gdk/win32/gdkprivate-win32.h: Declare them, and define a macro
WIN32_API_FAILED to call them, passing function or file name and
line number.

View File

@ -396,13 +396,14 @@ gdk_draw_segments (GdkDrawable *drawable,
gint nsegs)
{
g_return_if_fail (drawable != NULL);
g_return_if_fail (segs != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (nsegs >= 0);
if (nsegs == 0)
return;
g_return_if_fail (segs != NULL);
g_return_if_fail (gc != NULL);
g_return_if_fail (nsegs >= 0);
if (GDK_DRAWABLE_DESTROYED (drawable))
return;

View File

@ -190,6 +190,9 @@ gdk_win32_draw_rectangle (GdkDrawable *drawable,
GdkGCWin32Data *gc_data = GDK_GC_WIN32DATA (gc_private);
HDC hdc;
HGDIOBJ oldpen, oldbrush;
HBRUSH hbr = NULL;
POINT pts[4];
gboolean ok = TRUE;
GDK_NOTE (MISC, g_print ("gdk_win32_draw_rectangle: %#x (%d) %s%dx%d@+%d+%d\n",
GDK_DRAWABLE_XID (drawable),
@ -222,41 +225,43 @@ gdk_win32_draw_rectangle (GdkDrawable *drawable,
if (gc_data->fill_style == GDK_OPAQUE_STIPPLED)
{
if (!BeginPath (hdc))
WIN32_API_FAILED ("BeginPath");
else
{
/* Win9x doesn't support Rectangle calls in a path,
* thus use Polyline.
*/
POINT pts[4];
pts[0].x = x;
pts[0].y = y;
pts[1].x = x + width + 1;
pts[1].y = y;
pts[2].x = x + width + 1;
pts[2].y = y + height + 1;
pts[3].x = x;
pts[3].y = y + height + 1;
MoveToEx (hdc, x, y, NULL);
if (!Polyline (hdc, pts, 4))
WIN32_API_FAILED ("Polyline");
if (!CloseFigure (hdc))
WIN32_API_FAILED ("CloseFigure");
WIN32_API_FAILED ("BeginPath"), ok = FALSE;
if (!EndPath (hdc))
WIN32_API_FAILED ("EndPath");
/* Win9x doesn't support Rectangle calls in a path,
* thus use Polyline.
*/
if (!filled)
if (!WidenPath (hdc))
WIN32_API_FAILED ("WidenPath");
pts[0].x = x;
pts[0].y = y;
pts[1].x = x + width + 1;
pts[1].y = y;
pts[2].x = x + width + 1;
pts[2].y = y + height + 1;
pts[3].x = x;
pts[3].y = y + height + 1;
if (ok)
MoveToEx (hdc, x, y, NULL);
if (ok && !Polyline (hdc, pts, 4))
WIN32_API_FAILED ("Polyline"), ok = FALSE;
if (!FillPath (hdc))
WIN32_API_FAILED ("FillPath");
}
if (ok && !CloseFigure (hdc))
WIN32_API_FAILED ("CloseFigure"), ok = FALSE;
if (ok && !EndPath (hdc))
WIN32_API_FAILED ("EndPath"), ok = FALSE;
if (ok && !filled)
if (!WidenPath (hdc))
WIN32_API_FAILED ("WidenPath"), ok = FALSE;
if (ok && !FillPath (hdc))
WIN32_API_FAILED ("FillPath"), ok = FALSE;
if (hbr != NULL)
if (!DeleteObject (hbr))
WIN32_API_FAILED ("DeleteObject");
}
else
{
@ -358,7 +363,9 @@ gdk_win32_draw_polygon (GdkDrawable *drawable,
GdkGCPrivate *gc_private = (GdkGCPrivate*) gc;
GdkGCWin32Data *gc_data = GDK_GC_WIN32DATA (gc_private);
HDC hdc;
HBRUSH hbr = NULL;
POINT *pts;
gboolean ok = TRUE;
int i;
GDK_NOTE (MISC, g_print ("gdk_win32_draw_polygon: %#x (%d) %d\n",
@ -381,30 +388,32 @@ gdk_win32_draw_polygon (GdkDrawable *drawable,
if (gc_data->fill_style == GDK_OPAQUE_STIPPLED)
{
if (!BeginPath (hdc))
WIN32_API_FAILED ("BeginPath");
else
{
MoveToEx (hdc, points[0].x, points[0].y, NULL);
WIN32_API_FAILED ("BeginPath"), ok = FALSE;
if (pts[0].x == pts[npoints-1].x && pts[0].y == pts[npoints-1].y)
npoints--;
MoveToEx (hdc, points[0].x, points[0].y, NULL);
if (!Polyline (hdc, pts, 4))
WIN32_API_FAILED ("Polyline");
if (!CloseFigure (hdc))
WIN32_API_FAILED ("CloseFigure");
if (pts[0].x == pts[npoints-1].x && pts[0].y == pts[npoints-1].y)
npoints--;
if (!EndPath (hdc))
WIN32_API_FAILED ("EndPath");
if (ok && !Polyline (hdc, pts, 4))
WIN32_API_FAILED ("Polyline"), ok = FALSE;
if (!filled)
if (!WidenPath (hdc))
WIN32_API_FAILED ("WidenPath");
if (ok && !CloseFigure (hdc))
WIN32_API_FAILED ("CloseFigure"), ok = FALSE;
if (ok && !EndPath (hdc))
WIN32_API_FAILED ("EndPath"), ok = FALSE;
if (!FillPath (hdc))
WIN32_API_FAILED ("FillPath");
}
if (ok && !filled)
if (!WidenPath (hdc))
WIN32_API_FAILED ("WidenPath"), ok = FALSE;
if (ok && !FillPath (hdc))
WIN32_API_FAILED ("FillPath"), ok = FALSE;
if (hbr != NULL)
if (!DeleteObject (hbr))
WIN32_API_FAILED ("DeleteObject");
}
else
{
@ -748,6 +757,8 @@ gdk_win32_draw_segments (GdkDrawable *drawable,
GdkGCPrivate *gc_private = (GdkGCPrivate*) gc;
GdkGCWin32Data *gc_data = GDK_GC_WIN32DATA (gc_private);
HDC hdc;
HBRUSH hbr = NULL;
gboolean ok = TRUE;
int i;
GDK_NOTE (MISC, g_print ("gdk_win32_draw_segments: %#x destdc: (%d) %#x "
@ -762,31 +773,33 @@ gdk_win32_draw_segments (GdkDrawable *drawable,
if (gc_data->fill_style == GDK_OPAQUE_STIPPLED)
{
if (!BeginPath (hdc))
WIN32_API_FAILED ("BeginPath");
else
WIN32_API_FAILED ("BeginPath"), ok = FALSE;
for (i = 0; i < nsegs; i++)
{
for (i = 0; i < nsegs; i++)
{
if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
WIN32_API_FAILED ("MoveToEx");
if (!LineTo (hdc, segs[i].x2, segs[i].y2))
WIN32_API_FAILED ("LineTo #1");
if (ok && !MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
WIN32_API_FAILED ("MoveToEx"), ok = FALSE;
if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
WIN32_API_FAILED ("LineTo #1"), ok = FALSE;
/* Draw end pixel */
if (gc_data->pen_width == 1)
if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
WIN32_API_FAILED ("LineTo #2");
}
if (!EndPath (hdc))
WIN32_API_FAILED ("EndPath");
if (!WidenPath (hdc))
WIN32_API_FAILED ("WidenPath");
if (!FillPath (hdc))
WIN32_API_FAILED ("FillPath");
/* Draw end pixel */
if (ok && gc_data->pen_width == 1)
if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
WIN32_API_FAILED ("LineTo #2"), ok = FALSE;
}
if (ok && !EndPath (hdc))
WIN32_API_FAILED ("EndPath"), ok = FALSE;
if (ok && !WidenPath (hdc))
WIN32_API_FAILED ("WidenPath"), ok = FALSE;
if (ok && !FillPath (hdc))
WIN32_API_FAILED ("FillPath"), ok = FALSE;
if (hbr != NULL)
if (!DeleteObject (hbr))
WIN32_API_FAILED ("DeleteObject");
}
else
{

View File

@ -58,6 +58,7 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
GdkGCWin32Data *data)
{
char *s = "";
gint sw, sh;
GDK_NOTE (MISC, g_print ("{"));
@ -208,7 +209,36 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
data->stipple = values->stipple;
if (data->stipple != NULL)
{
gdk_drawable_ref (data->stipple);
gdk_drawable_get_size (data->stipple, &sw, &sh);
if (sw != 8 || sh != 8)
{
/* It seems that it *must* be 8x8, at least on my machine.
* Thus, tile an 8x8 bitmap with the stipple in case it is
* smaller, or simply use just the top left 8x8 in case it is
* larger.
*/
gchar dummy[8];
GdkPixmap *bm = gdk_bitmap_create_from_data (NULL, dummy, 8, 8);
GdkGC *gc = gdk_gc_new (bm);
gint i, j;
i = 0;
while (i < 8)
{
j = 0;
while (j < 8)
{
gdk_draw_drawable (bm, gc, data->stipple, 0, 0, i, j, sw, sh);
j += sh;
}
i += sw;
}
data->stipple = bm;
gdk_gc_unref (gc);
}
else
gdk_drawable_ref (data->stipple);
data->values_mask |= GDK_GC_STIPPLE;
GDK_NOTE (MISC, (g_print ("%sstipple=%#x", s,
GDK_DRAWABLE_XID (data->stipple)),
@ -776,15 +806,14 @@ predraw_set_foreground (GdkGCWin32Data *data,
switch (data->fill_style)
{
#if 1
case GDK_OPAQUE_STIPPLED:
if ((hbr = CreatePatternBrush (GDK_DRAWABLE_XID (data->stipple))) == NULL)
WIN32_API_FAILED ("CreatePatternBrush");
SetBrushOrgEx(data->xgc, data->ts_x_origin,
data->ts_y_origin, NULL);
break;
#endif
case GDK_SOLID:
default:
@ -792,7 +821,6 @@ predraw_set_foreground (GdkGCWin32Data *data,
WIN32_API_FAILED ("CreateSolidBrush");
break;
}
if (SelectObject (data->xgc, hbr) == NULL)
WIN32_API_FAILED ("SelectObject #3");
}

View File

@ -153,8 +153,8 @@ struct _GdkGCWin32Data
*/
HDC xgc;
GdkGCValuesMask values_mask;
gulong foreground;
gulong background;
gulong foreground; /* Pixel values from GdkColor, */
gulong background; /* not Win32 COLORREFs */
GdkFont *font;
gint rop2;
GdkFill fill_style;