gdiplus/metafile: Added support for EmfPlusFont objects.
[wine.git] / dlls / gdiplus / gdiplus_private.h
blobd4c1fd94afee2be9f15e333aaacc59e0ca3c0dad
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 VALID_MAGIC(x) (((x) & 0xfffff000) == 0xdbc01000)
45 #define TENSION_CONST (0.3)
47 #define GIF_DISPOSE_UNSPECIFIED 0
48 #define GIF_DISPOSE_DO_NOT_DISPOSE 1
49 #define GIF_DISPOSE_RESTORE_TO_BKGND 2
50 #define GIF_DISPOSE_RESTORE_TO_PREV 3
52 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc(size_t size)
54 return HeapAlloc(GetProcessHeap(), 0, size);
57 static inline void* __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t size)
59 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
62 static inline void* __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t size)
64 return HeapReAlloc(GetProcessHeap(), 0, mem, size);
67 static inline BOOL heap_free(void *mem)
69 return HeapFree(GetProcessHeap(), 0, mem);
72 COLORREF ARGB2COLORREF(ARGB color) DECLSPEC_HIDDEN;
73 HBITMAP ARGB2BMP(ARGB color) DECLSPEC_HIDDEN;
74 extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
75 REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN;
76 extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN;
77 extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN;
78 extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
79 extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
80 extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN;
82 #define WineCoordinateSpaceGdiDevice ((GpCoordinateSpace)4)
84 extern GpStatus gdi_transform_acquire(GpGraphics *graphics);
85 extern GpStatus gdi_transform_release(GpGraphics *graphics);
86 extern GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
87 GpCoordinateSpace src_space, GpMatrix *matrix) DECLSPEC_HIDDEN;
88 extern GpStatus gdip_transform_points(GpGraphics *graphics, GpCoordinateSpace dst_space,
89 GpCoordinateSpace src_space, GpPointF *points, INT count) DECLSPEC_HIDDEN;
91 extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN;
92 extern GpStatus encode_image_png(GpImage *image, IStream* stream, GDIPCONST EncoderParameters* params) DECLSPEC_HIDDEN;
94 extern GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) DECLSPEC_HIDDEN;
95 extern GpStatus METAFILE_GetDC(GpMetafile* metafile, HDC *hdc) DECLSPEC_HIDDEN;
96 extern GpStatus METAFILE_ReleaseDC(GpMetafile* metafile, HDC hdc) DECLSPEC_HIDDEN;
97 extern GpStatus METAFILE_GraphicsClear(GpMetafile* metafile, ARGB color) DECLSPEC_HIDDEN;
98 extern GpStatus METAFILE_FillRectangles(GpMetafile* metafile, GpBrush* brush,
99 GDIPCONST GpRectF* rects, INT count) DECLSPEC_HIDDEN;
100 extern GpStatus METAFILE_SetClipRect(GpMetafile* metafile,
101 REAL x, REAL y, REAL width, REAL height, CombineMode mode) DECLSPEC_HIDDEN;
102 extern GpStatus METAFILE_SetClipRegion(GpMetafile* metafile, GpRegion* region, CombineMode mode) DECLSPEC_HIDDEN;
103 extern GpStatus METAFILE_SetPageTransform(GpMetafile* metafile, GpUnit unit, REAL scale) DECLSPEC_HIDDEN;
104 extern GpStatus METAFILE_SetWorldTransform(GpMetafile* metafile, GDIPCONST GpMatrix* transform) DECLSPEC_HIDDEN;
105 extern GpStatus METAFILE_ScaleWorldTransform(GpMetafile* metafile, REAL sx, REAL sy, MatrixOrder order) DECLSPEC_HIDDEN;
106 extern GpStatus METAFILE_MultiplyWorldTransform(GpMetafile* metafile, GDIPCONST GpMatrix* matrix, MatrixOrder order) DECLSPEC_HIDDEN;
107 extern GpStatus METAFILE_RotateWorldTransform(GpMetafile* metafile, REAL angle, MatrixOrder order) DECLSPEC_HIDDEN;
108 extern GpStatus METAFILE_TranslateWorldTransform(GpMetafile* metafile, REAL dx, REAL dy, MatrixOrder order) DECLSPEC_HIDDEN;
109 extern GpStatus METAFILE_ResetWorldTransform(GpMetafile* metafile) DECLSPEC_HIDDEN;
110 extern GpStatus METAFILE_BeginContainer(GpMetafile* metafile, GDIPCONST GpRectF *dstrect,
111 GDIPCONST GpRectF *srcrect, GpUnit unit, DWORD StackIndex) DECLSPEC_HIDDEN;
112 extern GpStatus METAFILE_BeginContainerNoParams(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
113 extern GpStatus METAFILE_EndContainer(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
114 extern GpStatus METAFILE_SaveGraphics(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
115 extern GpStatus METAFILE_RestoreGraphics(GpMetafile* metafile, DWORD StackIndex) DECLSPEC_HIDDEN;
116 extern GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) DECLSPEC_HIDDEN;
117 extern GpStatus METAFILE_DrawImagePointsRect(GpMetafile* metafile, GpImage *image,
118 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
119 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
120 DrawImageAbort callback, VOID *callbackData) DECLSPEC_HIDDEN;
121 extern GpStatus METAFILE_AddSimpleProperty(GpMetafile *metafile, SHORT prop, SHORT val) DECLSPEC_HIDDEN;
122 extern GpStatus METAFILE_DrawPath(GpMetafile *metafile, GpPen *pen, GpPath *path) DECLSPEC_HIDDEN;
123 extern GpStatus METAFILE_FillPath(GpMetafile *metafile, GpBrush *brush, GpPath *path) DECLSPEC_HIDDEN;
124 extern void METAFILE_Free(GpMetafile *metafile) DECLSPEC_HIDDEN;
126 extern void calc_curve_bezier(const GpPointF *pts, REAL tension, REAL *x1,
127 REAL *y1, REAL *x2, REAL *y2) DECLSPEC_HIDDEN;
128 extern void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
129 REAL tension, REAL *x, REAL *y) DECLSPEC_HIDDEN;
131 extern void free_installed_fonts(void) DECLSPEC_HIDDEN;
133 extern BOOL lengthen_path(GpPath *path, INT len) DECLSPEC_HIDDEN;
135 extern DWORD write_region_data(const GpRegion *region, void *data) DECLSPEC_HIDDEN;
136 extern DWORD write_path_data(GpPath *path, void *data) DECLSPEC_HIDDEN;
138 extern GpStatus trace_path(GpGraphics *graphics, GpPath *path) DECLSPEC_HIDDEN;
140 typedef struct region_element region_element;
141 extern void delete_element(region_element *element) DECLSPEC_HIDDEN;
143 extern GpStatus get_hatch_data(GpHatchStyle hatchstyle, const char **result) DECLSPEC_HIDDEN;
145 static inline INT gdip_round(REAL x)
147 return (INT) floorf(x + 0.5);
150 static inline INT ceilr(REAL x)
152 return (INT) ceilf(x);
155 static inline REAL deg2rad(REAL degrees)
157 return M_PI * degrees / 180.0;
160 static inline ARGB color_over(ARGB bg, ARGB fg)
162 BYTE b, g, r, a;
163 BYTE bg_alpha, fg_alpha;
165 fg_alpha = (fg>>24)&0xff;
167 if (fg_alpha == 0xff) return fg;
169 if (fg_alpha == 0) return bg;
171 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
173 if (bg_alpha == 0) return fg;
175 a = bg_alpha + fg_alpha;
176 b = ((bg&0xff)*bg_alpha + (fg&0xff)*fg_alpha)/a;
177 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*fg_alpha)/a;
178 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*fg_alpha)/a;
180 return (a<<24)|(r<<16)|(g<<8)|b;
183 /* fg is premult, bg and return value are not */
184 static inline ARGB color_over_fgpremult(ARGB bg, ARGB fg)
186 BYTE b, g, r, a;
187 BYTE bg_alpha, fg_alpha;
189 fg_alpha = (fg>>24)&0xff;
191 if (fg_alpha == 0) return bg;
193 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
195 a = bg_alpha + fg_alpha;
196 b = ((bg&0xff)*bg_alpha + (fg&0xff)*0xff)/a;
197 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*0xff)/a;
198 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*0xff)/a;
200 return (a<<24)|(r<<16)|(g<<8)|b;
203 extern const char *debugstr_rectf(const RectF* rc) DECLSPEC_HIDDEN;
205 extern const char *debugstr_pointf(const PointF* pt) DECLSPEC_HIDDEN;
207 extern void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height,
208 BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride) DECLSPEC_HIDDEN;
210 extern GpStatus convert_pixels(INT width, INT height,
211 INT dst_stride, BYTE *dst_bits, PixelFormat dst_format,
212 INT src_stride, const BYTE *src_bits, PixelFormat src_format, ColorPalette *palette) DECLSPEC_HIDDEN;
214 extern PixelFormat apply_image_attributes(const GpImageAttributes *attributes, LPBYTE data,
215 UINT width, UINT height, INT stride, ColorAdjustType type, PixelFormat fmt) DECLSPEC_HIDDEN;
217 struct GpMatrix{
218 REAL matrix[6];
221 struct GpPen{
222 UINT style;
223 GpUnit unit;
224 REAL width;
225 GpLineCap endcap;
226 GpLineCap startcap;
227 GpDashCap dashcap;
228 GpCustomLineCap *customstart;
229 GpCustomLineCap *customend;
230 GpLineJoin join;
231 REAL miterlimit;
232 GpDashStyle dash;
233 REAL *dashes;
234 INT numdashes;
235 REAL offset; /* dash offset */
236 GpBrush *brush;
237 GpPenAlignment align;
238 GpMatrix transform;
241 struct GpGraphics{
242 HDC hdc;
243 HWND hwnd;
244 BOOL owndc;
245 BOOL alpha_hdc;
246 GpImage *image;
247 ImageType image_type;
248 SmoothingMode smoothing;
249 CompositingQuality compqual;
250 InterpolationMode interpolation;
251 PixelOffsetMode pixeloffset;
252 CompositingMode compmode;
253 TextRenderingHint texthint;
254 GpUnit unit; /* page unit */
255 REAL scale; /* page scale */
256 REAL xres, yres;
257 GpMatrix worldtrans; /* world transform */
258 BOOL busy; /* hdc handle obtained by GdipGetDC */
259 GpRegion *clip; /* in device coords */
260 UINT textcontrast; /* not used yet. get/set only */
261 struct list containers;
262 GraphicsContainer contid; /* last-issued container ID */
263 INT origin_x, origin_y;
264 INT gdi_transform_acquire_count, gdi_transform_save;
265 GpMatrix gdi_transform;
266 HRGN gdi_clip;
267 /* For giving the caller an HDC when we technically can't: */
268 HBITMAP temp_hbitmap;
269 int temp_hbitmap_width;
270 int temp_hbitmap_height;
271 BYTE *temp_bits;
272 HDC temp_hdc;
275 struct GpBrush{
276 GpBrushType bt;
279 struct GpHatch{
280 GpBrush brush;
281 GpHatchStyle hatchstyle;
282 ARGB forecol;
283 ARGB backcol;
286 struct GpSolidFill{
287 GpBrush brush;
288 ARGB color;
291 struct GpPathGradient{
292 GpBrush brush;
293 GpPath* path;
294 ARGB centercolor;
295 GpWrapMode wrap;
296 BOOL gamma;
297 GpPointF center;
298 GpPointF focus;
299 REAL* blendfac; /* blend factors */
300 REAL* blendpos; /* blend positions */
301 INT blendcount;
302 ARGB *surroundcolors;
303 INT surroundcolorcount;
304 ARGB* pblendcolor; /* preset blend colors */
305 REAL* pblendpos; /* preset blend positions */
306 INT pblendcount;
307 GpMatrix transform;
310 struct GpLineGradient{
311 GpBrush brush;
312 GpPointF startpoint;
313 GpPointF endpoint;
314 ARGB startcolor;
315 ARGB endcolor;
316 RectF rect;
317 GpWrapMode wrap;
318 BOOL gamma;
319 REAL* blendfac; /* blend factors */
320 REAL* blendpos; /* blend positions */
321 INT blendcount;
322 ARGB* pblendcolor; /* preset blend colors */
323 REAL* pblendpos; /* preset blend positions */
324 INT pblendcount;
325 GpMatrix transform;
328 struct GpTexture{
329 GpBrush brush;
330 GpMatrix transform;
331 GpImage *image;
332 GpImageAttributes *imageattributes;
333 BYTE *bitmap_bits; /* image bits converted to ARGB and run through imageattributes */
336 struct GpPath{
337 GpFillMode fill;
338 GpPathData pathdata;
339 BOOL newfigure; /* whether the next drawing action starts a new figure */
340 INT datalen; /* size of the arrays in pathdata */
343 struct GpPathIterator{
344 GpPathData pathdata;
345 INT subpath_pos; /* for NextSubpath methods */
346 INT marker_pos; /* for NextMarker methods */
347 INT pathtype_pos; /* for NextPathType methods */
350 struct GpCustomLineCap{
351 CustomLineCapType type;
352 GpPathData pathdata;
353 BOOL fill; /* TRUE for fill, FALSE for stroke */
354 GpLineCap cap; /* as far as I can tell, this value is ignored */
355 REAL inset; /* how much to adjust the end of the line */
356 GpLineJoin join;
357 REAL scale;
360 struct GpAdjustableArrowCap{
361 GpCustomLineCap cap;
364 struct GpImage{
365 IWICBitmapDecoder *decoder;
366 ImageType type;
367 GUID format;
368 UINT flags;
369 UINT frame_count, current_frame;
370 ColorPalette *palette;
371 REAL xres, yres;
372 LONG busy;
375 #define EmfPlusObjectTableSize 64
377 typedef enum EmfPlusObjectType
379 ObjectTypeInvalid,
380 ObjectTypeBrush,
381 ObjectTypePen,
382 ObjectTypePath,
383 ObjectTypeRegion,
384 ObjectTypeImage,
385 ObjectTypeFont,
386 ObjectTypeStringFormat,
387 ObjectTypeImageAttributes,
388 ObjectTypeCustomLineCap,
389 ObjectTypeMax = ObjectTypeCustomLineCap,
390 } EmfPlusObjectType;
392 /* Deserialized EmfPlusObject record. */
393 struct emfplus_object {
394 EmfPlusObjectType type;
395 union {
396 GpBrush *brush;
397 GpPath *path;
398 GpImage *image;
399 GpFont *font;
400 GpImageAttributes *image_attributes;
401 void *object;
402 } u;
405 struct GpMetafile{
406 GpImage image;
407 GpRectF bounds;
408 GpUnit unit;
409 MetafileType metafile_type;
410 HENHMETAFILE hemf;
411 int preserve_hemf; /* if true, hemf belongs to the app and should not be deleted */
413 /* recording */
414 HDC record_dc;
415 GpGraphics *record_graphics;
416 BYTE *comment_data;
417 DWORD comment_data_size;
418 DWORD comment_data_length;
419 IStream *record_stream;
420 BOOL auto_frame; /* If true, determine the frame automatically */
421 GpPointF auto_frame_min, auto_frame_max;
422 DWORD next_object_id;
424 /* playback */
425 GpGraphics *playback_graphics;
426 HDC playback_dc;
427 GpPointF playback_points[3];
428 GpRectF src_rect;
429 HANDLETABLE *handle_table;
430 int handle_count;
431 XFORM gdiworldtransform;
432 GpMatrix *world_transform;
433 GpUnit page_unit;
434 REAL page_scale;
435 GpRegion *base_clip; /* clip region in device space for all metafile output */
436 GpRegion *clip; /* clip region within the metafile */
437 struct list containers;
438 struct emfplus_object objtable[EmfPlusObjectTableSize];
441 struct GpBitmap{
442 GpImage image;
443 INT width;
444 INT height;
445 PixelFormat format;
446 ImageLockMode lockmode;
447 BYTE *bitmapbits; /* pointer to the buffer we passed in BitmapLockBits */
448 HBITMAP hbitmap;
449 HDC hdc;
450 BYTE *bits; /* actual image bits if this is a DIB */
451 INT stride; /* stride of bits if this is a DIB */
452 BYTE *own_bits; /* image bits that need to be freed with this object */
453 INT lockx, locky; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
454 IWICMetadataReader *metadata_reader; /* NULL if there is no metadata */
455 UINT prop_count;
456 PropertyItem *prop_item; /* cached image properties */
459 struct GpCachedBitmap{
460 GpImage *image;
463 struct color_key{
464 BOOL enabled;
465 ARGB low;
466 ARGB high;
469 struct color_matrix{
470 BOOL enabled;
471 ColorMatrixFlags flags;
472 ColorMatrix colormatrix;
473 ColorMatrix graymatrix;
476 struct color_remap_table{
477 BOOL enabled;
478 INT mapsize;
479 ColorMap *colormap;
482 struct GpImageAttributes{
483 WrapMode wrap;
484 ARGB outside_color;
485 BOOL clamp;
486 struct color_key colorkeys[ColorAdjustTypeCount];
487 struct color_matrix colormatrices[ColorAdjustTypeCount];
488 struct color_remap_table colorremaptables[ColorAdjustTypeCount];
489 BOOL gamma_enabled[ColorAdjustTypeCount];
490 REAL gamma[ColorAdjustTypeCount];
493 struct GpFont{
494 GpFontFamily *family;
495 OUTLINETEXTMETRICW otm;
496 REAL emSize; /* in font units */
497 Unit unit;
500 extern const struct GpStringFormat default_drawstring_format DECLSPEC_HIDDEN;
502 struct GpStringFormat{
503 INT attr;
504 LANGID lang;
505 LANGID digitlang;
506 StringAlignment align;
507 StringTrimming trimming;
508 HotkeyPrefix hkprefix;
509 StringAlignment line_align;
510 StringDigitSubstitute digitsub;
511 INT tabcount;
512 REAL firsttab;
513 REAL *tabs;
514 CharacterRange *character_ranges;
515 INT range_count;
516 BOOL generic_typographic;
519 extern void init_generic_string_formats(void) DECLSPEC_HIDDEN;
520 extern void free_generic_string_formats(void) DECLSPEC_HIDDEN;
522 struct GpFontCollection{
523 GpFontFamily **FontFamilies;
524 INT count;
525 INT allocated;
528 struct GpFontFamily{
529 WCHAR FamilyName[LF_FACESIZE];
530 UINT16 em_height, ascent, descent, line_spacing; /* in font units */
531 int dpi;
534 /* internal use */
535 typedef enum RegionType
537 RegionDataRect = 0x10000000,
538 RegionDataPath = 0x10000001,
539 RegionDataEmptyRect = 0x10000002,
540 RegionDataInfiniteRect = 0x10000003,
541 } RegionType;
543 struct region_element
545 DWORD type; /* Rectangle, Path, SpecialRectangle, or CombineMode */
546 union
548 GpRectF rect;
549 GpPath *path;
550 struct
552 struct region_element *left; /* the original region */
553 struct region_element *right; /* what *left was combined with */
554 } combine;
555 } elementdata;
558 struct GpRegion{
559 DWORD num_children;
560 region_element node;
563 typedef GpStatus (*gdip_format_string_callback)(HDC hdc,
564 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
565 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
566 INT lineno, const RectF *bounds, INT *underlined_indexes,
567 INT underlined_index_count, void *user_data);
569 GpStatus gdip_format_string(HDC hdc,
570 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
571 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, int ignore_empty_clip,
572 gdip_format_string_callback callback, void *user_data) DECLSPEC_HIDDEN;
574 void get_log_fontW(const GpFont *, GpGraphics *, LOGFONTW *) DECLSPEC_HIDDEN;
576 static inline BOOL image_lock(GpImage *image, BOOL *unlock)
578 LONG tid = GetCurrentThreadId(), owner_tid;
579 owner_tid = InterlockedCompareExchange(&image->busy, tid, 0);
580 *unlock = !owner_tid;
581 return !owner_tid || owner_tid==tid;
584 static inline void image_unlock(GpImage *image, BOOL unlock)
586 if (unlock) image->busy = 0;
589 #endif