tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 9525f21bd79b881116d440c89cdc3c8cc1a2c09c
parent a17d30fdccc1e5f442b88787647947bcc42e97e8
Author: Jonathan Kew <jkew@mozilla.com>
Date:   Tue, 16 Dec 2025 17:57:04 +0000

Bug 2001243 - Remove usage of deprecated dwrote functions in wr_glyph_rasterizer. r=gfx-reviewers,lsalzman

Since we updated the dwrote crate in bug 2000190, we can switch to newer versions
of these functions that return failures to the caller instead of just panic!()ing
in the event of a DirectWrite error.

I'm not sure how well we handle such failures -- we'll probably end up rendering
garbled text in cases where an expected font fails to load -- but that's preferable
to completely crashing the GPU process.

Differential Revision: https://phabricator.services.mozilla.com/D276688

Diffstat:
Mgfx/wr/wr_glyph_rasterizer/src/platform/windows/font.rs | 64+++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 35 insertions(+), 29 deletions(-)

diff --git a/gfx/wr/wr_glyph_rasterizer/src/platform/windows/font.rs b/gfx/wr/wr_glyph_rasterizer/src/platform/windows/font.rs @@ -155,13 +155,16 @@ impl FontContext { fn add_font_descriptor(&mut self, font_key: &FontKey, desc: &dwrote::FontDescriptor) { let system_fc = dwrote::FontCollection::get_system(false); - #[allow(deprecated)] - if let Some(font) = system_fc.get_font_from_descriptor(desc) { - let face = font.create_font_face(); - #[allow(deprecated)] - let file = face.get_files().pop().unwrap(); - let index = face.get_index(); - self.fonts.insert(*font_key, FontFace { cached: None, file, index, face }); + if let Ok(font) = system_fc.font_from_descriptor(desc) { + if let Some(font) = font { + let face = font.create_font_face(); + if let Ok(mut files) = face.files() { + if let Some(file) = files.pop() { + let index = face.get_index(); + self.fonts.insert(*font_key, FontFace { cached: None, file, index, face }); + } + } + } } } @@ -170,8 +173,7 @@ impl FontContext { return; } - #[allow(deprecated)] - if let Some(file) = dwrote::FontFile::new_from_data(data) { + if let Some(file) = dwrote::FontFile::new_from_buffer(data) { if let Ok(face) = file.create_face(index, dwrote::DWRITE_FONT_SIMULATIONS_NONE) { self.fonts.insert(*font_key, FontFace { cached: None, file, index, face }); return; @@ -370,9 +372,10 @@ impl FontContext { pub fn get_glyph_index(&mut self, font_key: FontKey, ch: char) -> Option<u32> { let face = &self.fonts.get(&font_key).unwrap().face; - #[allow(deprecated)] - let indices = face.get_glyph_indices(&[ch as u32]); - indices.first().map(|idx| *idx as u32) + if let Ok(indices) = face.glyph_indices(&[ch as u32]) { + return indices.first().map(|idx| *idx as u32); + } + None } pub fn get_glyph_dimensions( @@ -401,23 +404,26 @@ impl FontContext { let extra_width = extra_strikes as f64 * pixel_step; let face = self.get_font_face(font); - #[allow(deprecated)] - face.get_design_glyph_metrics(&[key.index() as u16], false) - .first() - .map(|metrics| { - let em_size = size / 16.; - let design_units_per_pixel = face.metrics().metrics0().designUnitsPerEm as f32 / 16. as f32; - let scaled_design_units_to_pixels = em_size / design_units_per_pixel; - let advance = metrics.advanceWidth as f32 * scaled_design_units_to_pixels; - - GlyphDimensions { - left: bounds.left, - top: -bounds.top, - width: width + extra_width.ceil() as i32, - height, - advance: advance + extra_width as f32, - } - }) + if let Ok(metrics) = face.design_glyph_metrics(&[key.index() as u16], false) { + return metrics + .first() + .map(|metrics| { + let em_size = size / 16.; + let design_units_per_pixel = face.metrics().metrics0().designUnitsPerEm as f32 / 16. as f32; + let scaled_design_units_to_pixels = em_size / design_units_per_pixel; + let advance = metrics.advanceWidth as f32 * scaled_design_units_to_pixels; + + GlyphDimensions { + left: bounds.left, + top: -bounds.top, + width: width + extra_width.ceil() as i32, + height, + advance: advance + extra_width as f32, + } + }); + } + + None } // DWrite ClearType gives us values in RGB, but WR expects BGRA.