Merge pull request #81 from fschutt/fix_compile_windows

Fix the API of glyph_dimensions to make webrender compile on Windows
This commit is contained in:
Patrick Walton 2018-04-27 08:41:10 -07:00 committed by GitHub
commit 2701757e29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 6 deletions

View File

@ -22,6 +22,7 @@ use std::iter::Cloned;
use std::mem;
use std::os::raw::c_void;
use std::ptr;
use std::collections::btree_map::Entry;
use std::slice::{self, Iter};
use std::sync::Arc;
use uuid::IID_ID2D1SimplifiedGeometrySink;
@ -36,7 +37,8 @@ use winapi::{IDWriteFontFileLoader, IDWriteFontFileLoaderVtbl, IDWriteFontFileSt
use winapi::{IDWriteFontFileStreamVtbl, IDWriteGeometrySink, IUnknown, IUnknownVtbl, TRUE, UINT16};
use winapi::{UINT32, UINT64, UINT};
use self::com::{PathfinderCoclass, PathfinderComObject, PathfinderComPtr};
use self::com::{PathfinderCoclass, PathfinderComObject};
pub use self::com::{PathfinderComPtr};
use {FontInstance, GlyphDimensions, GlyphImage, GlyphKey};
mod com;
@ -178,6 +180,19 @@ impl<FK> FontContext<FK> where FK: Clone + Hash + Eq + Ord {
}
}
/// Loads an OpenType font from a COM `IDWriteFontFace` handle.
pub fn add_native_font<H>(&mut self, font_key: &FK, handle: H) -> Result<(), ()>
where H: Into<PathfinderComPtr<IDWriteFontFace>>
{
match self.dwrite_font_faces.entry((*font_key).clone()) {
Entry::Occupied(_) => Ok(()),
Entry::Vacant(entry) => {
entry.insert(handle.into());
Ok(())
}
}
}
/// Unloads the font with the given font key from memory.
///
/// If the font isn't loaded, does nothing.
@ -193,11 +208,14 @@ impl<FK> FontContext<FK> where FK: Clone + Hash + Eq + Ord {
/// libraries (including Pathfinder) apply modifications to the outlines: for example, to
/// dilate them for easier reading. To retrieve extents that account for these modifications,
/// set `exact` to false.
pub fn glyph_dimensions(&self, font_instance: &FontInstance<FK>, glyph_key: &GlyphKey)
-> Option<GlyphDimensions> {
pub fn glyph_dimensions(&self,
font_instance: &FontInstance<FK>,
glyph_key: &GlyphKey,
_exact: bool)
-> Result<GlyphDimensions, ()> {
unsafe {
let font_face = match self.dwrite_font_faces.get(&font_instance.font_key) {
None => return None,
None => return Err(()),
Some(font_face) => (*font_face).clone(),
};
@ -206,10 +224,10 @@ impl<FK> FontContext<FK> where FK: Clone + Hash + Eq + Ord {
let result = (**font_face).GetDesignGlyphMetrics(&glyph_index, 1, &mut metrics, FALSE);
if !winerror::SUCCEEDED(result) {
return None
return Err(());
}
Some(GlyphDimensions {
Ok(GlyphDimensions {
advance: metrics.advanceWidth as f32,
origin: Point2D::new(metrics.leftSideBearing, metrics.bottomSideBearing),
size: Size2D::new((metrics.rightSideBearing - metrics.leftSideBearing) as u32,

View File

@ -53,6 +53,11 @@ extern crate uuid;
#[macro_use(DEFINE_GUID)]
extern crate winapi;
#[cfg(target_os = "windows")]
pub use self::directwrite::PathfinderComPtr;
#[cfg(target_os = "windows")]
pub use winapi::IDWriteFontFace;
use app_units::Au;
use euclid::{Point2D, Size2D};