gdiplusimpl.h 42 KB

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