Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google (Evan Stade) |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| 17 | */ |
| 18 | |
| 19 | #include <stdarg.h> |
| 20 | #include <math.h> |
Evan Stade | 44e9839 | 2007-08-15 16:22:09 -0700 | [diff] [blame] | 21 | #include <limits.h> |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 22 | |
| 23 | #include "windef.h" |
| 24 | #include "winbase.h" |
| 25 | #include "winuser.h" |
| 26 | #include "wingdi.h" |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 27 | #include "wine/unicode.h" |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 28 | |
| 29 | #define COBJMACROS |
| 30 | #include "objbase.h" |
| 31 | #include "ocidl.h" |
| 32 | #include "olectl.h" |
| 33 | #include "ole2.h" |
| 34 | |
Evan Stade | 3ea77f5 | 2007-08-07 18:42:00 -0700 | [diff] [blame] | 35 | #include "winreg.h" |
| 36 | #include "shlwapi.h" |
| 37 | |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 38 | #include "gdiplus.h" |
| 39 | #include "gdiplus_private.h" |
| 40 | #include "wine/debug.h" |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 41 | #include "wine/list.h" |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 42 | |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 43 | WINE_DEFAULT_DEBUG_CHANNEL(gdiplus); |
| 44 | |
| 45 | /* looks-right constants */ |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 46 | #define ANCHOR_WIDTH (2.0) |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 47 | #define MAX_ITERS (50) |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 48 | |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 49 | /* Converts angle (in degrees) to x/y coordinates */ |
| 50 | static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y) |
| 51 | { |
| 52 | REAL radAngle, hypotenuse; |
| 53 | |
| 54 | radAngle = deg2rad(angle); |
| 55 | hypotenuse = 50.0; /* arbitrary */ |
| 56 | |
| 57 | *x = x_0 + cos(radAngle) * hypotenuse; |
| 58 | *y = y_0 + sin(radAngle) * hypotenuse; |
| 59 | } |
| 60 | |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 61 | /* Converts from gdiplus path point type to gdi path point type. */ |
| 62 | static BYTE convert_path_point_type(BYTE type) |
| 63 | { |
| 64 | BYTE ret; |
| 65 | |
| 66 | switch(type & PathPointTypePathTypeMask){ |
| 67 | case PathPointTypeBezier: |
| 68 | ret = PT_BEZIERTO; |
| 69 | break; |
| 70 | case PathPointTypeLine: |
| 71 | ret = PT_LINETO; |
| 72 | break; |
| 73 | case PathPointTypeStart: |
| 74 | ret = PT_MOVETO; |
| 75 | break; |
| 76 | default: |
| 77 | ERR("Bad point type\n"); |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | if(type & PathPointTypeCloseSubpath) |
| 82 | ret |= PT_CLOSEFIGURE; |
| 83 | |
| 84 | return ret; |
| 85 | } |
| 86 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 87 | static INT prepare_dc(GpGraphics *graphics, GpPen *pen) |
| 88 | { |
| 89 | HPEN gdipen; |
| 90 | REAL width; |
Evan Stade | 1f61f48 | 2007-07-27 16:07:39 -0700 | [diff] [blame] | 91 | INT save_state = SaveDC(graphics->hdc), i, numdashes; |
Evan Stade | b7053b7 | 2007-07-24 17:18:58 -0700 | [diff] [blame] | 92 | GpPointF pt[2]; |
Evan Stade | 1f61f48 | 2007-07-27 16:07:39 -0700 | [diff] [blame] | 93 | DWORD dash_array[MAX_DASHLEN]; |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 94 | |
| 95 | EndPath(graphics->hdc); |
| 96 | |
Evan Stade | afa4d32 | 2007-08-13 18:34:31 -0700 | [diff] [blame] | 97 | if(pen->unit == UnitPixel){ |
| 98 | width = pen->width; |
| 99 | } |
| 100 | else{ |
| 101 | /* Get an estimate for the amount the pen width is affected by the world |
| 102 | * transform. (This is similar to what some of the wine drivers do.) */ |
| 103 | pt[0].X = 0.0; |
| 104 | pt[0].Y = 0.0; |
| 105 | pt[1].X = 1.0; |
| 106 | pt[1].Y = 1.0; |
| 107 | GdipTransformMatrixPoints(graphics->worldtrans, pt, 2); |
| 108 | width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) + |
| 109 | (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0); |
Evan Stade | b7053b7 | 2007-07-24 17:18:58 -0700 | [diff] [blame] | 110 | |
Evan Stade | afa4d32 | 2007-08-13 18:34:31 -0700 | [diff] [blame] | 111 | width *= pen->width * convert_unit(graphics->hdc, |
| 112 | pen->unit == UnitWorld ? graphics->unit : pen->unit); |
| 113 | } |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 114 | |
Evan Stade | 1f61f48 | 2007-07-27 16:07:39 -0700 | [diff] [blame] | 115 | if(pen->dash == DashStyleCustom){ |
| 116 | numdashes = min(pen->numdashes, MAX_DASHLEN); |
| 117 | |
| 118 | TRACE("dashes are: "); |
| 119 | for(i = 0; i < numdashes; i++){ |
| 120 | dash_array[i] = roundr(width * pen->dashes[i]); |
| 121 | TRACE("%d, ", dash_array[i]); |
| 122 | } |
| 123 | TRACE("\n and the pen style is %x\n", pen->style); |
| 124 | |
| 125 | gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, |
| 126 | numdashes, dash_array); |
| 127 | } |
| 128 | else |
| 129 | gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL); |
| 130 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 131 | SelectObject(graphics->hdc, gdipen); |
| 132 | |
| 133 | return save_state; |
| 134 | } |
| 135 | |
| 136 | static void restore_dc(GpGraphics *graphics, INT state) |
| 137 | { |
| 138 | DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN))); |
| 139 | RestoreDC(graphics->hdc, state); |
| 140 | } |
| 141 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 142 | /* This helper applies all the changes that the points listed in ptf need in |
| 143 | * order to be drawn on the device context. In the end, this should include at |
| 144 | * least: |
| 145 | * -scaling by page unit |
| 146 | * -applying world transformation |
| 147 | * -converting from float to int |
| 148 | * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx, |
| 149 | * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using |
| 150 | * gdi to draw, and these functions would irreparably mess with line widths. |
| 151 | */ |
| 152 | static void transform_and_round_points(GpGraphics *graphics, POINT *pti, |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 153 | GpPointF *ptf, INT count) |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 154 | { |
| 155 | REAL unitscale; |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 156 | GpMatrix *matrix; |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 157 | int i; |
| 158 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 159 | unitscale = convert_unit(graphics->hdc, graphics->unit); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 160 | |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 161 | /* apply page scale */ |
| 162 | if(graphics->unit != UnitDisplay) |
| 163 | unitscale *= graphics->scale; |
| 164 | |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 165 | GdipCloneMatrix(graphics->worldtrans, &matrix); |
| 166 | GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend); |
| 167 | GdipTransformMatrixPoints(matrix, ptf, count); |
Evan Stade | f52adfd | 2007-07-25 19:15:20 -0700 | [diff] [blame] | 168 | GdipDeleteMatrix(matrix); |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 169 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 170 | for(i = 0; i < count; i++){ |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 171 | pti[i].x = roundr(ptf[i].X); |
| 172 | pti[i].y = roundr(ptf[i].Y); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
Vincent Povirk | a616130 | 2009-05-01 14:26:50 -0500 | [diff] [blame] | 176 | static ARGB blend_colors(ARGB start, ARGB end, REAL position) |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 177 | { |
| 178 | ARGB result=0; |
| 179 | ARGB i; |
| 180 | for (i=0xff; i<=0xff0000; i = i << 8) |
Vincent Povirk | a616130 | 2009-05-01 14:26:50 -0500 | [diff] [blame] | 181 | result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 182 | return result; |
| 183 | } |
| 184 | |
Vincent Povirk | a616130 | 2009-05-01 14:26:50 -0500 | [diff] [blame] | 185 | static ARGB blend_line_gradient(GpLineGradient* brush, REAL position) |
| 186 | { |
| 187 | REAL blendfac; |
| 188 | |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 189 | /* clamp to between 0.0 and 1.0, using the wrap mode */ |
| 190 | if (brush->wrap == WrapModeTile) |
| 191 | { |
| 192 | position = fmodf(position, 1.0f); |
| 193 | if (position < 0.0f) position += 1.0f; |
| 194 | } |
| 195 | else /* WrapModeFlip* */ |
| 196 | { |
| 197 | position = fmodf(position, 2.0f); |
| 198 | if (position < 0.0f) position += 2.0f; |
| 199 | if (position > 1.0f) position = 2.0f - position; |
| 200 | } |
| 201 | |
Vincent Povirk | a616130 | 2009-05-01 14:26:50 -0500 | [diff] [blame] | 202 | if (brush->blendcount == 1) |
| 203 | blendfac = position; |
| 204 | else |
| 205 | { |
| 206 | int i=1; |
| 207 | REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac; |
| 208 | REAL range; |
| 209 | |
| 210 | /* locate the blend positions surrounding this position */ |
| 211 | while (position > brush->blendpos[i]) |
| 212 | i++; |
| 213 | |
| 214 | /* interpolate between the blend positions */ |
| 215 | left_blendpos = brush->blendpos[i-1]; |
| 216 | left_blendfac = brush->blendfac[i-1]; |
| 217 | right_blendpos = brush->blendpos[i]; |
| 218 | right_blendfac = brush->blendfac[i]; |
| 219 | range = right_blendpos - left_blendpos; |
| 220 | blendfac = (left_blendfac * (right_blendpos - position) + |
| 221 | right_blendfac * (position - left_blendpos)) / range; |
| 222 | } |
| 223 | return blend_colors(brush->startcolor, brush->endcolor, blendfac); |
| 224 | } |
| 225 | |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 226 | static void brush_fill_path(GpGraphics *graphics, GpBrush* brush) |
| 227 | { |
| 228 | switch (brush->bt) |
| 229 | { |
| 230 | case BrushTypeLinearGradient: |
| 231 | { |
| 232 | GpLineGradient *line = (GpLineGradient*)brush; |
| 233 | RECT rc; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 234 | |
| 235 | SelectClipPath(graphics->hdc, RGN_AND); |
| 236 | if (GetClipBox(graphics->hdc, &rc) != NULLREGION) |
| 237 | { |
| 238 | GpPointF endpointsf[2]; |
| 239 | POINT endpointsi[2]; |
| 240 | POINT poly[4]; |
| 241 | |
| 242 | SelectObject(graphics->hdc, GetStockObject(NULL_PEN)); |
| 243 | |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 244 | endpointsf[0] = line->startpoint; |
| 245 | endpointsf[1] = line->endpoint; |
| 246 | transform_and_round_points(graphics, endpointsi, endpointsf, 2); |
| 247 | |
| 248 | if (abs(endpointsi[0].x-endpointsi[1].x) > abs(endpointsi[0].y-endpointsi[1].y)) |
| 249 | { |
| 250 | /* vertical-ish gradient */ |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 251 | int startx, endx; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */ |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 252 | int startbottomx; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */ |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 253 | int width; |
| 254 | COLORREF col; |
| 255 | HBRUSH hbrush, hprevbrush; |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 256 | int leftx, rightx; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */ |
| 257 | int x; |
| 258 | int tilt; /* horizontal distance covered by a gradient line */ |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 259 | |
| 260 | startx = roundr((rc.top - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X); |
| 261 | endx = roundr((rc.top - endpointsf[1].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[1].X); |
| 262 | width = endx - startx; |
| 263 | startbottomx = roundr((rc.bottom - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X); |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 264 | tilt = startx - startbottomx; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 265 | |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 266 | if (startx >= startbottomx) |
| 267 | { |
| 268 | leftx = rc.left; |
| 269 | rightx = rc.right + tilt; |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | leftx = rc.left + tilt; |
| 274 | rightx = rc.right; |
| 275 | } |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 276 | |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 277 | poly[0].y = rc.bottom; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 278 | poly[1].y = rc.top; |
| 279 | poly[2].y = rc.top; |
| 280 | poly[3].y = rc.bottom; |
| 281 | |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 282 | for (x=leftx; x<=rightx; x++) |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 283 | { |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 284 | ARGB argb = blend_line_gradient(line, (x-startx)/(REAL)width); |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 285 | col = ARGB2COLORREF(argb); |
| 286 | hbrush = CreateSolidBrush(col); |
| 287 | hprevbrush = SelectObject(graphics->hdc, hbrush); |
Vincent Povirk | cb478a3 | 2009-05-01 15:37:35 -0500 | [diff] [blame] | 288 | poly[0].x = x - tilt - 1; |
| 289 | poly[1].x = x - 1; |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 290 | poly[2].x = x; |
| 291 | poly[3].x = x - tilt; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 292 | Polygon(graphics->hdc, poly, 4); |
| 293 | SelectObject(graphics->hdc, hprevbrush); |
| 294 | DeleteObject(hbrush); |
| 295 | } |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 296 | } |
| 297 | else if (endpointsi[0].y != endpointsi[1].y) |
| 298 | { |
| 299 | /* horizontal-ish gradient */ |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 300 | int starty, endy; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */ |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 301 | int startrighty; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */ |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 302 | int height; |
| 303 | COLORREF col; |
| 304 | HBRUSH hbrush, hprevbrush; |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 305 | int topy, bottomy; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */ |
| 306 | int y; |
| 307 | int tilt; /* vertical distance covered by a gradient line */ |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 308 | |
| 309 | starty = roundr((rc.left - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y); |
| 310 | endy = roundr((rc.left - endpointsf[1].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[1].Y); |
| 311 | height = endy - starty; |
| 312 | startrighty = roundr((rc.right - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y); |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 313 | tilt = starty - startrighty; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 314 | |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 315 | if (starty >= startrighty) |
| 316 | { |
| 317 | topy = rc.top; |
| 318 | bottomy = rc.bottom + tilt; |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | topy = rc.top + tilt; |
| 323 | bottomy = rc.bottom; |
| 324 | } |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 325 | |
| 326 | poly[0].x = rc.right; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 327 | poly[1].x = rc.left; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 328 | poly[2].x = rc.left; |
| 329 | poly[3].x = rc.right; |
| 330 | |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 331 | for (y=topy; y<=bottomy; y++) |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 332 | { |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 333 | ARGB argb = blend_line_gradient(line, (y-starty)/(REAL)height); |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 334 | col = ARGB2COLORREF(argb); |
| 335 | hbrush = CreateSolidBrush(col); |
| 336 | hprevbrush = SelectObject(graphics->hdc, hbrush); |
Vincent Povirk | cb478a3 | 2009-05-01 15:37:35 -0500 | [diff] [blame] | 337 | poly[0].y = y - tilt - 1; |
| 338 | poly[1].y = y - 1; |
Vincent Povirk | 966fd5e | 2009-05-01 15:23:02 -0500 | [diff] [blame] | 339 | poly[2].y = y; |
| 340 | poly[3].y = y - tilt; |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 341 | Polygon(graphics->hdc, poly, 4); |
| 342 | SelectObject(graphics->hdc, hprevbrush); |
| 343 | DeleteObject(hbrush); |
| 344 | } |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 345 | } |
| 346 | /* else startpoint == endpoint */ |
| 347 | } |
| 348 | break; |
| 349 | } |
Vincent Povirk | 60167df | 2009-05-20 11:24:18 -0500 | [diff] [blame] | 350 | case BrushTypeSolidColor: |
| 351 | { |
| 352 | GpSolidFill *fill = (GpSolidFill*)brush; |
| 353 | if (fill->bmp) |
| 354 | { |
| 355 | RECT rc; |
| 356 | /* partially transparent fill */ |
| 357 | |
| 358 | SelectClipPath(graphics->hdc, RGN_AND); |
| 359 | if (GetClipBox(graphics->hdc, &rc) != NULLREGION) |
| 360 | { |
| 361 | HDC hdc = CreateCompatibleDC(NULL); |
| 362 | HBITMAP oldbmp; |
| 363 | BLENDFUNCTION bf; |
| 364 | |
| 365 | if (!hdc) break; |
| 366 | |
| 367 | oldbmp = SelectObject(hdc, fill->bmp); |
| 368 | |
| 369 | bf.BlendOp = AC_SRC_OVER; |
| 370 | bf.BlendFlags = 0; |
| 371 | bf.SourceConstantAlpha = 255; |
| 372 | bf.AlphaFormat = AC_SRC_ALPHA; |
| 373 | |
| 374 | GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf); |
| 375 | |
| 376 | SelectObject(hdc, oldbmp); |
| 377 | DeleteDC(hdc); |
| 378 | } |
| 379 | |
| 380 | break; |
| 381 | } |
| 382 | /* else fall through */ |
| 383 | } |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 384 | default: |
| 385 | SelectObject(graphics->hdc, brush->gdibrush); |
| 386 | FillPath(graphics->hdc); |
| 387 | break; |
| 388 | } |
| 389 | } |
| 390 | |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 391 | /* GdipDrawPie/GdipFillPie helper function */ |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 392 | static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width, |
| 393 | REAL height, REAL startAngle, REAL sweepAngle) |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 394 | { |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 395 | GpPointF ptf[4]; |
| 396 | POINT pti[4]; |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 397 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 398 | ptf[0].X = x; |
| 399 | ptf[0].Y = y; |
| 400 | ptf[1].X = x + width; |
| 401 | ptf[1].Y = y + height; |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 402 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 403 | deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y); |
| 404 | deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y); |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 405 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 406 | transform_and_round_points(graphics, pti, ptf, 4); |
| 407 | |
| 408 | Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x, |
| 409 | pti[2].y, pti[3].x, pti[3].y); |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 412 | /* Draws the linecap the specified color and size on the hdc. The linecap is in |
Evan Stade | 8c5bcef | 2007-07-20 17:50:02 -0700 | [diff] [blame] | 413 | * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably |
| 414 | * should not be called on an hdc that has a path you care about. */ |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 415 | static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size, |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 416 | const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2) |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 417 | { |
Evan Stade | b7053b7 | 2007-07-24 17:18:58 -0700 | [diff] [blame] | 418 | HGDIOBJ oldbrush = NULL, oldpen = NULL; |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 419 | GpMatrix *matrix = NULL; |
Evan Stade | b7053b7 | 2007-07-24 17:18:58 -0700 | [diff] [blame] | 420 | HBRUSH brush = NULL; |
| 421 | HPEN pen = NULL; |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 422 | PointF ptf[4], *custptf = NULL; |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 423 | POINT pt[4], *custpt = NULL; |
| 424 | BYTE *tp = NULL; |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 425 | REAL theta, dsmall, dbig, dx, dy = 0.0; |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 426 | INT i, count; |
| 427 | LOGBRUSH lb; |
Evan Stade | b7053b7 | 2007-07-24 17:18:58 -0700 | [diff] [blame] | 428 | BOOL customstroke; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 429 | |
Evan Stade | 818051d | 2007-07-20 17:50:14 -0700 | [diff] [blame] | 430 | if((x1 == x2) && (y1 == y2)) |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 431 | return; |
| 432 | |
Evan Stade | 818051d | 2007-07-20 17:50:14 -0700 | [diff] [blame] | 433 | theta = gdiplus_atan2(y2 - y1, x2 - x1); |
| 434 | |
Evan Stade | b7053b7 | 2007-07-24 17:18:58 -0700 | [diff] [blame] | 435 | customstroke = (cap == LineCapCustom) && custom && (!custom->fill); |
| 436 | if(!customstroke){ |
| 437 | brush = CreateSolidBrush(color); |
| 438 | lb.lbStyle = BS_SOLID; |
| 439 | lb.lbColor = color; |
| 440 | lb.lbHatch = 0; |
| 441 | pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT | |
| 442 | PS_JOIN_MITER, 1, &lb, 0, |
| 443 | NULL); |
| 444 | oldbrush = SelectObject(graphics->hdc, brush); |
| 445 | oldpen = SelectObject(graphics->hdc, pen); |
| 446 | } |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 447 | |
| 448 | switch(cap){ |
| 449 | case LineCapFlat: |
| 450 | break; |
| 451 | case LineCapSquare: |
| 452 | case LineCapSquareAnchor: |
| 453 | case LineCapDiamondAnchor: |
| 454 | size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0; |
| 455 | if(cap == LineCapDiamondAnchor){ |
| 456 | dsmall = cos(theta + M_PI_2) * size; |
| 457 | dbig = sin(theta + M_PI_2) * size; |
| 458 | } |
| 459 | else{ |
| 460 | dsmall = cos(theta + M_PI_4) * size; |
| 461 | dbig = sin(theta + M_PI_4) * size; |
| 462 | } |
| 463 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 464 | ptf[0].X = x2 - dsmall; |
| 465 | ptf[1].X = x2 + dbig; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 466 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 467 | ptf[0].Y = y2 - dbig; |
| 468 | ptf[3].Y = y2 + dsmall; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 469 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 470 | ptf[1].Y = y2 - dsmall; |
| 471 | ptf[2].Y = y2 + dbig; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 472 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 473 | ptf[3].X = x2 - dbig; |
| 474 | ptf[2].X = x2 + dsmall; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 475 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 476 | transform_and_round_points(graphics, pt, ptf, 4); |
| 477 | Polygon(graphics->hdc, pt, 4); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 478 | |
| 479 | break; |
| 480 | case LineCapArrowAnchor: |
| 481 | size = size * 4.0 / sqrt(3.0); |
| 482 | |
Evan Stade | ea5898c | 2007-07-19 18:22:47 -0700 | [diff] [blame] | 483 | dx = cos(M_PI / 6.0 + theta) * size; |
| 484 | dy = sin(M_PI / 6.0 + theta) * size; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 485 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 486 | ptf[0].X = x2 - dx; |
| 487 | ptf[0].Y = y2 - dy; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 488 | |
Evan Stade | ea5898c | 2007-07-19 18:22:47 -0700 | [diff] [blame] | 489 | dx = cos(- M_PI / 6.0 + theta) * size; |
| 490 | dy = sin(- M_PI / 6.0 + theta) * size; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 491 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 492 | ptf[1].X = x2 - dx; |
| 493 | ptf[1].Y = y2 - dy; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 494 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 495 | ptf[2].X = x2; |
| 496 | ptf[2].Y = y2; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 497 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 498 | transform_and_round_points(graphics, pt, ptf, 3); |
| 499 | Polygon(graphics->hdc, pt, 3); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 500 | |
| 501 | break; |
| 502 | case LineCapRoundAnchor: |
| 503 | dx = dy = ANCHOR_WIDTH * size / 2.0; |
| 504 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 505 | ptf[0].X = x2 - dx; |
| 506 | ptf[0].Y = y2 - dy; |
| 507 | ptf[1].X = x2 + dx; |
| 508 | ptf[1].Y = y2 + dy; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 509 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 510 | transform_and_round_points(graphics, pt, ptf, 2); |
| 511 | Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y); |
| 512 | |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 513 | break; |
| 514 | case LineCapTriangle: |
| 515 | size = size / 2.0; |
| 516 | dx = cos(M_PI_2 + theta) * size; |
| 517 | dy = sin(M_PI_2 + theta) * size; |
| 518 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 519 | ptf[0].X = x2 - dx; |
| 520 | ptf[0].Y = y2 - dy; |
| 521 | ptf[1].X = x2 + dx; |
| 522 | ptf[1].Y = y2 + dy; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 523 | |
Evan Stade | ea5898c | 2007-07-19 18:22:47 -0700 | [diff] [blame] | 524 | dx = cos(theta) * size; |
| 525 | dy = sin(theta) * size; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 526 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 527 | ptf[2].X = x2 + dx; |
| 528 | ptf[2].Y = y2 + dy; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 529 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 530 | transform_and_round_points(graphics, pt, ptf, 3); |
| 531 | Polygon(graphics->hdc, pt, 3); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 532 | |
| 533 | break; |
| 534 | case LineCapRound: |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 535 | dx = dy = size / 2.0; |
| 536 | |
| 537 | ptf[0].X = x2 - dx; |
| 538 | ptf[0].Y = y2 - dy; |
| 539 | ptf[1].X = x2 + dx; |
| 540 | ptf[1].Y = y2 + dy; |
| 541 | |
Evan Stade | ea5898c | 2007-07-19 18:22:47 -0700 | [diff] [blame] | 542 | dx = -cos(M_PI_2 + theta) * size; |
| 543 | dy = -sin(M_PI_2 + theta) * size; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 544 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 545 | ptf[2].X = x2 - dx; |
| 546 | ptf[2].Y = y2 - dy; |
| 547 | ptf[3].X = x2 + dx; |
| 548 | ptf[3].Y = y2 + dy; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 549 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 550 | transform_and_round_points(graphics, pt, ptf, 4); |
| 551 | Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x, |
| 552 | pt[2].y, pt[3].x, pt[3].y); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 553 | |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 554 | break; |
| 555 | case LineCapCustom: |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 556 | if(!custom) |
| 557 | break; |
| 558 | |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 559 | count = custom->pathdata.Count; |
| 560 | custptf = GdipAlloc(count * sizeof(PointF)); |
| 561 | custpt = GdipAlloc(count * sizeof(POINT)); |
| 562 | tp = GdipAlloc(count); |
| 563 | |
| 564 | if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok)) |
| 565 | goto custend; |
| 566 | |
| 567 | memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF)); |
| 568 | |
| 569 | GdipScaleMatrix(matrix, size, size, MatrixOrderAppend); |
| 570 | GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2), |
| 571 | MatrixOrderAppend); |
| 572 | GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend); |
| 573 | GdipTransformMatrixPoints(matrix, custptf, count); |
| 574 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 575 | transform_and_round_points(graphics, custpt, custptf, count); |
| 576 | |
| 577 | for(i = 0; i < count; i++) |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 578 | tp[i] = convert_path_point_type(custom->pathdata.Types[i]); |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 579 | |
Evan Stade | 8c5bcef | 2007-07-20 17:50:02 -0700 | [diff] [blame] | 580 | if(custom->fill){ |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 581 | BeginPath(graphics->hdc); |
| 582 | PolyDraw(graphics->hdc, custpt, tp, count); |
| 583 | EndPath(graphics->hdc); |
| 584 | StrokeAndFillPath(graphics->hdc); |
Evan Stade | 8c5bcef | 2007-07-20 17:50:02 -0700 | [diff] [blame] | 585 | } |
| 586 | else |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 587 | PolyDraw(graphics->hdc, custpt, tp, count); |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 588 | |
| 589 | custend: |
| 590 | GdipFree(custptf); |
| 591 | GdipFree(custpt); |
| 592 | GdipFree(tp); |
| 593 | GdipDeleteMatrix(matrix); |
| 594 | break; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 595 | default: |
| 596 | break; |
| 597 | } |
| 598 | |
Evan Stade | b7053b7 | 2007-07-24 17:18:58 -0700 | [diff] [blame] | 599 | if(!customstroke){ |
| 600 | SelectObject(graphics->hdc, oldbrush); |
| 601 | SelectObject(graphics->hdc, oldpen); |
| 602 | DeleteObject(brush); |
| 603 | DeleteObject(pen); |
| 604 | } |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /* Shortens the line by the given percent by changing x2, y2. |
Evan Stade | f56fa32 | 2007-07-20 17:50:07 -0700 | [diff] [blame] | 608 | * If percent is > 1.0 then the line will change direction. |
| 609 | * If percent is negative it can lengthen the line. */ |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 610 | static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent) |
| 611 | { |
| 612 | REAL dist, theta, dx, dy; |
| 613 | |
| 614 | if((y1 == *y2) && (x1 == *x2)) |
| 615 | return; |
| 616 | |
Evan Stade | f56fa32 | 2007-07-20 17:50:07 -0700 | [diff] [blame] | 617 | dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent; |
Evan Stade | 818051d | 2007-07-20 17:50:14 -0700 | [diff] [blame] | 618 | theta = gdiplus_atan2((*y2 - y1), (*x2 - x1)); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 619 | dx = cos(theta) * dist; |
| 620 | dy = sin(theta) * dist; |
| 621 | |
Evan Stade | f56fa32 | 2007-07-20 17:50:07 -0700 | [diff] [blame] | 622 | *x2 = *x2 + dx; |
| 623 | *y2 = *y2 + dy; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | /* Shortens the line by the given amount by changing x2, y2. |
Evan Stade | f56fa32 | 2007-07-20 17:50:07 -0700 | [diff] [blame] | 627 | * If the amount is greater than the distance, the line will become length 0. |
| 628 | * If the amount is negative, it can lengthen the line. */ |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 629 | static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt) |
| 630 | { |
| 631 | REAL dx, dy, percent; |
| 632 | |
| 633 | dx = *x2 - x1; |
| 634 | dy = *y2 - y1; |
| 635 | if(dx == 0 && dy == 0) |
| 636 | return; |
| 637 | |
| 638 | percent = amt / sqrt(dx * dx + dy * dy); |
| 639 | if(percent >= 1.0){ |
| 640 | *x2 = x1; |
| 641 | *y2 = y1; |
| 642 | return; |
| 643 | } |
| 644 | |
| 645 | shorten_line_percent(x1, y1, x2, y2, percent); |
| 646 | } |
| 647 | |
| 648 | /* Draws lines between the given points, and if caps is true then draws an endcap |
Evan Stade | 88ab6d3 | 2007-08-02 17:53:13 -0700 | [diff] [blame] | 649 | * at the end of the last line. */ |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 650 | static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen, |
| 651 | GDIPCONST GpPointF * pt, INT count, BOOL caps) |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 652 | { |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 653 | POINT *pti = NULL; |
| 654 | GpPointF *ptcopy = NULL; |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 655 | GpStatus status = GenericError; |
| 656 | |
| 657 | if(!count) |
| 658 | return Ok; |
| 659 | |
| 660 | pti = GdipAlloc(count * sizeof(POINT)); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 661 | ptcopy = GdipAlloc(count * sizeof(GpPointF)); |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 662 | |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 663 | if(!pti || !ptcopy){ |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 664 | status = OutOfMemory; |
| 665 | goto end; |
| 666 | } |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 667 | |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 668 | memcpy(ptcopy, pt, count * sizeof(GpPointF)); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 669 | |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 670 | if(caps){ |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 671 | if(pen->endcap == LineCapArrowAnchor) |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 672 | shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y, |
| 673 | &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width); |
Evan Stade | f56fa32 | 2007-07-20 17:50:07 -0700 | [diff] [blame] | 674 | else if((pen->endcap == LineCapCustom) && pen->customend) |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 675 | shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y, |
| 676 | &ptcopy[count-1].X, &ptcopy[count-1].Y, |
| 677 | pen->customend->inset * pen->width); |
| 678 | |
| 679 | if(pen->startcap == LineCapArrowAnchor) |
| 680 | shorten_line_amt(ptcopy[1].X, ptcopy[1].Y, |
| 681 | &ptcopy[0].X, &ptcopy[0].Y, pen->width); |
| 682 | else if((pen->startcap == LineCapCustom) && pen->customstart) |
| 683 | shorten_line_amt(ptcopy[1].X, ptcopy[1].Y, |
| 684 | &ptcopy[0].X, &ptcopy[0].Y, |
Evan Stade | 02887b6 | 2007-08-07 18:42:44 -0700 | [diff] [blame] | 685 | pen->customstart->inset * pen->width); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 686 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 687 | draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend, |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 688 | pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 689 | draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart, |
Michael Stefaniuc | 1f26b14 | 2007-12-31 17:29:57 +0100 | [diff] [blame] | 690 | pt[1].X, pt[1].Y, pt[0].X, pt[0].Y); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 691 | } |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 692 | |
| 693 | transform_and_round_points(graphics, pti, ptcopy, count); |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 694 | |
Royal Chan | c86f2c2 | 2008-02-10 12:40:52 -0800 | [diff] [blame] | 695 | if(Polyline(graphics->hdc, pti, count)) |
| 696 | status = Ok; |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 697 | |
| 698 | end: |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 699 | GdipFree(pti); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 700 | GdipFree(ptcopy); |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 701 | |
| 702 | return status; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 705 | /* Conducts a linear search to find the bezier points that will back off |
| 706 | * the endpoint of the curve by a distance of amt. Linear search works |
| 707 | * better than binary in this case because there are multiple solutions, |
| 708 | * and binary searches often find a bad one. I don't think this is what |
| 709 | * Windows does but short of rendering the bezier without GDI's help it's |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 710 | * the best we can do. If rev then work from the start of the passed points |
| 711 | * instead of the end. */ |
| 712 | static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev) |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 713 | { |
| 714 | GpPointF origpt[4]; |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 715 | REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0; |
| 716 | INT i, first = 0, second = 1, third = 2, fourth = 3; |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 717 | |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 718 | if(rev){ |
| 719 | first = 3; |
| 720 | second = 2; |
| 721 | third = 1; |
| 722 | fourth = 0; |
| 723 | } |
| 724 | |
| 725 | origx = pt[fourth].X; |
| 726 | origy = pt[fourth].Y; |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 727 | memcpy(origpt, pt, sizeof(GpPointF) * 4); |
| 728 | |
| 729 | for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){ |
| 730 | /* reset bezier points to original values */ |
| 731 | memcpy(pt, origpt, sizeof(GpPointF) * 4); |
| 732 | /* Perform magic on bezier points. Order is important here.*/ |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 733 | shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent); |
| 734 | shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent); |
| 735 | shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent); |
| 736 | shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent); |
| 737 | shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent); |
| 738 | shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent); |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 739 | |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 740 | dx = pt[fourth].X - origx; |
| 741 | dy = pt[fourth].Y - origy; |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 742 | |
| 743 | diff = sqrt(dx * dx + dy * dy); |
| 744 | percent += 0.0005 * amt; |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | /* Draws bezier curves between given points, and if caps is true then draws an |
Evan Stade | 88ab6d3 | 2007-08-02 17:53:13 -0700 | [diff] [blame] | 749 | * endcap at the end of the last line. */ |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 750 | static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen, |
| 751 | GDIPCONST GpPointF * pt, INT count, BOOL caps) |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 752 | { |
Evan Stade | 7f0aa3a | 2007-08-02 17:53:08 -0700 | [diff] [blame] | 753 | POINT *pti; |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 754 | GpPointF *ptcopy; |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 755 | GpStatus status = GenericError; |
| 756 | |
| 757 | if(!count) |
| 758 | return Ok; |
| 759 | |
| 760 | pti = GdipAlloc(count * sizeof(POINT)); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 761 | ptcopy = GdipAlloc(count * sizeof(GpPointF)); |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 762 | |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 763 | if(!pti || !ptcopy){ |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 764 | status = OutOfMemory; |
| 765 | goto end; |
| 766 | } |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 767 | |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 768 | memcpy(ptcopy, pt, count * sizeof(GpPointF)); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 769 | |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 770 | if(caps){ |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 771 | if(pen->endcap == LineCapArrowAnchor) |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 772 | shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE); |
Evan Stade | 7f0aa3a | 2007-08-02 17:53:08 -0700 | [diff] [blame] | 773 | else if((pen->endcap == LineCapCustom) && pen->customend) |
| 774 | shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset, |
| 775 | FALSE); |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 776 | |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 777 | if(pen->startcap == LineCapArrowAnchor) |
| 778 | shorten_bezier_amt(ptcopy, pen->width, TRUE); |
Evan Stade | 7f0aa3a | 2007-08-02 17:53:08 -0700 | [diff] [blame] | 779 | else if((pen->startcap == LineCapCustom) && pen->customstart) |
Evan Stade | 02887b6 | 2007-08-07 18:42:44 -0700 | [diff] [blame] | 780 | shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 781 | |
Evan Stade | 55d70e8 | 2007-07-11 18:08:26 -0700 | [diff] [blame] | 782 | /* the direction of the line cap is parallel to the direction at the |
| 783 | * end of the bezier (which, if it has been shortened, is not the same |
| 784 | * as the direction from pt[count-2] to pt[count-1]) */ |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 785 | draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend, |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 786 | pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X), |
| 787 | pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y), |
Evan Stade | 55d70e8 | 2007-07-11 18:08:26 -0700 | [diff] [blame] | 788 | pt[count - 1].X, pt[count - 1].Y); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 789 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 790 | draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart, |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 791 | pt[0].X - (ptcopy[0].X - ptcopy[1].X), |
| 792 | pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y); |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 793 | } |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 794 | |
| 795 | transform_and_round_points(graphics, pti, ptcopy, count); |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 796 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 797 | PolyBezier(graphics->hdc, pti, count); |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 798 | |
| 799 | status = Ok; |
| 800 | |
| 801 | end: |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 802 | GdipFree(pti); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 803 | GdipFree(ptcopy); |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 804 | |
| 805 | return status; |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 808 | /* Draws a combination of bezier curves and lines between points. */ |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 809 | static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt, |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 810 | GDIPCONST BYTE * types, INT count, BOOL caps) |
| 811 | { |
Evan Stade | 7f0aa3a | 2007-08-02 17:53:08 -0700 | [diff] [blame] | 812 | POINT *pti = GdipAlloc(count * sizeof(POINT)); |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 813 | BYTE *tp = GdipAlloc(count); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 814 | GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF)); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 815 | INT i, j; |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 816 | GpStatus status = GenericError; |
| 817 | |
| 818 | if(!count){ |
| 819 | status = Ok; |
| 820 | goto end; |
| 821 | } |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 822 | if(!pti || !tp || !ptcopy){ |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 823 | status = OutOfMemory; |
| 824 | goto end; |
| 825 | } |
| 826 | |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 827 | for(i = 1; i < count; i++){ |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 828 | if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){ |
| 829 | if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier) |
| 830 | || !(types[i + 1] & PathPointTypeBezier)){ |
| 831 | ERR("Bad bezier points\n"); |
| 832 | goto end; |
| 833 | } |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 834 | i += 2; |
| 835 | } |
| 836 | } |
| 837 | |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 838 | memcpy(ptcopy, pt, count * sizeof(GpPointF)); |
| 839 | |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 840 | /* If we are drawing caps, go through the points and adjust them accordingly, |
| 841 | * and draw the caps. */ |
| 842 | if(caps){ |
| 843 | switch(types[count - 1] & PathPointTypePathTypeMask){ |
| 844 | case PathPointTypeBezier: |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 845 | if(pen->endcap == LineCapArrowAnchor) |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 846 | shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE); |
Evan Stade | 7f0aa3a | 2007-08-02 17:53:08 -0700 | [diff] [blame] | 847 | else if((pen->endcap == LineCapCustom) && pen->customend) |
| 848 | shorten_bezier_amt(&ptcopy[count - 4], |
| 849 | pen->width * pen->customend->inset, FALSE); |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 850 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 851 | draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend, |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 852 | pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X), |
| 853 | pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y), |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 854 | pt[count - 1].X, pt[count - 1].Y); |
| 855 | |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 856 | break; |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 857 | case PathPointTypeLine: |
| 858 | if(pen->endcap == LineCapArrowAnchor) |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 859 | shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y, |
| 860 | &ptcopy[count - 1].X, &ptcopy[count - 1].Y, |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 861 | pen->width); |
Evan Stade | f56fa32 | 2007-07-20 17:50:07 -0700 | [diff] [blame] | 862 | else if((pen->endcap == LineCapCustom) && pen->customend) |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 863 | shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y, |
| 864 | &ptcopy[count - 1].X, &ptcopy[count - 1].Y, |
Evan Stade | f56fa32 | 2007-07-20 17:50:07 -0700 | [diff] [blame] | 865 | pen->customend->inset * pen->width); |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 866 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 867 | draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend, |
Evan Stade | 85b5df4 | 2007-07-19 18:22:51 -0700 | [diff] [blame] | 868 | pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, |
| 869 | pt[count - 1].Y); |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 870 | |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 871 | break; |
| 872 | default: |
| 873 | ERR("Bad path last point\n"); |
| 874 | goto end; |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 875 | } |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 876 | |
| 877 | /* Find start of points */ |
| 878 | for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask) |
| 879 | == PathPointTypeStart); j++); |
| 880 | |
| 881 | switch(types[j] & PathPointTypePathTypeMask){ |
| 882 | case PathPointTypeBezier: |
| 883 | if(pen->startcap == LineCapArrowAnchor) |
| 884 | shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE); |
Evan Stade | 7f0aa3a | 2007-08-02 17:53:08 -0700 | [diff] [blame] | 885 | else if((pen->startcap == LineCapCustom) && pen->customstart) |
| 886 | shorten_bezier_amt(&ptcopy[j - 1], |
Evan Stade | 02887b6 | 2007-08-07 18:42:44 -0700 | [diff] [blame] | 887 | pen->width * pen->customstart->inset, TRUE); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 888 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 889 | draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart, |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 890 | pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X), |
| 891 | pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y), |
| 892 | pt[j - 1].X, pt[j - 1].Y); |
| 893 | |
| 894 | break; |
| 895 | case PathPointTypeLine: |
| 896 | if(pen->startcap == LineCapArrowAnchor) |
| 897 | shorten_line_amt(ptcopy[j].X, ptcopy[j].Y, |
| 898 | &ptcopy[j - 1].X, &ptcopy[j - 1].Y, |
| 899 | pen->width); |
| 900 | else if((pen->startcap == LineCapCustom) && pen->customstart) |
| 901 | shorten_line_amt(ptcopy[j].X, ptcopy[j].Y, |
| 902 | &ptcopy[j - 1].X, &ptcopy[j - 1].Y, |
| 903 | pen->customstart->inset * pen->width); |
| 904 | |
Evan Stade | 629e013 | 2007-07-27 16:07:50 -0700 | [diff] [blame] | 905 | draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart, |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 906 | pt[j].X, pt[j].Y, pt[j - 1].X, |
| 907 | pt[j - 1].Y); |
| 908 | |
| 909 | break; |
| 910 | default: |
| 911 | ERR("Bad path points\n"); |
| 912 | goto end; |
| 913 | } |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 914 | } |
Evan Stade | c3e8af4 | 2007-07-24 17:18:50 -0700 | [diff] [blame] | 915 | |
| 916 | transform_and_round_points(graphics, pti, ptcopy, count); |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 917 | |
| 918 | for(i = 0; i < count; i++){ |
| 919 | tp[i] = convert_path_point_type(types[i]); |
| 920 | } |
| 921 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 922 | PolyDraw(graphics->hdc, pti, tp, count); |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 923 | |
| 924 | status = Ok; |
| 925 | |
| 926 | end: |
| 927 | GdipFree(pti); |
Evan Stade | a84b567 | 2007-07-20 17:50:11 -0700 | [diff] [blame] | 928 | GdipFree(ptcopy); |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 929 | GdipFree(tp); |
| 930 | |
| 931 | return status; |
| 932 | } |
| 933 | |
Vincent Povirk | 08aa0ca | 2008-11-24 15:01:47 -0600 | [diff] [blame] | 934 | GpStatus trace_path(GpGraphics *graphics, GpPath *path) |
| 935 | { |
| 936 | GpStatus result; |
| 937 | |
| 938 | BeginPath(graphics->hdc); |
| 939 | result = draw_poly(graphics, NULL, path->pathdata.Points, |
| 940 | path->pathdata.Types, path->pathdata.Count, FALSE); |
| 941 | EndPath(graphics->hdc); |
| 942 | return result; |
| 943 | } |
| 944 | |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 945 | typedef struct _GraphicsContainerItem { |
| 946 | struct list entry; |
| 947 | GraphicsContainer contid; |
| 948 | |
| 949 | SmoothingMode smoothing; |
| 950 | CompositingQuality compqual; |
| 951 | InterpolationMode interpolation; |
| 952 | CompositingMode compmode; |
| 953 | TextRenderingHint texthint; |
| 954 | REAL scale; |
| 955 | GpUnit unit; |
| 956 | PixelOffsetMode pixeloffset; |
| 957 | UINT textcontrast; |
| 958 | GpMatrix* worldtrans; |
| 959 | GpRegion* clip; |
| 960 | } GraphicsContainerItem; |
| 961 | |
| 962 | static GpStatus init_container(GraphicsContainerItem** container, |
| 963 | GDIPCONST GpGraphics* graphics){ |
| 964 | GpStatus sts; |
| 965 | |
| 966 | *container = GdipAlloc(sizeof(GraphicsContainerItem)); |
| 967 | if(!(*container)) |
| 968 | return OutOfMemory; |
| 969 | |
| 970 | (*container)->contid = graphics->contid + 1; |
| 971 | |
| 972 | (*container)->smoothing = graphics->smoothing; |
| 973 | (*container)->compqual = graphics->compqual; |
| 974 | (*container)->interpolation = graphics->interpolation; |
| 975 | (*container)->compmode = graphics->compmode; |
| 976 | (*container)->texthint = graphics->texthint; |
| 977 | (*container)->scale = graphics->scale; |
| 978 | (*container)->unit = graphics->unit; |
| 979 | (*container)->textcontrast = graphics->textcontrast; |
| 980 | (*container)->pixeloffset = graphics->pixeloffset; |
| 981 | |
| 982 | sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans); |
| 983 | if(sts != Ok){ |
| 984 | GdipFree(*container); |
| 985 | *container = NULL; |
| 986 | return sts; |
| 987 | } |
| 988 | |
| 989 | sts = GdipCloneRegion(graphics->clip, &(*container)->clip); |
| 990 | if(sts != Ok){ |
| 991 | GdipDeleteMatrix((*container)->worldtrans); |
| 992 | GdipFree(*container); |
| 993 | *container = NULL; |
| 994 | return sts; |
| 995 | } |
| 996 | |
| 997 | return Ok; |
| 998 | } |
| 999 | |
| 1000 | static void delete_container(GraphicsContainerItem* container){ |
| 1001 | GdipDeleteMatrix(container->worldtrans); |
| 1002 | GdipDeleteRegion(container->clip); |
| 1003 | GdipFree(container); |
| 1004 | } |
| 1005 | |
| 1006 | static GpStatus restore_container(GpGraphics* graphics, |
| 1007 | GDIPCONST GraphicsContainerItem* container){ |
| 1008 | GpStatus sts; |
| 1009 | GpMatrix *newTrans; |
| 1010 | GpRegion *newClip; |
| 1011 | |
| 1012 | sts = GdipCloneMatrix(container->worldtrans, &newTrans); |
| 1013 | if(sts != Ok) |
| 1014 | return sts; |
| 1015 | |
| 1016 | sts = GdipCloneRegion(container->clip, &newClip); |
| 1017 | if(sts != Ok){ |
| 1018 | GdipDeleteMatrix(newTrans); |
| 1019 | return sts; |
| 1020 | } |
| 1021 | |
| 1022 | GdipDeleteMatrix(graphics->worldtrans); |
| 1023 | graphics->worldtrans = newTrans; |
| 1024 | |
| 1025 | GdipDeleteRegion(graphics->clip); |
| 1026 | graphics->clip = newClip; |
| 1027 | |
| 1028 | graphics->contid = container->contid - 1; |
| 1029 | |
| 1030 | graphics->smoothing = container->smoothing; |
| 1031 | graphics->compqual = container->compqual; |
| 1032 | graphics->interpolation = container->interpolation; |
| 1033 | graphics->compmode = container->compmode; |
| 1034 | graphics->texthint = container->texthint; |
| 1035 | graphics->scale = container->scale; |
| 1036 | graphics->unit = container->unit; |
| 1037 | graphics->textcontrast = container->textcontrast; |
| 1038 | graphics->pixeloffset = container->pixeloffset; |
| 1039 | |
| 1040 | return Ok; |
| 1041 | } |
| 1042 | |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1043 | GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics) |
| 1044 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1045 | TRACE("(%p, %p)\n", hdc, graphics); |
| 1046 | |
Stefan Leichter | bfffb4f | 2007-12-23 10:56:32 +0100 | [diff] [blame] | 1047 | return GdipCreateFromHDC2(hdc, NULL, graphics); |
| 1048 | } |
| 1049 | |
| 1050 | GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics) |
| 1051 | { |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 1052 | GpStatus retval; |
| 1053 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1054 | TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics); |
| 1055 | |
Stefan Leichter | bfffb4f | 2007-12-23 10:56:32 +0100 | [diff] [blame] | 1056 | if(hDevice != NULL) { |
Ken Sharp | e3f4859 | 2009-06-09 21:48:05 +0100 | [diff] [blame] | 1057 | FIXME("Don't know how to handle parameter hDevice\n"); |
Stefan Leichter | bfffb4f | 2007-12-23 10:56:32 +0100 | [diff] [blame] | 1058 | return NotImplemented; |
| 1059 | } |
| 1060 | |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1061 | if(hdc == NULL) |
| 1062 | return OutOfMemory; |
| 1063 | |
| 1064 | if(graphics == NULL) |
| 1065 | return InvalidParameter; |
| 1066 | |
Evan Stade | 6490dad | 2007-06-22 19:27:02 -0700 | [diff] [blame] | 1067 | *graphics = GdipAlloc(sizeof(GpGraphics)); |
| 1068 | if(!*graphics) return OutOfMemory; |
| 1069 | |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 1070 | if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){ |
| 1071 | GdipFree(*graphics); |
| 1072 | return retval; |
| 1073 | } |
| 1074 | |
Nikolay Sivov | ef50aa3 | 2008-08-27 02:03:27 +0400 | [diff] [blame] | 1075 | if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){ |
| 1076 | GdipFree((*graphics)->worldtrans); |
| 1077 | GdipFree(*graphics); |
| 1078 | return retval; |
| 1079 | } |
| 1080 | |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1081 | (*graphics)->hdc = hdc; |
Nikolay Sivov | 7258dea | 2008-09-05 16:51:25 +0400 | [diff] [blame] | 1082 | (*graphics)->hwnd = WindowFromDC(hdc); |
Vincent Povirk | 8a3d9ff | 2009-04-24 13:29:56 -0500 | [diff] [blame] | 1083 | (*graphics)->owndc = FALSE; |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 1084 | (*graphics)->smoothing = SmoothingModeDefault; |
Evan Stade | 60cad23 | 2007-07-13 17:51:25 -0700 | [diff] [blame] | 1085 | (*graphics)->compqual = CompositingQualityDefault; |
Evan Stade | a87ce7a | 2007-07-13 17:51:29 -0700 | [diff] [blame] | 1086 | (*graphics)->interpolation = InterpolationModeDefault; |
Evan Stade | d6bd866d | 2007-07-13 17:51:33 -0700 | [diff] [blame] | 1087 | (*graphics)->pixeloffset = PixelOffsetModeDefault; |
Evan Stade | e807eb9 | 2007-08-13 18:34:27 -0700 | [diff] [blame] | 1088 | (*graphics)->compmode = CompositingModeSourceOver; |
Evan Stade | 10b575b | 2007-07-23 20:24:41 -0700 | [diff] [blame] | 1089 | (*graphics)->unit = UnitDisplay; |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 1090 | (*graphics)->scale = 1.0; |
Nikolay Sivov | 366ae1e | 2008-08-24 14:45:18 +0400 | [diff] [blame] | 1091 | (*graphics)->busy = FALSE; |
Nikolay Sivov | 56173d4 | 2008-11-09 14:32:26 +0300 | [diff] [blame] | 1092 | (*graphics)->textcontrast = 4; |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 1093 | list_init(&(*graphics)->containers); |
| 1094 | (*graphics)->contid = 0; |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1095 | |
| 1096 | return Ok; |
| 1097 | } |
| 1098 | |
| 1099 | GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics) |
| 1100 | { |
| 1101 | GpStatus ret; |
Vincent Povirk | c3d2395 | 2009-04-24 13:34:55 -0500 | [diff] [blame] | 1102 | HDC hdc; |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1103 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1104 | TRACE("(%p, %p)\n", hwnd, graphics); |
| 1105 | |
Vincent Povirk | c3d2395 | 2009-04-24 13:34:55 -0500 | [diff] [blame] | 1106 | hdc = GetDC(hwnd); |
| 1107 | |
| 1108 | if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok) |
| 1109 | { |
| 1110 | ReleaseDC(hwnd, hdc); |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1111 | return ret; |
Vincent Povirk | c3d2395 | 2009-04-24 13:34:55 -0500 | [diff] [blame] | 1112 | } |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1113 | |
| 1114 | (*graphics)->hwnd = hwnd; |
Vincent Povirk | 8a3d9ff | 2009-04-24 13:29:56 -0500 | [diff] [blame] | 1115 | (*graphics)->owndc = TRUE; |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1116 | |
| 1117 | return Ok; |
| 1118 | } |
| 1119 | |
Nikolay Sivov | eb18ce9 | 2008-05-09 16:40:41 +0400 | [diff] [blame] | 1120 | /* FIXME: no icm handling */ |
| 1121 | GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics) |
| 1122 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1123 | TRACE("(%p, %p)\n", hwnd, graphics); |
| 1124 | |
Nikolay Sivov | eb18ce9 | 2008-05-09 16:40:41 +0400 | [diff] [blame] | 1125 | return GdipCreateFromHWND(hwnd, graphics); |
| 1126 | } |
| 1127 | |
Evan Stade | 5cc8c10 | 2007-07-24 17:19:05 -0700 | [diff] [blame] | 1128 | GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete, |
| 1129 | GpMetafile **metafile) |
| 1130 | { |
| 1131 | static int calls; |
| 1132 | |
| 1133 | if(!hemf || !metafile) |
| 1134 | return InvalidParameter; |
| 1135 | |
| 1136 | if(!(calls++)) |
| 1137 | FIXME("not implemented\n"); |
| 1138 | |
| 1139 | return NotImplemented; |
| 1140 | } |
| 1141 | |
Evan Stade | 021997f | 2007-07-24 17:19:15 -0700 | [diff] [blame] | 1142 | GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete, |
| 1143 | GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile) |
| 1144 | { |
Evan Stade | cfef981 | 2007-07-31 19:15:12 -0700 | [diff] [blame] | 1145 | IStream *stream = NULL; |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1146 | UINT read; |
| 1147 | BYTE* copy; |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1148 | HENHMETAFILE hemf; |
Evan Stade | cfef981 | 2007-07-31 19:15:12 -0700 | [diff] [blame] | 1149 | GpStatus retval = GenericError; |
Evan Stade | 021997f | 2007-07-24 17:19:15 -0700 | [diff] [blame] | 1150 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1151 | TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile); |
| 1152 | |
Evan Stade | 021997f | 2007-07-24 17:19:15 -0700 | [diff] [blame] | 1153 | if(!hwmf || !metafile || !placeable) |
| 1154 | return InvalidParameter; |
Evan Stade | 7d03a41 | 2007-08-07 18:42:16 -0700 | [diff] [blame] | 1155 | |
| 1156 | *metafile = NULL; |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1157 | read = GetMetaFileBitsEx(hwmf, 0, NULL); |
| 1158 | if(!read) |
| 1159 | return GenericError; |
| 1160 | copy = GdipAlloc(read); |
| 1161 | GetMetaFileBitsEx(hwmf, read, copy); |
| 1162 | |
Evan Stade | 192e111 | 2007-08-01 17:55:33 -0700 | [diff] [blame] | 1163 | hemf = SetWinMetaFileBits(read, copy, NULL, NULL); |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1164 | GdipFree(copy); |
| 1165 | |
| 1166 | read = GetEnhMetaFileBits(hemf, 0, NULL); |
| 1167 | copy = GdipAlloc(read); |
| 1168 | GetEnhMetaFileBits(hemf, read, copy); |
| 1169 | DeleteEnhMetaFile(hemf); |
| 1170 | |
| 1171 | if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){ |
| 1172 | ERR("could not make stream\n"); |
Evan Stade | 7d03a41 | 2007-08-07 18:42:16 -0700 | [diff] [blame] | 1173 | GdipFree(copy); |
| 1174 | goto err; |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | *metafile = GdipAlloc(sizeof(GpMetafile)); |
Evan Stade | cfef981 | 2007-07-31 19:15:12 -0700 | [diff] [blame] | 1178 | if(!*metafile){ |
| 1179 | retval = OutOfMemory; |
Evan Stade | 7d03a41 | 2007-08-07 18:42:16 -0700 | [diff] [blame] | 1180 | goto err; |
Evan Stade | cfef981 | 2007-07-31 19:15:12 -0700 | [diff] [blame] | 1181 | } |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1182 | |
| 1183 | if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture, |
Evan Stade | 7d03a41 | 2007-08-07 18:42:16 -0700 | [diff] [blame] | 1184 | (LPVOID*) &((*metafile)->image.picture)) != S_OK) |
| 1185 | goto err; |
| 1186 | |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1187 | |
| 1188 | (*metafile)->image.type = ImageTypeMetafile; |
Evan Stade | 586e63e | 2007-07-30 19:09:57 -0700 | [diff] [blame] | 1189 | (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch); |
| 1190 | (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Right) / ((REAL) placeable->Inch); |
| 1191 | (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right |
| 1192 | - placeable->BoundingBox.Left)) / ((REAL) placeable->Inch); |
| 1193 | (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom |
| 1194 | - placeable->BoundingBox.Top)) / ((REAL) placeable->Inch); |
| 1195 | (*metafile)->unit = UnitInch; |
| 1196 | |
Evan Stade | 50799cf | 2007-07-30 19:10:03 -0700 | [diff] [blame] | 1197 | if(delete) |
| 1198 | DeleteMetaFile(hwmf); |
| 1199 | |
Evan Stade | 7d03a41 | 2007-08-07 18:42:16 -0700 | [diff] [blame] | 1200 | return Ok; |
Evan Stade | cfef981 | 2007-07-31 19:15:12 -0700 | [diff] [blame] | 1201 | |
Evan Stade | 7d03a41 | 2007-08-07 18:42:16 -0700 | [diff] [blame] | 1202 | err: |
| 1203 | GdipFree(*metafile); |
Evan Stade | cfef981 | 2007-07-31 19:15:12 -0700 | [diff] [blame] | 1204 | IStream_Release(stream); |
Evan Stade | cfef981 | 2007-07-31 19:15:12 -0700 | [diff] [blame] | 1205 | return retval; |
Evan Stade | 021997f | 2007-07-24 17:19:15 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
Huw Davies | eb9d7f5 | 2008-07-10 15:30:30 +0100 | [diff] [blame] | 1208 | GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file, |
| 1209 | GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile) |
| 1210 | { |
| 1211 | HMETAFILE hmf = GetMetaFileW(file); |
| 1212 | |
| 1213 | TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile); |
| 1214 | |
| 1215 | if(!hmf) return InvalidParameter; |
| 1216 | |
| 1217 | return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile); |
| 1218 | } |
| 1219 | |
Andrew Eikum | c02e75c | 2009-06-01 20:02:11 -0500 | [diff] [blame] | 1220 | GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file, |
| 1221 | GpMetafile **metafile) |
| 1222 | { |
| 1223 | FIXME("(%p, %p): stub\n", file, metafile); |
| 1224 | return NotImplemented; |
| 1225 | } |
| 1226 | |
| 1227 | GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream, |
| 1228 | GpMetafile **metafile) |
| 1229 | { |
| 1230 | FIXME("(%p, %p): stub\n", stream, metafile); |
| 1231 | return NotImplemented; |
| 1232 | } |
| 1233 | |
Evan Stade | 3ea77f5 | 2007-08-07 18:42:00 -0700 | [diff] [blame] | 1234 | GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename, |
| 1235 | UINT access, IStream **stream) |
| 1236 | { |
| 1237 | DWORD dwMode; |
| 1238 | HRESULT ret; |
| 1239 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1240 | TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream); |
| 1241 | |
Evan Stade | 3ea77f5 | 2007-08-07 18:42:00 -0700 | [diff] [blame] | 1242 | if(!stream || !filename) |
| 1243 | return InvalidParameter; |
| 1244 | |
| 1245 | if(access & GENERIC_WRITE) |
| 1246 | dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE; |
| 1247 | else if(access & GENERIC_READ) |
| 1248 | dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE; |
| 1249 | else |
| 1250 | return InvalidParameter; |
| 1251 | |
| 1252 | ret = SHCreateStreamOnFileW(filename, dwMode, stream); |
| 1253 | |
| 1254 | return hresult_to_status(ret); |
| 1255 | } |
| 1256 | |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1257 | GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics) |
| 1258 | { |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 1259 | GraphicsContainerItem *cont, *next; |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1260 | TRACE("(%p)\n", graphics); |
| 1261 | |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1262 | if(!graphics) return InvalidParameter; |
Nikolay Sivov | 960de09 | 2008-08-26 01:58:33 +0400 | [diff] [blame] | 1263 | if(graphics->busy) return ObjectBusy; |
| 1264 | |
Vincent Povirk | 8a3d9ff | 2009-04-24 13:29:56 -0500 | [diff] [blame] | 1265 | if(graphics->owndc) |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1266 | ReleaseDC(graphics->hwnd, graphics->hdc); |
| 1267 | |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 1268 | LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){ |
| 1269 | list_remove(&cont->entry); |
| 1270 | delete_container(cont); |
| 1271 | } |
| 1272 | |
Nikolay Sivov | ef50aa3 | 2008-08-27 02:03:27 +0400 | [diff] [blame] | 1273 | GdipDeleteRegion(graphics->clip); |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 1274 | GdipDeleteMatrix(graphics->worldtrans); |
Nikolay Sivov | 6e37ec6 | 2008-08-24 14:45:05 +0400 | [diff] [blame] | 1275 | GdipFree(graphics); |
Evan Stade | d50be49 | 2007-06-11 11:54:03 -0700 | [diff] [blame] | 1276 | |
| 1277 | return Ok; |
| 1278 | } |
Evan Stade | 2689b18 | 2007-06-12 10:44:31 -0700 | [diff] [blame] | 1279 | |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1280 | GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x, |
| 1281 | REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle) |
| 1282 | { |
Evan Stade | 40f2273 | 2007-07-11 18:07:09 -0700 | [diff] [blame] | 1283 | INT save_state, num_pts; |
| 1284 | GpPointF points[MAX_ARC_PTS]; |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 1285 | GpStatus retval; |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1286 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1287 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, |
| 1288 | width, height, startAngle, sweepAngle); |
| 1289 | |
Royal Chan | ea92872 | 2008-02-25 21:06:27 -0800 | [diff] [blame] | 1290 | if(!graphics || !pen || width <= 0 || height <= 0) |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1291 | return InvalidParameter; |
| 1292 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1293 | if(graphics->busy) |
| 1294 | return ObjectBusy; |
| 1295 | |
Evan Stade | 40f2273 | 2007-07-11 18:07:09 -0700 | [diff] [blame] | 1296 | num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle); |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1297 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1298 | save_state = prepare_dc(graphics, pen); |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1299 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 1300 | retval = draw_polybezier(graphics, pen, points, num_pts, TRUE); |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1301 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1302 | restore_dc(graphics, save_state); |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1303 | |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 1304 | return retval; |
Evan Stade | c42f879 | 2007-06-19 19:31:19 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Royal Chan | fc31303 | 2008-02-25 21:02:59 -0800 | [diff] [blame] | 1307 | GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x, |
| 1308 | INT y, INT width, INT height, REAL startAngle, REAL sweepAngle) |
| 1309 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1310 | TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y, |
| 1311 | width, height, startAngle, sweepAngle); |
| 1312 | |
Nikolay Sivov | a77dc34 | 2008-05-08 00:39:05 +0400 | [diff] [blame] | 1313 | return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle); |
Royal Chan | fc31303 | 2008-02-25 21:02:59 -0800 | [diff] [blame] | 1314 | } |
| 1315 | |
Evan Stade | 8b9f534 | 2007-06-15 21:27:38 -0700 | [diff] [blame] | 1316 | GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1, |
| 1317 | REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4) |
| 1318 | { |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 1319 | INT save_state; |
| 1320 | GpPointF pt[4]; |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 1321 | GpStatus retval; |
Evan Stade | 8b9f534 | 2007-06-15 21:27:38 -0700 | [diff] [blame] | 1322 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1323 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, |
| 1324 | x2, y2, x3, y3, x4, y4); |
| 1325 | |
Evan Stade | 8b9f534 | 2007-06-15 21:27:38 -0700 | [diff] [blame] | 1326 | if(!graphics || !pen) |
| 1327 | return InvalidParameter; |
| 1328 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1329 | if(graphics->busy) |
| 1330 | return ObjectBusy; |
| 1331 | |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 1332 | pt[0].X = x1; |
| 1333 | pt[0].Y = y1; |
| 1334 | pt[1].X = x2; |
| 1335 | pt[1].Y = y2; |
| 1336 | pt[2].X = x3; |
| 1337 | pt[2].Y = y3; |
| 1338 | pt[3].X = x4; |
| 1339 | pt[3].Y = y4; |
Evan Stade | 8b9f534 | 2007-06-15 21:27:38 -0700 | [diff] [blame] | 1340 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1341 | save_state = prepare_dc(graphics, pen); |
Evan Stade | 8b9f534 | 2007-06-15 21:27:38 -0700 | [diff] [blame] | 1342 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 1343 | retval = draw_polybezier(graphics, pen, pt, 4, TRUE); |
Evan Stade | 69a807c | 2007-07-06 16:13:49 -0700 | [diff] [blame] | 1344 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1345 | restore_dc(graphics, save_state); |
Evan Stade | 8b9f534 | 2007-06-15 21:27:38 -0700 | [diff] [blame] | 1346 | |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 1347 | return retval; |
Evan Stade | 8b9f534 | 2007-06-15 21:27:38 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Royal Chan | da161a5 | 2008-02-25 21:00:43 -0800 | [diff] [blame] | 1350 | GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1, |
| 1351 | INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4) |
| 1352 | { |
| 1353 | INT save_state; |
| 1354 | GpPointF pt[4]; |
| 1355 | GpStatus retval; |
| 1356 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1357 | TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1, |
| 1358 | x2, y2, x3, y3, x4, y4); |
| 1359 | |
Royal Chan | da161a5 | 2008-02-25 21:00:43 -0800 | [diff] [blame] | 1360 | if(!graphics || !pen) |
| 1361 | return InvalidParameter; |
| 1362 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1363 | if(graphics->busy) |
| 1364 | return ObjectBusy; |
| 1365 | |
Royal Chan | da161a5 | 2008-02-25 21:00:43 -0800 | [diff] [blame] | 1366 | pt[0].X = x1; |
| 1367 | pt[0].Y = y1; |
| 1368 | pt[1].X = x2; |
| 1369 | pt[1].Y = y2; |
| 1370 | pt[2].X = x3; |
| 1371 | pt[2].Y = y3; |
| 1372 | pt[3].X = x4; |
| 1373 | pt[3].Y = y4; |
| 1374 | |
| 1375 | save_state = prepare_dc(graphics, pen); |
| 1376 | |
| 1377 | retval = draw_polybezier(graphics, pen, pt, 4, TRUE); |
| 1378 | |
| 1379 | restore_dc(graphics, save_state); |
| 1380 | |
| 1381 | return retval; |
| 1382 | } |
| 1383 | |
Nikolay Sivov | d020474 | 2008-07-03 03:04:50 +0400 | [diff] [blame] | 1384 | GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen, |
| 1385 | GDIPCONST GpPointF *points, INT count) |
| 1386 | { |
| 1387 | INT i; |
| 1388 | GpStatus ret; |
| 1389 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1390 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 1391 | |
Nikolay Sivov | d020474 | 2008-07-03 03:04:50 +0400 | [diff] [blame] | 1392 | if(!graphics || !pen || !points || (count <= 0)) |
| 1393 | return InvalidParameter; |
| 1394 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1395 | if(graphics->busy) |
| 1396 | return ObjectBusy; |
| 1397 | |
Nikolay Sivov | d020474 | 2008-07-03 03:04:50 +0400 | [diff] [blame] | 1398 | for(i = 0; i < floor(count / 4); i++){ |
| 1399 | ret = GdipDrawBezier(graphics, pen, |
| 1400 | points[4*i].X, points[4*i].Y, |
| 1401 | points[4*i + 1].X, points[4*i + 1].Y, |
| 1402 | points[4*i + 2].X, points[4*i + 2].Y, |
| 1403 | points[4*i + 3].X, points[4*i + 3].Y); |
| 1404 | if(ret != Ok) |
| 1405 | return ret; |
| 1406 | } |
| 1407 | |
| 1408 | return Ok; |
| 1409 | } |
| 1410 | |
| 1411 | GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen, |
| 1412 | GDIPCONST GpPoint *points, INT count) |
| 1413 | { |
| 1414 | GpPointF *pts; |
| 1415 | GpStatus ret; |
| 1416 | INT i; |
| 1417 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1418 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 1419 | |
Nikolay Sivov | d020474 | 2008-07-03 03:04:50 +0400 | [diff] [blame] | 1420 | if(!graphics || !pen || !points || (count <= 0)) |
| 1421 | return InvalidParameter; |
| 1422 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1423 | if(graphics->busy) |
| 1424 | return ObjectBusy; |
| 1425 | |
Nikolay Sivov | d020474 | 2008-07-03 03:04:50 +0400 | [diff] [blame] | 1426 | pts = GdipAlloc(sizeof(GpPointF) * count); |
| 1427 | if(!pts) |
| 1428 | return OutOfMemory; |
| 1429 | |
| 1430 | for(i = 0; i < count; i++){ |
| 1431 | pts[i].X = (REAL)points[i].X; |
| 1432 | pts[i].Y = (REAL)points[i].Y; |
| 1433 | } |
| 1434 | |
| 1435 | ret = GdipDrawBeziers(graphics,pen,pts,count); |
| 1436 | |
| 1437 | GdipFree(pts); |
| 1438 | |
| 1439 | return ret; |
| 1440 | } |
| 1441 | |
Nikolay Sivov | 55916bb | 2008-07-09 00:39:31 +0400 | [diff] [blame] | 1442 | GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen, |
| 1443 | GDIPCONST GpPointF *points, INT count) |
| 1444 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1445 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 1446 | |
Nikolay Sivov | 55916bb | 2008-07-09 00:39:31 +0400 | [diff] [blame] | 1447 | return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0); |
| 1448 | } |
| 1449 | |
| 1450 | GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen, |
| 1451 | GDIPCONST GpPoint *points, INT count) |
| 1452 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1453 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 1454 | |
Nikolay Sivov | 55916bb | 2008-07-09 00:39:31 +0400 | [diff] [blame] | 1455 | return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0); |
| 1456 | } |
| 1457 | |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1458 | GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen, |
| 1459 | GDIPCONST GpPointF *points, INT count, REAL tension) |
| 1460 | { |
Nikolay Sivov | 9c60a57 | 2008-09-03 19:57:09 +0400 | [diff] [blame] | 1461 | GpPath *path; |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1462 | GpStatus stat; |
| 1463 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1464 | TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension); |
| 1465 | |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1466 | if(!graphics || !pen || !points || count <= 0) |
| 1467 | return InvalidParameter; |
| 1468 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1469 | if(graphics->busy) |
| 1470 | return ObjectBusy; |
| 1471 | |
Nikolay Sivov | 9c60a57 | 2008-09-03 19:57:09 +0400 | [diff] [blame] | 1472 | if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok) |
| 1473 | return stat; |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1474 | |
Nikolay Sivov | 9c60a57 | 2008-09-03 19:57:09 +0400 | [diff] [blame] | 1475 | stat = GdipAddPathClosedCurve2(path, points, count, tension); |
| 1476 | if(stat != Ok){ |
| 1477 | GdipDeletePath(path); |
| 1478 | return stat; |
| 1479 | } |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1480 | |
Nikolay Sivov | 9c60a57 | 2008-09-03 19:57:09 +0400 | [diff] [blame] | 1481 | stat = GdipDrawPath(graphics, pen, path); |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1482 | |
Nikolay Sivov | 9c60a57 | 2008-09-03 19:57:09 +0400 | [diff] [blame] | 1483 | GdipDeletePath(path); |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1484 | |
| 1485 | return stat; |
| 1486 | } |
| 1487 | |
| 1488 | GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen, |
| 1489 | GDIPCONST GpPoint *points, INT count, REAL tension) |
| 1490 | { |
| 1491 | GpPointF *ptf; |
| 1492 | GpStatus stat; |
| 1493 | INT i; |
| 1494 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1495 | TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension); |
| 1496 | |
Nikolay Sivov | 8b8864b | 2008-07-09 00:39:19 +0400 | [diff] [blame] | 1497 | if(!points || count <= 0) |
| 1498 | return InvalidParameter; |
| 1499 | |
| 1500 | ptf = GdipAlloc(sizeof(GpPointF)*count); |
| 1501 | if(!ptf) |
| 1502 | return OutOfMemory; |
| 1503 | |
| 1504 | for(i = 0; i < count; i++){ |
| 1505 | ptf[i].X = (REAL)points[i].X; |
| 1506 | ptf[i].Y = (REAL)points[i].Y; |
| 1507 | } |
| 1508 | |
| 1509 | stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension); |
| 1510 | |
| 1511 | GdipFree(ptf); |
| 1512 | |
| 1513 | return stat; |
| 1514 | } |
| 1515 | |
Nikolay Sivov | fe1782e | 2008-04-29 00:09:55 +0400 | [diff] [blame] | 1516 | GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen, |
| 1517 | GDIPCONST GpPointF *points, INT count) |
| 1518 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1519 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 1520 | |
Nikolay Sivov | fe1782e | 2008-04-29 00:09:55 +0400 | [diff] [blame] | 1521 | return GdipDrawCurve2(graphics,pen,points,count,1.0); |
| 1522 | } |
| 1523 | |
| 1524 | GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen, |
| 1525 | GDIPCONST GpPoint *points, INT count) |
| 1526 | { |
| 1527 | GpPointF *pointsF; |
| 1528 | GpStatus ret; |
| 1529 | INT i; |
| 1530 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1531 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 1532 | |
Andrew Eikum | fe55f0d | 2009-06-28 13:33:52 -0500 | [diff] [blame] | 1533 | if(!points) |
Nikolay Sivov | fe1782e | 2008-04-29 00:09:55 +0400 | [diff] [blame] | 1534 | return InvalidParameter; |
| 1535 | |
| 1536 | pointsF = GdipAlloc(sizeof(GpPointF)*count); |
| 1537 | if(!pointsF) |
| 1538 | return OutOfMemory; |
| 1539 | |
| 1540 | for(i = 0; i < count; i++){ |
| 1541 | pointsF[i].X = (REAL)points[i].X; |
| 1542 | pointsF[i].Y = (REAL)points[i].Y; |
| 1543 | } |
| 1544 | |
| 1545 | ret = GdipDrawCurve(graphics,pen,pointsF,count); |
| 1546 | GdipFree(pointsF); |
| 1547 | |
| 1548 | return ret; |
| 1549 | } |
| 1550 | |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1551 | /* Approximates cardinal spline with Bezier curves. */ |
| 1552 | GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen, |
| 1553 | GDIPCONST GpPointF *points, INT count, REAL tension) |
| 1554 | { |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1555 | /* PolyBezier expects count*3-2 points. */ |
Evan Stade | b72dc0d | 2007-07-09 20:54:23 -0700 | [diff] [blame] | 1556 | INT i, len_pt = count*3-2, save_state; |
| 1557 | GpPointF *pt; |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1558 | REAL x1, x2, y1, y2; |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 1559 | GpStatus retval; |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1560 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1561 | TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension); |
| 1562 | |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1563 | if(!graphics || !pen) |
| 1564 | return InvalidParameter; |
| 1565 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1566 | if(graphics->busy) |
| 1567 | return ObjectBusy; |
| 1568 | |
Andrew Eikum | 119e9af | 2009-06-06 12:02:29 -0500 | [diff] [blame] | 1569 | if(count < 2) |
| 1570 | return InvalidParameter; |
| 1571 | |
Evan Stade | b72dc0d | 2007-07-09 20:54:23 -0700 | [diff] [blame] | 1572 | pt = GdipAlloc(len_pt * sizeof(GpPointF)); |
Andrew Eikum | 119e9af | 2009-06-06 12:02:29 -0500 | [diff] [blame] | 1573 | if(!pt) |
| 1574 | return OutOfMemory; |
| 1575 | |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1576 | tension = tension * TENSION_CONST; |
| 1577 | |
| 1578 | calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y, |
| 1579 | tension, &x1, &y1); |
| 1580 | |
Evan Stade | b72dc0d | 2007-07-09 20:54:23 -0700 | [diff] [blame] | 1581 | pt[0].X = points[0].X; |
| 1582 | pt[0].Y = points[0].Y; |
| 1583 | pt[1].X = x1; |
| 1584 | pt[1].Y = y1; |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1585 | |
| 1586 | for(i = 0; i < count-2; i++){ |
| 1587 | calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2); |
| 1588 | |
Evan Stade | b72dc0d | 2007-07-09 20:54:23 -0700 | [diff] [blame] | 1589 | pt[3*i+2].X = x1; |
| 1590 | pt[3*i+2].Y = y1; |
| 1591 | pt[3*i+3].X = points[i+1].X; |
| 1592 | pt[3*i+3].Y = points[i+1].Y; |
| 1593 | pt[3*i+4].X = x2; |
| 1594 | pt[3*i+4].Y = y2; |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | calc_curve_bezier_endp(points[count-1].X, points[count-1].Y, |
| 1598 | points[count-2].X, points[count-2].Y, tension, &x1, &y1); |
| 1599 | |
Evan Stade | b72dc0d | 2007-07-09 20:54:23 -0700 | [diff] [blame] | 1600 | pt[len_pt-2].X = x1; |
| 1601 | pt[len_pt-2].Y = y1; |
| 1602 | pt[len_pt-1].X = points[count-1].X; |
| 1603 | pt[len_pt-1].Y = points[count-1].Y; |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1604 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1605 | save_state = prepare_dc(graphics, pen); |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1606 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 1607 | retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE); |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1608 | |
Evan Stade | b72dc0d | 2007-07-09 20:54:23 -0700 | [diff] [blame] | 1609 | GdipFree(pt); |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1610 | restore_dc(graphics, save_state); |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1611 | |
Evan Stade | fa31217 | 2007-07-11 18:07:39 -0700 | [diff] [blame] | 1612 | return retval; |
Evan Stade | 5c8b83c | 2007-06-19 19:31:28 -0700 | [diff] [blame] | 1613 | } |
| 1614 | |
Nikolay Sivov | 00cfffb | 2008-04-29 00:09:44 +0400 | [diff] [blame] | 1615 | GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen, |
| 1616 | GDIPCONST GpPoint *points, INT count, REAL tension) |
| 1617 | { |
| 1618 | GpPointF *pointsF; |
| 1619 | GpStatus ret; |
| 1620 | INT i; |
| 1621 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1622 | TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension); |
| 1623 | |
Andrew Eikum | c2aa66d | 2009-06-28 13:33:59 -0500 | [diff] [blame] | 1624 | if(!points) |
Nikolay Sivov | 00cfffb | 2008-04-29 00:09:44 +0400 | [diff] [blame] | 1625 | return InvalidParameter; |
| 1626 | |
| 1627 | pointsF = GdipAlloc(sizeof(GpPointF)*count); |
| 1628 | if(!pointsF) |
| 1629 | return OutOfMemory; |
| 1630 | |
| 1631 | for(i = 0; i < count; i++){ |
| 1632 | pointsF[i].X = (REAL)points[i].X; |
| 1633 | pointsF[i].Y = (REAL)points[i].Y; |
| 1634 | } |
| 1635 | |
| 1636 | ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension); |
| 1637 | GdipFree(pointsF); |
| 1638 | |
| 1639 | return ret; |
| 1640 | } |
| 1641 | |
Andrew Eikum | 4c0edba | 2009-06-29 22:12:40 -0500 | [diff] [blame] | 1642 | GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen, |
| 1643 | GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments, |
| 1644 | REAL tension) |
| 1645 | { |
| 1646 | TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension); |
| 1647 | |
| 1648 | if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){ |
| 1649 | return InvalidParameter; |
| 1650 | } |
| 1651 | |
| 1652 | return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension); |
| 1653 | } |
| 1654 | |
| 1655 | GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen, |
| 1656 | GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments, |
| 1657 | REAL tension) |
| 1658 | { |
| 1659 | TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension); |
| 1660 | |
| 1661 | if(count < 0){ |
| 1662 | return OutOfMemory; |
| 1663 | } |
| 1664 | |
| 1665 | if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){ |
| 1666 | return InvalidParameter; |
| 1667 | } |
| 1668 | |
| 1669 | return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension); |
| 1670 | } |
| 1671 | |
Przemysław Białek | 864384e | 2008-06-27 10:59:23 +0200 | [diff] [blame] | 1672 | GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x, |
| 1673 | REAL y, REAL width, REAL height) |
| 1674 | { |
| 1675 | INT save_state; |
| 1676 | GpPointF ptf[2]; |
| 1677 | POINT pti[2]; |
| 1678 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1679 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height); |
| 1680 | |
Przemysław Białek | 864384e | 2008-06-27 10:59:23 +0200 | [diff] [blame] | 1681 | if(!graphics || !pen) |
| 1682 | return InvalidParameter; |
| 1683 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1684 | if(graphics->busy) |
| 1685 | return ObjectBusy; |
| 1686 | |
Przemysław Białek | 864384e | 2008-06-27 10:59:23 +0200 | [diff] [blame] | 1687 | ptf[0].X = x; |
| 1688 | ptf[0].Y = y; |
| 1689 | ptf[1].X = x + width; |
| 1690 | ptf[1].Y = y + height; |
| 1691 | |
| 1692 | save_state = prepare_dc(graphics, pen); |
| 1693 | SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH)); |
| 1694 | |
| 1695 | transform_and_round_points(graphics, pti, ptf, 2); |
| 1696 | |
| 1697 | Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y); |
| 1698 | |
| 1699 | restore_dc(graphics, save_state); |
| 1700 | |
| 1701 | return Ok; |
| 1702 | } |
| 1703 | |
| 1704 | GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x, |
| 1705 | INT y, INT width, INT height) |
| 1706 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1707 | TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height); |
| 1708 | |
Przemysław Białek | 864384e | 2008-06-27 10:59:23 +0200 | [diff] [blame] | 1709 | return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height); |
| 1710 | } |
| 1711 | |
| 1712 | |
Nikolay Sivov | 4924704 | 2008-04-29 00:10:01 +0400 | [diff] [blame] | 1713 | GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y) |
| 1714 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1715 | TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y); |
| 1716 | |
Nikolay Sivov | 4924704 | 2008-04-29 00:10:01 +0400 | [diff] [blame] | 1717 | /* IPicture::Render uses LONG coords */ |
| 1718 | return GdipDrawImageI(graphics,image,roundr(x),roundr(y)); |
| 1719 | } |
| 1720 | |
Evan Stade | de351ab | 2007-08-07 18:42:12 -0700 | [diff] [blame] | 1721 | GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x, |
| 1722 | INT y) |
| 1723 | { |
| 1724 | UINT width, height, srcw, srch; |
| 1725 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1726 | TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y); |
| 1727 | |
Evan Stade | de351ab | 2007-08-07 18:42:12 -0700 | [diff] [blame] | 1728 | if(!graphics || !image) |
| 1729 | return InvalidParameter; |
| 1730 | |
| 1731 | GdipGetImageWidth(image, &width); |
| 1732 | GdipGetImageHeight(image, &height); |
| 1733 | |
| 1734 | srcw = width * (((REAL) INCH_HIMETRIC) / |
| 1735 | ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX))); |
| 1736 | srch = height * (((REAL) INCH_HIMETRIC) / |
| 1737 | ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY))); |
| 1738 | |
| 1739 | if(image->type != ImageTypeMetafile){ |
| 1740 | y += height; |
| 1741 | height *= -1; |
| 1742 | } |
| 1743 | |
| 1744 | IPicture_Render(image->picture, graphics->hdc, x, y, width, height, |
| 1745 | 0, 0, srcw, srch, NULL); |
| 1746 | |
| 1747 | return Ok; |
| 1748 | } |
| 1749 | |
Andrew Eikum | eec8d51 | 2009-06-02 22:34:37 -0500 | [diff] [blame] | 1750 | GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image, |
| 1751 | REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight, |
| 1752 | GpUnit srcUnit) |
| 1753 | { |
| 1754 | FIXME("(%p, %p, %f, %f, %f, %f, %f, %f, %d): stub\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit); |
| 1755 | return NotImplemented; |
| 1756 | } |
| 1757 | |
| 1758 | GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image, |
| 1759 | INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight, |
| 1760 | GpUnit srcUnit) |
| 1761 | { |
| 1762 | FIXME("(%p, %p, %d, %d, %d, %d, %d, %d, %d): stub\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit); |
| 1763 | return NotImplemented; |
| 1764 | } |
| 1765 | |
Andrew Eikum | 156eeb0 | 2009-06-03 23:31:21 -0500 | [diff] [blame] | 1766 | GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image, |
| 1767 | GDIPCONST GpPointF *dstpoints, INT count) |
| 1768 | { |
| 1769 | FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count); |
| 1770 | return NotImplemented; |
| 1771 | } |
| 1772 | |
| 1773 | GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image, |
| 1774 | GDIPCONST GpPoint *dstpoints, INT count) |
| 1775 | { |
| 1776 | FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count); |
| 1777 | return NotImplemented; |
| 1778 | } |
| 1779 | |
Evan Stade | 04d4c26 | 2007-08-09 18:25:09 -0700 | [diff] [blame] | 1780 | /* FIXME: partially implemented (only works for rectangular parallelograms) */ |
Evan Stade | 460f01b | 2007-07-30 19:09:45 -0700 | [diff] [blame] | 1781 | GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image, |
Evan Stade | a9c4f30 | 2007-07-30 19:10:07 -0700 | [diff] [blame] | 1782 | GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth, |
| 1783 | REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes, |
| 1784 | DrawImageAbort callback, VOID * callbackData) |
Evan Stade | 460f01b | 2007-07-30 19:09:45 -0700 | [diff] [blame] | 1785 | { |
Evan Stade | a9c4f30 | 2007-07-30 19:10:07 -0700 | [diff] [blame] | 1786 | GpPointF ptf[3]; |
| 1787 | POINT pti[3]; |
Evan Stade | 6e0c574 | 2007-07-31 19:16:23 -0700 | [diff] [blame] | 1788 | REAL dx, dy; |
Evan Stade | 460f01b | 2007-07-30 19:09:45 -0700 | [diff] [blame] | 1789 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1790 | TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points, |
| 1791 | count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback, |
Evan Stade | a9c4f30 | 2007-07-30 19:10:07 -0700 | [diff] [blame] | 1792 | callbackData); |
Evan Stade | 460f01b | 2007-07-30 19:09:45 -0700 | [diff] [blame] | 1793 | |
Nikolay Sivov | 8cf5608 | 2008-04-25 01:58:36 +0400 | [diff] [blame] | 1794 | if(!graphics || !image || !points || count != 3) |
Evan Stade | a9c4f30 | 2007-07-30 19:10:07 -0700 | [diff] [blame] | 1795 | return InvalidParameter; |
Evan Stade | 460f01b | 2007-07-30 19:09:45 -0700 | [diff] [blame] | 1796 | |
Evan Stade | 6e0c574 | 2007-07-31 19:16:23 -0700 | [diff] [blame] | 1797 | if(srcUnit == UnitInch) |
| 1798 | dx = dy = (REAL) INCH_HIMETRIC; |
| 1799 | else if(srcUnit == UnitPixel){ |
| 1800 | dx = ((REAL) INCH_HIMETRIC) / |
| 1801 | ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX)); |
| 1802 | dy = ((REAL) INCH_HIMETRIC) / |
| 1803 | ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY)); |
| 1804 | } |
| 1805 | else |
Evan Stade | a9c4f30 | 2007-07-30 19:10:07 -0700 | [diff] [blame] | 1806 | return NotImplemented; |
| 1807 | |
| 1808 | memcpy(ptf, points, 3 * sizeof(GpPointF)); |
| 1809 | transform_and_round_points(graphics, pti, ptf, 3); |
| 1810 | |
Evan Stade | 6e0c574 | 2007-07-31 19:16:23 -0700 | [diff] [blame] | 1811 | /* IPicture renders bitmaps with the y-axis reversed |
| 1812 | * FIXME: flipping for unknown image type might not be correct. */ |
| 1813 | if(image->type != ImageTypeMetafile){ |
| 1814 | INT temp; |
| 1815 | temp = pti[0].y; |
| 1816 | pti[0].y = pti[2].y; |
| 1817 | pti[2].y = temp; |
| 1818 | } |
| 1819 | |
Evan Stade | a9c4f30 | 2007-07-30 19:10:07 -0700 | [diff] [blame] | 1820 | if(IPicture_Render(image->picture, graphics->hdc, |
| 1821 | pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y, |
Evan Stade | 6e0c574 | 2007-07-31 19:16:23 -0700 | [diff] [blame] | 1822 | srcx * dx, srcy * dy, |
| 1823 | srcwidth * dx, srcheight * dy, |
Evan Stade | a9c4f30 | 2007-07-30 19:10:07 -0700 | [diff] [blame] | 1824 | NULL) != S_OK){ |
| 1825 | if(callback) |
| 1826 | callback(callbackData); |
| 1827 | return GenericError; |
| 1828 | } |
| 1829 | |
| 1830 | return Ok; |
Evan Stade | 460f01b | 2007-07-30 19:09:45 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
Nikolay Sivov | 79b49a8 | 2008-04-29 00:10:05 +0400 | [diff] [blame] | 1833 | GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image, |
| 1834 | GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth, |
| 1835 | INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes, |
| 1836 | DrawImageAbort callback, VOID * callbackData) |
| 1837 | { |
| 1838 | GpPointF pointsF[3]; |
| 1839 | INT i; |
| 1840 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1841 | TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count, |
| 1842 | srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback, |
| 1843 | callbackData); |
| 1844 | |
Nikolay Sivov | 79b49a8 | 2008-04-29 00:10:05 +0400 | [diff] [blame] | 1845 | if(!points || count!=3) |
| 1846 | return InvalidParameter; |
| 1847 | |
| 1848 | for(i = 0; i < count; i++){ |
| 1849 | pointsF[i].X = (REAL)points[i].X; |
| 1850 | pointsF[i].Y = (REAL)points[i].Y; |
| 1851 | } |
| 1852 | |
| 1853 | return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy, |
| 1854 | (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes, |
| 1855 | callback, callbackData); |
| 1856 | } |
| 1857 | |
Evan Stade | 04d4c26 | 2007-08-09 18:25:09 -0700 | [diff] [blame] | 1858 | GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image, |
| 1859 | REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy, |
| 1860 | REAL srcwidth, REAL srcheight, GpUnit srcUnit, |
| 1861 | GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback, |
| 1862 | VOID * callbackData) |
| 1863 | { |
| 1864 | GpPointF points[3]; |
| 1865 | |
Francois Gouget | 758c453 | 2008-09-05 13:14:56 +0200 | [diff] [blame] | 1866 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n", |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1867 | graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy, |
| 1868 | srcwidth, srcheight, srcUnit, imageattr, callback, callbackData); |
| 1869 | |
Evan Stade | 04d4c26 | 2007-08-09 18:25:09 -0700 | [diff] [blame] | 1870 | points[0].X = dstx; |
| 1871 | points[0].Y = dsty; |
| 1872 | points[1].X = dstx + dstwidth; |
| 1873 | points[1].Y = dsty; |
| 1874 | points[2].X = dstx; |
| 1875 | points[2].Y = dsty + dstheight; |
| 1876 | |
| 1877 | return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy, |
| 1878 | srcwidth, srcheight, srcUnit, imageattr, callback, callbackData); |
| 1879 | } |
| 1880 | |
Jon Yang | 29bc9ba | 2008-02-28 21:54:47 -0800 | [diff] [blame] | 1881 | GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image, |
| 1882 | INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy, |
| 1883 | INT srcwidth, INT srcheight, GpUnit srcUnit, |
| 1884 | GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback, |
| 1885 | VOID * callbackData) |
| 1886 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1887 | GpPointF points[3]; |
| 1888 | |
Francois Gouget | 758c453 | 2008-09-05 13:14:56 +0200 | [diff] [blame] | 1889 | TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1890 | graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy, |
| 1891 | srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData); |
Jon Yang | 29bc9ba | 2008-02-28 21:54:47 -0800 | [diff] [blame] | 1892 | |
| 1893 | points[0].X = dstx; |
| 1894 | points[0].Y = dsty; |
| 1895 | points[1].X = dstx + dstwidth; |
| 1896 | points[1].Y = dsty; |
| 1897 | points[2].X = dstx; |
| 1898 | points[2].Y = dsty + dstheight; |
| 1899 | |
| 1900 | return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy, |
| 1901 | srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData); |
| 1902 | } |
| 1903 | |
Nikolay Sivov | 8cf5608 | 2008-04-25 01:58:36 +0400 | [diff] [blame] | 1904 | GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image, |
| 1905 | REAL x, REAL y, REAL width, REAL height) |
| 1906 | { |
| 1907 | RectF bounds; |
| 1908 | GpUnit unit; |
| 1909 | GpStatus ret; |
| 1910 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1911 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height); |
| 1912 | |
Nikolay Sivov | 8cf5608 | 2008-04-25 01:58:36 +0400 | [diff] [blame] | 1913 | if(!graphics || !image) |
| 1914 | return InvalidParameter; |
| 1915 | |
| 1916 | ret = GdipGetImageBounds(image, &bounds, &unit); |
| 1917 | if(ret != Ok) |
| 1918 | return ret; |
| 1919 | |
| 1920 | return GdipDrawImageRectRect(graphics, image, x, y, width, height, |
| 1921 | bounds.X, bounds.Y, bounds.Width, bounds.Height, |
| 1922 | unit, NULL, NULL, NULL); |
| 1923 | } |
| 1924 | |
| 1925 | GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image, |
| 1926 | INT x, INT y, INT width, INT height) |
| 1927 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1928 | TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height); |
| 1929 | |
Nikolay Sivov | 8cf5608 | 2008-04-25 01:58:36 +0400 | [diff] [blame] | 1930 | return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height); |
| 1931 | } |
| 1932 | |
Evan Stade | 5e29e37 | 2007-08-01 17:55:58 -0700 | [diff] [blame] | 1933 | GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1, |
| 1934 | REAL y1, REAL x2, REAL y2) |
| 1935 | { |
| 1936 | INT save_state; |
| 1937 | GpPointF pt[2]; |
| 1938 | GpStatus retval; |
| 1939 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1940 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2); |
| 1941 | |
Evan Stade | 5e29e37 | 2007-08-01 17:55:58 -0700 | [diff] [blame] | 1942 | if(!pen || !graphics) |
| 1943 | return InvalidParameter; |
| 1944 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1945 | if(graphics->busy) |
| 1946 | return ObjectBusy; |
| 1947 | |
Evan Stade | 5e29e37 | 2007-08-01 17:55:58 -0700 | [diff] [blame] | 1948 | pt[0].X = x1; |
| 1949 | pt[0].Y = y1; |
| 1950 | pt[1].X = x2; |
| 1951 | pt[1].Y = y2; |
| 1952 | |
| 1953 | save_state = prepare_dc(graphics, pen); |
| 1954 | |
| 1955 | retval = draw_polyline(graphics, pen, pt, 2, TRUE); |
| 1956 | |
| 1957 | restore_dc(graphics, save_state); |
| 1958 | |
| 1959 | return retval; |
| 1960 | } |
| 1961 | |
Evan Stade | 2689b18 | 2007-06-12 10:44:31 -0700 | [diff] [blame] | 1962 | GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1, |
| 1963 | INT y1, INT x2, INT y2) |
| 1964 | { |
Evan Stade | d9ef172 | 2007-07-02 15:13:05 -0700 | [diff] [blame] | 1965 | INT save_state; |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 1966 | GpPointF pt[2]; |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 1967 | GpStatus retval; |
Evan Stade | 2689b18 | 2007-06-12 10:44:31 -0700 | [diff] [blame] | 1968 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1969 | TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2); |
| 1970 | |
Evan Stade | 2689b18 | 2007-06-12 10:44:31 -0700 | [diff] [blame] | 1971 | if(!pen || !graphics) |
| 1972 | return InvalidParameter; |
| 1973 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 1974 | if(graphics->busy) |
| 1975 | return ObjectBusy; |
| 1976 | |
Evan Stade | 5128e5d | 2007-07-07 13:20:41 -0700 | [diff] [blame] | 1977 | pt[0].X = (REAL)x1; |
| 1978 | pt[0].Y = (REAL)y1; |
| 1979 | pt[1].X = (REAL)x2; |
| 1980 | pt[1].Y = (REAL)y2; |
| 1981 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1982 | save_state = prepare_dc(graphics, pen); |
Evan Stade | d9ef172 | 2007-07-02 15:13:05 -0700 | [diff] [blame] | 1983 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 1984 | retval = draw_polyline(graphics, pen, pt, 2, TRUE); |
Evan Stade | d9ef172 | 2007-07-02 15:13:05 -0700 | [diff] [blame] | 1985 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 1986 | restore_dc(graphics, save_state); |
Evan Stade | 2689b18 | 2007-06-12 10:44:31 -0700 | [diff] [blame] | 1987 | |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 1988 | return retval; |
Evan Stade | 2689b18 | 2007-06-12 10:44:31 -0700 | [diff] [blame] | 1989 | } |
Evan Stade | 4b9bfbe | 2007-06-12 10:51:20 -0700 | [diff] [blame] | 1990 | |
Evan Stade | f6f04f6 | 2007-06-21 16:15:13 -0700 | [diff] [blame] | 1991 | GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST |
| 1992 | GpPointF *points, INT count) |
| 1993 | { |
Evan Stade | 852aac8 | 2007-07-11 18:07:16 -0700 | [diff] [blame] | 1994 | INT save_state; |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 1995 | GpStatus retval; |
Evan Stade | f6f04f6 | 2007-06-21 16:15:13 -0700 | [diff] [blame] | 1996 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 1997 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 1998 | |
Evan Stade | f6f04f6 | 2007-06-21 16:15:13 -0700 | [diff] [blame] | 1999 | if(!pen || !graphics || (count < 2)) |
| 2000 | return InvalidParameter; |
| 2001 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2002 | if(graphics->busy) |
| 2003 | return ObjectBusy; |
| 2004 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2005 | save_state = prepare_dc(graphics, pen); |
Evan Stade | f6f04f6 | 2007-06-21 16:15:13 -0700 | [diff] [blame] | 2006 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2007 | retval = draw_polyline(graphics, pen, points, count, TRUE); |
Evan Stade | f6f04f6 | 2007-06-21 16:15:13 -0700 | [diff] [blame] | 2008 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2009 | restore_dc(graphics, save_state); |
Evan Stade | f6f04f6 | 2007-06-21 16:15:13 -0700 | [diff] [blame] | 2010 | |
Evan Stade | 6f4ab52 | 2007-07-11 18:07:44 -0700 | [diff] [blame] | 2011 | return retval; |
Evan Stade | f6f04f6 | 2007-06-21 16:15:13 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
Royal Chan | 6e7b534 | 2008-02-29 04:58:39 -0800 | [diff] [blame] | 2014 | GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST |
| 2015 | GpPoint *points, INT count) |
| 2016 | { |
| 2017 | INT save_state; |
| 2018 | GpStatus retval; |
| 2019 | GpPointF *ptf = NULL; |
| 2020 | int i; |
| 2021 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2022 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 2023 | |
Royal Chan | 6e7b534 | 2008-02-29 04:58:39 -0800 | [diff] [blame] | 2024 | if(!pen || !graphics || (count < 2)) |
| 2025 | return InvalidParameter; |
| 2026 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2027 | if(graphics->busy) |
| 2028 | return ObjectBusy; |
| 2029 | |
Royal Chan | 6e7b534 | 2008-02-29 04:58:39 -0800 | [diff] [blame] | 2030 | ptf = GdipAlloc(count * sizeof(GpPointF)); |
| 2031 | if(!ptf) return OutOfMemory; |
| 2032 | |
| 2033 | for(i = 0; i < count; i ++){ |
| 2034 | ptf[i].X = (REAL) points[i].X; |
| 2035 | ptf[i].Y = (REAL) points[i].Y; |
| 2036 | } |
| 2037 | |
| 2038 | save_state = prepare_dc(graphics, pen); |
| 2039 | |
| 2040 | retval = draw_polyline(graphics, pen, ptf, count, TRUE); |
| 2041 | |
| 2042 | restore_dc(graphics, save_state); |
| 2043 | |
| 2044 | GdipFree(ptf); |
| 2045 | return retval; |
| 2046 | } |
| 2047 | |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 2048 | GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path) |
| 2049 | { |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 2050 | INT save_state; |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 2051 | GpStatus retval; |
| 2052 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2053 | TRACE("(%p, %p, %p)\n", graphics, pen, path); |
| 2054 | |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 2055 | if(!pen || !graphics) |
| 2056 | return InvalidParameter; |
| 2057 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2058 | if(graphics->busy) |
| 2059 | return ObjectBusy; |
| 2060 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2061 | save_state = prepare_dc(graphics, pen); |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 2062 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2063 | retval = draw_poly(graphics, pen, path->pathdata.Points, |
Evan Stade | 9e88347 | 2007-07-13 17:51:49 -0700 | [diff] [blame] | 2064 | path->pathdata.Types, path->pathdata.Count, TRUE); |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 2065 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2066 | restore_dc(graphics, save_state); |
Evan Stade | 9d5f568 | 2007-07-11 18:07:34 -0700 | [diff] [blame] | 2067 | |
| 2068 | return retval; |
| 2069 | } |
| 2070 | |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 2071 | GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x, |
| 2072 | REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle) |
| 2073 | { |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2074 | INT save_state; |
| 2075 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2076 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, |
| 2077 | width, height, startAngle, sweepAngle); |
| 2078 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2079 | if(!graphics || !pen) |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 2080 | return InvalidParameter; |
| 2081 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2082 | if(graphics->busy) |
| 2083 | return ObjectBusy; |
| 2084 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2085 | save_state = prepare_dc(graphics, pen); |
| 2086 | SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH)); |
| 2087 | |
| 2088 | draw_pie(graphics, x, y, width, height, startAngle, sweepAngle); |
| 2089 | |
| 2090 | restore_dc(graphics, save_state); |
| 2091 | |
| 2092 | return Ok; |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Nikolay Sivov | 7193161 | 2008-04-24 20:48:00 +0400 | [diff] [blame] | 2095 | GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x, |
| 2096 | INT y, INT width, INT height, REAL startAngle, REAL sweepAngle) |
| 2097 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2098 | TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y, |
| 2099 | width, height, startAngle, sweepAngle); |
| 2100 | |
Nikolay Sivov | 7193161 | 2008-04-24 20:48:00 +0400 | [diff] [blame] | 2101 | return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle); |
| 2102 | } |
| 2103 | |
Nikolay Sivov | 172389e | 2008-04-20 21:27:10 +0400 | [diff] [blame] | 2104 | GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x, |
| 2105 | REAL y, REAL width, REAL height) |
Evan Stade | 4b9bfbe | 2007-06-12 10:51:20 -0700 | [diff] [blame] | 2106 | { |
Evan Stade | 14e0df1 | 2007-07-09 20:54:18 -0700 | [diff] [blame] | 2107 | INT save_state; |
Evan Stade | c84c204 | 2007-08-07 18:43:08 -0700 | [diff] [blame] | 2108 | GpPointF ptf[4]; |
| 2109 | POINT pti[4]; |
Evan Stade | 4b9bfbe | 2007-06-12 10:51:20 -0700 | [diff] [blame] | 2110 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2111 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height); |
| 2112 | |
Evan Stade | 4b9bfbe | 2007-06-12 10:51:20 -0700 | [diff] [blame] | 2113 | if(!pen || !graphics) |
| 2114 | return InvalidParameter; |
| 2115 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2116 | if(graphics->busy) |
| 2117 | return ObjectBusy; |
| 2118 | |
Evan Stade | c84c204 | 2007-08-07 18:43:08 -0700 | [diff] [blame] | 2119 | ptf[0].X = x; |
| 2120 | ptf[0].Y = y; |
| 2121 | ptf[1].X = x + width; |
| 2122 | ptf[1].Y = y; |
| 2123 | ptf[2].X = x + width; |
| 2124 | ptf[2].Y = y + height; |
| 2125 | ptf[3].X = x; |
| 2126 | ptf[3].Y = y + height; |
| 2127 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2128 | save_state = prepare_dc(graphics, pen); |
Evan Stade | 14e0df1 | 2007-07-09 20:54:18 -0700 | [diff] [blame] | 2129 | SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH)); |
Evan Stade | 4b9bfbe | 2007-06-12 10:51:20 -0700 | [diff] [blame] | 2130 | |
Evan Stade | c84c204 | 2007-08-07 18:43:08 -0700 | [diff] [blame] | 2131 | transform_and_round_points(graphics, pti, ptf, 4); |
| 2132 | Polygon(graphics->hdc, pti, 4); |
Evan Stade | 4b9bfbe | 2007-06-12 10:51:20 -0700 | [diff] [blame] | 2133 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2134 | restore_dc(graphics, save_state); |
Evan Stade | 4b9bfbe | 2007-06-12 10:51:20 -0700 | [diff] [blame] | 2135 | |
| 2136 | return Ok; |
| 2137 | } |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 2138 | |
Nikolay Sivov | 172389e | 2008-04-20 21:27:10 +0400 | [diff] [blame] | 2139 | GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x, |
| 2140 | INT y, INT width, INT height) |
| 2141 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2142 | TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height); |
| 2143 | |
Nikolay Sivov | 172389e | 2008-04-20 21:27:10 +0400 | [diff] [blame] | 2144 | return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height); |
| 2145 | } |
| 2146 | |
Evan Stade | 9d6e075 | 2007-08-13 18:34:46 -0700 | [diff] [blame] | 2147 | GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen, |
Francois Gouget | b6b97b1 | 2007-08-29 21:42:01 +0200 | [diff] [blame] | 2148 | GDIPCONST GpRectF* rects, INT count) |
Evan Stade | 9d6e075 | 2007-08-13 18:34:46 -0700 | [diff] [blame] | 2149 | { |
| 2150 | GpPointF *ptf; |
| 2151 | POINT *pti; |
| 2152 | INT save_state, i; |
| 2153 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2154 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count); |
| 2155 | |
Evan Stade | 9d6e075 | 2007-08-13 18:34:46 -0700 | [diff] [blame] | 2156 | if(!graphics || !pen || !rects || count < 1) |
| 2157 | return InvalidParameter; |
| 2158 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2159 | if(graphics->busy) |
| 2160 | return ObjectBusy; |
| 2161 | |
Evan Stade | 9d6e075 | 2007-08-13 18:34:46 -0700 | [diff] [blame] | 2162 | ptf = GdipAlloc(4 * count * sizeof(GpPointF)); |
| 2163 | pti = GdipAlloc(4 * count * sizeof(POINT)); |
| 2164 | |
| 2165 | if(!ptf || !pti){ |
| 2166 | GdipFree(ptf); |
| 2167 | GdipFree(pti); |
| 2168 | return OutOfMemory; |
| 2169 | } |
| 2170 | |
| 2171 | for(i = 0; i < count; i++){ |
| 2172 | ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X; |
| 2173 | ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y; |
| 2174 | ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width; |
| 2175 | ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height; |
| 2176 | } |
| 2177 | |
| 2178 | save_state = prepare_dc(graphics, pen); |
| 2179 | SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH)); |
| 2180 | |
| 2181 | transform_and_round_points(graphics, pti, ptf, 4 * count); |
| 2182 | |
| 2183 | for(i = 0; i < count; i++) |
| 2184 | Polygon(graphics->hdc, &pti[4 * i], 4); |
| 2185 | |
| 2186 | restore_dc(graphics, save_state); |
| 2187 | |
| 2188 | GdipFree(ptf); |
| 2189 | GdipFree(pti); |
| 2190 | |
| 2191 | return Ok; |
| 2192 | } |
| 2193 | |
Nikolay Sivov | 3903ac6 | 2008-04-24 20:48:08 +0400 | [diff] [blame] | 2194 | GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen, |
| 2195 | GDIPCONST GpRect* rects, INT count) |
| 2196 | { |
| 2197 | GpRectF *rectsF; |
| 2198 | GpStatus ret; |
| 2199 | INT i; |
| 2200 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2201 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count); |
| 2202 | |
Nikolay Sivov | 3903ac6 | 2008-04-24 20:48:08 +0400 | [diff] [blame] | 2203 | if(!rects || count<=0) |
| 2204 | return InvalidParameter; |
| 2205 | |
| 2206 | rectsF = GdipAlloc(sizeof(GpRectF) * count); |
| 2207 | if(!rectsF) |
| 2208 | return OutOfMemory; |
| 2209 | |
| 2210 | for(i = 0;i < count;i++){ |
| 2211 | rectsF[i].X = (REAL)rects[i].X; |
| 2212 | rectsF[i].Y = (REAL)rects[i].Y; |
| 2213 | rectsF[i].Width = (REAL)rects[i].Width; |
| 2214 | rectsF[i].Height = (REAL)rects[i].Height; |
| 2215 | } |
| 2216 | |
| 2217 | ret = GdipDrawRectangles(graphics, pen, rectsF, count); |
| 2218 | GdipFree(rectsF); |
| 2219 | |
| 2220 | return ret; |
| 2221 | } |
| 2222 | |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2223 | GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string, |
| 2224 | INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect, |
| 2225 | GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush) |
| 2226 | { |
Evan Stade | ca94939 | 2007-08-15 16:22:13 -0700 | [diff] [blame] | 2227 | HRGN rgn = NULL; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2228 | HFONT gdifont; |
| 2229 | LOGFONTW lfw; |
| 2230 | TEXTMETRICW textmet; |
| 2231 | GpPointF pt[2], rectcpy[4]; |
| 2232 | POINT corners[4]; |
| 2233 | WCHAR* stringdup; |
| 2234 | REAL angle, ang_cos, ang_sin, rel_width, rel_height; |
Stephan Rose | eb3904d | 2009-06-04 18:51:07 -0400 | [diff] [blame] | 2235 | INT sum = 0, height = 0, offsety = 0, fit, fitcpy, save_state, i, j, lret, nwidth, |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 2236 | nheight, lineend; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2237 | SIZE size; |
Vincent Povirk | aa9602d | 2009-06-29 16:36:11 -0500 | [diff] [blame] | 2238 | POINT drawbase; |
| 2239 | UINT drawflags; |
Evan Stade | be66c3c | 2007-08-15 16:22:17 -0700 | [diff] [blame] | 2240 | RECT drawcoord; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2241 | |
Vincent Povirk | 3dd5ce7 | 2009-05-13 13:55:46 -0500 | [diff] [blame] | 2242 | TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length), |
| 2243 | length, font, debugstr_rectf(rect), format, brush); |
| 2244 | |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2245 | if(!graphics || !string || !font || !brush || !rect) |
| 2246 | return InvalidParameter; |
| 2247 | |
Evan Stade | 3f32083 | 2007-08-15 16:22:00 -0700 | [diff] [blame] | 2248 | if((brush->bt != BrushTypeSolidColor)){ |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2249 | FIXME("not implemented for given parameters\n"); |
| 2250 | return NotImplemented; |
| 2251 | } |
| 2252 | |
Stephan Rose | eb3904d | 2009-06-04 18:51:07 -0400 | [diff] [blame] | 2253 | if(format){ |
Evan Stade | 3f32083 | 2007-08-15 16:22:00 -0700 | [diff] [blame] | 2254 | TRACE("may be ignoring some format flags: attr %x\n", format->attr); |
| 2255 | |
Stephan Rose | eb3904d | 2009-06-04 18:51:07 -0400 | [diff] [blame] | 2256 | /* Should be no need to explicitly test for StringAlignmentNear as |
| 2257 | * that is default behavior if no alignment is passed. */ |
| 2258 | if(format->vertalign != StringAlignmentNear){ |
| 2259 | RectF bounds; |
| 2260 | GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0); |
| 2261 | |
| 2262 | if(format->vertalign == StringAlignmentCenter) |
| 2263 | offsety = (rect->Height - bounds.Height) / 2; |
| 2264 | else if(format->vertalign == StringAlignmentFar) |
| 2265 | offsety = (rect->Height - bounds.Height); |
| 2266 | } |
| 2267 | } |
| 2268 | |
Evan Stade | d0cead3 | 2007-08-14 19:01:07 -0700 | [diff] [blame] | 2269 | if(length == -1) length = lstrlenW(string); |
| 2270 | |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2271 | stringdup = GdipAlloc(length * sizeof(WCHAR)); |
| 2272 | if(!stringdup) return OutOfMemory; |
| 2273 | |
| 2274 | save_state = SaveDC(graphics->hdc); |
| 2275 | SetBkMode(graphics->hdc, TRANSPARENT); |
| 2276 | SetTextColor(graphics->hdc, brush->lb.lbColor); |
| 2277 | |
| 2278 | rectcpy[3].X = rectcpy[0].X = rect->X; |
Stephan Rose | eb3904d | 2009-06-04 18:51:07 -0400 | [diff] [blame] | 2279 | rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2280 | rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width; |
Stephan Rose | eb3904d | 2009-06-04 18:51:07 -0400 | [diff] [blame] | 2281 | rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2282 | transform_and_round_points(graphics, corners, rectcpy, 4); |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2283 | |
Vincent Povirk | 0879b76 | 2009-04-01 14:08:12 -0500 | [diff] [blame] | 2284 | if (roundr(rect->Width) == 0) |
| 2285 | { |
| 2286 | rel_width = 1.0; |
| 2287 | nwidth = INT_MAX; |
Evan Stade | ca94939 | 2007-08-15 16:22:13 -0700 | [diff] [blame] | 2288 | } |
Vincent Povirk | 0879b76 | 2009-04-01 14:08:12 -0500 | [diff] [blame] | 2289 | else |
| 2290 | { |
Evan Stade | ca94939 | 2007-08-15 16:22:13 -0700 | [diff] [blame] | 2291 | rel_width = sqrt((corners[1].x - corners[0].x) * (corners[1].x - corners[0].x) + |
| 2292 | (corners[1].y - corners[0].y) * (corners[1].y - corners[0].y)) |
| 2293 | / rect->Width; |
Vincent Povirk | 0879b76 | 2009-04-01 14:08:12 -0500 | [diff] [blame] | 2294 | nwidth = roundr(rel_width * rect->Width); |
| 2295 | } |
| 2296 | |
| 2297 | if (roundr(rect->Height) == 0) |
| 2298 | { |
| 2299 | rel_height = 1.0; |
| 2300 | nheight = INT_MAX; |
| 2301 | } |
| 2302 | else |
| 2303 | { |
Evan Stade | ca94939 | 2007-08-15 16:22:13 -0700 | [diff] [blame] | 2304 | rel_height = sqrt((corners[2].x - corners[1].x) * (corners[2].x - corners[1].x) + |
| 2305 | (corners[2].y - corners[1].y) * (corners[2].y - corners[1].y)) |
| 2306 | / rect->Height; |
Evan Stade | ca94939 | 2007-08-15 16:22:13 -0700 | [diff] [blame] | 2307 | nheight = roundr(rel_height * rect->Height); |
Vincent Povirk | 0879b76 | 2009-04-01 14:08:12 -0500 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | if (roundr(rect->Width) != 0 && roundr(rect->Height) != 0) |
| 2311 | { |
| 2312 | /* FIXME: If only the width or only the height is 0, we should probably still clip */ |
Evan Stade | ca94939 | 2007-08-15 16:22:13 -0700 | [diff] [blame] | 2313 | rgn = CreatePolygonRgn(corners, 4, ALTERNATE); |
| 2314 | SelectClipRgn(graphics->hdc, rgn); |
| 2315 | } |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2316 | |
| 2317 | /* Use gdi to find the font, then perform transformations on it (height, |
| 2318 | * width, angle). */ |
| 2319 | SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw)); |
| 2320 | GetTextMetricsW(graphics->hdc, &textmet); |
Andrew Talbot | 5e8253a | 2008-02-29 22:06:47 +0000 | [diff] [blame] | 2321 | lfw = font->lfw; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2322 | |
| 2323 | lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height); |
| 2324 | lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width); |
| 2325 | |
| 2326 | pt[0].X = 0.0; |
| 2327 | pt[0].Y = 0.0; |
| 2328 | pt[1].X = 1.0; |
| 2329 | pt[1].Y = 0.0; |
| 2330 | GdipTransformMatrixPoints(graphics->worldtrans, pt, 2); |
Vincent Povirk | b330ebf | 2009-07-24 13:56:22 -0500 | [diff] [blame] | 2331 | angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X)); |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2332 | ang_cos = cos(angle); |
| 2333 | ang_sin = sin(angle); |
Vincent Povirk | b330ebf | 2009-07-24 13:56:22 -0500 | [diff] [blame] | 2334 | lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0); |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2335 | |
| 2336 | gdifont = CreateFontIndirectW(&lfw); |
| 2337 | DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw))); |
| 2338 | |
| 2339 | for(i = 0, j = 0; i < length; i++){ |
| 2340 | if(!isprintW(string[i]) && (string[i] != '\n')) |
| 2341 | continue; |
| 2342 | |
| 2343 | stringdup[j] = string[i]; |
| 2344 | j++; |
| 2345 | } |
| 2346 | |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2347 | length = j; |
| 2348 | |
Vincent Povirk | 9fceef3 | 2009-06-30 09:23:07 -0500 | [diff] [blame] | 2349 | if (!format || format->align == StringAlignmentNear) |
Vincent Povirk | aa9602d | 2009-06-29 16:36:11 -0500 | [diff] [blame] | 2350 | { |
| 2351 | drawbase.x = corners[0].x; |
| 2352 | drawbase.y = corners[0].y; |
| 2353 | drawflags = DT_NOCLIP | DT_EXPANDTABS; |
| 2354 | } |
| 2355 | else if (format->align == StringAlignmentCenter) |
| 2356 | { |
| 2357 | drawbase.x = (corners[0].x + corners[1].x)/2; |
| 2358 | drawbase.y = (corners[0].y + corners[1].y)/2; |
| 2359 | drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER; |
| 2360 | } |
| 2361 | else /* (format->align == StringAlignmentFar) */ |
| 2362 | { |
| 2363 | drawbase.x = corners[1].x; |
| 2364 | drawbase.y = corners[1].y; |
| 2365 | drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT; |
| 2366 | } |
| 2367 | |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2368 | while(sum < length){ |
Vincent Povirk | aa9602d | 2009-06-29 16:36:11 -0500 | [diff] [blame] | 2369 | drawcoord.left = drawcoord.right = drawbase.x + roundr(ang_sin * (REAL) height); |
| 2370 | drawcoord.top = drawcoord.bottom = drawbase.y + roundr(ang_cos * (REAL) height); |
Evan Stade | be66c3c | 2007-08-15 16:22:17 -0700 | [diff] [blame] | 2371 | |
Evan Stade | 92aa57b | 2007-08-15 16:21:56 -0700 | [diff] [blame] | 2372 | GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum, |
| 2373 | nwidth, &fit, NULL, &size); |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2374 | fitcpy = fit; |
| 2375 | |
| 2376 | if(fit == 0){ |
Vincent Povirk | aa9602d | 2009-06-29 16:36:11 -0500 | [diff] [blame] | 2377 | DrawTextW(graphics->hdc, stringdup + sum, 1, &drawcoord, drawflags); |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2378 | break; |
| 2379 | } |
| 2380 | |
| 2381 | for(lret = 0; lret < fit; lret++) |
| 2382 | if(*(stringdup + sum + lret) == '\n') |
| 2383 | break; |
| 2384 | |
| 2385 | /* Line break code (may look strange, but it imitates windows). */ |
| 2386 | if(lret < fit) |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 2387 | lineend = fit = lret; /* this is not an off-by-one error */ |
Evan Stade | 92aa57b | 2007-08-15 16:21:56 -0700 | [diff] [blame] | 2388 | else if(fit < (length - sum)){ |
| 2389 | if(*(stringdup + sum + fit) == ' ') |
| 2390 | while(*(stringdup + sum + fit) == ' ') |
| 2391 | fit++; |
| 2392 | else |
| 2393 | while(*(stringdup + sum + fit - 1) != ' '){ |
| 2394 | fit--; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2395 | |
Evan Stade | 92aa57b | 2007-08-15 16:21:56 -0700 | [diff] [blame] | 2396 | if(*(stringdup + sum + fit) == '\t') |
| 2397 | break; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2398 | |
Evan Stade | 92aa57b | 2007-08-15 16:21:56 -0700 | [diff] [blame] | 2399 | if(fit == 0){ |
| 2400 | fit = fitcpy; |
| 2401 | break; |
| 2402 | } |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2403 | } |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 2404 | lineend = fit; |
| 2405 | while(*(stringdup + sum + lineend - 1) == ' ' || |
| 2406 | *(stringdup + sum + lineend - 1) == '\t') |
| 2407 | lineend--; |
Evan Stade | 92aa57b | 2007-08-15 16:21:56 -0700 | [diff] [blame] | 2408 | } |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 2409 | else |
| 2410 | lineend = fit; |
| 2411 | DrawTextW(graphics->hdc, stringdup + sum, min(length - sum, lineend), |
Vincent Povirk | aa9602d | 2009-06-29 16:36:11 -0500 | [diff] [blame] | 2412 | &drawcoord, drawflags); |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2413 | |
| 2414 | sum += fit + (lret < fitcpy ? 1 : 0); |
| 2415 | height += size.cy; |
| 2416 | |
Evan Stade | ca94939 | 2007-08-15 16:22:13 -0700 | [diff] [blame] | 2417 | if(height > nheight) |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2418 | break; |
Evan Stade | 3f32083 | 2007-08-15 16:22:00 -0700 | [diff] [blame] | 2419 | |
| 2420 | /* Stop if this was a linewrap (but not if it was a linebreak). */ |
| 2421 | if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap)) |
| 2422 | break; |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2423 | } |
| 2424 | |
Andrew Talbot | dfac063 | 2007-09-25 20:52:58 +0100 | [diff] [blame] | 2425 | GdipFree(stringdup); |
Evan Stade | f7d27e0 | 2007-08-14 18:58:39 -0700 | [diff] [blame] | 2426 | DeleteObject(rgn); |
| 2427 | DeleteObject(gdifont); |
| 2428 | |
| 2429 | RestoreDC(graphics->hdc, save_state); |
| 2430 | |
| 2431 | return Ok; |
| 2432 | } |
| 2433 | |
Nikolay Sivov | 4a44100 | 2008-08-22 02:16:49 +0400 | [diff] [blame] | 2434 | GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush, |
| 2435 | GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill) |
| 2436 | { |
| 2437 | GpPath *path; |
| 2438 | GpStatus stat; |
| 2439 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2440 | TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points, |
| 2441 | count, tension, fill); |
| 2442 | |
Nikolay Sivov | 4a44100 | 2008-08-22 02:16:49 +0400 | [diff] [blame] | 2443 | if(!graphics || !brush || !points) |
| 2444 | return InvalidParameter; |
| 2445 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2446 | if(graphics->busy) |
| 2447 | return ObjectBusy; |
| 2448 | |
Nikolay Sivov | 4a44100 | 2008-08-22 02:16:49 +0400 | [diff] [blame] | 2449 | stat = GdipCreatePath(fill, &path); |
| 2450 | if(stat != Ok) |
| 2451 | return stat; |
| 2452 | |
| 2453 | stat = GdipAddPathClosedCurve2(path, points, count, tension); |
| 2454 | if(stat != Ok){ |
| 2455 | GdipDeletePath(path); |
| 2456 | return stat; |
| 2457 | } |
| 2458 | |
| 2459 | stat = GdipFillPath(graphics, brush, path); |
| 2460 | if(stat != Ok){ |
| 2461 | GdipDeletePath(path); |
| 2462 | return stat; |
| 2463 | } |
| 2464 | |
| 2465 | GdipDeletePath(path); |
| 2466 | |
| 2467 | return Ok; |
| 2468 | } |
| 2469 | |
| 2470 | GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush, |
| 2471 | GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill) |
| 2472 | { |
| 2473 | GpPointF *ptf; |
| 2474 | GpStatus stat; |
| 2475 | INT i; |
| 2476 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2477 | TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points, |
| 2478 | count, tension, fill); |
| 2479 | |
Nikolay Sivov | 4a44100 | 2008-08-22 02:16:49 +0400 | [diff] [blame] | 2480 | if(!points || count <= 0) |
| 2481 | return InvalidParameter; |
| 2482 | |
| 2483 | ptf = GdipAlloc(sizeof(GpPointF)*count); |
| 2484 | if(!ptf) |
| 2485 | return OutOfMemory; |
| 2486 | |
| 2487 | for(i = 0;i < count;i++){ |
| 2488 | ptf[i].X = (REAL)points[i].X; |
| 2489 | ptf[i].Y = (REAL)points[i].Y; |
| 2490 | } |
| 2491 | |
| 2492 | stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill); |
| 2493 | |
| 2494 | GdipFree(ptf); |
| 2495 | |
| 2496 | return stat; |
| 2497 | } |
| 2498 | |
Nikolay Sivov | fc2dc8b | 2008-04-29 00:10:10 +0400 | [diff] [blame] | 2499 | GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x, |
| 2500 | REAL y, REAL width, REAL height) |
| 2501 | { |
| 2502 | INT save_state; |
| 2503 | GpPointF ptf[2]; |
| 2504 | POINT pti[2]; |
| 2505 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2506 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height); |
| 2507 | |
Nikolay Sivov | fc2dc8b | 2008-04-29 00:10:10 +0400 | [diff] [blame] | 2508 | if(!graphics || !brush) |
| 2509 | return InvalidParameter; |
| 2510 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2511 | if(graphics->busy) |
| 2512 | return ObjectBusy; |
| 2513 | |
Nikolay Sivov | fc2dc8b | 2008-04-29 00:10:10 +0400 | [diff] [blame] | 2514 | ptf[0].X = x; |
| 2515 | ptf[0].Y = y; |
| 2516 | ptf[1].X = x + width; |
| 2517 | ptf[1].Y = y + height; |
| 2518 | |
| 2519 | save_state = SaveDC(graphics->hdc); |
| 2520 | EndPath(graphics->hdc); |
Nikolay Sivov | fc2dc8b | 2008-04-29 00:10:10 +0400 | [diff] [blame] | 2521 | |
| 2522 | transform_and_round_points(graphics, pti, ptf, 2); |
| 2523 | |
Vincent Povirk | e306316 | 2009-07-11 10:29:44 -0500 | [diff] [blame] | 2524 | BeginPath(graphics->hdc); |
Nikolay Sivov | fc2dc8b | 2008-04-29 00:10:10 +0400 | [diff] [blame] | 2525 | Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y); |
Vincent Povirk | e306316 | 2009-07-11 10:29:44 -0500 | [diff] [blame] | 2526 | EndPath(graphics->hdc); |
| 2527 | |
| 2528 | brush_fill_path(graphics, brush); |
Nikolay Sivov | fc2dc8b | 2008-04-29 00:10:10 +0400 | [diff] [blame] | 2529 | |
| 2530 | RestoreDC(graphics->hdc, save_state); |
| 2531 | |
| 2532 | return Ok; |
| 2533 | } |
| 2534 | |
| 2535 | GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x, |
| 2536 | INT y, INT width, INT height) |
| 2537 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2538 | TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height); |
| 2539 | |
Nikolay Sivov | fc2dc8b | 2008-04-29 00:10:10 +0400 | [diff] [blame] | 2540 | return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height); |
| 2541 | } |
| 2542 | |
Evan Stade | d362b58 | 2007-07-13 20:19:46 -0700 | [diff] [blame] | 2543 | GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path) |
| 2544 | { |
| 2545 | INT save_state; |
| 2546 | GpStatus retval; |
| 2547 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2548 | TRACE("(%p, %p, %p)\n", graphics, brush, path); |
| 2549 | |
Evan Stade | d362b58 | 2007-07-13 20:19:46 -0700 | [diff] [blame] | 2550 | if(!brush || !graphics || !path) |
| 2551 | return InvalidParameter; |
| 2552 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2553 | if(graphics->busy) |
| 2554 | return ObjectBusy; |
| 2555 | |
Evan Stade | d362b58 | 2007-07-13 20:19:46 -0700 | [diff] [blame] | 2556 | save_state = SaveDC(graphics->hdc); |
| 2557 | EndPath(graphics->hdc); |
Evan Stade | d362b58 | 2007-07-13 20:19:46 -0700 | [diff] [blame] | 2558 | SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE |
| 2559 | : WINDING)); |
| 2560 | |
| 2561 | BeginPath(graphics->hdc); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2562 | retval = draw_poly(graphics, NULL, path->pathdata.Points, |
Evan Stade | d362b58 | 2007-07-13 20:19:46 -0700 | [diff] [blame] | 2563 | path->pathdata.Types, path->pathdata.Count, FALSE); |
| 2564 | |
| 2565 | if(retval != Ok) |
| 2566 | goto end; |
| 2567 | |
| 2568 | EndPath(graphics->hdc); |
Vincent Povirk | 68dba4e | 2009-03-16 12:51:04 -0500 | [diff] [blame] | 2569 | brush_fill_path(graphics, brush); |
Evan Stade | d362b58 | 2007-07-13 20:19:46 -0700 | [diff] [blame] | 2570 | |
| 2571 | retval = Ok; |
| 2572 | |
| 2573 | end: |
| 2574 | RestoreDC(graphics->hdc, save_state); |
| 2575 | |
| 2576 | return retval; |
| 2577 | } |
| 2578 | |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 2579 | GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x, |
| 2580 | REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle) |
| 2581 | { |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2582 | INT save_state; |
| 2583 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2584 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", |
| 2585 | graphics, brush, x, y, width, height, startAngle, sweepAngle); |
| 2586 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2587 | if(!graphics || !brush) |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 2588 | return InvalidParameter; |
| 2589 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2590 | if(graphics->busy) |
| 2591 | return ObjectBusy; |
| 2592 | |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2593 | save_state = SaveDC(graphics->hdc); |
| 2594 | EndPath(graphics->hdc); |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2595 | |
Vincent Povirk | bedbd40 | 2009-07-11 10:32:34 -0500 | [diff] [blame] | 2596 | BeginPath(graphics->hdc); |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2597 | draw_pie(graphics, x, y, width, height, startAngle, sweepAngle); |
Vincent Povirk | bedbd40 | 2009-07-11 10:32:34 -0500 | [diff] [blame] | 2598 | EndPath(graphics->hdc); |
| 2599 | |
| 2600 | brush_fill_path(graphics, brush); |
Evan Stade | 4c424b3 | 2007-07-24 17:18:54 -0700 | [diff] [blame] | 2601 | |
| 2602 | RestoreDC(graphics->hdc, save_state); |
| 2603 | |
| 2604 | return Ok; |
Evan Stade | 72ab72c50 | 2007-06-18 16:55:51 -0700 | [diff] [blame] | 2605 | } |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 2606 | |
Nikolay Sivov | 2c059d7 | 2008-04-24 20:48:23 +0400 | [diff] [blame] | 2607 | GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x, |
| 2608 | INT y, INT width, INT height, REAL startAngle, REAL sweepAngle) |
| 2609 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2610 | TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", |
| 2611 | graphics, brush, x, y, width, height, startAngle, sweepAngle); |
| 2612 | |
Nikolay Sivov | 2c059d7 | 2008-04-24 20:48:23 +0400 | [diff] [blame] | 2613 | return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle); |
| 2614 | } |
| 2615 | |
Evan Stade | 1ef7793 | 2007-08-01 17:55:50 -0700 | [diff] [blame] | 2616 | GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush, |
| 2617 | GDIPCONST GpPointF *points, INT count, GpFillMode fillMode) |
| 2618 | { |
| 2619 | INT save_state; |
| 2620 | GpPointF *ptf = NULL; |
| 2621 | POINT *pti = NULL; |
| 2622 | GpStatus retval = Ok; |
| 2623 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2624 | TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode); |
| 2625 | |
Evan Stade | 1ef7793 | 2007-08-01 17:55:50 -0700 | [diff] [blame] | 2626 | if(!graphics || !brush || !points || !count) |
| 2627 | return InvalidParameter; |
| 2628 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2629 | if(graphics->busy) |
| 2630 | return ObjectBusy; |
| 2631 | |
Evan Stade | 1ef7793 | 2007-08-01 17:55:50 -0700 | [diff] [blame] | 2632 | ptf = GdipAlloc(count * sizeof(GpPointF)); |
| 2633 | pti = GdipAlloc(count * sizeof(POINT)); |
| 2634 | if(!ptf || !pti){ |
| 2635 | retval = OutOfMemory; |
| 2636 | goto end; |
| 2637 | } |
| 2638 | |
| 2639 | memcpy(ptf, points, count * sizeof(GpPointF)); |
| 2640 | |
| 2641 | save_state = SaveDC(graphics->hdc); |
| 2642 | EndPath(graphics->hdc); |
Evan Stade | 1ef7793 | 2007-08-01 17:55:50 -0700 | [diff] [blame] | 2643 | SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE |
| 2644 | : WINDING)); |
| 2645 | |
| 2646 | transform_and_round_points(graphics, pti, ptf, count); |
Vincent Povirk | 15fef07 | 2009-07-11 10:35:40 -0500 | [diff] [blame] | 2647 | |
| 2648 | BeginPath(graphics->hdc); |
Evan Stade | 1ef7793 | 2007-08-01 17:55:50 -0700 | [diff] [blame] | 2649 | Polygon(graphics->hdc, pti, count); |
Vincent Povirk | 15fef07 | 2009-07-11 10:35:40 -0500 | [diff] [blame] | 2650 | EndPath(graphics->hdc); |
| 2651 | |
| 2652 | brush_fill_path(graphics, brush); |
Evan Stade | 1ef7793 | 2007-08-01 17:55:50 -0700 | [diff] [blame] | 2653 | |
| 2654 | RestoreDC(graphics->hdc, save_state); |
| 2655 | |
| 2656 | end: |
| 2657 | GdipFree(ptf); |
| 2658 | GdipFree(pti); |
| 2659 | |
| 2660 | return retval; |
| 2661 | } |
| 2662 | |
Evan Stade | 6467526 | 2007-07-23 20:24:35 -0700 | [diff] [blame] | 2663 | GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush, |
| 2664 | GDIPCONST GpPoint *points, INT count, GpFillMode fillMode) |
| 2665 | { |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2666 | INT save_state, i; |
| 2667 | GpPointF *ptf = NULL; |
| 2668 | POINT *pti = NULL; |
| 2669 | GpStatus retval = Ok; |
Evan Stade | 6467526 | 2007-07-23 20:24:35 -0700 | [diff] [blame] | 2670 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2671 | TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode); |
| 2672 | |
Evan Stade | 6467526 | 2007-07-23 20:24:35 -0700 | [diff] [blame] | 2673 | if(!graphics || !brush || !points || !count) |
| 2674 | return InvalidParameter; |
| 2675 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2676 | if(graphics->busy) |
| 2677 | return ObjectBusy; |
| 2678 | |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2679 | ptf = GdipAlloc(count * sizeof(GpPointF)); |
| 2680 | pti = GdipAlloc(count * sizeof(POINT)); |
| 2681 | if(!ptf || !pti){ |
| 2682 | retval = OutOfMemory; |
| 2683 | goto end; |
| 2684 | } |
| 2685 | |
| 2686 | for(i = 0; i < count; i ++){ |
| 2687 | ptf[i].X = (REAL) points[i].X; |
| 2688 | ptf[i].Y = (REAL) points[i].Y; |
| 2689 | } |
| 2690 | |
Evan Stade | 6467526 | 2007-07-23 20:24:35 -0700 | [diff] [blame] | 2691 | save_state = SaveDC(graphics->hdc); |
| 2692 | EndPath(graphics->hdc); |
Evan Stade | 6467526 | 2007-07-23 20:24:35 -0700 | [diff] [blame] | 2693 | SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE |
| 2694 | : WINDING)); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2695 | |
| 2696 | transform_and_round_points(graphics, pti, ptf, count); |
Vincent Povirk | 38fc894 | 2009-07-11 10:37:22 -0500 | [diff] [blame] | 2697 | |
| 2698 | BeginPath(graphics->hdc); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2699 | Polygon(graphics->hdc, pti, count); |
Vincent Povirk | 38fc894 | 2009-07-11 10:37:22 -0500 | [diff] [blame] | 2700 | EndPath(graphics->hdc); |
| 2701 | |
| 2702 | brush_fill_path(graphics, brush); |
Evan Stade | 6467526 | 2007-07-23 20:24:35 -0700 | [diff] [blame] | 2703 | |
| 2704 | RestoreDC(graphics->hdc, save_state); |
Evan Stade | d01c697 | 2007-07-23 20:24:53 -0700 | [diff] [blame] | 2705 | |
| 2706 | end: |
| 2707 | GdipFree(ptf); |
| 2708 | GdipFree(pti); |
| 2709 | |
| 2710 | return retval; |
Evan Stade | 6467526 | 2007-07-23 20:24:35 -0700 | [diff] [blame] | 2711 | } |
| 2712 | |
Nikolay Sivov | e04a662 | 2008-08-03 12:19:36 +0400 | [diff] [blame] | 2713 | GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush, |
| 2714 | GDIPCONST GpPointF *points, INT count) |
| 2715 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2716 | TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count); |
| 2717 | |
Nikolay Sivov | e04a662 | 2008-08-03 12:19:36 +0400 | [diff] [blame] | 2718 | return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate); |
| 2719 | } |
| 2720 | |
| 2721 | GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush, |
| 2722 | GDIPCONST GpPoint *points, INT count) |
| 2723 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2724 | TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count); |
| 2725 | |
Nikolay Sivov | e04a662 | 2008-08-03 12:19:36 +0400 | [diff] [blame] | 2726 | return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate); |
| 2727 | } |
| 2728 | |
Evan Stade | b66c0a0 | 2007-08-08 19:42:10 -0700 | [diff] [blame] | 2729 | GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush, |
| 2730 | REAL x, REAL y, REAL width, REAL height) |
| 2731 | { |
| 2732 | INT save_state; |
| 2733 | GpPointF ptf[4]; |
| 2734 | POINT pti[4]; |
| 2735 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2736 | TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height); |
| 2737 | |
Evan Stade | b66c0a0 | 2007-08-08 19:42:10 -0700 | [diff] [blame] | 2738 | if(!graphics || !brush) |
| 2739 | return InvalidParameter; |
| 2740 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2741 | if(graphics->busy) |
| 2742 | return ObjectBusy; |
| 2743 | |
Evan Stade | b66c0a0 | 2007-08-08 19:42:10 -0700 | [diff] [blame] | 2744 | ptf[0].X = x; |
| 2745 | ptf[0].Y = y; |
| 2746 | ptf[1].X = x + width; |
| 2747 | ptf[1].Y = y; |
| 2748 | ptf[2].X = x + width; |
| 2749 | ptf[2].Y = y + height; |
| 2750 | ptf[3].X = x; |
| 2751 | ptf[3].Y = y + height; |
| 2752 | |
| 2753 | save_state = SaveDC(graphics->hdc); |
| 2754 | EndPath(graphics->hdc); |
Evan Stade | b66c0a0 | 2007-08-08 19:42:10 -0700 | [diff] [blame] | 2755 | |
| 2756 | transform_and_round_points(graphics, pti, ptf, 4); |
| 2757 | |
Vincent Povirk | 323e7e68 | 2009-05-06 16:34:19 -0500 | [diff] [blame] | 2758 | BeginPath(graphics->hdc); |
Evan Stade | b66c0a0 | 2007-08-08 19:42:10 -0700 | [diff] [blame] | 2759 | Polygon(graphics->hdc, pti, 4); |
Vincent Povirk | 323e7e68 | 2009-05-06 16:34:19 -0500 | [diff] [blame] | 2760 | EndPath(graphics->hdc); |
| 2761 | |
| 2762 | brush_fill_path(graphics, brush); |
Evan Stade | b66c0a0 | 2007-08-08 19:42:10 -0700 | [diff] [blame] | 2763 | |
| 2764 | RestoreDC(graphics->hdc, save_state); |
| 2765 | |
| 2766 | return Ok; |
| 2767 | } |
| 2768 | |
Evan Stade | bb904a2 | 2007-08-07 18:43:04 -0700 | [diff] [blame] | 2769 | GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush, |
| 2770 | INT x, INT y, INT width, INT height) |
| 2771 | { |
| 2772 | INT save_state; |
| 2773 | GpPointF ptf[4]; |
| 2774 | POINT pti[4]; |
| 2775 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2776 | TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height); |
| 2777 | |
Evan Stade | bb904a2 | 2007-08-07 18:43:04 -0700 | [diff] [blame] | 2778 | if(!graphics || !brush) |
| 2779 | return InvalidParameter; |
| 2780 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2781 | if(graphics->busy) |
| 2782 | return ObjectBusy; |
| 2783 | |
Evan Stade | bb904a2 | 2007-08-07 18:43:04 -0700 | [diff] [blame] | 2784 | ptf[0].X = x; |
| 2785 | ptf[0].Y = y; |
| 2786 | ptf[1].X = x + width; |
| 2787 | ptf[1].Y = y; |
| 2788 | ptf[2].X = x + width; |
| 2789 | ptf[2].Y = y + height; |
| 2790 | ptf[3].X = x; |
| 2791 | ptf[3].Y = y + height; |
| 2792 | |
| 2793 | save_state = SaveDC(graphics->hdc); |
| 2794 | EndPath(graphics->hdc); |
Evan Stade | bb904a2 | 2007-08-07 18:43:04 -0700 | [diff] [blame] | 2795 | |
| 2796 | transform_and_round_points(graphics, pti, ptf, 4); |
| 2797 | |
Vincent Povirk | 849af30 | 2009-07-11 10:38:47 -0500 | [diff] [blame] | 2798 | BeginPath(graphics->hdc); |
Evan Stade | bb904a2 | 2007-08-07 18:43:04 -0700 | [diff] [blame] | 2799 | Polygon(graphics->hdc, pti, 4); |
Vincent Povirk | 849af30 | 2009-07-11 10:38:47 -0500 | [diff] [blame] | 2800 | EndPath(graphics->hdc); |
| 2801 | |
| 2802 | brush_fill_path(graphics, brush); |
Evan Stade | bb904a2 | 2007-08-07 18:43:04 -0700 | [diff] [blame] | 2803 | |
| 2804 | RestoreDC(graphics->hdc, save_state); |
| 2805 | |
| 2806 | return Ok; |
| 2807 | } |
| 2808 | |
Nikolay Sivov | 7ce48b0 | 2008-04-29 00:10:15 +0400 | [diff] [blame] | 2809 | GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects, |
| 2810 | INT count) |
| 2811 | { |
| 2812 | GpStatus ret; |
| 2813 | INT i; |
| 2814 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2815 | TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count); |
| 2816 | |
Nikolay Sivov | 7ce48b0 | 2008-04-29 00:10:15 +0400 | [diff] [blame] | 2817 | if(!rects) |
| 2818 | return InvalidParameter; |
| 2819 | |
| 2820 | for(i = 0; i < count; i++){ |
| 2821 | ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height); |
| 2822 | if(ret != Ok) return ret; |
| 2823 | } |
| 2824 | |
| 2825 | return Ok; |
| 2826 | } |
| 2827 | |
| 2828 | GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects, |
| 2829 | INT count) |
| 2830 | { |
| 2831 | GpRectF *rectsF; |
| 2832 | GpStatus ret; |
| 2833 | INT i; |
| 2834 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2835 | TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count); |
| 2836 | |
Nikolay Sivov | 7ce48b0 | 2008-04-29 00:10:15 +0400 | [diff] [blame] | 2837 | if(!rects || count <= 0) |
| 2838 | return InvalidParameter; |
| 2839 | |
| 2840 | rectsF = GdipAlloc(sizeof(GpRectF)*count); |
| 2841 | if(!rectsF) |
| 2842 | return OutOfMemory; |
| 2843 | |
| 2844 | for(i = 0; i < count; i++){ |
| 2845 | rectsF[i].X = (REAL)rects[i].X; |
| 2846 | rectsF[i].Y = (REAL)rects[i].Y; |
| 2847 | rectsF[i].X = (REAL)rects[i].Width; |
| 2848 | rectsF[i].Height = (REAL)rects[i].Height; |
| 2849 | } |
| 2850 | |
| 2851 | ret = GdipFillRectangles(graphics,brush,rectsF,count); |
| 2852 | GdipFree(rectsF); |
| 2853 | |
| 2854 | return ret; |
| 2855 | } |
| 2856 | |
Nikolay Sivov | 9f0edc5 | 2009-02-03 22:17:47 +0300 | [diff] [blame] | 2857 | /***************************************************************************** |
| 2858 | * GdipFillRegion [GDIPLUS.@] |
| 2859 | */ |
Nikolay Sivov | 0e840f6 | 2008-07-10 23:15:59 +0400 | [diff] [blame] | 2860 | GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush, |
| 2861 | GpRegion* region) |
| 2862 | { |
Nikolay Sivov | 9f0edc5 | 2009-02-03 22:17:47 +0300 | [diff] [blame] | 2863 | INT save_state; |
| 2864 | GpStatus status; |
| 2865 | HRGN hrgn; |
Vincent Povirk | 6a8a770 | 2009-07-11 10:57:07 -0500 | [diff] [blame] | 2866 | RECT rc; |
Nikolay Sivov | 9f0edc5 | 2009-02-03 22:17:47 +0300 | [diff] [blame] | 2867 | |
| 2868 | TRACE("(%p, %p, %p)\n", graphics, brush, region); |
| 2869 | |
Nikolay Sivov | 0e840f6 | 2008-07-10 23:15:59 +0400 | [diff] [blame] | 2870 | if (!(graphics && brush && region)) |
| 2871 | return InvalidParameter; |
| 2872 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2873 | if(graphics->busy) |
| 2874 | return ObjectBusy; |
| 2875 | |
Nikolay Sivov | 9f0edc5 | 2009-02-03 22:17:47 +0300 | [diff] [blame] | 2876 | status = GdipGetRegionHRgn(region, graphics, &hrgn); |
| 2877 | if(status != Ok) |
| 2878 | return status; |
Nikolay Sivov | 0e840f6 | 2008-07-10 23:15:59 +0400 | [diff] [blame] | 2879 | |
Nikolay Sivov | 9f0edc5 | 2009-02-03 22:17:47 +0300 | [diff] [blame] | 2880 | save_state = SaveDC(graphics->hdc); |
| 2881 | EndPath(graphics->hdc); |
Nikolay Sivov | 9f0edc5 | 2009-02-03 22:17:47 +0300 | [diff] [blame] | 2882 | |
Vincent Povirk | 6a8a770 | 2009-07-11 10:57:07 -0500 | [diff] [blame] | 2883 | ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND); |
| 2884 | |
| 2885 | if (GetClipBox(graphics->hdc, &rc) != NULLREGION) |
| 2886 | { |
| 2887 | BeginPath(graphics->hdc); |
| 2888 | Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom); |
| 2889 | EndPath(graphics->hdc); |
| 2890 | |
| 2891 | brush_fill_path(graphics, brush); |
| 2892 | } |
Nikolay Sivov | 9f0edc5 | 2009-02-03 22:17:47 +0300 | [diff] [blame] | 2893 | |
| 2894 | RestoreDC(graphics->hdc, save_state); |
| 2895 | |
| 2896 | DeleteObject(hrgn); |
| 2897 | |
| 2898 | return Ok; |
Nikolay Sivov | 0e840f6 | 2008-07-10 23:15:59 +0400 | [diff] [blame] | 2899 | } |
| 2900 | |
Nikolay Sivov | f620b66 | 2008-06-18 11:33:10 +0400 | [diff] [blame] | 2901 | GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention) |
| 2902 | { |
| 2903 | static int calls; |
| 2904 | |
| 2905 | if(!graphics) |
| 2906 | return InvalidParameter; |
| 2907 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2908 | if(graphics->busy) |
| 2909 | return ObjectBusy; |
| 2910 | |
Nikolay Sivov | f620b66 | 2008-06-18 11:33:10 +0400 | [diff] [blame] | 2911 | if(!(calls++)) |
| 2912 | FIXME("not implemented\n"); |
| 2913 | |
| 2914 | return NotImplemented; |
| 2915 | } |
| 2916 | |
Nikolay Sivov | bcfe4e7 | 2009-02-02 22:58:27 +0300 | [diff] [blame] | 2917 | /***************************************************************************** |
| 2918 | * GdipGetClipBounds [GDIPLUS.@] |
| 2919 | */ |
| 2920 | GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect) |
| 2921 | { |
| 2922 | TRACE("(%p, %p)\n", graphics, rect); |
| 2923 | |
| 2924 | if(!graphics) |
| 2925 | return InvalidParameter; |
| 2926 | |
Nikolay Sivov | 8c09616 | 2009-02-02 23:48:01 +0300 | [diff] [blame] | 2927 | if(graphics->busy) |
| 2928 | return ObjectBusy; |
| 2929 | |
Nikolay Sivov | bcfe4e7 | 2009-02-02 22:58:27 +0300 | [diff] [blame] | 2930 | return GdipGetRegionBounds(graphics->clip, graphics, rect); |
| 2931 | } |
| 2932 | |
| 2933 | /***************************************************************************** |
| 2934 | * GdipGetClipBoundsI [GDIPLUS.@] |
| 2935 | */ |
| 2936 | GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect) |
| 2937 | { |
| 2938 | TRACE("(%p, %p)\n", graphics, rect); |
| 2939 | |
| 2940 | if(!graphics) |
| 2941 | return InvalidParameter; |
| 2942 | |
Nikolay Sivov | 8c09616 | 2009-02-02 23:48:01 +0300 | [diff] [blame] | 2943 | if(graphics->busy) |
| 2944 | return ObjectBusy; |
| 2945 | |
Nikolay Sivov | bcfe4e7 | 2009-02-02 22:58:27 +0300 | [diff] [blame] | 2946 | return GdipGetRegionBoundsI(graphics->clip, graphics, rect); |
| 2947 | } |
| 2948 | |
Evan Stade | e807eb9 | 2007-08-13 18:34:27 -0700 | [diff] [blame] | 2949 | /* FIXME: Compositing mode is not used anywhere except the getter/setter. */ |
| 2950 | GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics, |
| 2951 | CompositingMode *mode) |
| 2952 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2953 | TRACE("(%p, %p)\n", graphics, mode); |
| 2954 | |
Evan Stade | e807eb9 | 2007-08-13 18:34:27 -0700 | [diff] [blame] | 2955 | if(!graphics || !mode) |
| 2956 | return InvalidParameter; |
| 2957 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2958 | if(graphics->busy) |
| 2959 | return ObjectBusy; |
| 2960 | |
Evan Stade | e807eb9 | 2007-08-13 18:34:27 -0700 | [diff] [blame] | 2961 | *mode = graphics->compmode; |
| 2962 | |
| 2963 | return Ok; |
| 2964 | } |
| 2965 | |
Evan Stade | 60cad23 | 2007-07-13 17:51:25 -0700 | [diff] [blame] | 2966 | /* FIXME: Compositing quality is not used anywhere except the getter/setter. */ |
| 2967 | GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics, |
| 2968 | CompositingQuality *quality) |
| 2969 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2970 | TRACE("(%p, %p)\n", graphics, quality); |
| 2971 | |
Evan Stade | 60cad23 | 2007-07-13 17:51:25 -0700 | [diff] [blame] | 2972 | if(!graphics || !quality) |
| 2973 | return InvalidParameter; |
| 2974 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2975 | if(graphics->busy) |
| 2976 | return ObjectBusy; |
| 2977 | |
Evan Stade | 60cad23 | 2007-07-13 17:51:25 -0700 | [diff] [blame] | 2978 | *quality = graphics->compqual; |
| 2979 | |
| 2980 | return Ok; |
| 2981 | } |
| 2982 | |
Evan Stade | a87ce7a | 2007-07-13 17:51:29 -0700 | [diff] [blame] | 2983 | /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */ |
| 2984 | GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics, |
| 2985 | InterpolationMode *mode) |
| 2986 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 2987 | TRACE("(%p, %p)\n", graphics, mode); |
| 2988 | |
Evan Stade | a87ce7a | 2007-07-13 17:51:29 -0700 | [diff] [blame] | 2989 | if(!graphics || !mode) |
| 2990 | return InvalidParameter; |
| 2991 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 2992 | if(graphics->busy) |
| 2993 | return ObjectBusy; |
| 2994 | |
Evan Stade | a87ce7a | 2007-07-13 17:51:29 -0700 | [diff] [blame] | 2995 | *mode = graphics->interpolation; |
| 2996 | |
| 2997 | return Ok; |
| 2998 | } |
| 2999 | |
Nikolay Sivov | 63ae714 | 2008-12-11 10:32:43 +0300 | [diff] [blame] | 3000 | GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb) |
| 3001 | { |
| 3002 | if(!graphics || !argb) |
| 3003 | return InvalidParameter; |
| 3004 | |
| 3005 | if(graphics->busy) |
| 3006 | return ObjectBusy; |
| 3007 | |
| 3008 | FIXME("(%p, %p): stub\n", graphics, argb); |
| 3009 | |
| 3010 | return NotImplemented; |
| 3011 | } |
| 3012 | |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 3013 | GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale) |
| 3014 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3015 | TRACE("(%p, %p)\n", graphics, scale); |
| 3016 | |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 3017 | if(!graphics || !scale) |
| 3018 | return InvalidParameter; |
| 3019 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3020 | if(graphics->busy) |
| 3021 | return ObjectBusy; |
| 3022 | |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 3023 | *scale = graphics->scale; |
| 3024 | |
| 3025 | return Ok; |
| 3026 | } |
| 3027 | |
Evan Stade | 10b575b | 2007-07-23 20:24:41 -0700 | [diff] [blame] | 3028 | GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit) |
| 3029 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3030 | TRACE("(%p, %p)\n", graphics, unit); |
| 3031 | |
Evan Stade | 10b575b | 2007-07-23 20:24:41 -0700 | [diff] [blame] | 3032 | if(!graphics || !unit) |
| 3033 | return InvalidParameter; |
| 3034 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3035 | if(graphics->busy) |
| 3036 | return ObjectBusy; |
| 3037 | |
Evan Stade | 10b575b | 2007-07-23 20:24:41 -0700 | [diff] [blame] | 3038 | *unit = graphics->unit; |
| 3039 | |
| 3040 | return Ok; |
| 3041 | } |
| 3042 | |
Evan Stade | d6bd866d | 2007-07-13 17:51:33 -0700 | [diff] [blame] | 3043 | /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */ |
| 3044 | GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode |
| 3045 | *mode) |
| 3046 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3047 | TRACE("(%p, %p)\n", graphics, mode); |
| 3048 | |
Evan Stade | d6bd866d | 2007-07-13 17:51:33 -0700 | [diff] [blame] | 3049 | if(!graphics || !mode) |
| 3050 | return InvalidParameter; |
| 3051 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3052 | if(graphics->busy) |
| 3053 | return ObjectBusy; |
| 3054 | |
Evan Stade | d6bd866d | 2007-07-13 17:51:33 -0700 | [diff] [blame] | 3055 | *mode = graphics->pixeloffset; |
| 3056 | |
| 3057 | return Ok; |
| 3058 | } |
| 3059 | |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 3060 | /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */ |
| 3061 | GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode) |
| 3062 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3063 | TRACE("(%p, %p)\n", graphics, mode); |
| 3064 | |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 3065 | if(!graphics || !mode) |
| 3066 | return InvalidParameter; |
| 3067 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3068 | if(graphics->busy) |
| 3069 | return ObjectBusy; |
| 3070 | |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 3071 | *mode = graphics->smoothing; |
| 3072 | |
| 3073 | return Ok; |
| 3074 | } |
| 3075 | |
Nikolay Sivov | 56173d4 | 2008-11-09 14:32:26 +0300 | [diff] [blame] | 3076 | GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast) |
| 3077 | { |
| 3078 | TRACE("(%p, %p)\n", graphics, contrast); |
| 3079 | |
| 3080 | if(!graphics || !contrast) |
| 3081 | return InvalidParameter; |
| 3082 | |
| 3083 | *contrast = graphics->textcontrast; |
| 3084 | |
| 3085 | return Ok; |
| 3086 | } |
| 3087 | |
Evan Stade | 5662820 | 2007-08-14 19:00:09 -0700 | [diff] [blame] | 3088 | /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */ |
| 3089 | GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics, |
| 3090 | TextRenderingHint *hint) |
| 3091 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3092 | TRACE("(%p, %p)\n", graphics, hint); |
| 3093 | |
Evan Stade | 5662820 | 2007-08-14 19:00:09 -0700 | [diff] [blame] | 3094 | if(!graphics || !hint) |
| 3095 | return InvalidParameter; |
| 3096 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3097 | if(graphics->busy) |
| 3098 | return ObjectBusy; |
| 3099 | |
Evan Stade | 5662820 | 2007-08-14 19:00:09 -0700 | [diff] [blame] | 3100 | *hint = graphics->texthint; |
| 3101 | |
| 3102 | return Ok; |
| 3103 | } |
| 3104 | |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 3105 | GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix) |
| 3106 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3107 | TRACE("(%p, %p)\n", graphics, matrix); |
| 3108 | |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 3109 | if(!graphics || !matrix) |
| 3110 | return InvalidParameter; |
| 3111 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3112 | if(graphics->busy) |
| 3113 | return ObjectBusy; |
| 3114 | |
Andrew Talbot | 5e8253a | 2008-02-29 22:06:47 +0000 | [diff] [blame] | 3115 | *matrix = *graphics->worldtrans; |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 3116 | return Ok; |
| 3117 | } |
| 3118 | |
Nikolay Sivov | bff1678 | 2008-09-05 13:56:10 +0400 | [diff] [blame] | 3119 | GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color) |
| 3120 | { |
| 3121 | GpSolidFill *brush; |
| 3122 | GpStatus stat; |
| 3123 | RECT rect; |
| 3124 | |
| 3125 | TRACE("(%p, %x)\n", graphics, color); |
| 3126 | |
| 3127 | if(!graphics) |
| 3128 | return InvalidParameter; |
| 3129 | |
| 3130 | if(graphics->busy) |
| 3131 | return ObjectBusy; |
| 3132 | |
| 3133 | if((stat = GdipCreateSolidFill(color, &brush)) != Ok) |
| 3134 | return stat; |
| 3135 | |
| 3136 | if(graphics->hwnd){ |
| 3137 | if(!GetWindowRect(graphics->hwnd, &rect)){ |
| 3138 | GdipDeleteBrush((GpBrush*)brush); |
| 3139 | return GenericError; |
| 3140 | } |
| 3141 | |
| 3142 | GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, (REAL)(rect.right - rect.left), |
| 3143 | (REAL)(rect.bottom - rect.top)); |
| 3144 | } |
| 3145 | else |
| 3146 | GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, (REAL)GetDeviceCaps(graphics->hdc, HORZRES), |
| 3147 | (REAL)GetDeviceCaps(graphics->hdc, VERTRES)); |
| 3148 | |
| 3149 | GdipDeleteBrush((GpBrush*)brush); |
| 3150 | |
| 3151 | return Ok; |
| 3152 | } |
| 3153 | |
Nikolay Sivov | 813d6dc | 2008-08-28 17:49:41 +0400 | [diff] [blame] | 3154 | GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res) |
| 3155 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3156 | TRACE("(%p, %p)\n", graphics, res); |
| 3157 | |
Nikolay Sivov | 813d6dc | 2008-08-28 17:49:41 +0400 | [diff] [blame] | 3158 | if(!graphics || !res) |
| 3159 | return InvalidParameter; |
| 3160 | |
| 3161 | return GdipIsEmptyRegion(graphics->clip, graphics, res); |
| 3162 | } |
| 3163 | |
Nikolay Sivov | 3ecb8bd | 2008-09-26 22:34:39 +0400 | [diff] [blame] | 3164 | GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result) |
| 3165 | { |
| 3166 | FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics, x, y, result); |
| 3167 | |
| 3168 | if(!graphics || !result) |
| 3169 | return InvalidParameter; |
| 3170 | |
| 3171 | if(graphics->busy) |
| 3172 | return ObjectBusy; |
| 3173 | |
| 3174 | return NotImplemented; |
| 3175 | } |
| 3176 | |
| 3177 | GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result) |
| 3178 | { |
| 3179 | FIXME("(%p, %d, %d, %p) stub\n", graphics, x, y, result); |
| 3180 | |
| 3181 | if(!graphics || !result) |
| 3182 | return InvalidParameter; |
| 3183 | |
| 3184 | if(graphics->busy) |
| 3185 | return ObjectBusy; |
| 3186 | |
| 3187 | return NotImplemented; |
| 3188 | } |
| 3189 | |
Adam Petaccia | be4a226 | 2008-07-09 03:33:40 -0400 | [diff] [blame] | 3190 | GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics, |
| 3191 | GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font, |
| 3192 | GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat, |
| 3193 | INT regionCount, GpRegion** regions) |
| 3194 | { |
| 3195 | if (!(graphics && string && font && layoutRect && stringFormat && regions)) |
| 3196 | return InvalidParameter; |
| 3197 | |
| 3198 | FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics, debugstr_w(string), |
| 3199 | length, font, layoutRect, stringFormat, regionCount, regions); |
| 3200 | |
| 3201 | return NotImplemented; |
| 3202 | } |
| 3203 | |
Evan Stade | 44e9839 | 2007-08-15 16:22:09 -0700 | [diff] [blame] | 3204 | /* Find the smallest rectangle that bounds the text when it is printed in rect |
| 3205 | * according to the format options listed in format. If rect has 0 width and |
| 3206 | * height, then just find the smallest rectangle that bounds the text when it's |
| 3207 | * printed at location (rect->X, rect-Y). */ |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3208 | GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, |
| 3209 | GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font, |
| 3210 | GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds, |
| 3211 | INT *codepointsfitted, INT *linesfilled) |
| 3212 | { |
| 3213 | HFONT oldfont; |
| 3214 | WCHAR* stringdup; |
Evan Stade | 44e9839 | 2007-08-15 16:22:09 -0700 | [diff] [blame] | 3215 | INT sum = 0, height = 0, fit, fitcpy, max_width = 0, i, j, lret, nwidth, |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 3216 | nheight, lineend; |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3217 | SIZE size; |
| 3218 | |
Vincent Povirk | 0f80aa8 | 2009-05-13 14:30:00 -0500 | [diff] [blame] | 3219 | TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics, |
| 3220 | debugstr_wn(string, length), length, font, debugstr_rectf(rect), format, |
| 3221 | bounds, codepointsfitted, linesfilled); |
| 3222 | |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3223 | if(!graphics || !string || !font || !rect) |
| 3224 | return InvalidParameter; |
| 3225 | |
Hans Leidekker | 1e170c9 | 2008-11-24 10:22:26 +0100 | [diff] [blame] | 3226 | if(linesfilled) *linesfilled = 0; |
| 3227 | if(codepointsfitted) *codepointsfitted = 0; |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3228 | |
Evan Stade | d4107db | 2007-08-15 16:22:04 -0700 | [diff] [blame] | 3229 | if(format) |
| 3230 | TRACE("may be ignoring some format flags: attr %x\n", format->attr); |
| 3231 | |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3232 | if(length == -1) length = lstrlenW(string); |
| 3233 | |
Alexandre Julliard | a2d0467 | 2008-09-25 11:19:23 +0200 | [diff] [blame] | 3234 | stringdup = GdipAlloc((length + 1) * sizeof(WCHAR)); |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3235 | if(!stringdup) return OutOfMemory; |
| 3236 | |
| 3237 | oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw)); |
| 3238 | nwidth = roundr(rect->Width); |
Evan Stade | 44e9839 | 2007-08-15 16:22:09 -0700 | [diff] [blame] | 3239 | nheight = roundr(rect->Height); |
| 3240 | |
| 3241 | if((nwidth == 0) && (nheight == 0)) |
| 3242 | nwidth = nheight = INT_MAX; |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3243 | |
| 3244 | for(i = 0, j = 0; i < length; i++){ |
| 3245 | if(!isprintW(string[i]) && (string[i] != '\n')) |
| 3246 | continue; |
| 3247 | |
| 3248 | stringdup[j] = string[i]; |
| 3249 | j++; |
| 3250 | } |
| 3251 | |
| 3252 | stringdup[j] = 0; |
| 3253 | length = j; |
| 3254 | |
| 3255 | while(sum < length){ |
| 3256 | GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum, |
| 3257 | nwidth, &fit, NULL, &size); |
| 3258 | fitcpy = fit; |
| 3259 | |
| 3260 | if(fit == 0) |
| 3261 | break; |
| 3262 | |
| 3263 | for(lret = 0; lret < fit; lret++) |
| 3264 | if(*(stringdup + sum + lret) == '\n') |
| 3265 | break; |
| 3266 | |
| 3267 | /* Line break code (may look strange, but it imitates windows). */ |
| 3268 | if(lret < fit) |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 3269 | lineend = fit = lret; /* this is not an off-by-one error */ |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3270 | else if(fit < (length - sum)){ |
| 3271 | if(*(stringdup + sum + fit) == ' ') |
| 3272 | while(*(stringdup + sum + fit) == ' ') |
| 3273 | fit++; |
| 3274 | else |
| 3275 | while(*(stringdup + sum + fit - 1) != ' '){ |
| 3276 | fit--; |
| 3277 | |
| 3278 | if(*(stringdup + sum + fit) == '\t') |
| 3279 | break; |
| 3280 | |
| 3281 | if(fit == 0){ |
| 3282 | fit = fitcpy; |
| 3283 | break; |
| 3284 | } |
| 3285 | } |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 3286 | lineend = fit; |
| 3287 | while(*(stringdup + sum + lineend - 1) == ' ' || |
| 3288 | *(stringdup + sum + lineend - 1) == '\t') |
| 3289 | lineend--; |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3290 | } |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 3291 | else |
| 3292 | lineend = fit; |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3293 | |
Vincent Povirk | e0d9d17 | 2009-07-24 16:24:19 -0500 | [diff] [blame] | 3294 | GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend, |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3295 | nwidth, &j, NULL, &size); |
| 3296 | |
| 3297 | sum += fit + (lret < fitcpy ? 1 : 0); |
Hans Leidekker | 1e170c9 | 2008-11-24 10:22:26 +0100 | [diff] [blame] | 3298 | if(codepointsfitted) *codepointsfitted = sum; |
| 3299 | |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3300 | height += size.cy; |
Hans Leidekker | 1e170c9 | 2008-11-24 10:22:26 +0100 | [diff] [blame] | 3301 | if(linesfilled) *linesfilled += size.cy; |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3302 | max_width = max(max_width, size.cx); |
| 3303 | |
Evan Stade | 44e9839 | 2007-08-15 16:22:09 -0700 | [diff] [blame] | 3304 | if(height > nheight) |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3305 | break; |
Evan Stade | d4107db | 2007-08-15 16:22:04 -0700 | [diff] [blame] | 3306 | |
| 3307 | /* Stop if this was a linewrap (but not if it was a linebreak). */ |
| 3308 | if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap)) |
| 3309 | break; |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | bounds->X = rect->X; |
| 3313 | bounds->Y = rect->Y; |
| 3314 | bounds->Width = (REAL)max_width; |
Evan Stade | 44e9839 | 2007-08-15 16:22:09 -0700 | [diff] [blame] | 3315 | bounds->Height = (REAL) min(height, nheight); |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3316 | |
Andrew Talbot | dfac063 | 2007-09-25 20:52:58 +0100 | [diff] [blame] | 3317 | GdipFree(stringdup); |
Evan Stade | a51cf1d | 2007-08-15 16:21:52 -0700 | [diff] [blame] | 3318 | DeleteObject(SelectObject(graphics->hdc, oldfont)); |
| 3319 | |
| 3320 | return Ok; |
| 3321 | } |
| 3322 | |
Nikolay Sivov | ff88d4e | 2008-08-28 17:34:22 +0400 | [diff] [blame] | 3323 | GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics) |
| 3324 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3325 | TRACE("(%p)\n", graphics); |
| 3326 | |
Nikolay Sivov | ff88d4e | 2008-08-28 17:34:22 +0400 | [diff] [blame] | 3327 | if(!graphics) |
| 3328 | return InvalidParameter; |
| 3329 | |
| 3330 | if(graphics->busy) |
| 3331 | return ObjectBusy; |
| 3332 | |
| 3333 | return GdipSetInfinite(graphics->clip); |
| 3334 | } |
| 3335 | |
Nikolay Sivov | 169e87d | 2008-08-06 18:36:16 +0400 | [diff] [blame] | 3336 | GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics) |
| 3337 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3338 | TRACE("(%p)\n", graphics); |
| 3339 | |
Nikolay Sivov | 169e87d | 2008-08-06 18:36:16 +0400 | [diff] [blame] | 3340 | if(!graphics) |
| 3341 | return InvalidParameter; |
| 3342 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3343 | if(graphics->busy) |
| 3344 | return ObjectBusy; |
| 3345 | |
Nikolay Sivov | 169e87d | 2008-08-06 18:36:16 +0400 | [diff] [blame] | 3346 | graphics->worldtrans->matrix[0] = 1.0; |
| 3347 | graphics->worldtrans->matrix[1] = 0.0; |
| 3348 | graphics->worldtrans->matrix[2] = 0.0; |
| 3349 | graphics->worldtrans->matrix[3] = 1.0; |
| 3350 | graphics->worldtrans->matrix[4] = 0.0; |
| 3351 | graphics->worldtrans->matrix[5] = 0.0; |
| 3352 | |
| 3353 | return Ok; |
| 3354 | } |
| 3355 | |
Evan Stade | c760668 | 2007-07-13 17:51:37 -0700 | [diff] [blame] | 3356 | GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state) |
| 3357 | { |
Andrew Eikum | 1ef1394 | 2009-07-07 22:30:49 -0500 | [diff] [blame] | 3358 | return GdipEndContainer(graphics, state); |
Evan Stade | c760668 | 2007-07-13 17:51:37 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
Evan Stade | 3126c77 | 2007-08-13 18:34:35 -0700 | [diff] [blame] | 3361 | GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle, |
| 3362 | GpMatrixOrder order) |
| 3363 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3364 | TRACE("(%p, %.2f, %d)\n", graphics, angle, order); |
| 3365 | |
Evan Stade | 3126c77 | 2007-08-13 18:34:35 -0700 | [diff] [blame] | 3366 | if(!graphics) |
| 3367 | return InvalidParameter; |
| 3368 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3369 | if(graphics->busy) |
| 3370 | return ObjectBusy; |
| 3371 | |
Evan Stade | 3126c77 | 2007-08-13 18:34:35 -0700 | [diff] [blame] | 3372 | return GdipRotateMatrix(graphics->worldtrans, angle, order); |
| 3373 | } |
| 3374 | |
Evan Stade | c760668 | 2007-07-13 17:51:37 -0700 | [diff] [blame] | 3375 | GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state) |
| 3376 | { |
Andrew Eikum | 1ef1394 | 2009-07-07 22:30:49 -0500 | [diff] [blame] | 3377 | return GdipBeginContainer2(graphics, state); |
Evan Stade | c760668 | 2007-07-13 17:51:37 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3380 | GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics, |
| 3381 | GraphicsContainer *state) |
Hans Leidekker | 5ce729a | 2008-11-24 10:22:51 +0100 | [diff] [blame] | 3382 | { |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3383 | GraphicsContainerItem *container; |
| 3384 | GpStatus sts; |
| 3385 | |
| 3386 | TRACE("(%p, %p)\n", graphics, state); |
Hans Leidekker | 5ce729a | 2008-11-24 10:22:51 +0100 | [diff] [blame] | 3387 | |
| 3388 | if(!graphics || !state) |
| 3389 | return InvalidParameter; |
| 3390 | |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3391 | sts = init_container(&container, graphics); |
| 3392 | if(sts != Ok) |
| 3393 | return sts; |
| 3394 | |
| 3395 | list_add_head(&graphics->containers, &container->entry); |
| 3396 | *state = graphics->contid = container->contid; |
| 3397 | |
Hans Leidekker | 5ce729a | 2008-11-24 10:22:51 +0100 | [diff] [blame] | 3398 | return Ok; |
| 3399 | } |
| 3400 | |
Andrew Eikum | 3091506 | 2009-05-31 15:00:03 -0500 | [diff] [blame] | 3401 | GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state) |
| 3402 | { |
| 3403 | FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state); |
| 3404 | return NotImplemented; |
| 3405 | } |
| 3406 | |
| 3407 | GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state) |
| 3408 | { |
| 3409 | FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state); |
| 3410 | return NotImplemented; |
| 3411 | } |
| 3412 | |
Andrew Eikum | b850008 | 2009-06-01 20:01:43 -0500 | [diff] [blame] | 3413 | GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data) |
| 3414 | { |
| 3415 | FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data); |
| 3416 | return NotImplemented; |
| 3417 | } |
| 3418 | |
Andrew Eikum | a06c257 | 2009-07-07 22:30:29 -0500 | [diff] [blame] | 3419 | GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state) |
Hans Leidekker | 5ce729a | 2008-11-24 10:22:51 +0100 | [diff] [blame] | 3420 | { |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3421 | GpStatus sts; |
| 3422 | GraphicsContainerItem *container, *container2; |
Hans Leidekker | 5ce729a | 2008-11-24 10:22:51 +0100 | [diff] [blame] | 3423 | |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3424 | TRACE("(%p, %x)\n", graphics, state); |
| 3425 | |
| 3426 | if(!graphics) |
Hans Leidekker | 5ce729a | 2008-11-24 10:22:51 +0100 | [diff] [blame] | 3427 | return InvalidParameter; |
| 3428 | |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3429 | LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){ |
| 3430 | if(container->contid == state) |
| 3431 | break; |
| 3432 | } |
| 3433 | |
| 3434 | /* did not find a matching container */ |
| 3435 | if(&container->entry == &graphics->containers) |
| 3436 | return Ok; |
| 3437 | |
Andrew Eikum | a06c257 | 2009-07-07 22:30:29 -0500 | [diff] [blame] | 3438 | sts = restore_container(graphics, container); |
| 3439 | if(sts != Ok) |
| 3440 | return sts; |
| 3441 | |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3442 | /* remove all of the containers on top of the found container */ |
| 3443 | LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){ |
| 3444 | if(container->contid == state) |
| 3445 | break; |
| 3446 | list_remove(&container->entry); |
| 3447 | delete_container(container); |
| 3448 | } |
| 3449 | |
| 3450 | list_remove(&container->entry); |
Andrew Eikum | 632aef3 | 2009-07-05 17:04:20 -0500 | [diff] [blame] | 3451 | delete_container(container); |
| 3452 | |
Andrew Eikum | a06c257 | 2009-07-07 22:30:29 -0500 | [diff] [blame] | 3453 | return Ok; |
Hans Leidekker | 5ce729a | 2008-11-24 10:22:51 +0100 | [diff] [blame] | 3454 | } |
| 3455 | |
Evan Stade | 30fdcc7 | 2007-08-13 18:34:38 -0700 | [diff] [blame] | 3456 | GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx, |
| 3457 | REAL sy, GpMatrixOrder order) |
| 3458 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3459 | TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order); |
| 3460 | |
Evan Stade | 30fdcc7 | 2007-08-13 18:34:38 -0700 | [diff] [blame] | 3461 | if(!graphics) |
| 3462 | return InvalidParameter; |
| 3463 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3464 | if(graphics->busy) |
| 3465 | return ObjectBusy; |
| 3466 | |
Evan Stade | 30fdcc7 | 2007-08-13 18:34:38 -0700 | [diff] [blame] | 3467 | return GdipScaleMatrix(graphics->worldtrans, sx, sy, order); |
| 3468 | } |
| 3469 | |
Nikolay Sivov | c543f3d | 2008-10-22 20:03:10 +0400 | [diff] [blame] | 3470 | GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics, |
| 3471 | CombineMode mode) |
| 3472 | { |
| 3473 | TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode); |
| 3474 | |
| 3475 | if(!graphics || !srcgraphics) |
| 3476 | return InvalidParameter; |
| 3477 | |
| 3478 | return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode); |
| 3479 | } |
| 3480 | |
Evan Stade | e807eb9 | 2007-08-13 18:34:27 -0700 | [diff] [blame] | 3481 | GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics, |
| 3482 | CompositingMode mode) |
| 3483 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3484 | TRACE("(%p, %d)\n", graphics, mode); |
| 3485 | |
Evan Stade | e807eb9 | 2007-08-13 18:34:27 -0700 | [diff] [blame] | 3486 | if(!graphics) |
| 3487 | return InvalidParameter; |
| 3488 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3489 | if(graphics->busy) |
| 3490 | return ObjectBusy; |
| 3491 | |
Evan Stade | e807eb9 | 2007-08-13 18:34:27 -0700 | [diff] [blame] | 3492 | graphics->compmode = mode; |
| 3493 | |
| 3494 | return Ok; |
| 3495 | } |
| 3496 | |
Evan Stade | 60cad23 | 2007-07-13 17:51:25 -0700 | [diff] [blame] | 3497 | GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics, |
| 3498 | CompositingQuality quality) |
| 3499 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3500 | TRACE("(%p, %d)\n", graphics, quality); |
| 3501 | |
Evan Stade | 60cad23 | 2007-07-13 17:51:25 -0700 | [diff] [blame] | 3502 | if(!graphics) |
| 3503 | return InvalidParameter; |
| 3504 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3505 | if(graphics->busy) |
| 3506 | return ObjectBusy; |
| 3507 | |
Evan Stade | 60cad23 | 2007-07-13 17:51:25 -0700 | [diff] [blame] | 3508 | graphics->compqual = quality; |
| 3509 | |
| 3510 | return Ok; |
| 3511 | } |
| 3512 | |
Evan Stade | a87ce7a | 2007-07-13 17:51:29 -0700 | [diff] [blame] | 3513 | GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics, |
| 3514 | InterpolationMode mode) |
| 3515 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3516 | TRACE("(%p, %d)\n", graphics, mode); |
| 3517 | |
Evan Stade | a87ce7a | 2007-07-13 17:51:29 -0700 | [diff] [blame] | 3518 | if(!graphics) |
| 3519 | return InvalidParameter; |
| 3520 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3521 | if(graphics->busy) |
| 3522 | return ObjectBusy; |
| 3523 | |
Evan Stade | a87ce7a | 2007-07-13 17:51:29 -0700 | [diff] [blame] | 3524 | graphics->interpolation = mode; |
| 3525 | |
| 3526 | return Ok; |
| 3527 | } |
| 3528 | |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 3529 | GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale) |
| 3530 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3531 | TRACE("(%p, %.2f)\n", graphics, scale); |
| 3532 | |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 3533 | if(!graphics || (scale <= 0.0)) |
| 3534 | return InvalidParameter; |
| 3535 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3536 | if(graphics->busy) |
| 3537 | return ObjectBusy; |
| 3538 | |
Evan Stade | 8162139 | 2007-07-24 17:18:39 -0700 | [diff] [blame] | 3539 | graphics->scale = scale; |
| 3540 | |
| 3541 | return Ok; |
| 3542 | } |
| 3543 | |
Evan Stade | 10b575b | 2007-07-23 20:24:41 -0700 | [diff] [blame] | 3544 | GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit) |
| 3545 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3546 | TRACE("(%p, %d)\n", graphics, unit); |
| 3547 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3548 | if(!graphics) |
| 3549 | return InvalidParameter; |
| 3550 | |
| 3551 | if(graphics->busy) |
| 3552 | return ObjectBusy; |
| 3553 | |
| 3554 | if(unit == UnitWorld) |
Evan Stade | 10b575b | 2007-07-23 20:24:41 -0700 | [diff] [blame] | 3555 | return InvalidParameter; |
| 3556 | |
| 3557 | graphics->unit = unit; |
| 3558 | |
| 3559 | return Ok; |
| 3560 | } |
| 3561 | |
Evan Stade | d6bd866d | 2007-07-13 17:51:33 -0700 | [diff] [blame] | 3562 | GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode |
| 3563 | mode) |
| 3564 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3565 | TRACE("(%p, %d)\n", graphics, mode); |
| 3566 | |
Evan Stade | d6bd866d | 2007-07-13 17:51:33 -0700 | [diff] [blame] | 3567 | if(!graphics) |
| 3568 | return InvalidParameter; |
| 3569 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3570 | if(graphics->busy) |
| 3571 | return ObjectBusy; |
| 3572 | |
Evan Stade | d6bd866d | 2007-07-13 17:51:33 -0700 | [diff] [blame] | 3573 | graphics->pixeloffset = mode; |
| 3574 | |
| 3575 | return Ok; |
| 3576 | } |
| 3577 | |
Vincent Povirk | 27b47ea | 2009-05-06 16:03:27 -0500 | [diff] [blame] | 3578 | GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y) |
| 3579 | { |
| 3580 | static int calls; |
| 3581 | |
| 3582 | TRACE("(%p,%i,%i)\n", graphics, x, y); |
| 3583 | |
| 3584 | if (!(calls++)) |
| 3585 | FIXME("not implemented\n"); |
| 3586 | |
| 3587 | return NotImplemented; |
| 3588 | } |
| 3589 | |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 3590 | GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode) |
| 3591 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3592 | TRACE("(%p, %d)\n", graphics, mode); |
| 3593 | |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 3594 | if(!graphics) |
| 3595 | return InvalidParameter; |
| 3596 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3597 | if(graphics->busy) |
| 3598 | return ObjectBusy; |
| 3599 | |
Evan Stade | 53e17d2 | 2007-07-13 17:51:13 -0700 | [diff] [blame] | 3600 | graphics->smoothing = mode; |
| 3601 | |
| 3602 | return Ok; |
| 3603 | } |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 3604 | |
Nikolay Sivov | 7126473 | 2008-11-09 14:38:16 +0300 | [diff] [blame] | 3605 | GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast) |
| 3606 | { |
| 3607 | TRACE("(%p, %d)\n", graphics, contrast); |
| 3608 | |
| 3609 | if(!graphics) |
| 3610 | return InvalidParameter; |
| 3611 | |
| 3612 | graphics->textcontrast = contrast; |
| 3613 | |
| 3614 | return Ok; |
| 3615 | } |
| 3616 | |
Evan Stade | 5662820 | 2007-08-14 19:00:09 -0700 | [diff] [blame] | 3617 | GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics, |
| 3618 | TextRenderingHint hint) |
| 3619 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3620 | TRACE("(%p, %d)\n", graphics, hint); |
| 3621 | |
Evan Stade | 5662820 | 2007-08-14 19:00:09 -0700 | [diff] [blame] | 3622 | if(!graphics) |
| 3623 | return InvalidParameter; |
| 3624 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3625 | if(graphics->busy) |
| 3626 | return ObjectBusy; |
| 3627 | |
Evan Stade | 5662820 | 2007-08-14 19:00:09 -0700 | [diff] [blame] | 3628 | graphics->texthint = hint; |
| 3629 | |
| 3630 | return Ok; |
| 3631 | } |
| 3632 | |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 3633 | GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix) |
| 3634 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3635 | TRACE("(%p, %p)\n", graphics, matrix); |
| 3636 | |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 3637 | if(!graphics || !matrix) |
| 3638 | return InvalidParameter; |
| 3639 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3640 | if(graphics->busy) |
| 3641 | return ObjectBusy; |
| 3642 | |
Evan Stade | f30732f | 2007-07-24 17:18:47 -0700 | [diff] [blame] | 3643 | GdipDeleteMatrix(graphics->worldtrans); |
| 3644 | return GdipCloneMatrix(matrix, &graphics->worldtrans); |
| 3645 | } |
Evan Stade | 795b622 | 2007-08-09 18:25:31 -0700 | [diff] [blame] | 3646 | |
| 3647 | GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx, |
| 3648 | REAL dy, GpMatrixOrder order) |
| 3649 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3650 | TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order); |
| 3651 | |
Evan Stade | 795b622 | 2007-08-09 18:25:31 -0700 | [diff] [blame] | 3652 | if(!graphics) |
| 3653 | return InvalidParameter; |
| 3654 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3655 | if(graphics->busy) |
| 3656 | return ObjectBusy; |
| 3657 | |
Evan Stade | 795b622 | 2007-08-09 18:25:31 -0700 | [diff] [blame] | 3658 | return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order); |
| 3659 | } |
Lei Zhang | d9a4299 | 2008-04-08 14:44:41 -0700 | [diff] [blame] | 3660 | |
Nikolay Sivov | f8edb06 | 2009-02-02 23:33:41 +0300 | [diff] [blame] | 3661 | /***************************************************************************** |
| 3662 | * GdipSetClipHrgn [GDIPLUS.@] |
| 3663 | */ |
| 3664 | GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode) |
| 3665 | { |
| 3666 | GpRegion *region; |
| 3667 | GpStatus status; |
| 3668 | |
| 3669 | TRACE("(%p, %p, %d)\n", graphics, hrgn, mode); |
| 3670 | |
| 3671 | if(!graphics) |
| 3672 | return InvalidParameter; |
| 3673 | |
| 3674 | status = GdipCreateRegionHrgn(hrgn, ®ion); |
| 3675 | if(status != Ok) |
| 3676 | return status; |
| 3677 | |
| 3678 | status = GdipSetClipRegion(graphics, region, mode); |
| 3679 | |
| 3680 | GdipDeleteRegion(region); |
| 3681 | return status; |
| 3682 | } |
| 3683 | |
Nikolay Sivov | e2817e5 | 2008-09-26 22:18:09 +0400 | [diff] [blame] | 3684 | GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode) |
| 3685 | { |
| 3686 | TRACE("(%p, %p, %d)\n", graphics, path, mode); |
| 3687 | |
| 3688 | if(!graphics) |
| 3689 | return InvalidParameter; |
| 3690 | |
| 3691 | if(graphics->busy) |
| 3692 | return ObjectBusy; |
| 3693 | |
| 3694 | return GdipCombineRegionPath(graphics->clip, path, mode); |
| 3695 | } |
| 3696 | |
Nikolay Sivov | 8d9c486 | 2008-09-25 10:41:15 +0400 | [diff] [blame] | 3697 | GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y, |
| 3698 | REAL width, REAL height, |
| 3699 | CombineMode mode) |
Lei Zhang | d9a4299 | 2008-04-08 14:44:41 -0700 | [diff] [blame] | 3700 | { |
Nikolay Sivov | 8d9c486 | 2008-09-25 10:41:15 +0400 | [diff] [blame] | 3701 | GpRectF rect; |
| 3702 | |
| 3703 | TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode); |
Lei Zhang | d9a4299 | 2008-04-08 14:44:41 -0700 | [diff] [blame] | 3704 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3705 | if(!graphics) |
| 3706 | return InvalidParameter; |
| 3707 | |
| 3708 | if(graphics->busy) |
| 3709 | return ObjectBusy; |
| 3710 | |
Nikolay Sivov | 8d9c486 | 2008-09-25 10:41:15 +0400 | [diff] [blame] | 3711 | rect.X = x; |
| 3712 | rect.Y = y; |
| 3713 | rect.Width = width; |
| 3714 | rect.Height = height; |
Lei Zhang | d9a4299 | 2008-04-08 14:44:41 -0700 | [diff] [blame] | 3715 | |
Nikolay Sivov | 8d9c486 | 2008-09-25 10:41:15 +0400 | [diff] [blame] | 3716 | return GdipCombineRegionRect(graphics->clip, &rect, mode); |
| 3717 | } |
| 3718 | |
| 3719 | GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y, |
| 3720 | INT width, INT height, |
| 3721 | CombineMode mode) |
| 3722 | { |
| 3723 | TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode); |
| 3724 | |
| 3725 | if(!graphics) |
| 3726 | return InvalidParameter; |
| 3727 | |
| 3728 | if(graphics->busy) |
| 3729 | return ObjectBusy; |
| 3730 | |
| 3731 | return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode); |
Lei Zhang | d9a4299 | 2008-04-08 14:44:41 -0700 | [diff] [blame] | 3732 | } |
Lei Zhang | cec6c2e | 2008-04-09 12:35:29 -0700 | [diff] [blame] | 3733 | |
| 3734 | GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region, |
Nikolay Sivov | 0df5fb5 | 2008-08-27 23:30:59 +0400 | [diff] [blame] | 3735 | CombineMode mode) |
Lei Zhang | cec6c2e | 2008-04-09 12:35:29 -0700 | [diff] [blame] | 3736 | { |
Nikolay Sivov | 0df5fb5 | 2008-08-27 23:30:59 +0400 | [diff] [blame] | 3737 | TRACE("(%p, %p, %d)\n", graphics, region, mode); |
Lei Zhang | cec6c2e | 2008-04-09 12:35:29 -0700 | [diff] [blame] | 3738 | |
Nikolay Sivov | 0df5fb5 | 2008-08-27 23:30:59 +0400 | [diff] [blame] | 3739 | if(!graphics || !region) |
| 3740 | return InvalidParameter; |
Lei Zhang | cec6c2e | 2008-04-09 12:35:29 -0700 | [diff] [blame] | 3741 | |
Nikolay Sivov | 0df5fb5 | 2008-08-27 23:30:59 +0400 | [diff] [blame] | 3742 | if(graphics->busy) |
| 3743 | return ObjectBusy; |
| 3744 | |
| 3745 | return GdipCombineRegionRegion(graphics->clip, region, mode); |
Lei Zhang | cec6c2e | 2008-04-09 12:35:29 -0700 | [diff] [blame] | 3746 | } |
Lei Zhang | 54a0664 | 2008-04-10 12:40:21 -0700 | [diff] [blame] | 3747 | |
Nikolay Sivov | 4570501 | 2008-08-24 14:45:14 +0400 | [diff] [blame] | 3748 | GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile, |
Lei Zhang | 54a0664 | 2008-04-10 12:40:21 -0700 | [diff] [blame] | 3749 | UINT limitDpi) |
| 3750 | { |
| 3751 | static int calls; |
| 3752 | |
| 3753 | if(!(calls++)) |
| 3754 | FIXME("not implemented\n"); |
| 3755 | |
| 3756 | return NotImplemented; |
| 3757 | } |
Nikolay Sivov | 4697593 | 2008-04-24 20:48:17 +0400 | [diff] [blame] | 3758 | |
| 3759 | GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points, |
| 3760 | INT count) |
| 3761 | { |
| 3762 | INT save_state; |
| 3763 | POINT *pti; |
| 3764 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3765 | TRACE("(%p, %p, %d)\n", graphics, points, count); |
| 3766 | |
Nikolay Sivov | 4697593 | 2008-04-24 20:48:17 +0400 | [diff] [blame] | 3767 | if(!graphics || !pen || count<=0) |
| 3768 | return InvalidParameter; |
| 3769 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3770 | if(graphics->busy) |
| 3771 | return ObjectBusy; |
| 3772 | |
Nikolay Sivov | 4697593 | 2008-04-24 20:48:17 +0400 | [diff] [blame] | 3773 | pti = GdipAlloc(sizeof(POINT) * count); |
| 3774 | |
| 3775 | save_state = prepare_dc(graphics, pen); |
| 3776 | SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH)); |
| 3777 | |
| 3778 | transform_and_round_points(graphics, pti, (GpPointF*)points, count); |
| 3779 | Polygon(graphics->hdc, pti, count); |
| 3780 | |
| 3781 | restore_dc(graphics, save_state); |
| 3782 | GdipFree(pti); |
| 3783 | |
| 3784 | return Ok; |
| 3785 | } |
| 3786 | |
| 3787 | GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points, |
| 3788 | INT count) |
| 3789 | { |
| 3790 | GpStatus ret; |
| 3791 | GpPointF *ptf; |
| 3792 | INT i; |
| 3793 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3794 | TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count); |
| 3795 | |
Nikolay Sivov | 4697593 | 2008-04-24 20:48:17 +0400 | [diff] [blame] | 3796 | if(count<=0) return InvalidParameter; |
| 3797 | ptf = GdipAlloc(sizeof(GpPointF) * count); |
| 3798 | |
| 3799 | for(i = 0;i < count; i++){ |
| 3800 | ptf[i].X = (REAL)points[i].X; |
| 3801 | ptf[i].Y = (REAL)points[i].Y; |
| 3802 | } |
| 3803 | |
| 3804 | ret = GdipDrawPolygon(graphics,pen,ptf,count); |
| 3805 | GdipFree(ptf); |
| 3806 | |
| 3807 | return ret; |
| 3808 | } |
Nikolay Sivov | d576995 | 2008-04-29 00:10:20 +0400 | [diff] [blame] | 3809 | |
| 3810 | GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi) |
| 3811 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3812 | TRACE("(%p, %p)\n", graphics, dpi); |
| 3813 | |
Nikolay Sivov | d576995 | 2008-04-29 00:10:20 +0400 | [diff] [blame] | 3814 | if(!graphics || !dpi) |
| 3815 | return InvalidParameter; |
| 3816 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3817 | if(graphics->busy) |
| 3818 | return ObjectBusy; |
| 3819 | |
Nikolay Sivov | d576995 | 2008-04-29 00:10:20 +0400 | [diff] [blame] | 3820 | *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX); |
| 3821 | |
| 3822 | return Ok; |
| 3823 | } |
| 3824 | |
| 3825 | GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi) |
| 3826 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3827 | TRACE("(%p, %p)\n", graphics, dpi); |
| 3828 | |
Nikolay Sivov | d576995 | 2008-04-29 00:10:20 +0400 | [diff] [blame] | 3829 | if(!graphics || !dpi) |
| 3830 | return InvalidParameter; |
| 3831 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3832 | if(graphics->busy) |
| 3833 | return ObjectBusy; |
| 3834 | |
Nikolay Sivov | d576995 | 2008-04-29 00:10:20 +0400 | [diff] [blame] | 3835 | *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY); |
| 3836 | |
| 3837 | return Ok; |
| 3838 | } |
Nikolay Sivov | 510c26a | 2008-04-30 01:28:40 +0400 | [diff] [blame] | 3839 | |
| 3840 | GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix, |
| 3841 | GpMatrixOrder order) |
| 3842 | { |
| 3843 | GpMatrix m; |
| 3844 | GpStatus ret; |
| 3845 | |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3846 | TRACE("(%p, %p, %d)\n", graphics, matrix, order); |
| 3847 | |
Nikolay Sivov | 510c26a | 2008-04-30 01:28:40 +0400 | [diff] [blame] | 3848 | if(!graphics || !matrix) |
| 3849 | return InvalidParameter; |
| 3850 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3851 | if(graphics->busy) |
| 3852 | return ObjectBusy; |
| 3853 | |
Nikolay Sivov | 510c26a | 2008-04-30 01:28:40 +0400 | [diff] [blame] | 3854 | m = *(graphics->worldtrans); |
| 3855 | |
Michael Stefaniuc | b53877d | 2009-01-14 09:52:24 +0100 | [diff] [blame] | 3856 | ret = GdipMultiplyMatrix(&m, matrix, order); |
Nikolay Sivov | 510c26a | 2008-04-30 01:28:40 +0400 | [diff] [blame] | 3857 | if(ret == Ok) |
| 3858 | *(graphics->worldtrans) = m; |
| 3859 | |
| 3860 | return ret; |
| 3861 | } |
Huw Davies | 6cfb469 | 2008-05-12 16:51:32 +0100 | [diff] [blame] | 3862 | |
| 3863 | GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc) |
| 3864 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3865 | TRACE("(%p, %p)\n", graphics, hdc); |
| 3866 | |
Nikolay Sivov | 4570501 | 2008-08-24 14:45:14 +0400 | [diff] [blame] | 3867 | if(!graphics || !hdc) |
| 3868 | return InvalidParameter; |
| 3869 | |
Nikolay Sivov | 366ae1e | 2008-08-24 14:45:18 +0400 | [diff] [blame] | 3870 | if(graphics->busy) |
| 3871 | return ObjectBusy; |
| 3872 | |
| 3873 | *hdc = graphics->hdc; |
| 3874 | graphics->busy = TRUE; |
| 3875 | |
| 3876 | return Ok; |
Huw Davies | 6cfb469 | 2008-05-12 16:51:32 +0100 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc) |
| 3880 | { |
Nikolay Sivov | 29f4c9d | 2008-09-02 23:45:39 +0400 | [diff] [blame] | 3881 | TRACE("(%p, %p)\n", graphics, hdc); |
| 3882 | |
Nikolay Sivov | 4570501 | 2008-08-24 14:45:14 +0400 | [diff] [blame] | 3883 | if(!graphics) |
| 3884 | return InvalidParameter; |
| 3885 | |
Nikolay Sivov | 366ae1e | 2008-08-24 14:45:18 +0400 | [diff] [blame] | 3886 | if(graphics->hdc != hdc || !(graphics->busy)) |
Nikolay Sivov | 4570501 | 2008-08-24 14:45:14 +0400 | [diff] [blame] | 3887 | return InvalidParameter; |
| 3888 | |
Nikolay Sivov | 366ae1e | 2008-08-24 14:45:18 +0400 | [diff] [blame] | 3889 | graphics->busy = FALSE; |
| 3890 | |
| 3891 | return Ok; |
Huw Davies | 6cfb469 | 2008-05-12 16:51:32 +0100 | [diff] [blame] | 3892 | } |
Huw Davies | d5ccbe2 | 2008-05-12 16:57:28 +0100 | [diff] [blame] | 3893 | |
| 3894 | GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region) |
| 3895 | { |
Nikolay Sivov | ef50aa3 | 2008-08-27 02:03:27 +0400 | [diff] [blame] | 3896 | GpRegion *clip; |
| 3897 | GpStatus status; |
| 3898 | |
| 3899 | TRACE("(%p, %p)\n", graphics, region); |
| 3900 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3901 | if(!graphics || !region) |
| 3902 | return InvalidParameter; |
Huw Davies | d5ccbe2 | 2008-05-12 16:57:28 +0100 | [diff] [blame] | 3903 | |
Nikolay Sivov | f0a507e | 2008-08-24 14:45:23 +0400 | [diff] [blame] | 3904 | if(graphics->busy) |
| 3905 | return ObjectBusy; |
| 3906 | |
Nikolay Sivov | ef50aa3 | 2008-08-27 02:03:27 +0400 | [diff] [blame] | 3907 | if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok) |
| 3908 | return status; |
| 3909 | |
| 3910 | /* free everything except root node and header */ |
| 3911 | delete_element(®ion->node); |
| 3912 | memcpy(region, clip, sizeof(GpRegion)); |
| 3913 | |
| 3914 | return Ok; |
Huw Davies | d5ccbe2 | 2008-05-12 16:57:28 +0100 | [diff] [blame] | 3915 | } |
Huw Davies | 3ab7666 | 2008-07-10 15:26:58 +0100 | [diff] [blame] | 3916 | |
| 3917 | GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space, |
| 3918 | GpCoordinateSpace src_space, GpPointF *points, INT count) |
| 3919 | { |
Vincent Povirk | 2af29ed | 2009-03-23 16:34:12 -0500 | [diff] [blame] | 3920 | GpMatrix *matrix; |
| 3921 | GpStatus stat; |
| 3922 | REAL unitscale; |
| 3923 | |
Nikolay Sivov | c61ece6 | 2008-08-26 01:58:42 +0400 | [diff] [blame] | 3924 | if(!graphics || !points || count <= 0) |
| 3925 | return InvalidParameter; |
| 3926 | |
| 3927 | if(graphics->busy) |
| 3928 | return ObjectBusy; |
| 3929 | |
Vincent Povirk | 2af29ed | 2009-03-23 16:34:12 -0500 | [diff] [blame] | 3930 | TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count); |
Huw Davies | 3ab7666 | 2008-07-10 15:26:58 +0100 | [diff] [blame] | 3931 | |
Vincent Povirk | 2af29ed | 2009-03-23 16:34:12 -0500 | [diff] [blame] | 3932 | if (src_space == dst_space) return Ok; |
| 3933 | |
| 3934 | stat = GdipCreateMatrix(&matrix); |
| 3935 | if (stat == Ok) |
| 3936 | { |
| 3937 | unitscale = convert_unit(graphics->hdc, graphics->unit); |
| 3938 | |
| 3939 | if(graphics->unit != UnitDisplay) |
| 3940 | unitscale *= graphics->scale; |
| 3941 | |
| 3942 | /* transform from src_space to CoordinateSpacePage */ |
| 3943 | switch (src_space) |
| 3944 | { |
| 3945 | case CoordinateSpaceWorld: |
| 3946 | GdipMultiplyMatrix(matrix, graphics->worldtrans, MatrixOrderAppend); |
| 3947 | break; |
| 3948 | case CoordinateSpacePage: |
| 3949 | break; |
| 3950 | case CoordinateSpaceDevice: |
| 3951 | GdipScaleMatrix(matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend); |
| 3952 | break; |
| 3953 | } |
| 3954 | |
| 3955 | /* transform from CoordinateSpacePage to dst_space */ |
| 3956 | switch (dst_space) |
| 3957 | { |
| 3958 | case CoordinateSpaceWorld: |
| 3959 | { |
| 3960 | GpMatrix *inverted_transform; |
| 3961 | stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform); |
| 3962 | if (stat == Ok) |
| 3963 | { |
| 3964 | stat = GdipInvertMatrix(inverted_transform); |
| 3965 | if (stat == Ok) |
| 3966 | GdipMultiplyMatrix(matrix, inverted_transform, MatrixOrderAppend); |
| 3967 | GdipDeleteMatrix(inverted_transform); |
| 3968 | } |
| 3969 | break; |
| 3970 | } |
| 3971 | case CoordinateSpacePage: |
| 3972 | break; |
| 3973 | case CoordinateSpaceDevice: |
| 3974 | GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend); |
| 3975 | break; |
| 3976 | } |
| 3977 | |
| 3978 | if (stat == Ok) |
| 3979 | stat = GdipTransformMatrixPoints(matrix, points, count); |
| 3980 | |
| 3981 | GdipDeleteMatrix(matrix); |
| 3982 | } |
| 3983 | |
| 3984 | return stat; |
Huw Davies | 3ab7666 | 2008-07-10 15:26:58 +0100 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space, |
| 3988 | GpCoordinateSpace src_space, GpPoint *points, INT count) |
| 3989 | { |
Vincent Povirk | c486e81 | 2009-05-19 15:40:43 -0500 | [diff] [blame] | 3990 | GpPointF *pointsF; |
| 3991 | GpStatus ret; |
| 3992 | INT i; |
Huw Davies | 3ab7666 | 2008-07-10 15:26:58 +0100 | [diff] [blame] | 3993 | |
Vincent Povirk | c486e81 | 2009-05-19 15:40:43 -0500 | [diff] [blame] | 3994 | TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count); |
| 3995 | |
| 3996 | if(count <= 0) |
| 3997 | return InvalidParameter; |
| 3998 | |
| 3999 | pointsF = GdipAlloc(sizeof(GpPointF) * count); |
| 4000 | if(!pointsF) |
| 4001 | return OutOfMemory; |
| 4002 | |
| 4003 | for(i = 0; i < count; i++){ |
| 4004 | pointsF[i].X = (REAL)points[i].X; |
| 4005 | pointsF[i].Y = (REAL)points[i].Y; |
| 4006 | } |
| 4007 | |
| 4008 | ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count); |
| 4009 | |
| 4010 | if(ret == Ok) |
| 4011 | for(i = 0; i < count; i++){ |
| 4012 | points[i].X = roundr(pointsF[i].X); |
| 4013 | points[i].Y = roundr(pointsF[i].Y); |
| 4014 | } |
| 4015 | GdipFree(pointsF); |
| 4016 | |
| 4017 | return ret; |
Huw Davies | 3ab7666 | 2008-07-10 15:26:58 +0100 | [diff] [blame] | 4018 | } |
Hans Leidekker | 6122c77 | 2008-11-24 10:23:03 +0100 | [diff] [blame] | 4019 | |
| 4020 | HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void) |
| 4021 | { |
| 4022 | FIXME("\n"); |
| 4023 | |
| 4024 | return NULL; |
| 4025 | } |
Nikolay Sivov | 5da52e0 | 2009-01-31 00:07:30 +0300 | [diff] [blame] | 4026 | |
| 4027 | /***************************************************************************** |
| 4028 | * GdipTranslateClip [GDIPLUS.@] |
| 4029 | */ |
| 4030 | GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy) |
| 4031 | { |
| 4032 | TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy); |
| 4033 | |
| 4034 | if(!graphics) |
| 4035 | return InvalidParameter; |
| 4036 | |
Nikolay Sivov | 8c09616 | 2009-02-02 23:48:01 +0300 | [diff] [blame] | 4037 | if(graphics->busy) |
| 4038 | return ObjectBusy; |
| 4039 | |
Nikolay Sivov | 5da52e0 | 2009-01-31 00:07:30 +0300 | [diff] [blame] | 4040 | return GdipTranslateRegion(graphics->clip, dx, dy); |
| 4041 | } |
| 4042 | |
| 4043 | /***************************************************************************** |
| 4044 | * GdipTranslateClipI [GDIPLUS.@] |
| 4045 | */ |
| 4046 | GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy) |
| 4047 | { |
| 4048 | TRACE("(%p, %d, %d)\n", graphics, dx, dy); |
| 4049 | |
| 4050 | if(!graphics) |
| 4051 | return InvalidParameter; |
| 4052 | |
Nikolay Sivov | 8c09616 | 2009-02-02 23:48:01 +0300 | [diff] [blame] | 4053 | if(graphics->busy) |
| 4054 | return ObjectBusy; |
| 4055 | |
Nikolay Sivov | 5da52e0 | 2009-01-31 00:07:30 +0300 | [diff] [blame] | 4056 | return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy); |
| 4057 | } |
Ken Sharp | e3f4859 | 2009-06-09 21:48:05 +0100 | [diff] [blame] | 4058 | |
| 4059 | |
| 4060 | /***************************************************************************** |
| 4061 | * GdipMeasureDriverString [GDIPLUS.@] |
| 4062 | */ |
| 4063 | GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length, |
| 4064 | GDIPCONST GpFont *font, GDIPCONST PointF *positions, |
| 4065 | INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox) |
| 4066 | { |
| 4067 | FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox); |
| 4068 | return NotImplemented; |
| 4069 | } |
| 4070 | |
| 4071 | /***************************************************************************** |
| 4072 | * GdipGetVisibleClipBoundsI [GDIPLUS.@] |
| 4073 | */ |
| 4074 | GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect) |
| 4075 | { |
| 4076 | FIXME("(%p %p): stub\n", graphics, rect); |
| 4077 | return NotImplemented; |
| 4078 | } |
| 4079 | |
| 4080 | /***************************************************************************** |
| 4081 | * GdipDrawDriverString [GDIPLUS.@] |
| 4082 | */ |
| 4083 | GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length, |
| 4084 | GDIPCONST GpFont *font, GDIPCONST GpBrush *brush, |
| 4085 | GDIPCONST PointF *positions, INT flags, |
| 4086 | GDIPCONST GpMatrix *matrix ) |
| 4087 | { |
Francois Gouget | 489bd52 | 2009-06-15 11:00:03 +0200 | [diff] [blame] | 4088 | FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix); |
Ken Sharp | e3f4859 | 2009-06-09 21:48:05 +0100 | [diff] [blame] | 4089 | return NotImplemented; |
| 4090 | } |
Ken Sharp | e096b59 | 2009-06-22 21:59:59 +0100 | [diff] [blame] | 4091 | |
| 4092 | /***************************************************************************** |
| 4093 | * GdipIsVisibleRegionPointI [GDIPLUS.@] |
| 4094 | */ |
| 4095 | GpStatus WINGDIPAPI GdipIsVisibleRegionPointI(GpRegion *region, INT x, INT y, GpGraphics *graphics, BOOL *result) |
| 4096 | { |
| 4097 | FIXME("(%p %d %d %p %p): stub\n", region, x, y, graphics, result); |
| 4098 | return NotImplemented; |
| 4099 | } |
Alistair Leslie-Hughes | 7b2292f | 2009-07-30 13:56:42 +1000 | [diff] [blame^] | 4100 | |
| 4101 | /***************************************************************************** |
| 4102 | * GdipRecordMetafileI [GDIPLUS.@] |
| 4103 | */ |
| 4104 | GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect, |
| 4105 | MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile) |
| 4106 | { |
| 4107 | FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile); |
| 4108 | return NotImplemented; |
| 4109 | } |