Skip to main content

read_fonts/model/glyph/outline/
type1.rs

1//! Outlines from Type 1 charstrings.
2//!
3//! The charstrings are parsed and evaluated by [`crate::ps::type1`].
4
5use super::{DrawOptions, DrawnMetrics, PathSink};
6use crate::model::Error;
7use crate::{
8    ps::type1::{Type1Font, Type1Instance},
9    types::GlyphId,
10};
11
12/// A charstring from a Type 1 [`Font`](crate::model::Font).
13#[derive(Clone, Copy)]
14pub struct Type1Glyph<'a> {
15    /// The font at the location the glyph is drawn at.
16    pub(super) font: Type1Instance<'a>,
17    pub(super) glyph: GlyphId,
18}
19
20impl<'a> Type1Glyph<'a> {
21    /// Returns the glyph identifier.
22    pub fn glyph(&self) -> GlyphId {
23        self.glyph
24    }
25
26    /// Returns the Type 1 font that evaluates the charstring.
27    pub fn type1_font(&self) -> &'a Type1Font {
28        self.font.font()
29    }
30
31    pub(super) fn draw(
32        &self,
33        options: &DrawOptions,
34        mut sink: &mut dyn PathSink,
35    ) -> Result<DrawnMetrics, Error> {
36        let h_advance = self.font.draw(self.glyph, options.ppem, &mut sink)?;
37        Ok(DrawnMetrics {
38            h_advance,
39            ..Default::default()
40        })
41    }
42}