Skip to content

Commit

Permalink
Auto merge of #106 - NatalyaKovalova:Font, r=jdm
Browse files Browse the repository at this point in the history
Added font copy creation with variations

Is required for Servo's Webrender to up Core Graphics's version there and port Webrender to iOS.

@larsbergstrom

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-graphics-rs/106)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Nov 17, 2017
2 parents 956f58d + 5c4334c commit 8b4364a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use core_foundation::base::{CFRelease, CFRetain, CFTypeID, TCFType};
use core_foundation::string::{CFString, CFStringRef};
use core_foundation::dictionary::{CFDictionary, CFDictionaryRef};
use data_provider::CGDataProvider;
use geometry::CGRect;

Expand Down Expand Up @@ -59,6 +60,18 @@ impl CGFont {
}
}

pub fn create_copy_from_variations(&self, vars: &CFDictionary) -> Result<CGFont, ()> {
unsafe {
let font_ref = CGFontCreateCopyWithVariations(self.as_ptr(),
vars.as_concrete_TypeRef());
if !font_ref.is_null() {
Ok(CGFont::from_ptr(font_ref))
} else {
Err(())
}
}
}

pub fn postscript_name(&self) -> CFString {
unsafe {
let string_ref = CGFontCopyPostScriptName(self.as_ptr());
Expand Down Expand Up @@ -98,6 +111,7 @@ extern {
// TODO: basically nothing has bindings (even commented-out) besides what we use.
fn CGFontCreateWithDataProvider(provider: ::sys::CGDataProviderRef) -> ::sys::CGFontRef;
fn CGFontCreateWithFontName(name: CFStringRef) -> ::sys::CGFontRef;
fn CGFontCreateCopyWithVariations(font: ::sys::CGFontRef, vars: CFDictionaryRef) -> ::sys::CGFontRef;
fn CGFontGetTypeID() -> CFTypeID;

fn CGFontCopyPostScriptName(font: ::sys::CGFontRef) -> CFStringRef;
Expand Down

0 comments on commit 8b4364a

Please sign in to comment.