iOS support
This commit is contained in:
parent
2e5b70805f
commit
0a1adb0e18
|
@ -23,7 +23,7 @@ features = ["serde"]
|
|||
version = "0.4"
|
||||
optional = true
|
||||
|
||||
[target.'cfg(not(target_os = "macos"))'.dependencies]
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "ios")))'.dependencies]
|
||||
freetype = { version = "0.4" }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
//! Font loading using macOS Core Graphics/Quartz.
|
||||
|
||||
use core_graphics_sys::base::{kCGImageAlphaNoneSkipFirst, kCGBitmapByteOrder32Little};
|
||||
use core_graphics_sys::base::{CGFloat, kCGImageAlphaNoneSkipFirst, kCGBitmapByteOrder32Little};
|
||||
use core_graphics_sys::color_space::CGColorSpace;
|
||||
use core_graphics_sys::context::{CGContext, CGTextDrawingMode};
|
||||
use core_graphics_sys::data_provider::CGDataProvider;
|
||||
|
@ -45,7 +45,7 @@ const CG_ZERO_RECT: CGRect = CGRect {
|
|||
// direction.
|
||||
const FONT_DILATION_AMOUNT: f32 = 0.02;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
#[derive(Clone)]
|
||||
pub struct NativeFontHandle(pub CGFont);
|
||||
|
||||
|
@ -164,7 +164,7 @@ impl<FK> FontContext<FK> where FK: Clone + Hash + Eq + Ord {
|
|||
|
||||
// Round out to pixel boundaries.
|
||||
let units_per_em = core_graphics_font.get_units_per_em();
|
||||
let scale = font_instance.size.to_f64_px() / (units_per_em as f64);
|
||||
let scale = (font_instance.size.to_f64_px() as CGFloat) / (units_per_em as CGFloat);
|
||||
let bounding_box =
|
||||
Rect::new(Point2D::new(bounding_boxes[0].origin.x,
|
||||
bounding_boxes[0].origin.y),
|
||||
|
@ -287,8 +287,8 @@ impl<FK> FontContext<FK> where FK: Clone + Hash + Eq + Ord {
|
|||
core_graphics_context.fill_rect(CGRect {
|
||||
origin: CG_ZERO_POINT,
|
||||
size: CGSize {
|
||||
width: dimensions.size.width as f64,
|
||||
height: dimensions.size.height as f64,
|
||||
width: dimensions.size.width as CGFloat,
|
||||
height: dimensions.size.height as CGFloat,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -298,14 +298,14 @@ impl<FK> FontContext<FK> where FK: Clone + Hash + Eq + Ord {
|
|||
|
||||
// Set up the font.
|
||||
core_graphics_context.set_font(core_graphics_font);
|
||||
core_graphics_context.set_font_size(font_instance.size.to_f64_px());
|
||||
core_graphics_context.set_font_size(font_instance.size.to_f64_px() as CGFloat);
|
||||
|
||||
// Compute the rasterization origin.
|
||||
// TODO(pcwalton): Vertical subpixel positioning.
|
||||
let subpixel_offset = Point2D::new(glyph_key.subpixel_offset.into(), 0.0);
|
||||
let origin = CGPoint {
|
||||
x: -dimensions.origin.x as f64 + subpixel_offset.x,
|
||||
y: -dimensions.origin.y as f64,
|
||||
x: -dimensions.origin.x as CGFloat + subpixel_offset.x,
|
||||
y: -dimensions.origin.y as CGFloat,
|
||||
};
|
||||
|
||||
// Draw the glyph, and extract the pixels.
|
||||
|
|
|
@ -33,10 +33,10 @@ extern crate serde_derive;
|
|||
#[cfg(test)]
|
||||
extern crate env_logger;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
extern crate core_graphics as core_graphics_sys;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
extern crate core_text;
|
||||
|
||||
#[cfg(any(target_os = "linux", feature = "freetype-backend"))]
|
||||
|
@ -63,14 +63,14 @@ use euclid::{Point2D, Size2D};
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[cfg(all(target_os = "macos", not(feature = "freetype-backend")))]
|
||||
#[cfg(all(any(target_os = "macos", target_os = "ios"), not(feature = "freetype-backend")))]
|
||||
pub use core_graphics::{FontContext, GlyphOutline};
|
||||
#[cfg(all(target_os = "windows", not(feature = "freetype-backend")))]
|
||||
pub use directwrite::FontContext;
|
||||
#[cfg(any(target_os = "linux", feature = "freetype-backend"))]
|
||||
pub use freetype::FontContext;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
pub mod core_graphics;
|
||||
#[cfg(all(target_os = "windows", not(feature = "freetype-backend")))]
|
||||
mod directwrite;
|
||||
|
|
Loading…
Reference in New Issue