Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1854 lines
48 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * Graphics.hpp
  8. *
  9. * Abstract:
  10. *
  11. * Declarations for Graphics class
  12. *
  13. * Revision History:
  14. *
  15. * 12/04/1998 davidx
  16. * Created it.
  17. *
  18. \**************************************************************************/
  19. #ifndef _GRAPHICS_HPP
  20. #define _GRAPHICS_HPP
  21. #include "printer.hpp"
  22. #define GDIP_NOOP_ROP3 0x00AA0029 // do-nothing ROP
  23. // definitions copied from winddi.h :
  24. #ifndef _WINDDI_
  25. DECLARE_HANDLE(HSURF);
  26. DECLARE_HANDLE(DHSURF);
  27. DECLARE_HANDLE(DHPDEV);
  28. typedef struct _SURFOBJ
  29. {
  30. DHSURF dhsurf;
  31. HSURF hsurf;
  32. DHPDEV dhpdev;
  33. HDEV hdev;
  34. SIZEL sizlBitmap;
  35. ULONG cjBits;
  36. PVOID pvBits;
  37. PVOID pvScan0;
  38. LONG lDelta;
  39. ULONG iUniq;
  40. ULONG iBitmapFormat;
  41. USHORT iType;
  42. USHORT fjBitmap;
  43. } SURFOBJ;
  44. #endif
  45. // Forward declaration of the GpCachedBitmap class.
  46. class GpCachedBitmap;
  47. class CopyOnWriteBitmap;
  48. /**
  49. * Represent a graphics context
  50. */
  51. class GpGraphics
  52. {
  53. friend class GpBitmap;
  54. friend class CopyOnWriteBitmap;
  55. friend class GpMetafile;
  56. friend class MetafilePlayer;
  57. friend class HdcLock;
  58. friend class DriverUni;
  59. friend class MetafileRecorder;
  60. friend class DriverStringImager;
  61. friend class FullTextImager;
  62. friend class FastTextImager;
  63. friend class GpCachedBitmap;
  64. private:
  65. // We now use an ObjectTag to determine if the object is valid
  66. // instead of using a BOOL. This is much more robust and helps
  67. // with debugging. It also enables us to version our objects
  68. // more easily with a version number in the ObjectTag.
  69. ObjectTag Tag; // Keep this as the 1st value in the object!
  70. protected:
  71. VOID SetValid(BOOL valid)
  72. {
  73. Tag = valid ? ObjectTagGraphics : ObjectTagInvalid;
  74. }
  75. // This method is here so that we have a virtual function table so
  76. // that we can add virtual methods in V2 without shifting the position
  77. // of the Tag value within the data structure.
  78. virtual VOID DontCallThis()
  79. {
  80. DontCallThis();
  81. }
  82. public:
  83. LONG LockedByGetDC; // Used by GdipGetDC and GdipReleaseDC
  84. protected:
  85. static GpGraphics*
  86. GetForMetafile(
  87. IMetafileRecord * metafile,
  88. EmfType type,
  89. HDC hdc
  90. );
  91. // used by the MetafileRecorder in the EndRecording method
  92. VOID NoOpPatBlt(
  93. INT left,
  94. INT top,
  95. INT width,
  96. INT height
  97. )
  98. {
  99. // Get the devlock because the surface will be flushed when we get the
  100. // HDC
  101. Devlock devlock(Device);
  102. // Get the HDC in the correct state
  103. HDC hdc = Context->GetHdc(Surface);
  104. if (hdc != NULL)
  105. {
  106. ::PatBlt(hdc, left, top, width, height, GDIP_NOOP_ROP3);
  107. Context->ReleaseHdc(hdc);
  108. }
  109. // Now Reset the HDC so that this happens before the
  110. // EndOfFile record (which has to be the last record before the
  111. // EMF's EOF record).
  112. Context->ResetHdc();
  113. }
  114. // If we should send rects to the driver instead of a path
  115. BOOL UseDriverRects() const
  116. {
  117. return (Context->WorldToDevice.IsTranslateScale() &&
  118. ((!Context->AntiAliasMode) || DownLevel));
  119. }
  120. public:
  121. // Get a graphics context from an existing Win32 HDC or HWND
  122. static GpGraphics* GetFromHdc(HDC hdc, HANDLE hDevice = NULL);
  123. // Default behaviour is to ignore ICM mode.
  124. static GpGraphics* GetFromHwnd(
  125. HWND hwnd,
  126. HdcIcmMode icmMode = IcmModeOff
  127. );
  128. ~GpGraphics();
  129. // Internal use only
  130. static GpGraphics* GetFromHdcSurf(HDC hdc,
  131. SURFOBJ* surfObj,
  132. RECTL* bandClip);
  133. static GpGraphics* GetFromGdiScreenDC(HDC hdc);
  134. // Get the lock object
  135. GpLockable *GetObjectLock() const
  136. {
  137. return &Lockable;
  138. }
  139. // Check to see if the object is valid
  140. BOOL IsValid() const
  141. {
  142. #ifdef _X86_
  143. // We have to guarantee that the Tag field doesn't move for
  144. // versioning to work between releases of GDI+.
  145. ASSERT(offsetof(GpGraphics, Tag) == 4);
  146. #endif
  147. ASSERT((Tag == ObjectTagGraphics) || (Tag == ObjectTagInvalid));
  148. #if DBG
  149. if (Tag == ObjectTagInvalid)
  150. {
  151. WARNING1("Invalid Graphics");
  152. }
  153. #endif
  154. return (Tag == ObjectTagGraphics);
  155. }
  156. // Derive a win32 HDC from the graphics context
  157. HDC GetHdc();
  158. VOID ReleaseHdc(HDC hdc);
  159. // Flush any pending rendering
  160. VOID Flush(GpFlushIntention intention)
  161. {
  162. Devlock devlock(Device);
  163. DrvFlush(intention);
  164. }
  165. //------------------------------------------------------------------------
  166. // Manipulate the current world transform
  167. //------------------------------------------------------------------------
  168. GpStatus SetWorldTransform(const GpMatrix& matrix);
  169. GpStatus ResetWorldTransform();
  170. GpStatus MultiplyWorldTransform(const GpMatrix& matrix,
  171. GpMatrixOrder order = MatrixOrderPrepend);
  172. GpStatus TranslateWorldTransform(REAL dx, REAL dy,
  173. GpMatrixOrder order = MatrixOrderPrepend);
  174. GpStatus ScaleWorldTransform(REAL sx, REAL sy,
  175. GpMatrixOrder order = MatrixOrderPrepend);
  176. GpStatus RotateWorldTransform(REAL angle,
  177. GpMatrixOrder order = MatrixOrderPrepend);
  178. VOID GetWorldTransform(GpMatrix & matrix) const
  179. {
  180. matrix = Context->WorldToPage;
  181. }
  182. GpStatus GetDeviceToWorldTransform(GpMatrix * matrix) const;
  183. VOID GetWorldToDeviceTransform(GpMatrix * matrix) const
  184. {
  185. *matrix = Context->WorldToDevice;
  186. }
  187. VOID GetWorldToDeviceTransform(REAL * m) const
  188. {
  189. Context->WorldToDevice.GetMatrix(m);
  190. }
  191. VOID GetWorldPixelSize(REAL & xSize, REAL & ySize);
  192. // Manipulate the current page transform
  193. // !! *PageTransform's to be phased out...
  194. GpStatus SetPageTransform(GpPageUnit unit, REAL scale = 1);
  195. GpStatus ResetPageTransform()
  196. {
  197. return SetPageTransform(UnitDisplay);
  198. }
  199. GpPageUnit GetPageUnit() const { return Context->PageUnit; }
  200. REAL GetPageScale() const { return Context->PageScale; }
  201. GpStatus SetPageUnit(GpPageUnit unit)
  202. {
  203. return SetPageTransform(unit, GetPageScale());
  204. }
  205. GpStatus SetPageScale(REAL scale)
  206. {
  207. return SetPageTransform(GetPageUnit(), scale);
  208. }
  209. GpStatus TransformPoints(
  210. GpPointF * points,
  211. INT count,
  212. GpCoordinateSpace source = CoordinateSpaceWorld,
  213. GpCoordinateSpace dest = CoordinateSpaceDevice
  214. );
  215. /// GetScaleForAlternatePageUnit
  216. //
  217. // Return world unit scale factor corresponding to the difference
  218. // between the page units selected in the graphics and a unit specified
  219. // to an API such as pen thickness or font height.
  220. //
  221. // The returned vector provides the amount by which to multiply world
  222. // x and y coordinates so that they will behave according to the
  223. // alternate unit when passed through Context.WorldToDevice.
  224. REAL GetScaleForAlternatePageUnit(Unit unit) const
  225. {
  226. // pen width and font height must not use UnitDisplay because
  227. // it is a device dependent unit.
  228. ASSERT(unit != UnitDisplay);
  229. // The x:Y aspect ratio of the device resolution doesn't matter here,
  230. // we get exactly the same values whether we use DpiX/PageMultiplierX
  231. // or DpiY/PageMiltiplierY.
  232. switch (unit)
  233. {
  234. case UnitDocument:
  235. return ((GetDpiX()/300.0f) / Context->PageMultiplierX);
  236. case UnitPoint:
  237. return ((GetDpiX()/72.0f) / Context->PageMultiplierX);
  238. case UnitMillimeter:
  239. return ((GetDpiX()/25.4f) / Context->PageMultiplierX);
  240. case UnitInch:
  241. return (GetDpiX() / Context->PageMultiplierX);
  242. case UnitWorld:
  243. case UnitPixel:
  244. default:
  245. return 1.0f;
  246. }
  247. }
  248. // Clipping related methods
  249. GpStatus SetClip(GpGraphics* g, CombineMode combineMode);
  250. GpStatus SetClip(const GpRectF& rect, CombineMode combineMode);
  251. GpStatus SetClip(GpPath* path, CombineMode combineMode,
  252. BOOL isDevicePath = FALSE);
  253. GpStatus SetClip(GpRegion* region, CombineMode combineMode);
  254. GpStatus SetClip(HRGN hRgn, CombineMode combineMode);
  255. GpStatus ResetClip();
  256. GpStatus OffsetClip(REAL dx, REAL dy);
  257. GpRegion* GetClip() const;
  258. GpStatus GetClip(GpRegion* region) const;
  259. // save and restore graphics state
  260. INT Save();
  261. VOID Restore(INT gstate);
  262. // start and end container drawing
  263. INT
  264. BeginContainer(
  265. const GpRectF & destRect,
  266. const GpRectF & srcRect,
  267. GpPageUnit srcUnit,
  268. REAL srcDpiX = 0.0f, // for metafile playback only
  269. REAL srcDpiY = 0.0f,
  270. BOOL srcIsDisplay = TRUE // for metafile playback only
  271. );
  272. INT BeginContainer(
  273. // all these params are only applicable for metafile playback
  274. BOOL forceIdentityTransform = FALSE,
  275. REAL srcDpiX = 0.0f,
  276. REAL srcDpiY = 0.0f,
  277. BOOL srcIsDisplay = TRUE
  278. );
  279. VOID EndContainer(INT containerState);
  280. // Hit testing operations
  281. VOID GetClipBounds(GpRectF& rect) const;
  282. BOOL IsClipEmpty() const;
  283. VOID GetVisibleClipBounds(GpRectF& rect) const;
  284. BOOL IsVisibleClipEmpty() const;
  285. GpRegion* GetVisibleClip() const;
  286. HRGN GetVisibleClipHRgn() const
  287. {
  288. return Context->VisibleClip.GetHRgn();
  289. }
  290. BOOL IsVisible(const GpPointF& point) const;
  291. BOOL IsVisible(const GpRectF& rect) const;
  292. GpStatus GetPixelColor(REAL x, REAL y, ARGB* argb) const;
  293. // Set antialiasing mode
  294. VOID SetAntiAliasMode( BOOL newMode )
  295. {
  296. ASSERT(Context);
  297. // for Printer DC never set AA
  298. if (IsPrinter())
  299. {
  300. Context->AntiAliasMode = FALSE;
  301. return;
  302. }
  303. if (IsRecording() && (newMode != Context->AntiAliasMode))
  304. {
  305. Metafile->RecordSetAntiAliasMode(newMode);
  306. }
  307. Context->AntiAliasMode = newMode;
  308. }
  309. BOOL GetAntiAliasMode() const
  310. {
  311. ASSERT(Context);
  312. return(Context->AntiAliasMode);
  313. }
  314. // Set antialiasing text
  315. VOID SetTextRenderingHint( TextRenderingHint newMode)
  316. {
  317. ASSERT(Context);
  318. // for Printer DC never set AA or Clear Type text
  319. if (IsPrinter())
  320. {
  321. Context->TextRenderHint = TextRenderingHintSingleBitPerPixelGridFit;
  322. return;
  323. }
  324. if (IsRecording() && (newMode != Context->TextRenderHint))
  325. {
  326. Metafile->RecordSetTextRenderingHint(newMode);
  327. }
  328. Context->TextRenderHint = newMode;
  329. }
  330. TextRenderingHint GetTextRenderingHint() const
  331. {
  332. ASSERT(Context);
  333. return(Context->TextRenderHint);
  334. }
  335. // this procedure is meant to be used by internal text routines
  336. // and will return real text rendering hint (not TextRenderingHintSystemDefault)
  337. // we should always call CalculateTextRenderingHintInternal() before
  338. // calling GetTextRenderingHintInternal()
  339. TextRenderingHint GetTextRenderingHintInternal() const
  340. {
  341. return TextRenderingHintInternal;
  342. }
  343. Status SetTextContrast(UINT contrast)
  344. {
  345. ASSERT(Context);
  346. if (contrast > MAX_TEXT_CONTRAST_VALUE)
  347. return InvalidParameter;
  348. // for Printer DC never set AA or Clear Type text
  349. if (IsPrinter())
  350. {
  351. Context->TextContrast = 0;
  352. return Ok;
  353. }
  354. if (IsRecording() && (contrast != Context->TextContrast))
  355. {
  356. Metafile->RecordSetTextContrast(contrast);
  357. }
  358. Context->TextContrast = contrast;
  359. return Ok;
  360. }
  361. UINT GetTextContrast() const
  362. {
  363. ASSERT(Context);
  364. return Context->TextContrast;
  365. }
  366. // Rendering Origin
  367. // This is the origin used for Dither and Halftone matrix origins
  368. // and should be used for any raster operations that need an origin.
  369. VOID SetRenderingOrigin(INT x, INT y)
  370. {
  371. ASSERT(Context);
  372. if (IsRecording() &&
  373. (x != Context->RenderingOriginX ||
  374. y != Context->RenderingOriginY)
  375. )
  376. {
  377. Metafile->RecordSetRenderingOrigin(x, y);
  378. }
  379. Context->RenderingOriginX = x;
  380. Context->RenderingOriginY = y;
  381. }
  382. // Rendering Origin
  383. // Returns the origin used for the Dither and Halftone matrix origin.
  384. VOID GetRenderingOrigin(INT *x, INT *y) const
  385. {
  386. ASSERT(Context);
  387. ASSERT(x);
  388. ASSERT(y);
  389. *x = Context->RenderingOriginX;
  390. *y = Context->RenderingOriginY;
  391. }
  392. // Compositing mode
  393. VOID SetCompositingMode( GpCompositingMode newMode )
  394. {
  395. ASSERT(Context);
  396. if (IsRecording() && (newMode != Context->CompositingMode))
  397. {
  398. Metafile->RecordSetCompositingMode(newMode);
  399. }
  400. Context->CompositingMode = newMode;
  401. }
  402. GpCompositingMode GetCompositingMode() const
  403. {
  404. ASSERT(Context);
  405. return(Context->CompositingMode);
  406. }
  407. // Compositing quality
  408. VOID SetCompositingQuality( GpCompositingQuality newQuality )
  409. {
  410. ASSERT(Context);
  411. if (IsRecording() && (newQuality != Context->CompositingQuality))
  412. {
  413. Metafile->RecordSetCompositingQuality(newQuality);
  414. }
  415. Context->CompositingQuality = newQuality;
  416. }
  417. GpCompositingQuality GetCompositingQuality() const
  418. {
  419. ASSERT(Context);
  420. return(Context->CompositingQuality);
  421. }
  422. VOID SetInterpolationMode(InterpolationMode newMode)
  423. {
  424. ASSERT(Context);
  425. if (IsRecording() && (newMode != Context->FilterType))
  426. {
  427. Metafile->RecordSetInterpolationMode(newMode);
  428. }
  429. Context->FilterType = newMode;
  430. }
  431. InterpolationMode GetInterpolationMode() const
  432. {
  433. ASSERT(Context);
  434. return Context->FilterType;
  435. }
  436. VOID SetPixelOffsetMode(PixelOffsetMode newMode)
  437. {
  438. ASSERT(Context);
  439. if (newMode != Context->PixelOffset)
  440. {
  441. if (IsRecording())
  442. {
  443. Metafile->RecordSetPixelOffsetMode(newMode);
  444. }
  445. Context->PixelOffset = newMode;
  446. Context->InverseOk = FALSE;
  447. Context->UpdateWorldToDeviceMatrix();
  448. }
  449. }
  450. PixelOffsetMode GetPixelOffsetMode() const
  451. {
  452. ASSERT(Context);
  453. return Context->PixelOffset;
  454. }
  455. //------------------------------------------------------------------------
  456. // GetNearestColor (for <= 8bpp surfaces)
  457. //------------------------------------------------------------------------
  458. ARGB
  459. GetNearestColor(
  460. ARGB argb
  461. );
  462. //------------------------------------------------------------------------
  463. // Stroke vector shapes
  464. //------------------------------------------------------------------------
  465. GpStatus
  466. DrawLine(
  467. GpPen* pen,
  468. const GpPointF& pt1,
  469. const GpPointF& pt2
  470. )
  471. {
  472. GpPointF points[2];
  473. points[0] = pt1;
  474. points[1] = pt2;
  475. return(DrawLines(pen, &points[0], 2));
  476. }
  477. GpStatus
  478. DrawLine(
  479. GpPen* pen,
  480. REAL x1,
  481. REAL y1,
  482. REAL x2,
  483. REAL y2
  484. )
  485. {
  486. GpPointF points[2];
  487. points[0].X = x1;
  488. points[0].Y = y1;
  489. points[1].X = x2;
  490. points[1].Y = y2;
  491. return(DrawLines(pen, &points[0], 2));
  492. }
  493. GpStatus
  494. DrawLines(
  495. GpPen* pen,
  496. const GpPointF* points,
  497. INT count,
  498. BOOL closed = FALSE
  499. );
  500. GpStatus
  501. DrawArc(
  502. GpPen* pen,
  503. const GpRectF& rect,
  504. REAL startAngle,
  505. REAL sweepAngle
  506. );
  507. GpStatus
  508. DrawArc(
  509. GpPen* pen,
  510. REAL x,
  511. REAL y,
  512. REAL width,
  513. REAL height,
  514. REAL startAngle,
  515. REAL sweepAngle
  516. )
  517. {
  518. GpRectF rect(x, y, width, height);
  519. return DrawArc(pen, rect, startAngle, sweepAngle);
  520. }
  521. GpStatus
  522. DrawBezier(
  523. GpPen* pen,
  524. const GpPointF& pt1,
  525. const GpPointF& pt2,
  526. const GpPointF& pt3,
  527. const GpPointF& pt4
  528. )
  529. {
  530. GpPointF points[4];
  531. points[0] = pt1;
  532. points[1] = pt2;
  533. points[2] = pt3;
  534. points[3] = pt4;
  535. return DrawBeziers(pen, points, 4);
  536. }
  537. GpStatus
  538. DrawBezier(
  539. GpPen* pen,
  540. REAL x1, REAL y1,
  541. REAL x2, REAL y2,
  542. REAL x3, REAL y3,
  543. REAL x4, REAL y4
  544. )
  545. {
  546. GpPointF points[4];
  547. points[0].X = x1;
  548. points[0].Y = y1;
  549. points[1].X = x2;
  550. points[1].Y = y2;
  551. points[2].X = x3;
  552. points[2].Y = y3;
  553. points[3].X = x4;
  554. points[3].Y = y4;
  555. return DrawBeziers(pen, points, 4);
  556. }
  557. GpStatus
  558. DrawBeziers(
  559. GpPen* pen,
  560. const GpPointF* points,
  561. INT count
  562. );
  563. GpStatus
  564. DrawRect(
  565. GpPen* pen,
  566. const GpRectF& rect
  567. )
  568. {
  569. return(DrawRects(pen, &rect, 1));
  570. }
  571. GpStatus
  572. DrawRect(
  573. GpPen* pen,
  574. REAL x,
  575. REAL y,
  576. REAL width,
  577. REAL height
  578. )
  579. {
  580. GpRectF rect(x, y, width, height);
  581. return(DrawRects(pen, &rect, 1));
  582. }
  583. GpStatus
  584. DrawRects(
  585. GpPen* pen,
  586. const GpRectF* rects,
  587. INT count
  588. );
  589. GpStatus
  590. DrawEllipse(
  591. GpPen* pen,
  592. const GpRectF& rect
  593. );
  594. GpStatus
  595. DrawEllipse(
  596. GpPen* pen,
  597. REAL x,
  598. REAL y,
  599. REAL width,
  600. REAL height
  601. )
  602. {
  603. GpRectF rect(x, y, width, height);
  604. return DrawEllipse(pen, rect);
  605. }
  606. GpStatus
  607. DrawPie(
  608. GpPen* pen,
  609. const GpRectF& rect,
  610. REAL startAngle,
  611. REAL sweepAngle
  612. );
  613. GpStatus
  614. DrawPie(
  615. GpPen* pen,
  616. REAL x,
  617. REAL y,
  618. REAL width,
  619. REAL height,
  620. REAL startAngle,
  621. REAL sweepAngle
  622. )
  623. {
  624. GpRectF rect(x, y, width, height);
  625. return DrawPie(pen, rect, startAngle, sweepAngle);
  626. }
  627. GpStatus
  628. DrawPolygon(
  629. GpPen* pen,
  630. const GpPointF* points,
  631. INT count
  632. )
  633. {
  634. return(DrawLines(pen, points, count, TRUE));
  635. }
  636. GpStatus
  637. DrawPath(
  638. GpPen* pen,
  639. GpPath* path
  640. );
  641. GpStatus
  642. DrawPathData(
  643. GpPen* pen,
  644. const GpPointF* points,
  645. const BYTE *types,
  646. INT count,
  647. GpFillMode fillMode
  648. )
  649. {
  650. GpStatus status = GenericError;
  651. GpPath path(points, types, count, fillMode);
  652. if(path.IsValid())
  653. status = DrawPath(pen, &path);
  654. return status;
  655. }
  656. GpStatus
  657. DrawCurve(
  658. GpPen* pen,
  659. const GpPointF* points,
  660. INT count
  661. );
  662. GpStatus
  663. DrawCurve(
  664. GpPen* pen,
  665. const GpPointF* points,
  666. INT count,
  667. REAL tension,
  668. INT offset,
  669. INT numberOfSegments
  670. );
  671. GpStatus
  672. DrawClosedCurve(
  673. GpPen* pen,
  674. const GpPointF* points,
  675. INT count
  676. );
  677. GpStatus
  678. DrawClosedCurve(
  679. GpPen* pen,
  680. const GpPointF* points,
  681. INT count,
  682. REAL tension
  683. );
  684. //------------------------------------------------------------------------
  685. // Fill shapes
  686. //------------------------------------------------------------------------
  687. GpStatus
  688. Clear(
  689. const GpColor &color
  690. );
  691. GpStatus
  692. FillRect(
  693. GpBrush* brush,
  694. const GpRectF& rect
  695. )
  696. {
  697. return(FillRects(brush, &rect, 1));
  698. }
  699. GpStatus
  700. FillRect(
  701. GpBrush* brush,
  702. REAL x,
  703. REAL y,
  704. REAL width,
  705. REAL height
  706. )
  707. {
  708. GpRectF rect(x, y, width, height);
  709. return(FillRects(brush, &rect, 1));
  710. }
  711. GpStatus
  712. FillRects(
  713. GpBrush* brush,
  714. const GpRectF* rects,
  715. INT count
  716. );
  717. GpStatus
  718. FillPolygon(
  719. GpBrush* brush,
  720. const GpPointF* points,
  721. INT count
  722. )
  723. {
  724. return FillPolygon(brush, points, count, FillModeAlternate);
  725. }
  726. GpStatus
  727. FillPolygon(
  728. GpBrush* brush,
  729. const GpPointF* points,
  730. INT count,
  731. GpFillMode fillMode
  732. );
  733. GpStatus
  734. FillEllipse(
  735. GpBrush* brush,
  736. const GpRectF& rect
  737. );
  738. GpStatus
  739. FillEllipse(
  740. GpBrush* brush,
  741. REAL x,
  742. REAL y,
  743. REAL width,
  744. REAL height
  745. )
  746. {
  747. GpRectF rect(x, y, width, height);
  748. return FillEllipse(brush, rect);
  749. }
  750. GpStatus
  751. FillPie(
  752. GpBrush* brush,
  753. const GpRectF& rect,
  754. REAL startAngle,
  755. REAL sweepAngle
  756. );
  757. GpStatus
  758. FillPie(
  759. GpBrush* brush,
  760. REAL x,
  761. REAL y,
  762. REAL width,
  763. REAL height,
  764. REAL startAngle,
  765. REAL sweepAngle
  766. )
  767. {
  768. GpRectF rect(x, y, width, height);
  769. return FillPie(brush, rect, startAngle, sweepAngle);
  770. }
  771. GpStatus
  772. FillPath(
  773. const GpBrush* brush,
  774. GpPath* path
  775. );
  776. GpStatus
  777. FillPathData(
  778. GpBrush* brush,
  779. const GpPointF* points,
  780. const BYTE *types,
  781. INT count,
  782. GpFillMode fillMode
  783. )
  784. {
  785. GpStatus status = GenericError;
  786. GpPath path(points, types, count, fillMode);
  787. if(path.IsValid())
  788. status = FillPath(brush, &path);
  789. return status;
  790. }
  791. GpStatus
  792. FillClosedCurve(
  793. GpBrush* brush,
  794. const GpPointF* points,
  795. INT count,
  796. REAL tension = 0.5,
  797. GpFillMode fillMode = FillModeAlternate
  798. );
  799. GpStatus
  800. FillRegion(
  801. GpBrush* brush,
  802. GpRegion* region
  803. );
  804. //------------------------------------------------------------------------
  805. // Draw text strings
  806. //------------------------------------------------------------------------
  807. #define DG_NOGDI 4 // Disable optimisation through GDI
  808. #define DG_SIDEWAY 0x80000000 // flag used by the drivers (Meta Driver) for sideway runs.
  809. // To be removed, replaced by DrawRealizedGlyphs and GdiDrawGlyphs
  810. GpStatus
  811. DrawGlyphs(
  812. const UINT16 *glyphIndices,
  813. INT count,
  814. const GpFontFace *face,
  815. INT style,
  816. REAL emSize,
  817. Unit unit,
  818. const GpBrush *brush,
  819. const UINT32 *px,
  820. const UINT32 *py,
  821. INT flags,
  822. const GpMatrix *pmx = NULL
  823. );
  824. // Internal text drawing APIs
  825. protected:
  826. // should be called once per DrawString/DrawDriverString call
  827. // checks for invalid text rendering hint combinations
  828. GpStatus CheckTextMode();
  829. // this method is meant to calculate TextRenderingHintInternal
  830. // we call this method once and only once before using GetTextRenderingHintInternal()
  831. void CalculateTextRenderingHintInternal();
  832. public:
  833. GpStatus DrawPlacedGlyphs(
  834. const GpFaceRealization *faceRealization,
  835. const GpBrush *brush,
  836. INT flags,
  837. const WCHAR *string,
  838. UINT stringLength,
  839. BOOL rightToLeft,
  840. const UINT16 *glyphs,
  841. const UINT16 *glyphMap,
  842. const PointF *glyphOrigins,
  843. INT glyphCount,
  844. ItemScript Script,
  845. BOOL sideways // e.g. FE characters in vertical text
  846. );
  847. GpStatus DrawDriverGlyphs(
  848. const UINT16 *glyphs,
  849. INT glyphCount,
  850. const GpFont *font,
  851. const GpFontFace *face,
  852. const GpBrush *brush,
  853. const WCHAR *string,
  854. const PointF *positions,
  855. INT flags,
  856. const GpMatrix *matrix
  857. );
  858. // External text drawing APIs
  859. GpStatus
  860. DrawString(
  861. const WCHAR *string,
  862. INT length,
  863. const GpFont *font,
  864. const RectF *layoutRect,
  865. const GpStringFormat *format,
  866. const GpBrush *brush
  867. );
  868. GpStatus
  869. MeasureString(
  870. const WCHAR *string,
  871. INT length,
  872. const GpFont *font,
  873. const RectF *layoutRect,
  874. const GpStringFormat *format,
  875. RectF *boundingBox,
  876. INT *codepointsFitted,
  877. INT *linesFilled
  878. );
  879. GpStatus
  880. MeasureCharacterRanges(
  881. const WCHAR *string,
  882. INT length,
  883. const GpFont *font,
  884. const RectF &layoutRect,
  885. const GpStringFormat *format,
  886. INT regionCount,
  887. GpRegion **regions
  888. );
  889. /// Start API for graphicstext.cpp
  890. GpStatus
  891. RecordEmfPlusDrawDriverString(
  892. const UINT16 *text,
  893. INT glyphCount,
  894. const GpFont *font,
  895. const GpFontFace *face,
  896. const GpBrush *brush,
  897. const PointF *positions,
  898. INT flags,
  899. const GpMatrix *matrix // optional
  900. );
  901. GpStatus
  902. DrawDriverString(
  903. const UINT16 *text,
  904. INT length,
  905. const GpFont *font,
  906. const GpBrush *brush,
  907. const PointF *positions,
  908. INT flags,
  909. const GpMatrix *matrix
  910. );
  911. GpStatus
  912. MeasureDriverString(
  913. const UINT16 *text,
  914. INT glyphCount,
  915. const GpFont *font,
  916. const PointF *positions,
  917. INT flags,
  918. const GpMatrix *matrix, // In - Optional glyph transform
  919. RectF *boundingBox // Out - Overall bounding box of cells
  920. );
  921. GpStatus
  922. DrawFontStyleLine(
  923. const PointF *baselineOrigin, // baseline origin
  924. REAL baselineLength, // baseline length
  925. const GpFontFace *face, // font face
  926. const GpBrush *brush, // brush
  927. BOOL vertical, // vertical text?
  928. REAL emSize, // font EM size in world unit
  929. INT style, // kind of lines to be drawn
  930. const GpMatrix *matrix = NULL // additional transform
  931. );
  932. REAL GetDevicePenWidth(
  933. REAL widthInWorldUnits,
  934. const GpMatrix *matrix = NULL
  935. );
  936. /// End API for graphicstext.cpp
  937. GpStatus
  938. DrawCachedBitmap(
  939. GpCachedBitmap *cb,
  940. INT x,
  941. INT y
  942. )
  943. {
  944. return DrvDrawCachedBitmap(cb, x, y);
  945. }
  946. //------------------------------------------------------------------------
  947. // Draw images (both bitmap and metafile)
  948. //------------------------------------------------------------------------
  949. GpStatus
  950. DrawImage(
  951. GpImage* image,
  952. const GpPointF& point
  953. );
  954. GpStatus
  955. DrawImage(
  956. GpImage* image,
  957. REAL x,
  958. REAL y
  959. )
  960. {
  961. GpPointF point(x, y);
  962. return DrawImage(image, point);
  963. }
  964. GpStatus
  965. DrawImage(
  966. GpImage* image,
  967. const GpRectF& destRect
  968. );
  969. GpStatus
  970. DrawImage(
  971. GpImage* image,
  972. REAL x,
  973. REAL y,
  974. REAL width,
  975. REAL height
  976. )
  977. {
  978. GpRectF destRect(x, y, width, height);
  979. return DrawImage(image, destRect);
  980. }
  981. GpStatus
  982. DrawImage(
  983. GpImage* image,
  984. const GpPointF* destPoints,
  985. INT count
  986. );
  987. GpStatus
  988. DrawImage(
  989. GpImage* image,
  990. REAL x,
  991. REAL y,
  992. const GpRectF & srcRect,
  993. GpPageUnit srcUnit
  994. );
  995. GpStatus
  996. DrawImage(
  997. GpImage* image,
  998. const GpRectF& destRect,
  999. const GpRectF& srcRect,
  1000. GpPageUnit srcUnit,
  1001. const GpImageAttributes* imageAttributes = NULL,
  1002. DrawImageAbort callback = NULL,
  1003. VOID* callbackData = NULL
  1004. );
  1005. GpStatus
  1006. DrawImage(
  1007. GpImage* image,
  1008. const GpPointF* destPoints,
  1009. INT count,
  1010. const GpRectF& srcRect,
  1011. GpPageUnit srcUnit,
  1012. const GpImageAttributes* imageAttributes = NULL,
  1013. DrawImageAbort callback = NULL,
  1014. VOID* callbackData = NULL
  1015. );
  1016. GpStatus
  1017. EnumerateMetafile(
  1018. const GpMetafile * metafile,
  1019. const PointF & destPoint,
  1020. EnumerateMetafileProc callback,
  1021. VOID * callbackData,
  1022. const GpImageAttributes * imageAttributes
  1023. );
  1024. GpStatus
  1025. EnumerateMetafile(
  1026. const GpMetafile * metafile,
  1027. const RectF & destRect,
  1028. EnumerateMetafileProc callback,
  1029. VOID * callbackData,
  1030. const GpImageAttributes * imageAttributes
  1031. );
  1032. GpStatus
  1033. EnumerateMetafile(
  1034. const GpMetafile * metafile,
  1035. const PointF * destPoints,
  1036. INT count,
  1037. EnumerateMetafileProc callback,
  1038. VOID * callbackData,
  1039. const GpImageAttributes * imageAttributes
  1040. );
  1041. GpStatus
  1042. EnumerateMetafile(
  1043. const GpMetafile * metafile,
  1044. const PointF & destPoint,
  1045. const RectF & srcRect,
  1046. Unit srcUnit,
  1047. EnumerateMetafileProc callback,
  1048. VOID * callbackData,
  1049. const GpImageAttributes * imageAttributes
  1050. );
  1051. GpStatus
  1052. EnumerateMetafile(
  1053. const GpMetafile * metafile,
  1054. const RectF & destRect,
  1055. const RectF & srcRect,
  1056. Unit srcUnit,
  1057. EnumerateMetafileProc callback,
  1058. VOID * callbackData,
  1059. const GpImageAttributes * imageAttributes
  1060. );
  1061. GpStatus
  1062. EnumerateMetafile(
  1063. const GpMetafile * metafile,
  1064. const PointF * destPoints,
  1065. INT count,
  1066. const RectF & srcRect,
  1067. Unit srcUnit,
  1068. EnumerateMetafileProc callback,
  1069. VOID * callbackData,
  1070. const GpImageAttributes * imageAttributes
  1071. );
  1072. GpStatus
  1073. Comment(
  1074. UINT sizeData,
  1075. const BYTE * data
  1076. )
  1077. {
  1078. GpStatus status = InvalidParameter;
  1079. if (IsRecording())
  1080. {
  1081. status = Metafile->RecordComment(sizeData, data);
  1082. if (status != Ok)
  1083. {
  1084. SetValid(FALSE); // Prevent any more recording
  1085. }
  1086. }
  1087. return status;
  1088. }
  1089. // Called only by metafile player
  1090. GpStatus
  1091. EnumEmf(
  1092. MetafilePlayer * player,
  1093. HENHMETAFILE hEmf,
  1094. const GpRectF & destRect,
  1095. const GpRectF & srcRect,
  1096. const GpRectF & deviceDestRect,
  1097. MetafileType type,
  1098. BOOL isTranslateScale,
  1099. BOOL renderToBitmap,
  1100. const GpMatrix & flipAndCropTransform
  1101. );
  1102. // Called only by metafile player
  1103. GpStatus
  1104. EnumEmfPlusDual(
  1105. MetafilePlayer * player,
  1106. HENHMETAFILE hEmf,
  1107. const GpRectF& destRect, // inclusive, exclusive
  1108. const GpRectF& deviceDestRect, // inclusive, exclusive
  1109. BOOL isTranslateScale,
  1110. BOOL renderToBitmap
  1111. );
  1112. protected:
  1113. // if an HWND is passed in, the default ICM mode is off.
  1114. // if an HDC is passed in, the icmMode flag is ignored.
  1115. GpGraphics(
  1116. HWND hwnd,
  1117. HDC hdc,
  1118. INT clientWidth,
  1119. INT clientHeight,
  1120. HdcIcmMode icmMode = IcmModeOff,
  1121. BOOL gdiLayered = FALSE
  1122. );
  1123. GpGraphics(DpBitmap * surface);
  1124. GpStatus GetDCDrawBounds(HDC hdc, RECT *rect);
  1125. public:
  1126. // The Context dpi and the Surface dpi are always the same,
  1127. // except possibly during metafile playback when the Context
  1128. // may be using the metafile dpi (which is what rendering
  1129. // should use).
  1130. REAL GetDpiX() const { return Context->GetDpiX(); }
  1131. REAL GetDpiY() const { return Context->GetDpiY(); }
  1132. BOOL IsPrinter() const { return Printer; }
  1133. protected:
  1134. enum HalftoneType
  1135. {
  1136. HalftoneTypeNone,
  1137. HalftoneType16Color,
  1138. HalftoneType216Color,
  1139. HalftoneType15Bpp,
  1140. HalftoneType16Bpp,
  1141. };
  1142. HalftoneType GetHalftoneType() const
  1143. {
  1144. EpPaletteMap* paletteMap = BottomContext.PaletteMap;
  1145. // !! TODO: Verify this works on when switching modes
  1146. if (paletteMap != NULL)
  1147. {
  1148. // we are doing 8bpp palette map
  1149. if (paletteMap->IsVGAOnly())
  1150. {
  1151. return HalftoneType16Color;
  1152. }
  1153. else
  1154. {
  1155. return HalftoneType216Color;
  1156. }
  1157. }
  1158. else if (Surface->PixelFormat == PixelFormat16bppRGB555)
  1159. {
  1160. return HalftoneType15Bpp;
  1161. }
  1162. else if (Surface->PixelFormat == PixelFormat16bppRGB565)
  1163. {
  1164. return HalftoneType16Bpp;
  1165. }
  1166. else
  1167. {
  1168. return HalftoneTypeNone;
  1169. }
  1170. }
  1171. //--------------------------------------------------------------
  1172. // Internal fill and draw routines that do not record
  1173. // path, rect, or region in a metafile.
  1174. //--------------------------------------------------------------
  1175. GpStatus
  1176. RenderFillRects(
  1177. GpRectF* bounds,
  1178. INT count,
  1179. const GpRectF* rects,
  1180. GpBrush* brush
  1181. )
  1182. {
  1183. GpRect deviceBounds;
  1184. GpStatus status = BoundsFToRect(bounds, &deviceBounds);
  1185. if (status == Ok && !IsTotallyClipped(&deviceBounds))
  1186. {
  1187. // Now that we've done a bunch of work in accumulating the bounds,
  1188. // acquire the device lock before calling the driver:
  1189. Devlock devlock(Device);
  1190. return DrvFillRects(&deviceBounds, count, rects, brush->GetDeviceBrush());
  1191. }
  1192. return status;
  1193. }
  1194. GpStatus
  1195. RenderFillRegion(
  1196. GpRectF* bounds,
  1197. GpRegion* region,
  1198. GpBrush* brush,
  1199. GpRect* metafileBounds
  1200. )
  1201. {
  1202. GpRect deviceBounds;
  1203. GpStatus status = BoundsFToRect(bounds, &deviceBounds);
  1204. BOOL isInfinite = FALSE;
  1205. GpMatrix identity;
  1206. if (status == Ok && !IsTotallyClipped(&deviceBounds))
  1207. {
  1208. // Now that we've done a bunch of work in accumulating the bounds,
  1209. // acquire the device lock before calling the driver:
  1210. status = region->UpdateDeviceRegion(&(Context->WorldToDevice));
  1211. if (status == Ok)
  1212. {
  1213. DpRegion * deviceRegion = &(region->DeviceRegion);
  1214. DpRegion metafileRegion;
  1215. if (metafileBounds != NULL)
  1216. {
  1217. metafileRegion.Set(metafileBounds);
  1218. metafileRegion.And(deviceRegion);
  1219. if (!metafileRegion.IsValid())
  1220. {
  1221. return GenericError;
  1222. }
  1223. deviceRegion = &metafileRegion;
  1224. }
  1225. // Get the actual bounds now to give to the driver
  1226. deviceRegion->GetBounds(&deviceBounds);
  1227. // Make sure there is still something to fill so we
  1228. // don't ASSERT later on.
  1229. if ((deviceBounds.Width > 0) && (deviceBounds.Height > 0))
  1230. {
  1231. Devlock devlock(Device);
  1232. return DrvFillRegion(&deviceBounds, deviceRegion, brush->GetDeviceBrush());
  1233. }
  1234. }
  1235. }
  1236. return status;
  1237. }
  1238. GpStatus RenderDrawPath(
  1239. GpRectF *bounds,
  1240. GpPath *path,
  1241. GpPen *pen
  1242. );
  1243. GpStatus RenderFillPath(
  1244. GpRectF *bounds,
  1245. GpPath *path,
  1246. const GpBrush *brush
  1247. );
  1248. VOID
  1249. GetImageDestPageSize(
  1250. const GpImage * image,
  1251. REAL srcWidth,
  1252. REAL srcHeight,
  1253. GpPageUnit srcUnit,
  1254. REAL & destWidth,
  1255. REAL & destHeight
  1256. );
  1257. VOID
  1258. DeviceToWorldTransformRect(
  1259. const GpRect & deviceRect,
  1260. GpRectF & rect
  1261. ) const;
  1262. static GpGraphics *GetFromGdiBitmap(HDC hdc);
  1263. static GpGraphics *GetFromGdipBitmap(
  1264. GpBitmap* bitmap,
  1265. ImageInfo * imageInfo,
  1266. EpScanBitmap * scanBitmap,
  1267. BOOL isDisplay
  1268. );
  1269. static GpGraphics *GetFromGdiPrinterDC(HDC hdc);
  1270. static GpGraphics *GetFromGdiEmfDC(HDC hdc);
  1271. static GpGraphics *GetFromDirectDrawSurface(IDirectDrawSurface7 * surface);
  1272. static GpGraphics *GetFromGdiPrinterDC(HDC hdc, HANDLE hPrinter);
  1273. static INT GetPostscriptLevel(HDC hdc, HANDLE hPrinter);
  1274. GpStatus StartPrinterEMF();
  1275. GpStatus EndPrinterEMF();
  1276. BOOL IsTotallyClipped(GpRect *rect) const;
  1277. BOOL IsRecording() const { return Metafile != NULL; }
  1278. BOOL IsDisplay() const { return Context->IsDisplay; }
  1279. VOID DoResetClip()
  1280. {
  1281. Context->AppClip.SetInfinite();
  1282. // ContainerClip always contains the clipping for the container,
  1283. // intersected with the WindowClip.
  1284. Context->VisibleClip.Set(&(Context->ContainerClip));
  1285. }
  1286. // The AppClip has been set into VisibleClip; now intersect it with
  1287. // the container clip and the window clip.
  1288. GpStatus AndVisibleClip()
  1289. {
  1290. // ContainerClip always contains the clipping for the container,
  1291. // intersected with the WindowClip.
  1292. return Context->VisibleClip.And(&(Context->ContainerClip));
  1293. }
  1294. GpStatus
  1295. CombineClip(
  1296. const GpRectF & rect,
  1297. CombineMode combineMode
  1298. );
  1299. GpStatus
  1300. CombineClip(
  1301. const GpPath * path,
  1302. CombineMode combineMode,
  1303. BOOL isDevicePath = FALSE
  1304. );
  1305. GpStatus
  1306. CombineClip(
  1307. GpRegion * region,
  1308. CombineMode combineMode
  1309. );
  1310. GpStatus
  1311. InheritAppClippingAndTransform(
  1312. HDC hdc
  1313. );
  1314. VOID
  1315. ResetState(
  1316. INT x,
  1317. INT y,
  1318. INT width,
  1319. INT height
  1320. );
  1321. VOID
  1322. UpdateDrawBounds(
  1323. INT x,
  1324. INT y,
  1325. INT width,
  1326. INT height
  1327. );
  1328. //--------------------------------------------------------------------------
  1329. // Routines for calling the driver
  1330. //--------------------------------------------------------------------------
  1331. VOID
  1332. DrvFlush(
  1333. GpFlushIntention intention
  1334. )
  1335. {
  1336. ASSERTMSG(Device->DeviceLock.IsLockedByCurrentThread(),
  1337. ("DeviceLock must be held by current thread"));
  1338. Driver->Flush(Device, Surface, intention);
  1339. }
  1340. GpStatus
  1341. DrvStrokePath(
  1342. const GpRect *drawBounds,
  1343. const DpPath *path,
  1344. const DpPen *pen
  1345. )
  1346. {
  1347. ASSERTMSG(GetObjectLock()->IsLocked(),
  1348. ("Graphics object must be locked"));
  1349. ASSERTMSG(Device->DeviceLock.IsLockedByCurrentThread(),
  1350. ("DeviceLock must be held by current thread"));
  1351. FPUStateSaver::AssertMode();
  1352. Surface->Uniqueness = (DWORD)GpObject::GenerateUniqueness();
  1353. return(Driver->StrokePath(Context, Surface, drawBounds, path, pen));
  1354. }
  1355. GpStatus
  1356. DrvFillRects(
  1357. const GpRect *drawBounds,
  1358. INT numRects,
  1359. const GpRectF *rects,
  1360. const DpBrush *brush
  1361. )
  1362. {
  1363. ASSERTMSG(GetObjectLock()->IsLocked(),
  1364. ("Graphics object must be locked"));
  1365. ASSERTMSG(Device->DeviceLock.IsLockedByCurrentThread(),
  1366. ("DeviceLock must be held by current thread"));
  1367. FPUStateSaver::AssertMode();
  1368. Surface->Uniqueness = (DWORD)GpObject::GenerateUniqueness();
  1369. return(Driver->FillRects(Context, Surface, drawBounds,
  1370. numRects, rects, brush));
  1371. }
  1372. GpStatus
  1373. DrvFillPath(
  1374. const GpRect *drawBounds,
  1375. const DpPath *path,
  1376. const DpBrush *brush
  1377. )
  1378. {
  1379. ASSERTMSG(GetObjectLock()->IsLocked(),
  1380. ("Graphics object must be locked"));
  1381. ASSERTMSG(Device->DeviceLock.IsLockedByCurrentThread(),
  1382. ("DeviceLock must be held by current thread"));
  1383. FPUStateSaver::AssertMode();
  1384. Surface->Uniqueness = (DWORD)GpObject::GenerateUniqueness();
  1385. return(Driver->FillPath(Context, Surface, drawBounds, path, brush));
  1386. }
  1387. GpStatus
  1388. DrvFillRegion(
  1389. const GpRect *drawBounds,
  1390. const DpRegion *region,
  1391. const DpBrush *brush
  1392. )
  1393. {
  1394. ASSERTMSG(GetObjectLock()->IsLocked(),
  1395. ("Graphics object must be locked"));
  1396. ASSERTMSG(Device->DeviceLock.IsLockedByCurrentThread(),
  1397. ("DeviceLock must be held by current thread"));
  1398. FPUStateSaver::AssertMode();
  1399. Surface->Uniqueness = (DWORD)GpObject::GenerateUniqueness();
  1400. return(Driver->FillRegion(Context, Surface, drawBounds, region, brush));
  1401. }
  1402. GpStatus
  1403. DrvDrawGlyphs(
  1404. const GpRect *drawBounds,
  1405. const GpGlyphPos *glyphPos,
  1406. const GpGlyphPos *glyphPathPos,
  1407. INT count,
  1408. const DpBrush *brush,
  1409. const GpFaceRealization *faceRealization,
  1410. const UINT16 *glyphs,
  1411. const UINT16 *glyphMap,
  1412. const PointF *glyphOrigins,
  1413. INT glyphCount,
  1414. const WCHAR *string,
  1415. UINT stringLength,
  1416. ItemScript script,
  1417. INT edgeGlyphAdvance,
  1418. BOOL rightToLeft,
  1419. INT flags
  1420. )
  1421. {
  1422. // check the input parameter!!
  1423. GpStatus status;
  1424. DrawGlyphData drawGlyphData;
  1425. drawGlyphData.context = Context;
  1426. drawGlyphData.surface = Surface;
  1427. drawGlyphData.drawBounds = drawBounds;
  1428. drawGlyphData.glyphPos = glyphPos;
  1429. drawGlyphData.glyphPathPos = glyphPathPos;
  1430. drawGlyphData.count = count;
  1431. drawGlyphData.brush = brush;
  1432. drawGlyphData.faceRealization = faceRealization;
  1433. drawGlyphData.glyphs = glyphs;
  1434. drawGlyphData.glyphMap = glyphMap;
  1435. drawGlyphData.glyphOrigins = glyphOrigins;
  1436. drawGlyphData.glyphCount = glyphCount;
  1437. drawGlyphData.string = string;
  1438. drawGlyphData.stringLength = stringLength;
  1439. drawGlyphData.script = script;
  1440. drawGlyphData.edgeGlyphAdvance = edgeGlyphAdvance;
  1441. drawGlyphData.rightToLeft = rightToLeft;
  1442. drawGlyphData.flags = flags;
  1443. status = Driver->DrawGlyphs(&drawGlyphData);
  1444. return status;
  1445. }
  1446. // Draw the CachedBitmap on this graphics.
  1447. // This routine sets up the rendering origin and the locks
  1448. // and calls the appropriate driver.
  1449. GpStatus
  1450. DrvDrawCachedBitmap(
  1451. GpCachedBitmap *inputCachedBitmap,
  1452. INT x,
  1453. INT y
  1454. );
  1455. GpStatus
  1456. DrvDrawImage(
  1457. const GpRect *drawBounds,
  1458. GpBitmap *intputBitmap,
  1459. INT numPoints,
  1460. const GpPointF *dstPoints,
  1461. const GpRectF *srcRect,
  1462. const GpImageAttributes *imageAttributes,
  1463. DrawImageAbort callback,
  1464. VOID *callbackData,
  1465. DriverDrawImageFlags flags
  1466. );
  1467. GpStatus
  1468. DrvMoveBits(
  1469. const GpRect *drawBounds,
  1470. const GpRect *dstRect,
  1471. const GpPoint *srcPoint
  1472. )
  1473. {
  1474. GpStatus status;
  1475. ASSERTMSG(GetObjectLock()->IsLocked(),
  1476. ("Graphics object must be locked"));
  1477. ASSERTMSG(Device->DeviceLock.IsLockedByCurrentThread(),
  1478. ("DeviceLock must be held by current thread"));
  1479. FPUStateSaver::AssertMode();
  1480. Surface->Uniqueness = (DWORD)GpObject::GenerateUniqueness();
  1481. status = Driver->MoveBits(Context, Surface, drawBounds, dstRect,
  1482. srcPoint);
  1483. return status;
  1484. }
  1485. public:
  1486. // Simple inline function to return the selected surface.
  1487. DpBitmap *GetSurface() {
  1488. return Surface;
  1489. }
  1490. // Simple inline function to return the driver.
  1491. DpDriver *GetDriver() {
  1492. return Driver;
  1493. }
  1494. protected:
  1495. enum GraphicsType
  1496. {
  1497. GraphicsBitmap = 1,
  1498. GraphicsScreen = 2,
  1499. GraphicsMetafile = 3,
  1500. };
  1501. mutable GpLockable Lockable;
  1502. GpRect SurfaceBounds; // Bounds of surface in device units.
  1503. DpBitmap *Surface; // Selected surface
  1504. GpBitmap *GdipBitmap; // point to GpBitmap if the graphics is created from one
  1505. IMetafileRecord * Metafile; // For recording metafiles
  1506. BOOL Printer; // Whether this object is a printer
  1507. PGDIPPRINTINIT PrintInit; // Initialization data for printer types
  1508. HGLOBAL PrinterEMF;
  1509. GpMetafile *PrinterMetafile;
  1510. GpGraphics *PrinterGraphics;
  1511. BOOL DownLevel; // Whether or not to do down-level metafile
  1512. GraphicsType Type; // Type of GpGraphics created
  1513. BOOL CreatedDevice; // Whether 'Device' was created at GpGraphics
  1514. // construction time, and so needs to be
  1515. // freed in the GpGraphics destructor
  1516. GpDevice *Device; // Associated device
  1517. DpDriver *Driver; // Associate driver interface
  1518. DpContext *Context; // Contains all the driver-viewable state:
  1519. // Transforms, clipping, alpha/antialias/etc.
  1520. // modes
  1521. DpContext BottomContext; // Always the bottom of the Context Stack
  1522. DpRegion WindowClip; // The clip region of the window
  1523. TextRenderingHint TextRenderingHintInternal; // cached internal value of TextRenderingHint
  1524. // valid during one call to Draw(Driver)String
  1525. };
  1526. #endif // !_GRAPHICS_HPP