2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #define _USE_MATH_DEFINES 1
28 #include "GraphicsContext.h"
32 #include "AffineTransform.h"
33 #include "GraphicsContextPlatformPrivate.h"
36 #include <CoreGraphics/CGPDFContext.h>
37 #include <wtf/MathExtras.h>
43 static void setCGFillColor(CGContextRef context, const Color& color)
45 CGFloat red, green, blue, alpha;
46 color.getRGBA(red, green, blue, alpha);
47 CGContextSetRGBFillColor(context, red, green, blue, alpha);
50 static void setCGStrokeColor(CGContextRef context, const Color& color)
52 CGFloat red, green, blue, alpha;
53 color.getRGBA(red, green, blue, alpha);
54 CGContextSetRGBStrokeColor(context, red, green, blue, alpha);
57 GraphicsContext::GraphicsContext(CGContextRef cgContext)
58 : m_common(createGraphicsContextPrivate())
59 , m_data(new GraphicsContextPlatformPrivate(cgContext))
61 setPaintingDisabled(!cgContext);
63 // Make sure the context starts in sync with our state.
64 setPlatformFillColor(fillColor());
65 setPlatformStrokeColor(strokeColor());
69 GraphicsContext::~GraphicsContext()
71 destroyGraphicsContextPrivate(m_common);
75 CGContextRef GraphicsContext::platformContext() const
77 ASSERT(!paintingDisabled());
78 ASSERT(m_data->m_cgContext);
79 return m_data->m_cgContext;
82 void GraphicsContext::savePlatformState()
84 // Note: Do not use this function within this class implementation, since we want to avoid the extra
85 // save of the secondary context (in GraphicsContextPlatformPrivate.h).
86 CGContextSaveGState(platformContext());
90 void GraphicsContext::restorePlatformState()
92 // Note: Do not use this function within this class implementation, since we want to avoid the extra
93 // restore of the secondary context (in GraphicsContextPlatformPrivate.h).
94 CGContextRestoreGState(platformContext());
96 m_data->m_userToDeviceTransformKnownToBeIdentity = false;
99 // Draws a filled rectangle with a stroked border.
100 void GraphicsContext::drawRect(const IntRect& rect)
102 if (paintingDisabled())
105 CGContextRef context = platformContext();
107 if (fillColor().alpha())
108 CGContextFillRect(context, rect);
110 if (strokeStyle() != NoStroke && strokeColor().alpha()) {
111 // We do a fill of four rects to simulate the stroke of a border.
112 Color oldFillColor = fillColor();
113 if (oldFillColor != strokeColor())
114 setCGFillColor(context, strokeColor());
116 FloatRect(rect.x(), rect.y(), rect.width(), 1),
117 FloatRect(rect.x(), rect.bottom() - 1, rect.width(), 1),
118 FloatRect(rect.x(), rect.y() + 1, 1, rect.height() - 2),
119 FloatRect(rect.right() - 1, rect.y() + 1, 1, rect.height() - 2)
121 CGContextFillRects(context, rects, 4);
122 if (oldFillColor != strokeColor())
123 setCGFillColor(context, oldFillColor);
127 // This is only used to draw borders.
128 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
130 if (paintingDisabled())
133 if (strokeStyle() == NoStroke || !strokeColor().alpha())
136 float width = strokeThickness();
138 FloatPoint p1 = point1;
139 FloatPoint p2 = point2;
140 bool isVerticalLine = (p1.x() == p2.x());
142 // For odd widths, we add in 0.5 to the appropriate x/y so that the float arithmetic
143 // works out. For example, with a border width of 3, KHTML will pass us (y1+y2)/2, e.g.,
144 // (50+53)/2 = 103/2 = 51 when we want 51.5. It is always true that an even width gave
145 // us a perfect position, but an odd width gave us a position that is off by exactly 0.5.
146 if (strokeStyle() == DottedStroke || strokeStyle() == DashedStroke) {
147 if (isVerticalLine) {
156 if (((int)width) % 2) {
157 if (isVerticalLine) {
158 // We're a vertical line. Adjust our x.
162 // We're a horizontal line. Adjust our y.
169 switch (strokeStyle()) {
174 patWidth = (int)width;
177 patWidth = 3 * (int)width;
181 CGContextRef context = platformContext();
182 CGContextSaveGState(context);
184 CGContextSetShouldAntialias(context, false);
187 // Do a rect fill of our endpoints. This ensures we always have the
188 // appearance of being a border. We then draw the actual dotted/dashed line.
189 setCGFillColor(context, strokeColor()); // The save/restore make it safe to mutate the fill color here without setting it back to the old color.
190 if (isVerticalLine) {
191 CGContextFillRect(context, FloatRect(p1.x() - width / 2, p1.y() - width, width, width));
192 CGContextFillRect(context, FloatRect(p2.x() - width / 2, p2.y(), width, width));
194 CGContextFillRect(context, FloatRect(p1.x() - width, p1.y() - width / 2, width, width));
195 CGContextFillRect(context, FloatRect(p2.x(), p2.y() - width / 2, width, width));
198 // Example: 80 pixels with a width of 30 pixels.
199 // Remainder is 20. The maximum pixels of line we could paint
200 // will be 50 pixels.
201 int distance = (isVerticalLine ? (point2.y() - point1.y()) : (point2.x() - point1.x())) - 2*(int)width;
202 int remainder = distance % patWidth;
203 int coverage = distance - remainder;
204 int numSegments = coverage / patWidth;
206 float patternOffset = 0.0f;
207 // Special case 1px dotted borders for speed.
209 patternOffset = 1.0f;
211 bool evenNumberOfSegments = numSegments % 2 == 0;
213 evenNumberOfSegments = !evenNumberOfSegments;
214 if (evenNumberOfSegments) {
216 patternOffset += patWidth - remainder;
217 patternOffset += remainder / 2;
219 patternOffset = patWidth / 2;
222 patternOffset = (patWidth - remainder)/2;
226 const CGFloat dottedLine[2] = { patWidth, patWidth };
227 CGContextSetLineDash(context, patternOffset, dottedLine, 2);
230 CGContextBeginPath(context);
231 CGContextMoveToPoint(context, p1.x(), p1.y());
232 CGContextAddLineToPoint(context, p2.x(), p2.y());
234 CGContextStrokePath(context);
236 CGContextRestoreGState(context);
239 // This method is only used to draw the little circles used in lists.
240 void GraphicsContext::drawEllipse(const IntRect& rect)
242 // FIXME: CG added CGContextAddEllipseinRect in Tiger, so we should be able to quite easily draw an ellipse.
243 // This code can only handle circles, not ellipses. But khtml only
244 // uses it for circles.
245 ASSERT(rect.width() == rect.height());
247 if (paintingDisabled())
250 CGContextRef context = platformContext();
251 CGContextBeginPath(context);
252 float r = (float)rect.width() / 2;
253 CGContextAddArc(context, rect.x() + r, rect.y() + r, r, 0.0f, 2.0f * piFloat, 0);
254 CGContextClosePath(context);
256 if (fillColor().alpha()) {
257 if (strokeStyle() != NoStroke)
259 CGContextDrawPath(context, kCGPathFillStroke);
261 CGContextFillPath(context);
262 } else if (strokeStyle() != NoStroke)
263 CGContextStrokePath(context);
267 void GraphicsContext::strokeArc(const IntRect& rect, int startAngle, int angleSpan)
269 if (paintingDisabled() || strokeStyle() == NoStroke || strokeThickness() <= 0.0f || !strokeColor().alpha())
272 CGContextRef context = platformContext();
273 CGContextSaveGState(context);
274 CGContextBeginPath(context);
275 CGContextSetShouldAntialias(context, false);
279 float w = (float)rect.width();
280 float h = (float)rect.height();
281 float scaleFactor = h / w;
282 float reverseScaleFactor = w / h;
285 scale(FloatSize(1, scaleFactor));
287 float hRadius = w / 2;
288 float vRadius = h / 2;
289 float fa = startAngle;
290 float falen = fa + angleSpan;
291 float start = -fa * piFloat / 180.0f;
292 float end = -falen * piFloat / 180.0f;
293 CGContextAddArc(context, x + hRadius, (y + vRadius) * reverseScaleFactor, hRadius, start, end, true);
296 scale(FloatSize(1, reverseScaleFactor));
299 float width = strokeThickness();
302 switch (strokeStyle()) {
304 patWidth = (int)(width / 2);
307 patWidth = 3 * (int)(width / 2);
314 // Example: 80 pixels with a width of 30 pixels.
315 // Remainder is 20. The maximum pixels of line we could paint
316 // will be 50 pixels.
318 if (hRadius == vRadius)
319 distance = static_cast<int>((piFloat * hRadius) / 2.0f);
320 else // We are elliptical and will have to estimate the distance
321 distance = static_cast<int>((piFloat * sqrtf((hRadius * hRadius + vRadius * vRadius) / 2.0f)) / 2.0f);
323 int remainder = distance % patWidth;
324 int coverage = distance - remainder;
325 int numSegments = coverage / patWidth;
327 float patternOffset = 0.0f;
328 // Special case 1px dotted borders for speed.
330 patternOffset = 1.0f;
332 bool evenNumberOfSegments = numSegments % 2 == 0;
334 evenNumberOfSegments = !evenNumberOfSegments;
335 if (evenNumberOfSegments) {
337 patternOffset += patWidth - remainder;
338 patternOffset += remainder / 2.0f;
340 patternOffset = patWidth / 2.0f;
343 patternOffset = (patWidth - remainder) / 2.0f;
347 const CGFloat dottedLine[2] = { patWidth, patWidth };
348 CGContextSetLineDash(context, patternOffset, dottedLine, 2);
351 CGContextStrokePath(context);
353 CGContextRestoreGState(context);
356 void GraphicsContext::drawConvexPolygon(size_t npoints, const FloatPoint* points, bool shouldAntialias)
358 if (paintingDisabled() || !fillColor().alpha() && (strokeThickness() <= 0 || strokeStyle() == NoStroke))
364 CGContextRef context = platformContext();
366 CGContextSaveGState(context);
368 CGContextSetShouldAntialias(context, shouldAntialias);
370 CGContextBeginPath(context);
371 CGContextMoveToPoint(context, points[0].x(), points[0].y());
372 for (size_t i = 1; i < npoints; i++)
373 CGContextAddLineToPoint(context, points[i].x(), points[i].y());
374 CGContextClosePath(context);
376 if (fillColor().alpha()) {
377 if (strokeStyle() != NoStroke)
378 CGContextDrawPath(context, kCGPathEOFillStroke);
380 CGContextEOFillPath(context);
382 CGContextStrokePath(context);
384 CGContextRestoreGState(context);
387 void GraphicsContext::fillRect(const IntRect& rect, const Color& color)
389 if (paintingDisabled())
392 CGContextRef context = platformContext();
393 Color oldFillColor = fillColor();
394 if (oldFillColor != color)
395 setCGFillColor(context, color);
396 CGContextFillRect(context, rect);
397 if (oldFillColor != color)
398 setCGFillColor(context, oldFillColor);
402 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color)
404 if (paintingDisabled())
407 CGContextRef context = platformContext();
408 Color oldFillColor = fillColor();
409 if (oldFillColor != color)
410 setCGFillColor(context, color);
411 CGContextFillRect(context, rect);
412 if (oldFillColor != color)
413 setCGFillColor(context, oldFillColor);
417 void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color)
419 if (paintingDisabled() || !color.alpha())
422 CGContextRef context = platformContext();
423 Color oldFillColor = fillColor();
424 if (oldFillColor != color)
425 setCGFillColor(context, color);
427 addPath(Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight));
428 CGContextFillPath(context);
430 if (oldFillColor != color)
431 setCGFillColor(context, oldFillColor);
435 void GraphicsContext::clip(const IntRect& rect)
437 if (paintingDisabled())
439 CGContextClipToRect(platformContext(), rect);
443 void GraphicsContext::clipOut(const IntRect& rect)
445 if (paintingDisabled())
448 CGRect rects[2] = { CGContextGetClipBoundingBox(platformContext()), rect };
449 CGContextBeginPath(platformContext());
450 CGContextAddRects(platformContext(), rects, 2);
451 CGContextEOClip(platformContext());
454 void GraphicsContext::clipOutEllipseInRect(const IntRect& rect)
456 if (paintingDisabled())
459 CGContextBeginPath(platformContext());
460 CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext()));
461 CGContextAddEllipseInRect(platformContext(), rect);
462 CGContextEOClip(platformContext());
465 void GraphicsContext::addInnerRoundedRectClip(const IntRect& rect, int thickness)
467 if (paintingDisabled())
471 CGContextRef context = platformContext();
474 CGContextAddEllipseInRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
475 // Add inner ellipse.
476 CGContextAddEllipseInRect(context, CGRectMake(rect.x() + thickness, rect.y() + thickness,
477 rect.width() - (thickness * 2), rect.height() - (thickness * 2)));
479 CGContextEOClip(context);
482 void GraphicsContext::beginTransparencyLayer(float opacity)
484 if (paintingDisabled())
486 CGContextRef context = platformContext();
487 CGContextSaveGState(context);
488 CGContextSetAlpha(context, opacity);
489 CGContextBeginTransparencyLayer(context, 0);
490 m_data->beginTransparencyLayer();
491 m_data->m_userToDeviceTransformKnownToBeIdentity = false;
494 void GraphicsContext::endTransparencyLayer()
496 if (paintingDisabled())
498 CGContextRef context = platformContext();
499 CGContextEndTransparencyLayer(context);
500 CGContextRestoreGState(context);
501 m_data->endTransparencyLayer();
502 m_data->m_userToDeviceTransformKnownToBeIdentity = false;
505 void GraphicsContext::setShadow(const IntSize& size, int blur, const Color& color)
507 // Extreme "blur" values can make text drawing crash or take crazy long times, so clamp
508 blur = min(blur, 1000);
510 if (paintingDisabled())
512 // Check for an invalid color, as this means that the color was not set for the shadow
513 // and we should therefore just use the default shadow color.
514 CGContextRef context = platformContext();
515 if (!color.isValid())
516 CGContextSetShadow(context, CGSizeMake(size.width(), -size.height()), blur); // y is flipped.
518 CGColorRef colorCG = cgColor(color);
519 CGContextSetShadowWithColor(context,
520 CGSizeMake(size.width(), -size.height()), // y is flipped.
523 CGColorRelease(colorCG);
527 void GraphicsContext::clearShadow()
529 if (paintingDisabled())
531 CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
534 void GraphicsContext::setMiterLimit(float limit)
536 if (paintingDisabled())
538 CGContextSetMiterLimit(platformContext(), limit);
541 void GraphicsContext::setAlpha(float alpha)
543 if (paintingDisabled())
545 CGContextSetAlpha(platformContext(), alpha);
548 void GraphicsContext::clearRect(const FloatRect& r)
550 if (paintingDisabled())
552 CGContextClearRect(platformContext(), r);
555 void GraphicsContext::strokeRect(const FloatRect& r, float lineWidth)
557 if (paintingDisabled())
559 CGContextStrokeRectWithWidth(platformContext(), r, lineWidth);
562 void GraphicsContext::setLineCap(LineCap cap)
564 if (paintingDisabled())
568 CGContextSetLineCap(platformContext(), kCGLineCapButt);
571 CGContextSetLineCap(platformContext(), kCGLineCapRound);
574 CGContextSetLineCap(platformContext(), kCGLineCapSquare);
579 void GraphicsContext::setLineJoin(LineJoin join)
581 if (paintingDisabled())
585 CGContextSetLineJoin(platformContext(), kCGLineJoinMiter);
588 CGContextSetLineJoin(platformContext(), kCGLineJoinRound);
591 CGContextSetLineJoin(platformContext(), kCGLineJoinBevel);
596 void GraphicsContext::beginPath()
598 CGContextBeginPath(platformContext());
601 void GraphicsContext::addPath(const Path& path)
603 CGContextAddPath(platformContext(), path.platformPath());
606 void GraphicsContext::clip(const Path& path)
608 if (paintingDisabled())
610 CGContextRef context = platformContext();
611 CGContextBeginPath(context);
612 CGContextAddPath(context, path.platformPath());
613 CGContextClip(context);
617 void GraphicsContext::clipOut(const Path& path)
619 if (paintingDisabled())
622 CGContextBeginPath(platformContext());
623 CGContextAddRect(platformContext(), CGContextGetClipBoundingBox(platformContext()));
624 CGContextAddPath(platformContext(), path.platformPath());
625 CGContextEOClip(platformContext());
628 void GraphicsContext::scale(const FloatSize& size)
630 if (paintingDisabled())
632 CGContextScaleCTM(platformContext(), size.width(), size.height());
634 m_data->m_userToDeviceTransformKnownToBeIdentity = false;
637 void GraphicsContext::rotate(float angle)
639 if (paintingDisabled())
641 CGContextRotateCTM(platformContext(), angle);
642 m_data->rotate(angle);
643 m_data->m_userToDeviceTransformKnownToBeIdentity = false;
646 void GraphicsContext::translate(float x, float y)
648 if (paintingDisabled())
650 CGContextTranslateCTM(platformContext(), x, y);
651 m_data->translate(x, y);
652 m_data->m_userToDeviceTransformKnownToBeIdentity = false;
655 void GraphicsContext::concatCTM(const AffineTransform& transform)
657 if (paintingDisabled())
659 CGContextConcatCTM(platformContext(), transform);
660 m_data->concatCTM(transform);
661 m_data->m_userToDeviceTransformKnownToBeIdentity = false;
664 FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect)
666 // It is not enough just to round to pixels in device space. The rotation part of the
667 // affine transform matrix to device space can mess with this conversion if we have a
668 // rotating image like the hands of the world clock widget. We just need the scale, so
669 // we get the affine transform matrix and extract the scale.
671 if (m_data->m_userToDeviceTransformKnownToBeIdentity)
674 CGAffineTransform deviceMatrix = CGContextGetUserSpaceToDeviceSpaceTransform(platformContext());
675 if (CGAffineTransformIsIdentity(deviceMatrix)) {
676 m_data->m_userToDeviceTransformKnownToBeIdentity = true;
680 float deviceScaleX = sqrtf(deviceMatrix.a * deviceMatrix.a + deviceMatrix.b * deviceMatrix.b);
681 float deviceScaleY = sqrtf(deviceMatrix.c * deviceMatrix.c + deviceMatrix.d * deviceMatrix.d);
683 CGPoint deviceOrigin = CGPointMake(rect.x() * deviceScaleX, rect.y() * deviceScaleY);
684 CGPoint deviceLowerRight = CGPointMake((rect.x() + rect.width()) * deviceScaleX,
685 (rect.y() + rect.height()) * deviceScaleY);
687 deviceOrigin.x = roundf(deviceOrigin.x);
688 deviceOrigin.y = roundf(deviceOrigin.y);
689 deviceLowerRight.x = roundf(deviceLowerRight.x);
690 deviceLowerRight.y = roundf(deviceLowerRight.y);
692 // Don't let the height or width round to 0 unless either was originally 0
693 if (deviceOrigin.y == deviceLowerRight.y && rect.height() != 0)
694 deviceLowerRight.y += 1;
695 if (deviceOrigin.x == deviceLowerRight.x && rect.width() != 0)
696 deviceLowerRight.x += 1;
698 FloatPoint roundedOrigin = FloatPoint(deviceOrigin.x / deviceScaleX, deviceOrigin.y / deviceScaleY);
699 FloatPoint roundedLowerRight = FloatPoint(deviceLowerRight.x / deviceScaleX, deviceLowerRight.y / deviceScaleY);
700 return FloatRect(roundedOrigin, roundedLowerRight - roundedOrigin);
703 void GraphicsContext::drawLineForText(const IntPoint& point, int width, bool printing)
705 if (paintingDisabled())
711 CGContextSaveGState(platformContext());
715 float lineLength = width;
717 // Use a minimum thickness of 0.5 in user space.
718 // See http://bugs.webkit.org/show_bug.cgi?id=4255 for details of why 0.5 is the right minimum thickness to use.
719 float thickness = max(strokeThickness(), 0.5f);
722 // On screen, use a minimum thickness of 1.0 in user space (later rounded to an integral number in device space).
723 float adjustedThickness = max(thickness, 1.0f);
725 // FIXME: This should be done a better way.
726 // We try to round all parameters to integer boundaries in device space. If rounding pixels in device space
727 // makes our thickness more than double, then there must be a shrinking-scale factor and rounding to pixels
728 // in device space will make the underlines too thick.
729 CGRect lineRect = roundToDevicePixels(FloatRect(x, y, lineLength, adjustedThickness));
730 if (lineRect.size.height < thickness * 2.0) {
731 x = lineRect.origin.x;
732 y = lineRect.origin.y;
733 lineLength = lineRect.size.width;
734 thickness = lineRect.size.height;
735 CGContextSetShouldAntialias(platformContext(), false);
739 if (fillColor() != strokeColor())
740 setCGFillColor(platformContext(), strokeColor());
741 CGContextFillRect(platformContext(), CGRectMake(x, y, lineLength, thickness));
743 CGContextRestoreGState(platformContext());
746 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
748 if (paintingDisabled())
751 CFURLRef urlRef = link.createCFURL();
753 CGContextRef context = platformContext();
755 // Get the bounding box to handle clipping.
756 CGRect box = CGContextGetClipBoundingBox(context);
758 IntRect intBox((int)box.origin.x, (int)box.origin.y, (int)box.size.width, (int)box.size.height);
759 IntRect rect = destRect;
760 rect.intersect(intBox);
762 CGPDFContextSetURLForRect(context, urlRef,
763 CGRectApplyAffineTransform(rect, CGContextGetCTM(context)));
769 void GraphicsContext::setUseLowQualityImageInterpolation(bool lowQualityMode)
771 if (paintingDisabled())
774 CGContextSetInterpolationQuality(platformContext(), lowQualityMode ? kCGInterpolationNone : kCGInterpolationDefault);
777 bool GraphicsContext::useLowQualityImageInterpolation() const
779 if (paintingDisabled())
782 return CGContextGetInterpolationQuality(platformContext());
785 void GraphicsContext::setPlatformTextDrawingMode(int mode)
787 if (paintingDisabled())
790 // Wow, wish CG had used bits here.
791 CGContextRef context = platformContext();
793 case cTextInvisible: // Invisible
794 CGContextSetTextDrawingMode(context, kCGTextInvisible);
796 case cTextFill: // Fill
797 CGContextSetTextDrawingMode(context, kCGTextFill);
799 case cTextStroke: // Stroke
800 CGContextSetTextDrawingMode(context, kCGTextStroke);
802 case 3: // Fill | Stroke
803 CGContextSetTextDrawingMode(context, kCGTextFillStroke);
805 case cTextClip: // Clip
806 CGContextSetTextDrawingMode(context, kCGTextClip);
808 case 5: // Fill | Clip
809 CGContextSetTextDrawingMode(context, kCGTextFillClip);
811 case 6: // Stroke | Clip
812 CGContextSetTextDrawingMode(context, kCGTextStrokeClip);
814 case 7: // Fill | Stroke | Clip
815 CGContextSetTextDrawingMode(context, kCGTextFillStrokeClip);
822 void GraphicsContext::setPlatformStrokeColor(const Color& color)
824 if (paintingDisabled())
826 setCGStrokeColor(platformContext(), color);
829 void GraphicsContext::setPlatformStrokeThickness(float thickness)
831 if (paintingDisabled())
833 CGContextSetLineWidth(platformContext(), thickness);
836 void GraphicsContext::setPlatformFillColor(const Color& color)
838 if (paintingDisabled())
840 setCGFillColor(platformContext(), color);
845 #endif // PLATFORM(CG)