From 74ac0a9651931a57d917c7eb83c21447a64cf7c6 Mon Sep 17 00:00:00 2001 From: fschutt Date: Sat, 28 Apr 2018 11:08:54 +0200 Subject: [PATCH] Fix From conversion from NativeFontHandleWrapper to PathfinderComPtr See https://github.com/pcwalton/pathfinder/pull/81 and https://github.com/servo/webrender/issues/2645 - this fixes 1 compile error, where we can't convert from a NativeFontHandleWrapper to a ComPtr. We need this, so that PathfinderFontContext::add_native_font() works correctly. --- webrender/src/glyph_rasterizer.rs | 2 +- webrender/src/platform/windows/font.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/webrender/src/glyph_rasterizer.rs b/webrender/src/glyph_rasterizer.rs index 7185d73c62..772c47638f 100644 --- a/webrender/src/glyph_rasterizer.rs +++ b/webrender/src/glyph_rasterizer.rs @@ -1076,4 +1076,4 @@ fn request_render_task_from_pathfinder(glyph_key: &GlyphKey, } #[cfg(feature = "pathfinder")] -pub struct NativeFontHandleWrapper<'a>(pub &'a NativeFontHandle); +pub struct NativeFontHandleWrapper<'a>(pub &'a NativeFontHandle); \ No newline at end of file diff --git a/webrender/src/platform/windows/font.rs b/webrender/src/platform/windows/font.rs index 08a6e25f9a..d4c3476d4a 100644 --- a/webrender/src/platform/windows/font.rs +++ b/webrender/src/platform/windows/font.rs @@ -11,6 +11,10 @@ use glyph_rasterizer::{GlyphRasterResult, RasterizedGlyph}; use internal_types::{FastHashMap, ResourceCacheError}; use std::collections::hash_map::Entry; use std::sync::Arc; +#[cfg(feature = "pathfinder")] +use pathfinder_font_renderer::{PathfinderComPtr, IDWriteFontFace}; +#[cfg(feature = "pathfinder")] +use glyph_rasterizer::NativeFontHandleWrapper; lazy_static! { static ref DEFAULT_FONT_DESCRIPTOR: dwrote::FontDescriptor = dwrote::FontDescriptor { @@ -439,3 +443,16 @@ impl FontContext { }) } } + +#[cfg(feature = "pathfinder")] +impl<'a> From> for PathfinderComPtr { + fn from(font_handle: NativeFontHandleWrapper<'a>) -> Self { + let system_fc = ::dwrote::FontCollection::system(); + let font = match system_fc.get_font_from_descriptor(&font_handle.0) { + Some(font) => font, + None => panic!("missing descriptor {:?}", font_handle.0), + }; + let face = font.create_font_face(); + PathfinderComPtr::new(face.as_ptr()) + } +} \ No newline at end of file