From d072ab30afe60ebb27b93453eccff7fed198873a Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 16 Oct 2015 17:29:05 -0700 Subject: [PATCH] Add support for fill colors and font AA. Also, mark Core Graphics contexts as `Send` and `Sync` since (I believe) they are thread-safe. --- src/context.rs | 26 ++++++++++++++++++++++++++ src/font.rs | 3 +++ 2 files changed, 29 insertions(+) diff --git a/src/context.rs b/src/context.rs index 38653c7..c37fe2a 100644 --- a/src/context.rs +++ b/src/context.rs @@ -7,6 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use base::CGFloat; use color_space::{CGColorSpace, CGColorSpaceRef}; use core_foundation::base::{CFRelease, CFRetain, CFTypeID, CFTypeRef, TCFType}; use libc::{c_void, size_t}; @@ -118,6 +119,24 @@ impl CGContext { CGBitmapContextGetBytesPerRow(self.as_concrete_TypeRef()) } } + + pub fn set_rgb_fill_color(&self, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { + unsafe { + CGContextSetRGBFillColor(self.as_concrete_TypeRef(), red, green, blue, alpha) + } + } + + pub fn set_allows_font_smoothing(&self, allows_font_smoothing: bool) { + unsafe { + CGContextSetAllowsFontSmoothing(self.as_concrete_TypeRef(), allows_font_smoothing) + } + } + + pub fn set_should_smooth_fonts(&self, should_smooth_fonts: bool) { + unsafe { + CGContextSetShouldSmoothFonts(self.as_concrete_TypeRef(), should_smooth_fonts) + } + } } #[link(name = "ApplicationServices", kind = "framework")] @@ -135,5 +154,12 @@ extern { fn CGBitmapContextGetHeight(context: CGContextRef) -> size_t; fn CGBitmapContextGetBytesPerRow(context: CGContextRef) -> size_t; fn CGContextGetTypeID() -> CFTypeID; + fn CGContextSetAllowsFontSmoothing(c: CGContextRef, allowsFontSmoothing: bool); + fn CGContextSetShouldSmoothFonts(c: CGContextRef, shouldSmoothFonts: bool); + fn CGContextSetRGBFillColor(context: CGContextRef, + red: CGFloat, + green: CGFloat, + blue: CGFloat, + alpha: CGFloat); } diff --git a/src/font.rs b/src/font.rs index ca2449e..8fcf21f 100644 --- a/src/font.rs +++ b/src/font.rs @@ -25,6 +25,9 @@ pub struct CGFont { obj: CGFontRef, } +unsafe impl Send for CGFont {} +unsafe impl Sync for CGFont {} + impl Clone for CGFont { #[inline] fn clone(&self) -> CGFont {