eb139741bab7777be708bae6909f6d4716b1c141
[reactos.git] / sdk / include / psdk / gdiplusheaders.h
1 /*
2 * GdiPlusHeaders.h
3 *
4 * Windows GDI+
5 *
6 * This file is part of the w32api package.
7 *
8 * THIS SOFTWARE IS NOT COPYRIGHTED
9 *
10 * This source code is offered for use in the public domain. You may
11 * use, modify or distribute it freely.
12 *
13 * This code is distributed in the hope that it will be useful but
14 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
15 * DISCLAIMED. This includes but is not limited to warranties of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19 #ifndef _GDIPLUSHEADERS_H
20 #define _GDIPLUSHEADERS_H
21
22 class Image : public GdiplusBase
23 {
24 public:
25 friend class Graphics;
26 friend class TextureBrush;
27
28 Image(IStream *stream, BOOL useEmbeddedColorManagement = FALSE) : nativeImage(NULL)
29 {
30 if (useEmbeddedColorManagement)
31 lastStatus = DllExports::GdipLoadImageFromStreamICM(stream, &nativeImage);
32 else
33 lastStatus = DllExports::GdipLoadImageFromStream(stream, &nativeImage);
34 }
35
36 Image(const WCHAR *filename, BOOL useEmbeddedColorManagement = FALSE) : nativeImage(NULL)
37 {
38 if (useEmbeddedColorManagement)
39 lastStatus = DllExports::GdipLoadImageFromFileICM(filename, &nativeImage);
40 else
41 lastStatus = DllExports::GdipLoadImageFromFile(filename, &nativeImage);
42 }
43
44 Image *
45 Clone()
46 {
47 GpImage *cloneimage = NULL;
48 SetStatus(DllExports::GdipCloneImage(nativeImage, &cloneimage));
49 return new Image(cloneimage, lastStatus);
50 }
51
52 virtual ~Image()
53 {
54 DllExports::GdipDisposeImage(nativeImage);
55 }
56
57 static Image *
58 FromFile(const WCHAR *filename, BOOL useEmbeddedColorManagement = FALSE)
59 {
60 return new Image(filename, useEmbeddedColorManagement);
61 }
62
63 static Image *
64 FromStream(IStream *stream, BOOL useEmbeddedColorManagement = FALSE)
65 {
66 return new Image(stream, useEmbeddedColorManagement);
67 }
68
69 Status
70 GetAllPropertyItems(UINT totalBufferSize, UINT numProperties, PropertyItem *allItems)
71 {
72 if (allItems == NULL)
73 return SetStatus(InvalidParameter);
74 return SetStatus(DllExports::GdipGetAllPropertyItems(nativeImage, totalBufferSize, numProperties, allItems));
75 }
76
77 Status
78 GetBounds(RectF *srcRect, Unit *srcUnit)
79 {
80 return SetStatus(DllExports::GdipGetImageBounds(nativeImage, srcRect, srcUnit));
81 }
82
83 Status
84 GetEncoderParameterList(const CLSID *clsidEncoder, UINT size, EncoderParameters *buffer)
85 {
86 #if 1
87 // FIXME: Not available yet
88 return SetStatus(NotImplemented);
89 #else
90 return SetStatus(DllExports::GdipGetEncoderParameterList(nativeImage, clsidEncoder, size, buffer));
91 #endif
92 }
93
94 UINT
95 GetEncoderParameterListSize(const CLSID *clsidEncoder)
96 {
97 #if 1
98 // FIXME: Not available yet
99 return SetStatus(NotImplemented);
100 #else
101 UINT size = 0;
102 SetStatus(DllExports::GdipGetEncoderParameterListSize(nativeImage, clsidEncoder, &size));
103 return size;
104 #endif
105 }
106
107 UINT
108 GetFlags()
109 {
110 UINT flags = 0;
111 SetStatus(DllExports::GdipGetImageFlags(nativeImage, &flags));
112 return flags;
113 }
114
115 UINT
116 GetFrameCount(const GUID *dimensionID)
117 {
118 UINT count = 0;
119 SetStatus(DllExports::GdipImageGetFrameCount(nativeImage, dimensionID, &count));
120 return count;
121 }
122
123 UINT
124 GetFrameDimensionsCount()
125 {
126 UINT count = 0;
127 SetStatus(DllExports::GdipImageGetFrameDimensionsCount(nativeImage, &count));
128 return count;
129 }
130
131 Status
132 GetFrameDimensionsList(GUID *dimensionIDs, UINT count)
133 {
134 return SetStatus(DllExports::GdipImageGetFrameDimensionsList(nativeImage, dimensionIDs, count));
135 }
136
137 UINT
138 GetHeight()
139 {
140 UINT height = 0;
141 SetStatus(DllExports::GdipGetImageHeight(nativeImage, &height));
142 return height;
143 }
144
145 REAL
146 GetHorizontalResolution()
147 {
148 REAL resolution = 0.0f;
149 SetStatus(DllExports::GdipGetImageHorizontalResolution(nativeImage, &resolution));
150 return resolution;
151 }
152
153 Status
154 GetLastStatus()
155 {
156 return lastStatus;
157 }
158
159 Status
160 GetPalette(ColorPalette *palette, INT size)
161 {
162 return SetStatus(DllExports::GdipGetImagePalette(nativeImage, palette, size));
163 }
164
165 INT
166 GetPaletteSize()
167 {
168 INT size = 0;
169 SetStatus(DllExports::GdipGetImagePaletteSize(nativeImage, &size));
170 return size;
171 }
172
173 Status
174 GetPhysicalDimension(SizeF *size)
175 {
176 if (size == NULL)
177 return SetStatus(InvalidParameter);
178
179 return SetStatus(DllExports::GdipGetImageDimension(nativeImage, &size->Width, &size->Height));
180 }
181
182 PixelFormat
183 GetPixelFormat()
184 {
185 PixelFormat format;
186 SetStatus(DllExports::GdipGetImagePixelFormat(nativeImage, &format));
187 return format;
188 }
189
190 UINT
191 GetPropertyCount()
192 {
193 UINT numOfProperty = 0;
194 SetStatus(DllExports::GdipGetPropertyCount(nativeImage, &numOfProperty));
195 return numOfProperty;
196 }
197
198 Status
199 GetPropertyIdList(UINT numOfProperty, PROPID *list)
200 {
201 return SetStatus(DllExports::GdipGetPropertyIdList(nativeImage, numOfProperty, list));
202 }
203
204 Status
205 GetPropertyItem(PROPID propId, UINT propSize, PropertyItem *buffer)
206 {
207 return SetStatus(DllExports::GdipGetPropertyItem(nativeImage, propId, propSize, buffer));
208 }
209
210 UINT
211 GetPropertyItemSize(PROPID propId)
212 {
213 UINT size = 0;
214 SetStatus(DllExports::GdipGetPropertyItemSize(nativeImage, propId, &size));
215 return size;
216 }
217
218 Status
219 GetPropertySize(UINT *totalBufferSize, UINT *numProperties)
220 {
221 return SetStatus(DllExports::GdipGetPropertySize(nativeImage, totalBufferSize, numProperties));
222 }
223
224 Status
225 GetRawFormat(GUID *format)
226 {
227 return SetStatus(DllExports::GdipGetImageRawFormat(nativeImage, format));
228 }
229
230 Image *
231 GetThumbnailImage(UINT thumbWidth, UINT thumbHeight, GetThumbnailImageAbort callback, VOID *callbackData)
232 {
233 GpImage *thumbImage = NULL;
234 SetStatus(DllExports::GdipGetImageThumbnail(
235 nativeImage, thumbWidth, thumbHeight, &thumbImage, callback, callbackData));
236 Image *newImage = new Image(thumbImage, lastStatus);
237 if (newImage == NULL)
238 {
239 DllExports::GdipDisposeImage(thumbImage);
240 }
241 return newImage;
242 }
243
244 ImageType
245 GetType()
246 {
247 ImageType type;
248 SetStatus(DllExports::GdipGetImageType(nativeImage, &type));
249 return type;
250 }
251
252 REAL
253 GetVerticalResolution()
254 {
255 REAL resolution = 0.0f;
256 SetStatus(DllExports::GdipGetImageVerticalResolution(nativeImage, &resolution));
257 return resolution;
258 }
259
260 UINT
261 GetWidth()
262 {
263 UINT width = 0;
264 SetStatus(DllExports::GdipGetImageWidth(nativeImage, &width));
265 return width;
266 }
267
268 Status
269 RemovePropertyItem(PROPID propId)
270 {
271 return SetStatus(DllExports::GdipRemovePropertyItem(nativeImage, propId));
272 }
273
274 Status
275 RotateFlip(RotateFlipType rotateFlipType)
276 {
277 return SetStatus(DllExports::GdipImageRotateFlip(nativeImage, rotateFlipType));
278 }
279
280 Status
281 Save(IStream *stream, const CLSID *clsidEncoder, const EncoderParameters *encoderParams)
282 {
283 return SetStatus(DllExports::GdipSaveImageToStream(nativeImage, stream, clsidEncoder, encoderParams));
284 }
285
286 Status
287 Save(const WCHAR *filename, const CLSID *clsidEncoder, const EncoderParameters *encoderParams)
288 {
289 return SetStatus(DllExports::GdipSaveImageToFile(nativeImage, filename, clsidEncoder, encoderParams));
290 }
291
292 Status
293 SaveAdd(const EncoderParameters *encoderParams)
294 {
295 #if 1
296 // FIXME: Not available yet
297 return SetStatus(NotImplemented);
298 #else
299 return SetStatus(DllExports::GdipSaveAdd(nativeImage, encoderParams));
300 #endif
301 }
302
303 Status
304 SaveAdd(Image *newImage, const EncoderParameters *encoderParams)
305 {
306 #if 1
307 // FIXME: Not available yet
308 return SetStatus(NotImplemented);
309 #else
310 if (!newImage)
311 return SetStatus(InvalidParameter);
312
313 return SetStatus(DllExports::GdipSaveAddImage(nativeImage, newImage->nativeImage, encoderParams));
314 #endif
315 }
316
317 Status
318 SelectActiveFrame(const GUID *dimensionID, UINT frameIndex)
319 {
320 return SetStatus(DllExports::GdipImageSelectActiveFrame(nativeImage, dimensionID, frameIndex));
321 }
322
323 Status
324 SetPalette(const ColorPalette *palette)
325 {
326 return SetStatus(DllExports::GdipSetImagePalette(nativeImage, palette));
327 }
328
329 Status
330 SetPropertyItem(const PropertyItem *item)
331 {
332 return SetStatus(DllExports::GdipSetPropertyItem(nativeImage, item));
333 }
334
335 #if 0
336 ImageLayout
337 GetLayout() const
338 {
339 return SetStatus(NotImplemented);
340 }
341
342 Status
343 SetLayout(const ImageLayout layout)
344 {
345 return SetStatus(NotImplemented);
346 }
347 #endif
348
349 protected:
350 GpImage *nativeImage;
351 mutable Status lastStatus;
352
353 Image()
354 {
355 }
356
357 Image(GpImage *image, Status status) : nativeImage(image), lastStatus(status)
358 {
359 }
360
361 Status
362 SetStatus(Status status) const
363 {
364 if (status != Ok)
365 lastStatus = status;
366 return status;
367 }
368
369 void
370 SetNativeImage(GpImage *image)
371 {
372 nativeImage = image;
373 }
374
375 private:
376 // Image is not copyable
377 Image(const Image &);
378 Image &
379 operator=(const Image &);
380 };
381
382 class Bitmap : public Image
383 {
384 friend class CachedBitmap;
385
386 public:
387 // Bitmap(IDirectDrawSurface7 *surface) // <-- FIXME: compiler does not like this
388 // {
389 // lastStatus = DllExports::GdipCreateBitmapFromDirectDrawSurface(surface, &bitmap);
390 // }
391
392 Bitmap(INT width, INT height, Graphics *target)
393 {
394 GpBitmap *bitmap = NULL;
395 lastStatus = DllExports::GdipCreateBitmapFromGraphics(width, height, target ? target->graphics : NULL, &bitmap);
396 SetNativeImage(bitmap);
397 }
398
399 Bitmap(const BITMAPINFO *gdiBitmapInfo, VOID *gdiBitmapData)
400 {
401 GpBitmap *bitmap = NULL;
402 lastStatus = DllExports::GdipCreateBitmapFromGdiDib(gdiBitmapInfo, gdiBitmapData, &bitmap);
403 SetNativeImage(bitmap);
404 }
405
406 Bitmap(INT width, INT height, PixelFormat format)
407 {
408 GpBitmap *bitmap = NULL;
409 lastStatus = DllExports::GdipCreateBitmapFromScan0(width, height, 0, format, NULL, &bitmap);
410 SetNativeImage(bitmap);
411 }
412
413 Bitmap(HBITMAP hbm, HPALETTE hpal)
414 {
415 GpBitmap *bitmap = NULL;
416 lastStatus = DllExports::GdipCreateBitmapFromHBITMAP(hbm, hpal, &bitmap);
417 SetNativeImage(bitmap);
418 }
419
420 Bitmap(INT width, INT height, INT stride, PixelFormat format, BYTE *scan0)
421 {
422 GpBitmap *bitmap = NULL;
423 lastStatus = DllExports::GdipCreateBitmapFromScan0(width, height, stride, format, scan0, &bitmap);
424 SetNativeImage(bitmap);
425 }
426
427 Bitmap(const WCHAR *filename, BOOL useIcm)
428 {
429 GpBitmap *bitmap = NULL;
430
431 if (useIcm)
432 lastStatus = DllExports::GdipCreateBitmapFromFileICM(filename, &bitmap);
433 else
434 lastStatus = DllExports::GdipCreateBitmapFromFile(filename, &bitmap);
435
436 SetNativeImage(bitmap);
437 }
438
439 Bitmap(HINSTANCE hInstance, const WCHAR *bitmapName)
440 {
441 GpBitmap *bitmap = NULL;
442 lastStatus = DllExports::GdipCreateBitmapFromResource(hInstance, bitmapName, &bitmap);
443 SetNativeImage(bitmap);
444 }
445
446 Bitmap(HICON hicon)
447 {
448 GpBitmap *bitmap = NULL;
449 lastStatus = DllExports::GdipCreateBitmapFromHICON(hicon, &bitmap);
450 SetNativeImage(bitmap);
451 }
452
453 Bitmap(IStream *stream, BOOL useIcm)
454 {
455 GpBitmap *bitmap = NULL;
456 if (useIcm)
457 lastStatus = DllExports::GdipCreateBitmapFromStreamICM(stream, &bitmap);
458 else
459 lastStatus = DllExports::GdipCreateBitmapFromStream(stream, &bitmap);
460 SetNativeImage(bitmap);
461 }
462
463 Bitmap *
464 Clone(const Rect &rect, PixelFormat format)
465 {
466 return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
467 }
468
469 Bitmap *
470 Clone(const RectF &rect, PixelFormat format)
471 {
472 return Clone(rect.X, rect.Y, rect.Width, rect.Height, format);
473 }
474
475 Bitmap *
476 Clone(REAL x, REAL y, REAL width, REAL height, PixelFormat format)
477 {
478 GpBitmap *bitmap = NULL;
479 lastStatus = DllExports::GdipCloneBitmapArea(x, y, width, height, format, GetNativeBitmap(), &bitmap);
480
481 if (lastStatus != Ok)
482 return NULL;
483
484 Bitmap *newBitmap = new Bitmap(bitmap);
485 if (newBitmap == NULL)
486 {
487 DllExports::GdipDisposeImage(bitmap);
488 }
489
490 return newBitmap;
491 }
492
493 Bitmap *
494 Clone(INT x, INT y, INT width, INT height, PixelFormat format)
495 {
496 GpBitmap *bitmap = NULL;
497 lastStatus = DllExports::GdipCloneBitmapAreaI(x, y, width, height, format, GetNativeBitmap(), &bitmap);
498
499 if (lastStatus != Ok)
500 return NULL;
501
502 Bitmap *newBitmap = new Bitmap(bitmap);
503 if (newBitmap == NULL)
504 {
505 DllExports::GdipDisposeImage(bitmap);
506 }
507
508 return newBitmap;
509 }
510
511 static Bitmap *
512 FromBITMAPINFO(const BITMAPINFO *gdiBitmapInfo, VOID *gdiBitmapData)
513 {
514 return new Bitmap(gdiBitmapInfo, gdiBitmapData);
515 }
516
517 // static Bitmap *FromDirectDrawSurface7(IDirectDrawSurface7 *surface) // <-- FIXME: compiler does not like this
518 // {
519 // return new Bitmap(surface);
520 // }
521
522 static Bitmap *
523 FromFile(const WCHAR *filename, BOOL useEmbeddedColorManagement)
524 {
525 return new Bitmap(filename, useEmbeddedColorManagement);
526 }
527
528 static Bitmap *
529 FromHBITMAP(HBITMAP hbm, HPALETTE hpal)
530 {
531 return new Bitmap(hbm, hpal);
532 }
533
534 static Bitmap *
535 FromHICON(HICON hicon)
536 {
537 return new Bitmap(hicon);
538 }
539
540 static Bitmap *
541 FromResource(HINSTANCE hInstance, const WCHAR *bitmapName)
542 {
543 return new Bitmap(hInstance, bitmapName);
544 }
545
546 static Bitmap *
547 FromStream(IStream *stream, BOOL useEmbeddedColorManagement)
548 {
549 return new Bitmap(stream, useEmbeddedColorManagement);
550 }
551
552 Status
553 GetHBITMAP(const Color &colorBackground, HBITMAP *hbmReturn)
554 {
555 return SetStatus(
556 DllExports::GdipCreateHBITMAPFromBitmap(GetNativeBitmap(), hbmReturn, colorBackground.GetValue()));
557 }
558
559 Status
560 GetHICON(HICON *hicon)
561 {
562 return SetStatus(DllExports::GdipCreateHICONFromBitmap(GetNativeBitmap(), hicon));
563 }
564
565 Status
566 GetPixel(INT x, INT y, Color *color)
567 {
568 ARGB argb;
569 Status s = SetStatus(DllExports::GdipBitmapGetPixel(GetNativeBitmap(), x, y, &argb));
570 if (color)
571 color->SetValue(argb);
572 return s;
573 }
574
575 Status
576 LockBits(const Rect *rect, UINT flags, PixelFormat format, BitmapData *lockedBitmapData)
577 {
578 return SetStatus(DllExports::GdipBitmapLockBits(GetNativeBitmap(), rect, flags, format, lockedBitmapData));
579 }
580
581 Status
582 SetPixel(INT x, INT y, const Color &color)
583 {
584 return SetStatus(DllExports::GdipBitmapSetPixel(GetNativeBitmap(), x, y, color.GetValue()));
585 }
586
587 Status
588 SetResolution(REAL xdpi, REAL ydpi)
589 {
590 return SetStatus(DllExports::GdipBitmapSetResolution(GetNativeBitmap(), xdpi, ydpi));
591 }
592
593 Status
594 UnlockBits(BitmapData *lockedBitmapData)
595 {
596 return SetStatus(DllExports::GdipBitmapUnlockBits(GetNativeBitmap(), lockedBitmapData));
597 }
598
599 protected:
600 Bitmap()
601 {
602 }
603
604 Bitmap(GpBitmap *nativeBitmap)
605 {
606 lastStatus = Ok;
607 SetNativeImage(nativeBitmap);
608 }
609
610 GpBitmap *
611 GetNativeBitmap() const
612 {
613 return static_cast<GpBitmap *>(nativeImage);
614 }
615 };
616
617 class CachedBitmap : public GdiplusBase
618 {
619 public:
620 CachedBitmap(Bitmap *bitmap, Graphics *graphics)
621 {
622 nativeCachedBitmap = NULL;
623 lastStatus = DllExports::GdipCreateCachedBitmap(
624 bitmap->GetNativeBitmap(), graphics ? graphics->graphics : NULL, &nativeCachedBitmap);
625 }
626
627 ~CachedBitmap()
628 {
629 DllExports::GdipDeleteCachedBitmap(nativeCachedBitmap);
630 }
631
632 Status
633 GetLastStatus()
634 {
635 return lastStatus;
636 }
637
638 protected:
639 mutable Status lastStatus;
640 GpCachedBitmap *nativeCachedBitmap;
641
642 private:
643 // CachedBitmap is not copyable
644 CachedBitmap(const CachedBitmap &);
645 CachedBitmap &
646 operator=(const CachedBitmap &);
647 };
648
649 class FontCollection : public GdiplusBase
650 {
651 friend class FontFamily;
652
653 public:
654 FontCollection() : nativeFontCollection(NULL), lastStatus(Ok)
655 {
656 }
657
658 virtual ~FontCollection()
659 {
660 }
661
662 Status
663 GetFamilies(INT numSought, FontFamily *gpfamilies, INT *numFound) const
664 {
665 return SetStatus(NotImplemented);
666 }
667
668 INT
669 GetFamilyCount() const
670 {
671 INT numFound = 0;
672 lastStatus = DllExports::GdipGetFontCollectionFamilyCount(nativeFontCollection, &numFound);
673 return numFound;
674 }
675
676 Status
677 GetLastStatus() const
678 {
679 return lastStatus;
680 }
681
682 protected:
683 GpFontCollection *nativeFontCollection;
684 mutable Status lastStatus;
685
686 Status
687 SetStatus(Status status) const
688 {
689 if (status != Ok)
690 lastStatus = status;
691 return status;
692 }
693
694 private:
695 // FontCollection is not copyable
696 FontCollection(const FontCollection &);
697 FontCollection &
698 operator=(const FontCollection &);
699 };
700
701 class FontFamily : public GdiplusBase
702 {
703 friend class Font;
704
705 public:
706 FontFamily()
707 {
708 }
709
710 FontFamily(const WCHAR *name, const FontCollection *fontCollection)
711 {
712 GpFontCollection *theCollection = fontCollection ? fontCollection->nativeFontCollection : NULL;
713 status = DllExports::GdipCreateFontFamilyFromName(name, theCollection, &fontFamily);
714 }
715
716 FontFamily *
717 Clone()
718 {
719 return NULL;
720 }
721
722 static const FontFamily *
723 GenericMonospace()
724 {
725 FontFamily *genericMonospace = new FontFamily();
726 genericMonospace->status =
727 DllExports::GdipGetGenericFontFamilyMonospace(genericMonospace ? &genericMonospace->fontFamily : NULL);
728 return genericMonospace;
729 }
730
731 static const FontFamily *
732 GenericSansSerif()
733 {
734 FontFamily *genericSansSerif = new FontFamily();
735 genericSansSerif->status =
736 DllExports::GdipGetGenericFontFamilySansSerif(genericSansSerif ? &genericSansSerif->fontFamily : NULL);
737 return genericSansSerif;
738 }
739
740 static const FontFamily *
741 GenericSerif()
742 {
743 FontFamily *genericSerif = new FontFamily();
744 genericSerif->status =
745 DllExports::GdipGetGenericFontFamilyMonospace(genericSerif ? &genericSerif->fontFamily : NULL);
746 return genericSerif;
747 }
748
749 UINT16
750 GetCellAscent(INT style) const
751 {
752 UINT16 CellAscent;
753 SetStatus(DllExports::GdipGetCellAscent(fontFamily, style, &CellAscent));
754 return CellAscent;
755 }
756
757 UINT16
758 GetCellDescent(INT style) const
759 {
760 UINT16 CellDescent;
761 SetStatus(DllExports::GdipGetCellDescent(fontFamily, style, &CellDescent));
762 return CellDescent;
763 }
764
765 UINT16
766 GetEmHeight(INT style)
767 {
768 UINT16 EmHeight;
769 SetStatus(DllExports::GdipGetEmHeight(fontFamily, style, &EmHeight));
770 return EmHeight;
771 }
772
773 Status
774 GetFamilyName(WCHAR name[LF_FACESIZE], WCHAR language) const
775 {
776 return SetStatus(DllExports::GdipGetFamilyName(fontFamily, name, language));
777 }
778
779 Status
780 GetLastStatus() const
781 {
782 return status;
783 }
784
785 UINT16
786 GetLineSpacing(INT style) const
787 {
788 UINT16 LineSpacing;
789 SetStatus(DllExports::GdipGetLineSpacing(fontFamily, style, &LineSpacing));
790 return LineSpacing;
791 }
792
793 BOOL
794 IsAvailable() const
795 {
796 return FALSE;
797 }
798
799 BOOL
800 IsStyleAvailable(INT style) const
801 {
802 BOOL StyleAvailable;
803 SetStatus(DllExports::GdipIsStyleAvailable(fontFamily, style, &StyleAvailable));
804 return StyleAvailable;
805 }
806
807 private:
808 mutable Status status;
809 GpFontFamily *fontFamily;
810
811 Status
812 SetStatus(Status status) const
813 {
814 if (status == Ok)
815 return status;
816 this->status = status;
817 return status;
818 }
819 };
820
821 class InstalledFontFamily : public FontFamily
822 {
823 public:
824 InstalledFontFamily()
825 {
826 }
827 };
828
829 class PrivateFontCollection : public FontCollection
830 {
831 public:
832 PrivateFontCollection()
833 {
834 nativeFontCollection = NULL;
835 lastStatus = DllExports::GdipNewPrivateFontCollection(&nativeFontCollection);
836 }
837
838 virtual ~PrivateFontCollection()
839 {
840 DllExports::GdipDeletePrivateFontCollection(&nativeFontCollection);
841 }
842
843 Status
844 AddFontFile(const WCHAR *filename)
845 {
846 return SetStatus(DllExports::GdipPrivateAddFontFile(nativeFontCollection, filename));
847 }
848
849 Status
850 AddMemoryFont(const VOID *memory, INT length)
851 {
852 return SetStatus(DllExports::GdipPrivateAddMemoryFont(nativeFontCollection, memory, length));
853 }
854 };
855
856 class Font : public GdiplusBase
857 {
858 public:
859 friend class FontFamily;
860 friend class FontCollection;
861 friend class Graphics;
862
863 Font(const FontFamily *family, REAL emSize, INT style, Unit unit)
864 {
865 status = DllExports::GdipCreateFont(family->fontFamily, emSize, style, unit, &font);
866 }
867
868 Font(HDC hdc, const HFONT hfont)
869 {
870 }
871
872 Font(HDC hdc, const LOGFONTA *logfont)
873 {
874 status = DllExports::GdipCreateFontFromLogfontA(hdc, logfont, &font);
875 }
876
877 Font(HDC hdc, const LOGFONTW *logfont)
878 {
879 status = DllExports::GdipCreateFontFromLogfontW(hdc, logfont, &font);
880 }
881
882 Font(const WCHAR *familyName, REAL emSize, INT style, Unit unit, const FontCollection *fontCollection)
883 {
884 }
885
886 Font(HDC hdc)
887 {
888 status = DllExports::GdipCreateFontFromDC(hdc, &font);
889 }
890
891 Font *
892 Clone() const
893 {
894 Font *cloneFont = new Font();
895 cloneFont->status = DllExports::GdipCloneFont(font, cloneFont ? &cloneFont->font : NULL);
896 return cloneFont;
897 }
898
899 Status
900 GetFamily(FontFamily *family) const
901 {
902 return SetStatus(DllExports::GdipGetFamily(font, family ? &family->fontFamily : NULL));
903 }
904
905 REAL
906 GetHeight(const Graphics *graphics) const
907 {
908 REAL height;
909 SetStatus(DllExports::GdipGetFontHeight(font, graphics ? graphics->graphics : NULL, &height));
910 return height;
911 }
912
913 REAL
914 GetHeight(REAL dpi) const
915 {
916 REAL height;
917 SetStatus(DllExports::GdipGetFontHeightGivenDPI(font, dpi, &height));
918 return height;
919 }
920
921 Status
922 GetLastStatus() const
923 {
924 return status;
925 }
926
927 Status
928 GetLogFontA(const Graphics *g, LOGFONTA *logfontA) const
929 {
930 return SetStatus(DllExports::GdipGetLogFontA(font, g ? g->graphics : NULL, logfontA));
931 }
932
933 Status
934 GetLogFontW(const Graphics *g, LOGFONTW *logfontW) const
935 {
936 return SetStatus(DllExports::GdipGetLogFontW(font, g ? g->graphics : NULL, logfontW));
937 }
938
939 REAL
940 GetSize() const
941 {
942 REAL size;
943 SetStatus(DllExports::GdipGetFontSize(font, &size));
944 return size;
945 }
946
947 INT
948 GetStyle() const
949 {
950 INT style;
951 SetStatus(DllExports::GdipGetFontStyle(font, &style));
952 return style;
953 }
954
955 Unit
956 GetUnit() const
957 {
958 Unit unit;
959 SetStatus(DllExports::GdipGetFontUnit(font, &unit));
960 return unit;
961 }
962
963 BOOL
964 IsAvailable() const
965 {
966 return FALSE;
967 }
968
969 protected:
970 Font()
971 {
972 }
973
974 private:
975 mutable Status status;
976 GpFont *font;
977
978 Status
979 SetStatus(Status status) const
980 {
981 if (status == Ok)
982 return status;
983 this->status = status;
984 return status;
985 }
986 };
987
988 class Region : public GdiplusBase
989 {
990 public:
991 friend class Graphics;
992 friend class GraphicsPath;
993 friend class Matrix;
994
995 Region(const Rect &rect)
996 {
997 status = DllExports::GdipCreateRegionRectI(&rect, &region);
998 }
999
1000 Region()
1001 {
1002 status = DllExports::GdipCreateRegion(&region);
1003 }
1004
1005 Region(const BYTE *regionData, INT size)
1006 {
1007 status = DllExports::GdipCreateRegionRgnData(regionData, size, &region);
1008 }
1009
1010 Region(const GraphicsPath *path)
1011 {
1012 status = DllExports::GdipCreateRegionPath(path->nativePath, &region);
1013 }
1014
1015 Region(HRGN hRgn)
1016 {
1017 status = DllExports::GdipCreateRegionHrgn(hRgn, &region);
1018 }
1019
1020 Region(const RectF &rect)
1021 {
1022 status = DllExports::GdipCreateRegionRect(&rect, &region);
1023 }
1024
1025 Region *
1026 Clone()
1027 {
1028 Region *cloneRegion = new Region();
1029 cloneRegion->status = DllExports::GdipCloneRegion(region, cloneRegion ? &cloneRegion->region : NULL);
1030 return cloneRegion;
1031 }
1032
1033 Status
1034 Complement(const GraphicsPath *path)
1035 {
1036 GpPath *thePath = path ? path->nativePath : NULL;
1037 return SetStatus(DllExports::GdipCombineRegionPath(region, thePath, CombineModeComplement));
1038 }
1039
1040 Status
1041 Complement(const Region *region)
1042 {
1043 GpRegion *theRegion = region ? region->region : NULL;
1044 return SetStatus(DllExports::GdipCombineRegionRegion(this->region, theRegion, CombineModeComplement));
1045 }
1046
1047 Status
1048 Complement(const Rect &rect)
1049 {
1050 return SetStatus(DllExports::GdipCombineRegionRectI(region, &rect, CombineModeComplement));
1051 }
1052
1053 Status
1054 Complement(const RectF &rect)
1055 {
1056 return SetStatus(DllExports::GdipCombineRegionRect(region, &rect, CombineModeComplement));
1057 }
1058
1059 BOOL
1060 Equals(const Region *region, const Graphics *g) const
1061 {
1062 BOOL result;
1063 SetStatus(DllExports::GdipIsEqualRegion(
1064 this->region, region ? region->region : NULL, g ? g->graphics : NULL, &result));
1065 return result;
1066 }
1067
1068 Status
1069 Exclude(const GraphicsPath *path)
1070 {
1071 return SetStatus(DllExports::GdipCombineRegionPath(region, path ? path->nativePath : NULL, CombineModeExclude));
1072 }
1073
1074 Status
1075 Exclude(const RectF &rect)
1076 {
1077 return SetStatus(DllExports::GdipCombineRegionRect(region, &rect, CombineModeExclude));
1078 }
1079
1080 Status
1081 Exclude(const Rect &rect)
1082 {
1083 return SetStatus(DllExports::GdipCombineRegionRectI(region, &rect, CombineModeExclude));
1084 }
1085
1086 Status
1087 Exclude(const Region *region)
1088 {
1089 return SetStatus(
1090 DllExports::GdipCombineRegionRegion(this->region, region ? region->region : NULL, CombineModeExclude));
1091 }
1092
1093 static Region *
1094 FromHRGN(HRGN hRgn)
1095 {
1096 return new Region(hRgn);
1097 }
1098
1099 Status
1100 GetBounds(Rect *rect, const Graphics *g) const
1101 {
1102 return SetStatus(DllExports::GdipGetRegionBoundsI(region, g ? g->graphics : NULL, rect));
1103 }
1104
1105 Status
1106 GetBounds(RectF *rect, const Graphics *g) const
1107 {
1108 return SetStatus(DllExports::GdipGetRegionBounds(region, g ? g->graphics : NULL, rect));
1109 }
1110
1111 Status
1112 GetData(BYTE *buffer, UINT bufferSize, UINT *sizeFilled) const
1113 {
1114 return SetStatus(DllExports::GdipGetRegionData(region, buffer, bufferSize, sizeFilled));
1115 }
1116
1117 UINT
1118 GetDataSize() const
1119 {
1120 UINT bufferSize;
1121 SetStatus(DllExports::GdipGetRegionDataSize(region, &bufferSize));
1122 return bufferSize;
1123 }
1124
1125 HRGN
1126 GetHRGN(const Graphics *g) const
1127 {
1128 HRGN hRgn;
1129 SetStatus(DllExports::GdipGetRegionHRgn(region, g ? g->graphics : NULL, &hRgn));
1130 return hRgn;
1131 }
1132
1133 Status
1134 GetLastStatus()
1135 {
1136 return status;
1137 }
1138
1139 Status
1140 GetRegionScans(const Matrix *matrix, Rect *rects, INT *count) const
1141 {
1142 return SetStatus(DllExports::GdipGetRegionScansI(region, rects, count, matrix ? matrix->nativeMatrix : NULL));
1143 }
1144
1145 Status
1146 GetRegionScans(const Matrix *matrix, RectF *rects, INT *count) const
1147 {
1148 return SetStatus(DllExports::GdipGetRegionScans(region, rects, count, matrix ? matrix->nativeMatrix : NULL));
1149 }
1150
1151 UINT
1152 GetRegionScansCount(const Matrix *matrix) const
1153 {
1154 UINT count;
1155 SetStatus(DllExports::GdipGetRegionScansCount(region, &count, matrix ? matrix->nativeMatrix : NULL));
1156 return count;
1157 }
1158
1159 Status
1160 Intersect(const Rect &rect)
1161 {
1162 return SetStatus(DllExports::GdipCombineRegionRectI(region, &rect, CombineModeIntersect));
1163 }
1164
1165 Status
1166 Intersect(const GraphicsPath *path)
1167 {
1168 GpPath *thePath = path ? path->nativePath : NULL;
1169 return SetStatus(DllExports::GdipCombineRegionPath(region, thePath, CombineModeIntersect));
1170 }
1171
1172 Status
1173 Intersect(const RectF &rect)
1174 {
1175 return SetStatus(DllExports::GdipCombineRegionRect(region, &rect, CombineModeIntersect));
1176 }
1177
1178 Status
1179 Intersect(const Region *region)
1180 {
1181 return SetStatus(
1182 DllExports::GdipCombineRegionRegion(this->region, region ? region->region : NULL, CombineModeIntersect));
1183 }
1184
1185 BOOL
1186 IsEmpty(const Graphics *g) const
1187 {
1188 BOOL result;
1189 SetStatus(DllExports::GdipIsEmptyRegion(region, g ? g->graphics : NULL, &result));
1190 return result;
1191 }
1192
1193 BOOL
1194 IsInfinite(const Graphics *g) const
1195 {
1196 BOOL result;
1197 SetStatus(DllExports::GdipIsInfiniteRegion(region, g ? g->graphics : NULL, &result));
1198 return result;
1199 }
1200
1201 BOOL
1202 IsVisible(const PointF &point, const Graphics *g) const
1203 {
1204 BOOL result;
1205 SetStatus(DllExports::GdipIsVisibleRegionPoint(region, point.X, point.Y, g ? g->graphics : NULL, &result));
1206 return result;
1207 }
1208
1209 BOOL
1210 IsVisible(const RectF &rect, const Graphics *g) const
1211 {
1212 BOOL result;
1213 SetStatus(DllExports::GdipIsVisibleRegionRect(
1214 region, rect.X, rect.Y, rect.Width, rect.Height, g ? g->graphics : NULL, &result));
1215 return result;
1216 }
1217
1218 BOOL
1219 IsVisible(const Rect &rect, const Graphics *g) const
1220 {
1221 BOOL result;
1222 SetStatus(DllExports::GdipIsVisibleRegionRectI(
1223 region, rect.X, rect.Y, rect.Width, rect.Height, g ? g->graphics : NULL, &result));
1224 return result;
1225 }
1226
1227 BOOL
1228 IsVisible(INT x, INT y, const Graphics *g) const
1229 {
1230 BOOL result;
1231 SetStatus(DllExports::GdipIsVisibleRegionPointI(region, x, y, g ? g->graphics : NULL, &result));
1232 return result;
1233 }
1234
1235 BOOL
1236 IsVisible(REAL x, REAL y, const Graphics *g) const
1237 {
1238 BOOL result;
1239 SetStatus(DllExports::GdipIsVisibleRegionPoint(region, x, y, g ? g->graphics : NULL, &result));
1240 return result;
1241 }
1242
1243 BOOL
1244 IsVisible(INT x, INT y, INT width, INT height, const Graphics *g) const
1245 {
1246 BOOL result;
1247 SetStatus(DllExports::GdipIsVisibleRegionRectI(region, x, y, width, height, g ? g->graphics : NULL, &result));
1248 return result;
1249 }
1250
1251 BOOL
1252 IsVisible(const Point &point, const Graphics *g) const
1253 {
1254 BOOL result;
1255 SetStatus(DllExports::GdipIsVisibleRegionPointI(region, point.X, point.Y, g ? g->graphics : NULL, &result));
1256 return result;
1257 }
1258
1259 BOOL
1260 IsVisible(REAL x, REAL y, REAL width, REAL height, const Graphics *g) const
1261 {
1262 BOOL result;
1263 SetStatus(DllExports::GdipIsVisibleRegionRect(region, x, y, width, height, g ? g->graphics : NULL, &result));
1264 return result;
1265 }
1266
1267 Status
1268 MakeEmpty()
1269 {
1270 return SetStatus(DllExports::GdipSetEmpty(region));
1271 }
1272
1273 Status
1274 MakeInfinite()
1275 {
1276 return SetStatus(DllExports::GdipSetInfinite(region));
1277 }
1278
1279 Status
1280 Transform(const Matrix *matrix)
1281 {
1282 return SetStatus(DllExports::GdipTransformRegion(region, matrix ? matrix->nativeMatrix : NULL));
1283 }
1284
1285 Status
1286 Translate(REAL dx, REAL dy)
1287 {
1288 return SetStatus(DllExports::GdipTranslateRegion(region, dx, dy));
1289 }
1290
1291 Status
1292 Translate(INT dx, INT dy)
1293 {
1294 return SetStatus(DllExports::GdipTranslateRegionI(region, dx, dy));
1295 }
1296
1297 Status
1298 Union(const Rect &rect)
1299 {
1300 return SetStatus(DllExports::GdipCombineRegionRectI(region, &rect, CombineModeUnion));
1301 }
1302
1303 Status
1304 Union(const Region *region)
1305 {
1306 return SetStatus(
1307 DllExports::GdipCombineRegionRegion(this->region, region ? region->region : NULL, CombineModeUnion));
1308 }
1309
1310 Status
1311 Union(const RectF &rect)
1312 {
1313 return SetStatus(DllExports::GdipCombineRegionRect(region, &rect, CombineModeUnion));
1314 }
1315
1316 Status
1317 Union(const GraphicsPath *path)
1318 {
1319 return SetStatus(DllExports::GdipCombineRegionPath(region, path ? path->nativePath : NULL, CombineModeUnion));
1320 }
1321
1322 Status
1323 Xor(const GraphicsPath *path)
1324 {
1325 return SetStatus(DllExports::GdipCombineRegionPath(region, path ? path->nativePath : NULL, CombineModeXor));
1326 }
1327
1328 Status
1329 Xor(const RectF &rect)
1330 {
1331 return SetStatus(DllExports::GdipCombineRegionRect(region, &rect, CombineModeXor));
1332 }
1333
1334 Status
1335 Xor(const Rect &rect)
1336 {
1337 return SetStatus(DllExports::GdipCombineRegionRectI(region, &rect, CombineModeXor));
1338 }
1339
1340 Status
1341 Xor(const Region *region)
1342 {
1343 return SetStatus(
1344 DllExports::GdipCombineRegionRegion(this->region, region ? region->region : NULL, CombineModeXor));
1345 }
1346
1347 private:
1348 mutable Status status;
1349 GpRegion *region;
1350
1351 Status
1352 SetStatus(Status status) const
1353 {
1354 if (status == Ok)
1355 return status;
1356 this->status = status;
1357 return status;
1358 }
1359 };
1360
1361 class CustomLineCap : public GdiplusBase
1362 {
1363 public:
1364 CustomLineCap(const GraphicsPath *fillPath, const GraphicsPath *strokePath, LineCap baseCap, REAL baseInset = 0);
1365
1366 ~CustomLineCap();
1367
1368 CustomLineCap *
1369 Clone();
1370
1371 LineCap
1372 GetBaseCap();
1373
1374 REAL
1375 GetBaseInset();
1376
1377 Status
1378 GetLastStatus();
1379
1380 Status
1381 GetStrokeCaps(LineCap *startCap, LineCap *endCap);
1382
1383 LineJoin
1384 GetStrokeJoin();
1385
1386 REAL
1387 GetWidthScale();
1388
1389 Status
1390 SetBaseCap(LineCap baseCap);
1391
1392 Status
1393 SetBaseInset(REAL inset);
1394
1395 Status
1396 SetStrokeCap(LineCap strokeCap);
1397
1398 Status
1399 SetStrokeCaps(LineCap startCap, LineCap endCap);
1400
1401 Status
1402 SetStrokeJoin(LineJoin lineJoin);
1403
1404 Status
1405 SetWidthScale(IN REAL widthScale);
1406
1407 protected:
1408 GpCustomLineCap *nativeCap;
1409 mutable Status lastStatus;
1410
1411 CustomLineCap() : nativeCap(NULL), lastStatus(Ok)
1412 {
1413 }
1414
1415 CustomLineCap(GpCustomLineCap *nativeCap, Status status)
1416 {
1417 lastStatus = status;
1418 SetNativeCap(nativeCap);
1419 }
1420
1421 void
1422 SetNativeCap(GpCustomLineCap *cap)
1423 {
1424 nativeCap = cap;
1425 }
1426
1427 Status
1428 SetStatus(Status status) const
1429 {
1430 if (status == Ok)
1431 lastStatus = status;
1432 return status;
1433 }
1434
1435 private:
1436 // CustomLineCap is not copyable
1437 CustomLineCap(const CustomLineCap &);
1438 CustomLineCap &
1439 operator=(const CustomLineCap &);
1440 };
1441
1442 inline TextureBrush::TextureBrush(Image *image, WrapMode wrapMode, const RectF &dstRect)
1443 {
1444 GpTexture *texture = NULL;
1445 lastStatus = DllExports::GdipCreateTexture2(
1446 image->nativeImage, wrapMode, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, &texture);
1447 SetNativeBrush(texture);
1448 }
1449
1450 inline TextureBrush::TextureBrush(Image *image, Rect &dstRect, ImageAttributes *imageAttributes)
1451 {
1452 GpTexture *texture = NULL;
1453 GpImageAttributes *attrs = imageAttributes ? imageAttributes->nativeImageAttr : NULL;
1454 lastStatus = DllExports::GdipCreateTextureIA(
1455 image->nativeImage, attrs, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, &texture);
1456 SetNativeBrush(texture);
1457 }
1458
1459 inline TextureBrush::TextureBrush(Image *image, WrapMode wrapMode, INT dstX, INT dstY, INT dstWidth, INT dstHeight)
1460 {
1461 GpTexture *texture = NULL;
1462 lastStatus =
1463 DllExports::GdipCreateTexture2I(image->nativeImage, wrapMode, dstX, dstY, dstWidth, dstHeight, &texture);
1464 SetNativeBrush(texture);
1465 }
1466
1467 inline TextureBrush::TextureBrush(Image *image, WrapMode wrapMode, REAL dstX, REAL dstY, REAL dstWidth, REAL dstHeight)
1468 {
1469 GpTexture *texture = NULL;
1470 lastStatus =
1471 DllExports::GdipCreateTexture2(image->nativeImage, wrapMode, dstX, dstY, dstWidth, dstHeight, &texture);
1472 SetNativeBrush(texture);
1473 }
1474
1475 inline TextureBrush::TextureBrush(Image *image, RectF &dstRect, ImageAttributes *imageAttributes)
1476 {
1477 GpTexture *texture = NULL;
1478 GpImageAttributes *attrs = imageAttributes ? imageAttributes->nativeImageAttr : NULL;
1479 lastStatus = DllExports::GdipCreateTextureIA(
1480 image->nativeImage, attrs, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, &texture);
1481 SetNativeBrush(texture);
1482 }
1483
1484 inline TextureBrush::TextureBrush(Image *image, WrapMode wrapMode)
1485 {
1486 GpTexture *texture = NULL;
1487 lastStatus = DllExports::GdipCreateTexture(image->nativeImage, wrapMode, &texture);
1488 SetNativeBrush(texture);
1489 }
1490
1491 inline TextureBrush::TextureBrush(Image *image, WrapMode wrapMode, const Rect &dstRect)
1492 {
1493 GpTexture *texture = NULL;
1494 lastStatus = DllExports::GdipCreateTexture2I(
1495 image->nativeImage, wrapMode, dstRect.X, dstRect.Y, dstRect.Width, dstRect.Height, &texture);
1496 SetNativeBrush(texture);
1497 }
1498
1499 inline Image *
1500 TextureBrush::GetImage() const
1501 {
1502 #if 1
1503 return NULL; // FIXME
1504 #else
1505 GpImage *image = NULL;
1506 GpTexture *texture = GetNativeTexture();
1507 SetStatus(DllExports::GdipGetTextureImage(texture, &image));
1508 if (lastStatus != Ok)
1509 return NULL;
1510
1511 Image *newImage = new Image(image, lastStatus);
1512 if (!newImage)
1513 DllExports::GdipDisposeImage(image);
1514 return newImage;
1515 #endif
1516 }
1517
1518 #endif /* _GDIPLUSHEADERS_H */