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:
commit
2701757e29
|
@ -22,6 +22,7 @@ use std::iter::Cloned;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use std::collections::btree_map::Entry;
|
||||||
use std::slice::{self, Iter};
|
use std::slice::{self, Iter};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use uuid::IID_ID2D1SimplifiedGeometrySink;
|
use uuid::IID_ID2D1SimplifiedGeometrySink;
|
||||||
|
@ -36,7 +37,8 @@ use winapi::{IDWriteFontFileLoader, IDWriteFontFileLoaderVtbl, IDWriteFontFileSt
|
||||||
use winapi::{IDWriteFontFileStreamVtbl, IDWriteGeometrySink, IUnknown, IUnknownVtbl, TRUE, UINT16};
|
use winapi::{IDWriteFontFileStreamVtbl, IDWriteGeometrySink, IUnknown, IUnknownVtbl, TRUE, UINT16};
|
||||||
use winapi::{UINT32, UINT64, UINT};
|
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};
|
use {FontInstance, GlyphDimensions, GlyphImage, GlyphKey};
|
||||||
|
|
||||||
mod com;
|
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.
|
/// Unloads the font with the given font key from memory.
|
||||||
///
|
///
|
||||||
/// If the font isn't loaded, does nothing.
|
/// 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
|
/// libraries (including Pathfinder) apply modifications to the outlines: for example, to
|
||||||
/// dilate them for easier reading. To retrieve extents that account for these modifications,
|
/// dilate them for easier reading. To retrieve extents that account for these modifications,
|
||||||
/// set `exact` to false.
|
/// set `exact` to false.
|
||||||
pub fn glyph_dimensions(&self, font_instance: &FontInstance<FK>, glyph_key: &GlyphKey)
|
pub fn glyph_dimensions(&self,
|
||||||
-> Option<GlyphDimensions> {
|
font_instance: &FontInstance<FK>,
|
||||||
|
glyph_key: &GlyphKey,
|
||||||
|
_exact: bool)
|
||||||
|
-> Result<GlyphDimensions, ()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let font_face = match self.dwrite_font_faces.get(&font_instance.font_key) {
|
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(),
|
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);
|
let result = (**font_face).GetDesignGlyphMetrics(&glyph_index, 1, &mut metrics, FALSE);
|
||||||
if !winerror::SUCCEEDED(result) {
|
if !winerror::SUCCEEDED(result) {
|
||||||
return None
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(GlyphDimensions {
|
Ok(GlyphDimensions {
|
||||||
advance: metrics.advanceWidth as f32,
|
advance: metrics.advanceWidth as f32,
|
||||||
origin: Point2D::new(metrics.leftSideBearing, metrics.bottomSideBearing),
|
origin: Point2D::new(metrics.leftSideBearing, metrics.bottomSideBearing),
|
||||||
size: Size2D::new((metrics.rightSideBearing - metrics.leftSideBearing) as u32,
|
size: Size2D::new((metrics.rightSideBearing - metrics.leftSideBearing) as u32,
|
||||||
|
|
|
@ -53,6 +53,11 @@ extern crate uuid;
|
||||||
#[macro_use(DEFINE_GUID)]
|
#[macro_use(DEFINE_GUID)]
|
||||||
extern crate winapi;
|
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 app_units::Au;
|
||||||
use euclid::{Point2D, Size2D};
|
use euclid::{Point2D, Size2D};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue