Skip to content

Commit d4efb3c

Browse files
author
bors-servo
authored
Auto merge of #5 - lsalzman:font-face-simulations, r=glennw
add create_font_face_with_simulations to FontFace This is needed to be able to support synthetic bold on an arbitrary font face in WebRender, without which we can't properly support bold for many bitmapped Asian fonts.
2 parents bb40022 + dbbb7c4 commit d4efb3c

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "dwrote"
33
description = "Lightweight binding to DirectWrite."
44
repository = "https://github.com/servo/dwrote-rs"
55
license = "MPL-2.0"
6-
version = "0.4.0"
6+
version = "0.4.1"
77
authors = ["Vladimir Vukicevic <[email protected]>"]
88

99
[lib]

src/font_face.rs

+35-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::cell::UnsafeCell;
88
use std::mem::zeroed;
99

1010
use comptr::ComPtr;
11-
use super::{FontMetrics, FontFile, DefaultDWriteRenderParams};
11+
use super::{FontMetrics, FontFile, DefaultDWriteRenderParams, DWriteFactory};
1212

1313
use winapi;
1414

@@ -35,18 +35,44 @@ impl FontFace {
3535
(*self.native.get()).as_ptr()
3636
}
3737

38+
unsafe fn get_raw_files(&self) -> Vec<*mut winapi::IDWriteFontFile> {
39+
let mut number_of_files: u32 = 0;
40+
let hr = (*self.native.get()).GetFiles(&mut number_of_files, ptr::null_mut());
41+
assert!(hr == 0);
42+
43+
let mut file_ptrs: Vec<*mut winapi::IDWriteFontFile> =
44+
vec![ptr::null_mut(); number_of_files as usize];
45+
let hr = (*self.native.get()).GetFiles(&mut number_of_files, file_ptrs.as_mut_ptr());
46+
assert!(hr == 0);
47+
file_ptrs
48+
}
49+
3850
pub fn get_files(&self) -> Vec<FontFile> {
3951
unsafe {
40-
let mut number_of_files: u32 = 0;
41-
let hr = (*self.native.get()).GetFiles(&mut number_of_files, ptr::null_mut());
42-
assert!(hr == 0);
52+
let file_ptrs = self.get_raw_files();
53+
file_ptrs.iter().map(|p| FontFile::take(ComPtr::already_addrefed(*p))).collect()
54+
}
55+
}
4356

44-
let mut file_ptrs: Vec<*mut winapi::IDWriteFontFile> =
45-
vec![ptr::null_mut(); number_of_files as usize];
46-
let hr = (*self.native.get()).GetFiles(&mut number_of_files, file_ptrs.as_mut_ptr());
57+
pub fn create_font_face_with_simulations(&self, simulations: winapi::DWRITE_FONT_SIMULATIONS) -> FontFace {
58+
unsafe {
59+
let file_ptrs = self.get_raw_files();
60+
let face_type = (*self.native.get()).GetType();
61+
let face_index = (*self.native.get()).GetIndex();
62+
let mut face: ComPtr<winapi::IDWriteFontFace> = ComPtr::new();
63+
let hr = (*DWriteFactory()).CreateFontFace(
64+
face_type,
65+
file_ptrs.len() as u32,
66+
file_ptrs.as_ptr(),
67+
face_index,
68+
simulations,
69+
face.getter_addrefs()
70+
);
71+
for p in file_ptrs {
72+
let _ = ComPtr::<winapi::IDWriteFontFile>::already_addrefed(p);
73+
}
4774
assert!(hr == 0);
48-
49-
file_ptrs.iter().map(|p| FontFile::take(ComPtr::already_addrefed(*p))).collect()
75+
FontFace::take(face)
5076
}
5177
}
5278

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub use winapi::{DWRITE_FONT_SIMULATIONS_NONE,
5757
DWRITE_FONT_SIMULATIONS_BOLD,
5858
DWRITE_FONT_SIMULATIONS_OBLIQUE};
5959
pub use winapi::{DWRITE_TEXTURE_ALIASED_1x1, DWRITE_TEXTURE_CLEARTYPE_3x1};
60+
pub use winapi::{DWRITE_FONT_SIMULATIONS};
6061
pub use winapi::{DWRITE_RENDERING_MODE};
6162
pub use winapi::{DWRITE_MEASURING_MODE};
6263
pub use winapi::{DWRITE_TEXTURE_TYPE};

0 commit comments

Comments
 (0)