From 74f8c9b9efdb0aa9ccf3bd8ca0649d67154fd667 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 23 Feb 2015 10:00:42 +0000 Subject: [PATCH] Added some initialisation to the CoreGraphics context to counteract hosts that disable font anti-aliasing. --- .../native/juce_mac_CoreGraphicsContext.mm | 31 ++++++++----------- .../native/juce_mac_CoreGraphicsHelpers.h | 8 ++--- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm index b1920861f5..ac7f27a04a 100644 --- a/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm +++ b/modules/juce_graphics/native/juce_mac_CoreGraphicsContext.mm @@ -25,7 +25,7 @@ #include "juce_mac_CoreGraphicsContext.h" //============================================================================== -class CoreGraphicsImage : public ImagePixelData +class CoreGraphicsImage : public ImagePixelData { public: CoreGraphicsImage (const Image::PixelFormat format, const int w, const int h, const bool clearImage) @@ -174,6 +174,7 @@ CoreGraphicsContext::CoreGraphicsContext (CGContextRef c, const float h, const f CGContextRetain (context); CGContextSaveGState(context); CGContextSetShouldSmoothFonts (context, true); + CGContextSetAllowsFontSmoothing (context, true); CGContextSetShouldAntialias (context, true); CGContextSetBlendMode (context, kCGBlendModeNormal); rgbColourSpace = CGColorSpaceCreateDeviceRGB(); @@ -215,8 +216,6 @@ float CoreGraphicsContext::getPhysicalPixelScaleFactor() const CGAffineTransform t = CGContextGetCTM (context); return targetScale * (float) (juce_hypot (t.a, t.c) + juce_hypot (t.b, t.d)) / 2.0f; - -// return targetScale * (float) (t.a + t.d) / 2.0f; } bool CoreGraphicsContext::clipToRectangle (const Rectangle& r) @@ -245,19 +244,17 @@ bool CoreGraphicsContext::clipToRectangleListWithoutTest (const RectangleList(); return false; } - else - { - const size_t numRects = (size_t) clipRegion.getNumRectangles(); - HeapBlock rects (numRects); - int i = 0; - for (const Rectangle* r = clipRegion.begin(), * const e = clipRegion.end(); r != e; ++r) - rects[i++] = CGRectMake (r->getX(), flipHeight - r->getBottom(), r->getWidth(), r->getHeight()); + const size_t numRects = (size_t) clipRegion.getNumRectangles(); + HeapBlock rects (numRects); - CGContextClipToRects (context, rects, numRects); - lastClipRectIsValid = false; - return true; - } + int i = 0; + for (const Rectangle* r = clipRegion.begin(), * const e = clipRegion.end(); r != e; ++r) + rects[i++] = CGRectMake (r->getX(), flipHeight - r->getBottom(), r->getWidth(), r->getHeight()); + + CGContextClipToRects (context, rects, numRects); + lastClipRectIsValid = false; + return true; } bool CoreGraphicsContext::clipToRectangleList (const RectangleList& clipRegion) @@ -752,9 +749,8 @@ void CoreGraphicsContext::drawGradient() void CoreGraphicsContext::createPath (const Path& path) const { CGContextBeginPath (context); - Path::Iterator i (path); - while (i.next()) + for (Path::Iterator i (path); i.next();) { switch (i.elementType) { @@ -771,9 +767,8 @@ void CoreGraphicsContext::createPath (const Path& path) const void CoreGraphicsContext::createPath (const Path& path, const AffineTransform& transform) const { CGContextBeginPath (context); - Path::Iterator i (path); - while (i.next()) + for (Path::Iterator i (path); i.next();) { switch (i.elementType) { diff --git a/modules/juce_graphics/native/juce_mac_CoreGraphicsHelpers.h b/modules/juce_graphics/native/juce_mac_CoreGraphicsHelpers.h index ca6f699268..bc9e66bd33 100644 --- a/modules/juce_graphics/native/juce_mac_CoreGraphicsHelpers.h +++ b/modules/juce_graphics/native/juce_mac_CoreGraphicsHelpers.h @@ -30,25 +30,25 @@ namespace { template - Rectangle convertToRectInt (const RectType& r) noexcept + Rectangle convertToRectInt (RectType r) noexcept { return Rectangle ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height); } template - Rectangle convertToRectFloat (const RectType& r) noexcept + Rectangle convertToRectFloat (RectType r) noexcept { return Rectangle (r.origin.x, r.origin.y, r.size.width, r.size.height); } template - CGRect convertToCGRect (const RectType& r) noexcept + CGRect convertToCGRect (RectType r) noexcept { return CGRectMake ((CGFloat) r.getX(), (CGFloat) r.getY(), (CGFloat) r.getWidth(), (CGFloat) r.getHeight()); } template - CGPoint convertToCGPoint (const PointType& p) noexcept + CGPoint convertToCGPoint (PointType p) noexcept { return CGPointMake ((CGFloat) p.x, (CGFloat) p.y); }