#[cfg(windows)]
pub mod dwrite;
#[cfg(windows)]
pub use dwrite::DWriteEngine;
#[cfg(target_os = "macos")]
pub mod coretext;
#[cfg(target_os = "macos")]
pub use coretext::CoreTextEngine;
#[cfg(windows)]
pub type PlatformTextEngine = DWriteEngine;
#[cfg(target_os = "macos")]
pub type PlatformTextEngine = CoreTextEngine;
use tiny_skia::Pixmap;
use crate::geometry::{Color, Rect, Size};
use crate::spec::Align;
pub const WEIGHT_NORMAL: u16 = 400;
thread_local! {
static WEIGHT: std::cell::Cell<u16> = const { std::cell::Cell::new(WEIGHT_NORMAL) };
}
pub fn set_weight(w: u16) {
WEIGHT.with(|c| c.set(w));
}
pub fn current_weight() -> u16 {
WEIGHT.with(|c| c.get())
}
pub trait TextEngine {
fn set_scale(&mut self, _scale: f32) {}
fn measure(
&mut self,
text: &str,
family: Option<&str>,
size: f32,
max_width: Option<f32>,
) -> Size;
fn draw(
&mut self,
pixmap: &mut Pixmap,
text: &str,
rect: Rect,
color: Color,
align: Align,
family: Option<&str>,
size: f32,
clip: Option<Rect>,
);
}
pub struct NullTextEngine;
impl TextEngine for NullTextEngine {
fn measure(
&mut self,
text: &str,
_family: Option<&str>,
size: f32,
_max_width: Option<f32>,
) -> Size {
let w = (text.chars().count() as f32 * size * 0.6).ceil() as i32;
Size::new(w, size.ceil() as i32)
}
fn draw(
&mut self,
_pixmap: &mut Pixmap,
_text: &str,
_rect: Rect,
_color: Color,
_align: Align,
_family: Option<&str>,
_size: f32,
_clip: Option<Rect>,
) {
}
}