tools: Add support for generating cursor files from SVG.
[wine.git] / dlls / gdiplus / gdiplus_private.h
blob88109d733c05fc157ba1a9b10a8d6d05f593ec31
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
19 #ifndef __WINE_GP_PRIVATE_H_
20 #define __WINE_GP_PRIVATE_H_
22 #include <math.h>
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "wingdi.h"
27 #include "winbase.h"
28 #include "winuser.h"
30 #include "objbase.h"
31 #include "ocidl.h"
32 #include "wincodecsdk.h"
33 #include "wine/list.h"
35 #include "gdiplus.h"
37 #define GP_DEFAULT_PENSTYLE (PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT | PS_JOIN_MITER)
38 #define MAX_ARC_PTS (13)
39 #define MAX_DASHLEN (16) /* this is a limitation of gdi */
40 #define INCH_HIMETRIC (2540)
42 #define VERSION_MAGIC 0xdbc01001
43 #define VERSION_MAGIC2 0xdbc01002
44 #define TENSION_CONST (0.3)
46 #define GIF_DISPOSE_UNSPECIFIED 0
47 #define GIF_DISPOSE_DO_NOT_DISPOSE 1
48 #define GIF_DISPOSE_RESTORE_TO_BKGND 2
49 #define GIF_DISPOSE_RESTORE_TO_PREV 3
51 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
53 return HeapAlloc(GetProcessHeap(), 0, size);
56 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size)
58 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
61 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t size)
63 return HeapReAlloc(GetProcessHeap(), 0, mem, size);
66 static inline BOOL heap_free(void *mem)
68 return HeapFree(GetProcessHeap(), 0, mem);
71 COLORREF ARGB2COLORREF(ARGB color) DECLSPEC_HIDDEN;
72 HBITMAP ARGB2BMP(ARGB color) DECLSPEC_HIDDEN;
73 extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
74 REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN;
75 extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN;
76 extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN;
77 extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
78 extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
79 extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN;
81 extern GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
82 GpCoordinateSpace src_space, GpMatrix *matrix) DECLSPEC_HIDDEN;
84 extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN;
85 extern GpStatus encode_image_png(GpImage *image, IStream* stream, GDIPCONST EncoderParameters* params) DECLSPEC_HIDDEN;
87 extern GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) DECLSPEC_HIDDEN;
88 extern GpStatus METAFILE_GetDC(GpMetafile* metafile, HDC *hdc) DECLSPEC_HIDDEN;
89 extern GpStatus METAFILE_ReleaseDC(GpMetafile* metafile, HDC hdc) DECLSPEC_HIDDEN;
90 extern GpStatus METAFILE_GraphicsClear(GpMetafile* metafile, ARGB color) DECLSPEC_HIDDEN;
91 extern GpStatus METAFILE_FillRectangles(GpMetafile* metafile, GpBrush* brush,
92 GDIPCONST GpRectF* rects, INT count) DECLSPEC_HIDDEN;
93 extern GpStatus METAFILE_SetClipRect(GpMetafile* metafile,
94 REAL x, REAL y, REAL width, REAL height, CombineMode mode) DECLSPEC_HIDDEN;
95 extern GpStatus METAFILE_SetPageTransform(GpMetafile* metafile, GpUnit unit, REAL scale) DECLSPEC_HIDDEN;
96 extern GpStatus METAFILE_SetWorldTransform(GpMetafile* metafile, GDIPCONST GpMatrix* transform) DECLSPEC_HIDDEN;
97 extern GpStatus METAFILE_ScaleWorldTransform(GpMetafile* metafile, REAL sx, REAL sy, MatrixOrder order) DECLSPEC_HIDDEN;
98 extern GpStatus METAFILE_MultiplyWorldTransform(GpMetafile* metafile, GDIPCONST GpMatrix* matrix, MatrixOrder order) DECLSPEC_HIDDEN;
99 extern GpStatus METAFILE_RotateWorldTransform(GpMetafile* metafile, REAL angle, MatrixOrder order) DECLSPEC_HIDDEN;
100 extern GpStatus METAFILE_TranslateWorldTransform(GpMetafile* metafile, REAL dx, REAL dy, MatrixOrder order) DECLSPEC_HIDDEN;
101 extern GpStatus METAFILE_ResetWorldTransform(GpMetafile* metafile) DECLSPEC_HIDDEN;
102 extern GpStatus METAFILE_BeginContainer(GpMetafile* metafile, GDIPCONST GpRectF *dstrect,
103 GDIPCONST GpRectF *srcrect, GpUnit unit, DWORD StackIndex) DECLSPEC_HIDDEN;
104 extern GpStatus METAFILE_BeginContainerNoParams(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
105 extern GpStatus METAFILE_EndContainer(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
106 extern GpStatus METAFILE_SaveGraphics(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
107 extern GpStatus METAFILE_RestoreGraphics(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
108 extern GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) DECLSPEC_HIDDEN;
109 extern GpStatus METAFILE_DrawImagePointsRect(GpMetafile* metafile, GpImage *image,
110 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
111 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
112 DrawImageAbort callback, VOID *callbackData) DECLSPEC_HIDDEN;
113 extern GpStatus METAFILE_AddSimpleProperty(GpMetafile *metafile, SHORT prop, SHORT val) DECLSPEC_HIDDEN;
114 extern GpStatus METAFILE_DrawPath(GpMetafile *metafile, GpPen *pen, GpPath *path) DECLSPEC_HIDDEN;
115 extern GpStatus METAFILE_FillPath(GpMetafile *metafile, GpBrush *brush, GpPath *path) DECLSPEC_HIDDEN;
117 extern void calc_curve_bezier(const GpPointF *pts, REAL tension, REAL *x1,
118 REAL *y1, REAL *x2, REAL *y2) DECLSPEC_HIDDEN;
119 extern void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
120 REAL tension, REAL *x, REAL *y) DECLSPEC_HIDDEN;
122 extern void free_installed_fonts(void) DECLSPEC_HIDDEN;
124 extern BOOL lengthen_path(GpPath *path, INT len) DECLSPEC_HIDDEN;
126 extern GpStatus trace_path(GpGraphics *graphics, GpPath *path) DECLSPEC_HIDDEN;
128 typedef struct region_element region_element;
129 extern void delete_element(region_element *element) DECLSPEC_HIDDEN;
131 extern GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result) DECLSPEC_HIDDEN;
133 static inline INT gdip_round(REAL x)
135 return (INT) floorf(x + 0.5);
138 static inline INT ceilr(REAL x)
140 return (INT) ceilf(x);
143 static inline REAL deg2rad(REAL degrees)
145 return M_PI * degrees / 180.0;
148 static inline ARGB color_over(ARGB bg, ARGB fg)
150 BYTE b, g, r, a;
151 BYTE bg_alpha, fg_alpha;
153 fg_alpha = (fg>>24)&0xff;
155 if (fg_alpha == 0xff) return fg;
157 if (fg_alpha == 0) return bg;
159 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
161 if (bg_alpha == 0) return fg;
163 a = bg_alpha + fg_alpha;
164 b = ((bg&0xff)*bg_alpha + (fg&0xff)*fg_alpha)/a;
165 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*fg_alpha)/a;
166 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*fg_alpha)/a;
168 return (a<<24)|(r<<16)|(g<<8)|b;
171 /* fg is premult, bg and return value are not */
172 static inline ARGB color_over_fgpremult(ARGB bg, ARGB fg)
174 BYTE b, g, r, a;
175 BYTE bg_alpha, fg_alpha;
177 fg_alpha = (fg>>24)&0xff;
179 if (fg_alpha == 0) return bg;
181 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
183 a = bg_alpha + fg_alpha;
184 b = ((bg&0xff)*bg_alpha + (fg&0xff)*0xff)/a;
185 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*0xff)/a;
186 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*0xff)/a;
188 return (a<<24)|(r<<16)|(g<<8)|b;
191 extern const char *debugstr_rectf(const RectF* rc) DECLSPEC_HIDDEN;
193 extern const char *debugstr_pointf(const PointF* pt) DECLSPEC_HIDDEN;
195 extern void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height,
196 BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride) DECLSPEC_HIDDEN;
198 extern GpStatus convert_pixels(INT width, INT height,
199 INT dst_stride, BYTE *dst_bits, PixelFormat dst_format,
200 INT src_stride, const BYTE *src_bits, PixelFormat src_format, ColorPalette *palette) DECLSPEC_HIDDEN;
202 extern PixelFormat apply_image_attributes(const GpImageAttributes *attributes, LPBYTE data,
203 UINT width, UINT height, INT stride, ColorAdjustType type, PixelFormat fmt) DECLSPEC_HIDDEN;
205 struct GpMatrix{
206 REAL matrix[6];
209 struct GpPen{
210 UINT style;
211 GpUnit unit;
212 REAL width;
213 GpLineCap endcap;
214 GpLineCap startcap;
215 GpDashCap dashcap;
216 GpCustomLineCap *customstart;
217 GpCustomLineCap *customend;
218 GpLineJoin join;
219 REAL miterlimit;
220 GpDashStyle dash;
221 REAL *dashes;
222 INT numdashes;
223 REAL offset; /* dash offset */
224 GpBrush *brush;
225 GpPenAlignment align;
226 GpMatrix transform;
229 struct GpGraphics{
230 HDC hdc;
231 HWND hwnd;
232 BOOL owndc;
233 BOOL alpha_hdc;
234 GpImage *image;
235 ImageType image_type;
236 SmoothingMode smoothing;
237 CompositingQuality compqual;
238 InterpolationMode interpolation;
239 PixelOffsetMode pixeloffset;
240 CompositingMode compmode;
241 TextRenderingHint texthint;
242 GpUnit unit; /* page unit */
243 REAL scale; /* page scale */
244 REAL xres, yres;
245 GpMatrix worldtrans; /* world transform */
246 BOOL busy; /* hdc handle obtained by GdipGetDC */
247 GpRegion *clip; /* in device coords */
248 UINT textcontrast; /* not used yet. get/set only */
249 struct list containers;
250 GraphicsContainer contid; /* last-issued container ID */
251 INT origin_x, origin_y;
252 /* For giving the caller an HDC when we technically can't: */
253 HBITMAP temp_hbitmap;
254 int temp_hbitmap_width;
255 int temp_hbitmap_height;
256 BYTE *temp_bits;
257 HDC temp_hdc;
260 struct GpBrush{
261 GpBrushType bt;
264 struct GpHatch{
265 GpBrush brush;
266 HatchStyle hatchstyle;
267 ARGB forecol;
268 ARGB backcol;
271 struct GpSolidFill{
272 GpBrush brush;
273 ARGB color;
276 struct GpPathGradient{
277 GpBrush brush;
278 GpPath* path;
279 ARGB centercolor;
280 GpWrapMode wrap;
281 BOOL gamma;
282 GpPointF center;
283 GpPointF focus;
284 REAL* blendfac; /* blend factors */
285 REAL* blendpos; /* blend positions */
286 INT blendcount;
287 ARGB *surroundcolors;
288 INT surroundcolorcount;
289 ARGB* pblendcolor; /* preset blend colors */
290 REAL* pblendpos; /* preset blend positions */
291 INT pblendcount;
292 GpMatrix transform;
295 struct GpLineGradient{
296 GpBrush brush;
297 GpPointF startpoint;
298 GpPointF endpoint;
299 ARGB startcolor;
300 ARGB endcolor;
301 RectF rect;
302 GpWrapMode wrap;
303 BOOL gamma;
304 REAL* blendfac; /* blend factors */
305 REAL* blendpos; /* blend positions */
306 INT blendcount;
307 ARGB* pblendcolor; /* preset blend colors */
308 REAL* pblendpos; /* preset blend positions */
309 INT pblendcount;
312 struct GpTexture{
313 GpBrush brush;
314 GpMatrix transform;
315 GpImage *image;
316 GpImageAttributes *imageattributes;
317 BYTE *bitmap_bits; /* image bits converted to ARGB and run through imageattributes */
320 struct GpPath{
321 GpFillMode fill;
322 GpPathData pathdata;
323 BOOL newfigure; /* whether the next drawing action starts a new figure */
324 INT datalen; /* size of the arrays in pathdata */
327 struct GpPathIterator{
328 GpPathData pathdata;
329 INT subpath_pos; /* for NextSubpath methods */
330 INT marker_pos; /* for NextMarker methods */
331 INT pathtype_pos; /* for NextPathType methods */
334 struct GpCustomLineCap{
335 CustomLineCapType type;
336 GpPathData pathdata;
337 BOOL fill; /* TRUE for fill, FALSE for stroke */
338 GpLineCap cap; /* as far as I can tell, this value is ignored */
339 REAL inset; /* how much to adjust the end of the line */
340 GpLineJoin join;
341 REAL scale;
344 struct GpAdjustableArrowCap{
345 GpCustomLineCap cap;
348 struct GpImage{
349 IWICBitmapDecoder *decoder;
350 ImageType type;
351 GUID format;
352 UINT flags;
353 UINT frame_count, current_frame;
354 ColorPalette *palette;
355 REAL xres, yres;
356 LONG busy;
359 struct GpMetafile{
360 GpImage image;
361 GpRectF bounds;
362 GpUnit unit;
363 MetafileType metafile_type;
364 HENHMETAFILE hemf;
365 int preserve_hemf; /* if true, hemf belongs to the app and should not be deleted */
367 /* recording */
368 HDC record_dc;
369 GpGraphics *record_graphics;
370 BYTE *comment_data;
371 DWORD comment_data_size;
372 DWORD comment_data_length;
373 IStream *record_stream;
374 BOOL auto_frame; /* If true, determine the frame automatically */
375 GpPointF auto_frame_min, auto_frame_max;
376 DWORD next_object_id;
378 /* playback */
379 GpGraphics *playback_graphics;
380 HDC playback_dc;
381 GpPointF playback_points[3];
382 GpRectF src_rect;
383 HANDLETABLE *handle_table;
384 int handle_count;
385 XFORM gdiworldtransform;
386 GpMatrix *world_transform;
387 GpUnit page_unit;
388 REAL page_scale;
389 GpRegion *base_clip; /* clip region in device space for all metafile output */
390 GpRegion *clip; /* clip region within the metafile */
391 struct list containers;
394 struct GpBitmap{
395 GpImage image;
396 INT width;
397 INT height;
398 PixelFormat format;
399 ImageLockMode lockmode;
400 BYTE *bitmapbits; /* pointer to the buffer we passed in BitmapLockBits */
401 HBITMAP hbitmap;
402 HDC hdc;
403 BYTE *bits; /* actual image bits if this is a DIB */
404 INT stride; /* stride of bits if this is a DIB */
405 BYTE *own_bits; /* image bits that need to be freed with this object */
406 INT lockx, locky; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
407 IWICMetadataReader *metadata_reader; /* NULL if there is no metadata */
408 UINT prop_count;
409 PropertyItem *prop_item; /* cached image properties */
412 struct GpCachedBitmap{
413 GpImage *image;
416 struct color_key{
417 BOOL enabled;
418 ARGB low;
419 ARGB high;
422 struct color_matrix{
423 BOOL enabled;
424 ColorMatrixFlags flags;
425 ColorMatrix colormatrix;
426 ColorMatrix graymatrix;
429 struct color_remap_table{
430 BOOL enabled;
431 INT mapsize;
432 ColorMap *colormap;
435 struct GpImageAttributes{
436 WrapMode wrap;
437 ARGB outside_color;
438 BOOL clamp;
439 struct color_key colorkeys[ColorAdjustTypeCount];
440 struct color_matrix colormatrices[ColorAdjustTypeCount];
441 struct color_remap_table colorremaptables[ColorAdjustTypeCount];
442 BOOL gamma_enabled[ColorAdjustTypeCount];
443 REAL gamma[ColorAdjustTypeCount];
446 struct GpFont{
447 GpFontFamily *family;
448 OUTLINETEXTMETRICW otm;
449 REAL emSize; /* in font units */
450 Unit unit;
453 extern const struct GpStringFormat default_drawstring_format DECLSPEC_HIDDEN;
455 struct GpStringFormat{
456 INT attr;
457 LANGID lang;
458 LANGID digitlang;
459 StringAlignment align;
460 StringTrimming trimming;
461 HotkeyPrefix hkprefix;
462 StringAlignment line_align;
463 StringDigitSubstitute digitsub;
464 INT tabcount;
465 REAL firsttab;
466 REAL *tabs;
467 CharacterRange *character_ranges;
468 INT range_count;
469 BOOL generic_typographic;
472 extern void init_generic_string_formats(void) DECLSPEC_HIDDEN;
473 extern void free_generic_string_formats(void) DECLSPEC_HIDDEN;
475 struct GpFontCollection{
476 GpFontFamily **FontFamilies;
477 INT count;
478 INT allocated;
481 struct GpFontFamily{
482 WCHAR FamilyName[LF_FACESIZE];
483 UINT16 em_height, ascent, descent, line_spacing; /* in font units */
484 int dpi;
487 /* internal use */
488 typedef enum RegionType
490 RegionDataRect = 0x10000000,
491 RegionDataPath = 0x10000001,
492 RegionDataEmptyRect = 0x10000002,
493 RegionDataInfiniteRect = 0x10000003,
494 } RegionType;
496 struct region_element
498 DWORD type; /* Rectangle, Path, SpecialRectangle, or CombineMode */
499 union
501 GpRectF rect;
502 GpPath *path;
503 struct
505 struct region_element *left; /* the original region */
506 struct region_element *right; /* what *left was combined with */
507 } combine;
508 } elementdata;
511 struct GpRegion{
512 DWORD num_children;
513 region_element node;
516 typedef GpStatus (*gdip_format_string_callback)(HDC hdc,
517 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
518 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
519 INT lineno, const RectF *bounds, INT *underlined_indexes,
520 INT underlined_index_count, void *user_data);
522 GpStatus gdip_format_string(HDC hdc,
523 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
524 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, int ignore_empty_clip,
525 gdip_format_string_callback callback, void *user_data) DECLSPEC_HIDDEN;
527 void get_log_fontW(const GpFont *, GpGraphics *, LOGFONTW *) DECLSPEC_HIDDEN;
529 static inline BOOL image_lock(GpImage *image, BOOL *unlock)
531 LONG tid = GetCurrentThreadId(), owner_tid;
532 owner_tid = InterlockedCompareExchange(&image->busy, tid, 0);
533 *unlock = !owner_tid;
534 return !owner_tid || owner_tid==tid;
537 static inline void image_unlock(GpImage *image, BOOL unlock)
539 if (unlock) image->busy = 0;
542 #endif