use std::ops::Range;
use peniko::{
FontData, Style,
kurbo::{Diagonal2, Join},
};
use super::{StreamOffsets, Transform};
#[derive(Copy, Clone, Default, Debug)]
pub struct Glyph {
pub id: u32,
pub x: f32,
pub y: f32,
}
#[derive(Clone, Copy, Debug)]
pub struct FontEmbolden {
pub amount: Diagonal2,
pub join: Join,
pub miter_limit: f64,
pub tolerance: f64,
}
impl FontEmbolden {
pub fn new(amount: Diagonal2) -> Self {
Self {
amount,
..Self::default()
}
}
pub fn with_join(mut self, join: Join) -> Self {
self.join = join;
self
}
pub fn with_miter_limit(mut self, miter_limit: f64) -> Self {
self.miter_limit = miter_limit;
self
}
pub fn with_tolerance(mut self, tolerance: f64) -> Self {
self.tolerance = tolerance;
self
}
}
impl Default for FontEmbolden {
fn default() -> Self {
Self {
amount: Diagonal2::new(0.0, 0.0),
join: Join::Miter,
miter_limit: 4.0,
tolerance: 0.1,
}
}
}
#[derive(Clone)]
pub struct GlyphRun {
pub font: FontData,
pub transform: Transform,
pub glyph_transform: Option<Transform>,
pub brush_transform: Option<Transform>,
pub font_size: f32,
pub font_embolden: FontEmbolden,
pub hint: bool,
pub normalized_coords: Range<usize>,
pub style: Style,
pub glyphs: Range<usize>,
pub stream_offsets: StreamOffsets,
pub text: Option<std::sync::Arc<str>>,
}
pub fn draw_outline(
outline: &skrifa::outline::OutlineGlyph<'_>,
settings: skrifa::outline::DrawSettings<'_>,
pen: &mut dyn skrifa::outline::OutlinePen,
) -> Result<skrifa::outline::AdjustedMetrics, skrifa::outline::DrawError> {
outline.draw(settings, &mut AnyPen(pen))
}
struct AnyPen<'a>(&'a mut dyn skrifa::outline::OutlinePen);
impl skrifa::outline::OutlinePen for AnyPen<'_> {
fn move_to(&mut self, x: f32, y: f32) {
self.0.move_to(x, y);
}
fn line_to(&mut self, x: f32, y: f32) {
self.0.line_to(x, y);
}
fn quad_to(&mut self, cx0: f32, cy0: f32, x: f32, y: f32) {
self.0.quad_to(cx0, cy0, x, y);
}
fn curve_to(&mut self, cx0: f32, cy0: f32, cx1: f32, cy1: f32, x: f32, y: f32) {
self.0.curve_to(cx0, cy0, cx1, cy1, x, y);
}
fn close(&mut self) {
self.0.close();
}
}