mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Switch to use CGFont binding. Give out the same CGFont for each new ScaledFont. Closes #152. Closes #184.
This commit is contained in:
parent
786746d3c6
commit
7fbba0b441
6 changed files with 18 additions and 25 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 8db099ac74ddb4e416eef8f2d237d4ec47787fbe
|
||||
Subproject commit 55b0d15f154986d85a53893e198ab6c750c0b728
|
|
@ -1 +1 @@
|
|||
Subproject commit 04c0856f7d3e3c600463c0a205556c65bf74bdf3
|
||||
Subproject commit eec9e9f417d2efad4710e6fa601030810fe92a4e
|
|
@ -1 +1 @@
|
|||
Subproject commit 55de520630efbaef7de03832b6d3621d2b4b4d29
|
||||
Subproject commit c413a96a8c6b70815b4d5ad7469c7983af417728
|
|
@ -1 +1 @@
|
|||
Subproject commit ea18d1d47385d64f6a7938c4a9e68423084c9657
|
||||
Subproject commit 2b306ea65aaa348ec3158588fa78779fd4a1629b
|
|
@ -355,9 +355,9 @@ impl Font {
|
|||
|
||||
#[cfg(target_os="macos")]
|
||||
priv fn create_azure_font() -> ScaledFont {
|
||||
let ct_font = &self.handle.ctfont;
|
||||
let cg_font = self.handle.get_CGFont();
|
||||
let size = self.style.pt_size as AzFloat;
|
||||
ScaledFont::new(self.backend, ct_font, size)
|
||||
ScaledFont::new(self.backend, &cg_font, size)
|
||||
}
|
||||
|
||||
#[cfg(target_os="linux")]
|
||||
|
|
|
@ -6,6 +6,7 @@ use cf = core_foundation;
|
|||
use cf::base::{
|
||||
CFIndex,
|
||||
CFTypeRef,
|
||||
CFWrapper,
|
||||
};
|
||||
use cf::data::{CFData, CFDataRef};
|
||||
use cf::string::UniChar;
|
||||
|
@ -13,7 +14,7 @@ use cg = core_graphics;
|
|||
|
||||
use cg::base::{CGFloat, CGAffineTransform};
|
||||
use cg::data_provider::{CGDataProviderRef, CGDataProvider};
|
||||
use cg::font::{CGFontCreateWithDataProvider, CGFontRef, CGFontRelease, CGGlyph};
|
||||
use cg::font::{CGFont, CGFontRef, CGGlyph};
|
||||
use cg::geometry::CGRect;
|
||||
|
||||
use ct = core_text;
|
||||
|
@ -65,32 +66,24 @@ pub impl QuartzFontTable : FontTableMethods {
|
|||
}
|
||||
|
||||
pub struct QuartzFontHandle {
|
||||
priv mut cgfont: Option<CGFontRef>,
|
||||
priv mut cgfont: Option<CGFont>,
|
||||
ctfont: CTFont,
|
||||
|
||||
drop {
|
||||
// TODO(Issue #152): use a wrapped CGFont.
|
||||
do (copy self.cgfont).iter |cgfont| {
|
||||
assert cgfont.is_not_null();
|
||||
CGFontRelease(*cgfont);
|
||||
}
|
||||
}
|
||||
drop { }
|
||||
}
|
||||
|
||||
pub impl QuartzFontHandle {
|
||||
static fn new_from_buffer(_fctx: &QuartzFontContextHandle, buf: ~[u8],
|
||||
style: &SpecifiedFontStyle) -> Result<QuartzFontHandle, ()> {
|
||||
let fontprov = vec::as_imm_buf(buf, |cbuf, len| {
|
||||
let fontprov : CGDataProvider = vec::as_imm_buf(buf, |cbuf, len| {
|
||||
cg::data_provider::new_from_buffer(cbuf, len)
|
||||
});
|
||||
|
||||
let cgfont = CGFontCreateWithDataProvider(*fontprov.borrow_ref());
|
||||
if cgfont.is_null() { return Err(()); }
|
||||
|
||||
let ctfont = ct::font::new_from_CGFont(cgfont, style.pt_size);
|
||||
let cgfont = cg::font::create_with_data_provider(&fontprov);
|
||||
let ctfont = ct::font::new_from_CGFont(&cgfont, style.pt_size);
|
||||
|
||||
let result = Ok(QuartzFontHandle {
|
||||
cgfont : Some(cgfont),
|
||||
cgfont : Some(move cgfont),
|
||||
ctfont : move ctfont,
|
||||
});
|
||||
|
||||
|
@ -106,13 +99,13 @@ pub impl QuartzFontHandle {
|
|||
return move result;
|
||||
}
|
||||
|
||||
fn get_CGFont() -> CGFontRef {
|
||||
fn get_CGFont() -> CGFont {
|
||||
match self.cgfont {
|
||||
Some(cg) => cg,
|
||||
Some(ref font) => move CFWrapper::wrap_shared(*font.borrow_ref()),
|
||||
None => {
|
||||
let cgfont = self.ctfont.copy_to_CGFont();
|
||||
self.cgfont = Some(cgfont);
|
||||
cgfont
|
||||
self.cgfont = Some(CFWrapper::clone(&cgfont));
|
||||
move cgfont
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue