Skip to content

Commit b984e11

Browse files
author
bors-servo
authored
Auto merge of #30 - lsalzman:new-from-path-analysis, r=jrmuizel
make FontFile::new_from_path analyze the font This is necessary to resolve Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1455848 We need to switch over to using paths instead of descriptors, but FontFile::new_from_path does not call analyze() such that create_face() will always fail. This fixes that.
2 parents 1ed6bc5 + cc439a2 commit b984e11

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
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.7.0"
6+
version = "0.8.0"
77
authors = ["Vladimir Vukicevic <vladimir@pobox.com>"]
88

99
[lib]

src/font_file.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use winapi::um::dwrite::{IDWriteFontFace, IDWriteFontFile, IDWriteFontFileStream
2121
use winapi::um::dwrite::{IDWriteFontFileLoader, IDWriteLocalFontFileLoader};
2222
use winapi::um::dwrite::{DWRITE_FONT_SIMULATIONS, DWRITE_FONT_FACE_TYPE_UNKNOWN};
2323
use winapi::um::dwrite::{DWRITE_FONT_FACE_TYPE, DWRITE_FONT_FILE_TYPE_UNKNOWN};
24+
use winapi::um::winnt::HRESULT;
2425

2526
use font_file_loader_impl::DataFontHelper;
2627
use font_face::FontFace;
@@ -47,12 +48,18 @@ impl FontFile {
4748
return None
4849
}
4950

50-
Some(FontFile {
51+
let mut ff = FontFile {
5152
native: UnsafeCell::new(font_file),
5253
stream: UnsafeCell::new(None),
5354
data_key: 0,
5455
face_type: DWRITE_FONT_FACE_TYPE_UNKNOWN,
55-
})
56+
};
57+
58+
if ff.analyze() == 0 {
59+
None
60+
} else {
61+
Some(ff)
62+
}
5663
}
5764
}
5865

@@ -204,14 +211,20 @@ impl FontFile {
204211
}
205212
}
206213

207-
pub fn create_face(&self, face_index: u32, simulations: DWRITE_FONT_SIMULATIONS) -> FontFace {
214+
pub fn create_face(&self,
215+
face_index: u32,
216+
simulations: DWRITE_FONT_SIMULATIONS,
217+
) -> Result<FontFace, HRESULT> {
208218
unsafe {
209219
let mut face: ComPtr<IDWriteFontFace> = ComPtr::new();
210220
let ptr = self.as_com_ptr();
211221
let hr = (*DWriteFactory()).CreateFontFace(self.face_type, 1, &ptr.as_ptr(),
212222
face_index, simulations, face.getter_addrefs());
213-
assert!(hr == 0);
214-
FontFace::take(face)
223+
if hr != 0 {
224+
Err(hr)
225+
} else {
226+
Ok(FontFace::take(face))
227+
}
215228
}
216229
}
217230
}

0 commit comments

Comments
 (0)