riched20: Initial support for changing font properties.
[wine/multimedia.git] / dlls / gdiplus / gdiplus_private.h
blob57b3de3d5510fef2dc1d5da0964b1c80a58e6a20
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 TENSION_CONST (0.3)
45 #define GIF_DISPOSE_UNSPECIFIED 0
46 #define GIF_DISPOSE_DO_NOT_DISPOSE 1
47 #define GIF_DISPOSE_RESTORE_TO_BKGND 2
48 #define GIF_DISPOSE_RESTORE_TO_PREV 3
50 COLORREF ARGB2COLORREF(ARGB color) DECLSPEC_HIDDEN;
51 HBITMAP ARGB2BMP(ARGB color) DECLSPEC_HIDDEN;
52 extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
53 REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN;
54 extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN;
55 extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN;
56 extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
57 extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
58 extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN;
60 extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN;
62 extern GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) DECLSPEC_HIDDEN;
63 extern GpStatus METAFILE_GetDC(GpMetafile* metafile, HDC *hdc) DECLSPEC_HIDDEN;
64 extern GpStatus METAFILE_ReleaseDC(GpMetafile* metafile, HDC hdc) DECLSPEC_HIDDEN;
65 extern GpStatus METAFILE_FillRectangles(GpMetafile* metafile, GpBrush* brush,
66 GDIPCONST GpRectF* rects, INT count) DECLSPEC_HIDDEN;
67 extern GpStatus METAFILE_SetPageTransform(GpMetafile* metafile, GpUnit unit, REAL scale) DECLSPEC_HIDDEN;
68 extern GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) DECLSPEC_HIDDEN;
70 extern void calc_curve_bezier(const GpPointF *pts, REAL tension, REAL *x1,
71 REAL *y1, REAL *x2, REAL *y2) DECLSPEC_HIDDEN;
72 extern void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
73 REAL tension, REAL *x, REAL *y) DECLSPEC_HIDDEN;
75 extern void free_installed_fonts(void) DECLSPEC_HIDDEN;
77 extern BOOL lengthen_path(GpPath *path, INT len) DECLSPEC_HIDDEN;
79 extern GpStatus trace_path(GpGraphics *graphics, GpPath *path) DECLSPEC_HIDDEN;
81 typedef struct region_element region_element;
82 extern void delete_element(region_element *element) DECLSPEC_HIDDEN;
84 extern GpStatus get_hatch_data(HatchStyle hatchstyle, const char **result) DECLSPEC_HIDDEN;
86 static inline INT gdip_round(REAL x)
88 return (INT) floorf(x + 0.5);
91 static inline INT ceilr(REAL x)
93 return (INT) ceilf(x);
96 static inline REAL deg2rad(REAL degrees)
98 return M_PI * degrees / 180.0;
101 static inline ARGB color_over(ARGB bg, ARGB fg)
103 BYTE b, g, r, a;
104 BYTE bg_alpha, fg_alpha;
106 fg_alpha = (fg>>24)&0xff;
108 if (fg_alpha == 0xff) return fg;
110 if (fg_alpha == 0) return bg;
112 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
114 if (bg_alpha == 0) return fg;
116 a = bg_alpha + fg_alpha;
117 b = ((bg&0xff)*bg_alpha + (fg&0xff)*fg_alpha)/a;
118 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*fg_alpha)/a;
119 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*fg_alpha)/a;
121 return (a<<24)|(r<<16)|(g<<8)|b;
124 /* fg is premult, bg and return value are not */
125 static inline ARGB color_over_fgpremult(ARGB bg, ARGB fg)
127 BYTE b, g, r, a;
128 BYTE bg_alpha, fg_alpha;
130 fg_alpha = (fg>>24)&0xff;
132 if (fg_alpha == 0) return bg;
134 bg_alpha = (((bg>>24)&0xff) * (0xff-fg_alpha)) / 0xff;
136 a = bg_alpha + fg_alpha;
137 b = ((bg&0xff)*bg_alpha + (fg&0xff)*0xff)/a;
138 g = (((bg>>8)&0xff)*bg_alpha + ((fg>>8)&0xff)*0xff)/a;
139 r = (((bg>>16)&0xff)*bg_alpha + ((fg>>16)&0xff)*0xff)/a;
141 return (a<<24)|(r<<16)|(g<<8)|b;
144 extern const char *debugstr_rectf(const RectF* rc) DECLSPEC_HIDDEN;
146 extern const char *debugstr_pointf(const PointF* pt) DECLSPEC_HIDDEN;
148 extern void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height,
149 BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride) DECLSPEC_HIDDEN;
151 extern GpStatus convert_pixels(INT width, INT height,
152 INT dst_stride, BYTE *dst_bits, PixelFormat dst_format,
153 INT src_stride, const BYTE *src_bits, PixelFormat src_format, ColorPalette *palette) DECLSPEC_HIDDEN;
155 struct GpMatrix{
156 REAL matrix[6];
159 struct GpPen{
160 UINT style;
161 GpUnit unit;
162 REAL width;
163 GpLineCap endcap;
164 GpLineCap startcap;
165 GpDashCap dashcap;
166 GpCustomLineCap *customstart;
167 GpCustomLineCap *customend;
168 GpLineJoin join;
169 REAL miterlimit;
170 GpDashStyle dash;
171 REAL *dashes;
172 INT numdashes;
173 REAL offset; /* dash offset */
174 GpBrush *brush;
175 GpPenAlignment align;
178 struct GpGraphics{
179 HDC hdc;
180 HWND hwnd;
181 BOOL owndc;
182 BOOL alpha_hdc;
183 GpImage *image;
184 ImageType image_type;
185 SmoothingMode smoothing;
186 CompositingQuality compqual;
187 InterpolationMode interpolation;
188 PixelOffsetMode pixeloffset;
189 CompositingMode compmode;
190 TextRenderingHint texthint;
191 GpUnit unit; /* page unit */
192 REAL scale; /* page scale */
193 REAL xres, yres;
194 GpMatrix worldtrans; /* world transform */
195 BOOL busy; /* hdc handle obtained by GdipGetDC */
196 GpRegion *clip; /* in device coords */
197 UINT textcontrast; /* not used yet. get/set only */
198 struct list containers;
199 GraphicsContainer contid; /* last-issued container ID */
200 INT origin_x, origin_y;
201 /* For giving the caller an HDC when we technically can't: */
202 HBITMAP temp_hbitmap;
203 int temp_hbitmap_width;
204 int temp_hbitmap_height;
205 BYTE *temp_bits;
206 HDC temp_hdc;
209 struct GpBrush{
210 GpBrushType bt;
213 struct GpHatch{
214 GpBrush brush;
215 HatchStyle hatchstyle;
216 ARGB forecol;
217 ARGB backcol;
220 struct GpSolidFill{
221 GpBrush brush;
222 ARGB color;
225 struct GpPathGradient{
226 GpBrush brush;
227 GpPath* path;
228 ARGB centercolor;
229 GpWrapMode wrap;
230 BOOL gamma;
231 GpPointF center;
232 GpPointF focus;
233 REAL* blendfac; /* blend factors */
234 REAL* blendpos; /* blend positions */
235 INT blendcount;
236 ARGB *surroundcolors;
237 INT surroundcolorcount;
238 ARGB* pblendcolor; /* preset blend colors */
239 REAL* pblendpos; /* preset blend positions */
240 INT pblendcount;
241 GpMatrix transform;
244 struct GpLineGradient{
245 GpBrush brush;
246 GpPointF startpoint;
247 GpPointF endpoint;
248 ARGB startcolor;
249 ARGB endcolor;
250 RectF rect;
251 GpWrapMode wrap;
252 BOOL gamma;
253 REAL* blendfac; /* blend factors */
254 REAL* blendpos; /* blend positions */
255 INT blendcount;
256 ARGB* pblendcolor; /* preset blend colors */
257 REAL* pblendpos; /* preset blend positions */
258 INT pblendcount;
261 struct GpTexture{
262 GpBrush brush;
263 GpMatrix transform;
264 GpImage *image;
265 GpImageAttributes *imageattributes;
266 BYTE *bitmap_bits; /* image bits converted to ARGB and run through imageattributes */
269 struct GpPath{
270 GpFillMode fill;
271 GpPathData pathdata;
272 BOOL newfigure; /* whether the next drawing action starts a new figure */
273 INT datalen; /* size of the arrays in pathdata */
276 struct GpPathIterator{
277 GpPathData pathdata;
278 INT subpath_pos; /* for NextSubpath methods */
279 INT marker_pos; /* for NextMarker methods */
280 INT pathtype_pos; /* for NextPathType methods */
283 struct GpCustomLineCap{
284 GpPathData pathdata;
285 BOOL fill; /* TRUE for fill, FALSE for stroke */
286 GpLineCap cap; /* as far as I can tell, this value is ignored */
287 REAL inset; /* how much to adjust the end of the line */
288 GpLineJoin join;
289 REAL scale;
292 struct GpAdustableArrowCap{
293 GpCustomLineCap cap;
296 struct GpImage{
297 IPicture *picture;
298 IWICBitmapDecoder *decoder;
299 ImageType type;
300 GUID format;
301 UINT flags;
302 UINT frame_count, current_frame;
303 ColorPalette *palette;
304 REAL xres, yres;
307 struct GpMetafile{
308 GpImage image;
309 GpRectF bounds;
310 GpUnit unit;
311 MetafileType metafile_type;
312 HENHMETAFILE hemf;
313 int preserve_hemf; /* if true, hemf belongs to the app and should not be deleted */
315 /* recording */
316 HDC record_dc;
317 GpGraphics *record_graphics;
318 BYTE *comment_data;
319 DWORD comment_data_size;
320 DWORD comment_data_length;
322 /* playback */
323 GpGraphics *playback_graphics;
324 HDC playback_dc;
325 GpPointF playback_points[3];
326 GpRectF src_rect;
327 HANDLETABLE *handle_table;
328 int handle_count;
329 GpMatrix *world_transform;
330 GpUnit page_unit;
331 REAL page_scale;
334 struct GpBitmap{
335 GpImage image;
336 INT width;
337 INT height;
338 PixelFormat format;
339 ImageLockMode lockmode;
340 INT numlocks;
341 BYTE *bitmapbits; /* pointer to the buffer we passed in BitmapLockBits */
342 HBITMAP hbitmap;
343 HDC hdc;
344 BYTE *bits; /* actual image bits if this is a DIB */
345 INT stride; /* stride of bits if this is a DIB */
346 BYTE *own_bits; /* image bits that need to be freed with this object */
347 INT lockx, locky; /* X and Y coordinates of the rect when a bitmap is locked for writing. */
348 IWICMetadataReader *metadata_reader; /* NULL if there is no metadata */
349 UINT prop_count;
350 PropertyItem *prop_item; /* cached image properties */
353 struct GpCachedBitmap{
354 GpImage *image;
357 struct color_key{
358 BOOL enabled;
359 ARGB low;
360 ARGB high;
363 struct color_matrix{
364 BOOL enabled;
365 ColorMatrixFlags flags;
366 ColorMatrix colormatrix;
367 ColorMatrix graymatrix;
370 struct color_remap_table{
371 BOOL enabled;
372 INT mapsize;
373 ColorMap *colormap;
376 struct GpImageAttributes{
377 WrapMode wrap;
378 ARGB outside_color;
379 BOOL clamp;
380 struct color_key colorkeys[ColorAdjustTypeCount];
381 struct color_matrix colormatrices[ColorAdjustTypeCount];
382 struct color_remap_table colorremaptables[ColorAdjustTypeCount];
383 BOOL gamma_enabled[ColorAdjustTypeCount];
384 REAL gamma[ColorAdjustTypeCount];
387 struct GpFont{
388 GpFontFamily *family;
389 OUTLINETEXTMETRICW otm;
390 REAL emSize; /* in font units */
391 Unit unit;
394 struct GpStringFormat{
395 INT attr;
396 LANGID lang;
397 LANGID digitlang;
398 StringAlignment align;
399 StringTrimming trimming;
400 HotkeyPrefix hkprefix;
401 StringAlignment vertalign;
402 StringDigitSubstitute digitsub;
403 INT tabcount;
404 REAL firsttab;
405 REAL *tabs;
406 CharacterRange *character_ranges;
407 INT range_count;
408 BOOL generic_typographic;
411 struct GpFontCollection{
412 GpFontFamily **FontFamilies;
413 INT count;
414 INT allocated;
417 struct GpFontFamily{
418 WCHAR FamilyName[LF_FACESIZE];
419 UINT16 em_height, ascent, descent, line_spacing; /* in font units */
420 int dpi;
423 /* internal use */
424 typedef enum RegionType
426 RegionDataRect = 0x10000000,
427 RegionDataPath = 0x10000001,
428 RegionDataEmptyRect = 0x10000002,
429 RegionDataInfiniteRect = 0x10000003,
430 } RegionType;
432 struct region_element
434 DWORD type; /* Rectangle, Path, SpecialRectangle, or CombineMode */
435 union
437 GpRectF rect;
438 GpPath *path;
439 struct
441 struct region_element *left; /* the original region */
442 struct region_element *right; /* what *left was combined with */
443 } combine;
444 } elementdata;
447 struct GpRegion{
448 DWORD num_children;
449 region_element node;
452 typedef GpStatus (*gdip_format_string_callback)(HDC hdc,
453 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
454 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
455 INT lineno, const RectF *bounds, INT *underlined_indexes,
456 INT underlined_index_count, void *user_data);
458 GpStatus gdip_format_string(HDC hdc,
459 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
460 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, int ignore_empty_clip,
461 gdip_format_string_callback callback, void *user_data) DECLSPEC_HIDDEN;
463 void get_log_fontW(const GpFont *, GpGraphics *, LOGFONTW *) DECLSPEC_HIDDEN;
465 #endif