Qt 4.8
qpaintengine_mac_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QPAINTENGINE_MAC_P_H
43 #define QPAINTENGINE_MAC_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include "QtGui/qpaintengine.h"
57 #include "private/qt_mac_p.h"
58 #include "private/qpaintengine_p.h"
59 #include "private/qpolygonclipper_p.h"
60 #include "private/qfont_p.h"
61 #include "QtCore/qhash.h"
62 
63 typedef struct CGColorSpace *CGColorSpaceRef;
65 
68 {
70 
71 public:
74 
75  bool begin(QPaintDevice *pdev);
76  bool end();
79 
80  void updateState(const QPaintEngineState &state);
81 
82  void updatePen(const QPen &pen);
83  void updateBrush(const QBrush &brush, const QPointF &pt);
84  void updateFont(const QFont &font);
85  void updateOpacity(qreal opacity);
86  void updateMatrix(const QTransform &matrix);
87  void updateTransform(const QTransform &matrix);
88  void updateClipRegion(const QRegion &region, Qt::ClipOperation op);
89  void updateClipPath(const QPainterPath &path, Qt::ClipOperation op);
91  void updateRenderHints(QPainter::RenderHints hints);
92 
93  void drawLines(const QLineF *lines, int lineCount);
94  void drawRects(const QRectF *rects, int rectCount);
95  void drawPoints(const QPointF *p, int pointCount);
96  void drawEllipse(const QRectF &r);
97  void drawPath(const QPainterPath &path);
98 
99  void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode);
100  void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
101  void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
102 
103  void drawTextItem(const QPointF &pos, const QTextItem &item);
104  void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
105  Qt::ImageConversionFlags flags = Qt::AutoColor);
106 
108 
109  CGContextRef handle() const;
110 
111  static void initialize();
112  static void cleanup();
113  static void clearColorSpace(QWidget* w);
114 
115  QPainter::RenderHints supportedRenderHints() const;
116 
117  //avoid partial shadowed overload warnings...
118  void drawLines(const QLine *lines, int lineCount) { QPaintEngine::drawLines(lines, lineCount); }
119  void drawRects(const QRect *rects, int rectCount) { QPaintEngine::drawRects(rects, rectCount); }
120  void drawPoints(const QPoint *p, int pointCount) { QPaintEngine::drawPoints(p, pointCount); }
122  void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
123  { QPaintEngine::drawPolygon(points, pointCount, mode); }
124 
125  bool supportsTransformations(qreal, const QTransform &) const { return true; };
126 
127 protected:
128  friend class QMacPrintEngine;
130  friend void qt_mac_display_change_callbk(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void *);
131  friend void qt_color_profile_changed(CFNotificationCenterRef center, void *,
132  CFStringRef , const void *, CFDictionaryRef);
134 
135 private:
139  static void cleanUpMacColorSpaces();
141 };
142 
143 /*****************************************************************************
144  Private data
145  *****************************************************************************/
147 {
149 public:
151  : hd(0), shading(0), stackCount(0), complexXForm(false), disabledSmoothFonts(false)
152  {
153  }
154 
155  struct {
161  } current;
162 
163  //state info (shared with QD)
164  CGAffineTransform orig_xform;
165 
166  //cg structures
168  CGShadingRef shading;
172  enum { CosmeticNone, CosmeticTransformPath, CosmeticSetPenWidth } cosmeticPen;
173 
174  // pixel and cosmetic pen size in user coordinates.
177 
178  //internal functions
179  enum { CGStroke=0x01, CGEOFill=0x02, CGFill=0x04 };
180  void drawPath(uchar ops, CGMutablePathRef path = 0);
181  void setClip(const QRegion *rgn=0);
182  void resetClip();
183  void setFillBrush(const QPointF &origin=QPoint());
184  void setStrokePen(const QPen &pen);
185  inline void saveGraphicsState();
186  inline void restoreGraphicsState();
187  float penOffset();
188  QPointF devicePixelSize(CGContextRef context);
189  float adjustPenWidth(float penWidth);
190  inline void setTransform(const QTransform *matrix=0)
191  {
192  CGContextConcatCTM(hd, CGAffineTransformInvert(CGContextGetCTM(hd)));
193  CGAffineTransform xform = orig_xform;
194  if(matrix) {
195  extern CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &);
196  xform = CGAffineTransformConcat(qt_mac_convert_transform_to_cg(*matrix), xform);
197  }
198  CGContextConcatCTM(hd, xform);
199  CGContextSetTextMatrix(hd, xform);
200  }
201 };
202 
204 {
205  ++stackCount;
206  CGContextSaveGState(hd);
207 }
208 
210 {
211  --stackCount;
212  Q_ASSERT(stackCount >= 0);
213  CGContextRestoreGState(hd);
214 }
215 
217 {
218 public:
219  QMacQuartzPaintDevice(CGContextRef cg, int width, int height, int bytesPerLine)
220  : mCG(cg), mWidth(width), mHeight(height), mBytesPerLine(bytesPerLine)
221  { }
222  int devType() const { return QInternal::MacQuartz; }
223  CGContextRef cgContext() const { return mCG; }
224  int metric(PaintDeviceMetric metric) const {
225  switch (metric) {
226  case PdmWidth:
227  return mWidth;
228  case PdmHeight:
229  return mHeight;
230  case PdmWidthMM:
231  return (qt_defaultDpiX() * mWidth) / 2.54;
232  case PdmHeightMM:
233  return (qt_defaultDpiY() * mHeight) / 2.54;
234  case PdmNumColors:
235  return 0;
236  case PdmDepth:
237  return 32;
238  case PdmDpiX:
239  case PdmPhysicalDpiX:
240  return qt_defaultDpiX();
241  case PdmDpiY:
242  case PdmPhysicalDpiY:
243  return qt_defaultDpiY();
244  }
245  return 0;
246  }
247  QPaintEngine *paintEngine() const { qWarning("This function should never be called."); return 0; }
248 private:
250  int mWidth;
251  int mHeight;
253 };
254 
256 
257 #endif // QPAINTENGINE_MAC_P_H
bool supportsTransformations(qreal, const QTransform &) const
CGContextRef cgContext() const
const struct __CFString * CFStringRef
static CGColorSpaceRef macDisplayColorSpace(const QWidget *widget=0)
static CGColorSpaceRef macGenericColorSpace()
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool end()
Reimplement this function to finish painting on the current paint device.
QPointer< QWidget > widget
friend void qt_color_profile_changed(CFNotificationCenterRef center, void *, CFStringRef, const void *, CFDictionaryRef)
CompositionMode
Defines the modes supported for digital image compositing.
Definition: qpainter.h:138
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
void drawEllipse(const QRect &r)
The default implementation of this function calls the floating point version of this function...
void drawPoints(const QPointF *p, int pointCount)
Draws the first pointCount points in the buffer points.
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
bool begin(QPaintDevice *pdev)
Reimplement this function to initialise your paint engine when painting is to start on the paint devi...
QPaintEngineState * state
Definition: qpaintengine.h:239
void updateRenderHints(QPainter::RenderHints hints)
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
virtual void drawRects(const QRect *rects, int rectCount)
The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF an...
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
void updateClipPath(const QPainterPath &path, Qt::ClipOperation op)
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void updatePen(const QPen &pen)
virtual void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the buffer points.
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
Reimplement this function to draw the pixmap in the given rect, starting at the given p...
void updateBrush(const QBrush &brush, const QPointF &pt)
QPaintEngine * paintEngine() const
int metric(PaintDeviceMetric metric) const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
CGContextRef handle() const
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void drawRects(const QRect *rects, int rectCount)
The default implementation converts the first rectCount rectangles in the buffer rects to a QRectF an...
void updateClipRegion(const QRegion &region, Qt::ClipOperation op)
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
static void setClip(QPainter *painter, QGraphicsItem *item)
void drawPath(const QPainterPath &path)
The default implementation ignores the path and does nothing.
void drawEllipse(const QRectF &r)
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect...
unsigned char uchar
Definition: qglobal.h:994
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
void updateCompositionMode(QPainter::CompositionMode mode)
friend void qt_mac_display_change_callbk(CGDirectDisplayID, CGDisplayChangeSummaryFlags, void *)
void updateMatrix(const QTransform &matrix)
void drawTextItem(const QPointF &pos, const QTextItem &item)
This function draws the text item textItem at position p.
void drawLines(const QLine *lines, int lineCount)
The default implementation converts the first lineCount lines in lines to a QLineF and calls the floa...
void updateOpacity(qreal opacity)
QPainter::RenderHints supportedRenderHints() const
Q_CORE_EXPORT void qWarning(const char *,...)
static void clearColorSpace(QWidget *w)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
Type type() const
Reimplement this function to return the paint engine Type.
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
void updateFont(const QFont &font)
void drawLines(const QLineF *lines, int lineCount)
The default implementation splits the list of lines in lines into lineCount separate calls to drawPat...
virtual void drawLines(const QLine *lines, int lineCount)
The default implementation converts the first lineCount lines in lines to a QLineF and calls the floa...
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QMacQuartzPaintDevice(CGContextRef cg, int width, int height, int bytesPerLine)
static QHash< QWidget *, CGColorSpaceRef > m_displayColorSpaceHash
struct CGColorSpace * CGColorSpaceRef
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
void drawPoints(const QPoint *p, int pointCount)
Draws the first pointCount points in the buffer points.
virtual void drawEllipse(const QRectF &r)
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect...
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
static CGColorSpaceRef m_genericColorSpace
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount rectangles in the buffer rects.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
CGAffineTransform qt_mac_convert_transform_to_cg(const QTransform &t)
void updateTransform(const QTransform &matrix)
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void updateState(const QPaintEngineState &state)
Reimplement this function to update the state of a paint engine.
void setTransform(const QTransform *matrix=0)
The QPaintEngineState class provides information about the active paint engine&#39;s current state...
Definition: qpaintengine.h:289
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
struct CGContext * CGContextRef
The QTextItem class provides all the information required to draw text in a custom paint engine...
Definition: qpaintengine.h:68
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r...
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
ClipOperation
Definition: qnamespace.h:1495