| 1 | use craterust-analyzer cargo ab_glyph 0.2.32 crate/::{v2rust-analyzer cargo ab_glyph 0.2.32 glyph/v2/, Fontrust-analyzer cargo ab_glyph 0.2.32 font/Font#, FontRefrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontRef#, FontVecrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontVec#, GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#, InvalidFontrust-analyzer cargo ab_glyph 0.2.32 err/InvalidFont#, Outlinerust-analyzer cargo ab_glyph 0.2.32 outlined/Outline#}; |
| 2 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::syncrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 3 | #[cfg(not(feature = "std"))] |
| 4 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 5 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/; |
| 6 | |
| 7 | /// `Font` implementor that wraps another concrete `Font + 'static` type storing in an `Arc`. |
| 8 | /// |
| 9 | /// Provides convenient type erasure & cheap clones (particularly for `FontVec`). |
| 10 | /// |
| 11 | /// # Example |
| 12 | /// ``` |
| 13 | /// use ab_glyph::{Font, FontArc}; |
| 14 | /// |
| 15 | /// # fn main() -> Result<(), ab_glyph::InvalidFont> { |
| 16 | /// let font = FontArc::try_from_slice(include_bytes!("../../dev/fonts/Exo2-Light.otf"))?; |
| 17 | /// |
| 18 | /// assert_eq!(font.glyph_id('s'), ab_glyph::GlyphId(56)); |
| 19 | /// # Ok(()) } |
| 20 | /// ``` |
| 21 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)] |
| 22 | pub struct FontArcrust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Fontrust-analyzer cargo ab_glyph 0.2.32 font/Font# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static>); |
| 23 | |
| 24 | impl FontArcrust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc# { |
| 25 | /// # Example |
| 26 | /// ``` |
| 27 | /// # use ab_glyph::*; |
| 28 | /// # fn main() -> Result<(), ab_glyph::InvalidFont> { |
| 29 | /// # let font_data = include_bytes!("../../dev/fonts/Exo2-Light.otf").to_vec(); |
| 30 | /// # let font_vec = FontVec::try_from_vec(font_data)?; |
| 31 | /// let font_arc = FontArc::new(font_vec); |
| 32 | /// # Ok(()) } |
| 33 | /// ``` |
| 34 | #[inline] |
| 35 | pub fn newrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc]new().<F: Fontrust-analyzer cargo ab_glyph 0.2.32 font/Font# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static>(font: F) -> Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc] { |
| 36 | Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc](Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(font)) |
| 37 | } |
| 38 | |
| 39 | /// Creates an `FontArc` from owned data. |
| 40 | /// |
| 41 | /// # Example |
| 42 | /// ``` |
| 43 | /// # use ab_glyph::*; |
| 44 | /// # fn main() -> Result<(), InvalidFont> { |
| 45 | /// # let owned_font_data = include_bytes!("../../dev/fonts/Exo2-Light.otf").to_vec(); |
| 46 | /// let font = FontArc::try_from_vec(owned_font_data)?; |
| 47 | /// # Ok(()) } |
| 48 | /// ``` |
| 49 | #[inline] |
| 50 | pub fn try_from_vecrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc]try_from_vec().(data: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc], InvalidFontrust-analyzer cargo ab_glyph 0.2.32 err/InvalidFont#> { |
| 51 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(FontVecrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontVec#::try_from_vecrust-analyzer cargo ab_glyph 0.2.32 ttfp/impl#[FontVec]try_from_vec().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 52 | } |
| 53 | |
| 54 | /// Creates an `FontArc` from a byte-slice. |
| 55 | /// |
| 56 | /// # Example |
| 57 | /// ``` |
| 58 | /// # use ab_glyph::*; |
| 59 | /// # fn main() -> Result<(), InvalidFont> { |
| 60 | /// let font = FontArc::try_from_slice(include_bytes!("../../dev/fonts/Exo2-Light.otf"))?; |
| 61 | /// # Ok(()) } |
| 62 | /// ``` |
| 63 | #[inline] |
| 64 | pub fn try_from_slicerust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc]try_from_slice().(data: &'static [u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc], InvalidFontrust-analyzer cargo ab_glyph 0.2.32 err/InvalidFont#> { |
| 65 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(FontRefrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontRef#::try_from_slicerust-analyzer cargo ab_glyph 0.2.32 ttfp/impl#[`FontRef<'font>`]try_from_slice().(data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | impl fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for FontArcrust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc# { |
| 70 | fn fmtrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 71 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "FontArc") |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | impl Fontrust-analyzer cargo ab_glyph 0.2.32 font/Font# for FontArcrust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc# { |
| 76 | #[inline] |
| 77 | fn units_per_emrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]units_per_em().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<f32> { |
| 78 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..units_per_emrust-analyzer cargo ab_glyph 0.2.32 font/Font#units_per_em().() |
| 79 | } |
| 80 | |
| 81 | #[inline] |
| 82 | fn ascent_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]ascent_unscaled().(&self) -> f32 { |
| 83 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..ascent_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#ascent_unscaled().() |
| 84 | } |
| 85 | |
| 86 | #[inline] |
| 87 | fn descent_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]descent_unscaled().(&self) -> f32 { |
| 88 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..descent_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#descent_unscaled().() |
| 89 | } |
| 90 | |
| 91 | #[inline] |
| 92 | fn line_gap_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]line_gap_unscaled().(&self) -> f32 { |
| 93 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..line_gap_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#line_gap_unscaled().() |
| 94 | } |
| 95 | |
| 96 | #[inline] |
| 97 | fn italic_anglerust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]italic_angle().(&self) -> f32 { |
| 98 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..italic_anglerust-analyzer cargo ab_glyph 0.2.32 font/Font#italic_angle().() |
| 99 | } |
| 100 | |
| 101 | #[inline] |
| 102 | fn glyph_idrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]glyph_id().(&self, c: char) -> GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId# { |
| 103 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..glyph_idrust-analyzer cargo ab_glyph 0.2.32 font/Font#glyph_id().(c) |
| 104 | } |
| 105 | |
| 106 | #[inline] |
| 107 | fn h_advance_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]h_advance_unscaled().(&self, id: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#) -> f32 { |
| 108 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..h_advance_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#h_advance_unscaled().(id) |
| 109 | } |
| 110 | |
| 111 | #[inline] |
| 112 | fn h_side_bearing_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]h_side_bearing_unscaled().(&self, id: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#) -> f32 { |
| 113 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..h_side_bearing_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#h_side_bearing_unscaled().(id) |
| 114 | } |
| 115 | |
| 116 | #[inline] |
| 117 | fn v_advance_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]v_advance_unscaled().(&self, id: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#) -> f32 { |
| 118 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..v_advance_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#v_advance_unscaled().(id) |
| 119 | } |
| 120 | |
| 121 | #[inline] |
| 122 | fn v_side_bearing_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]v_side_bearing_unscaled().(&self, id: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#) -> f32 { |
| 123 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..v_side_bearing_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#v_side_bearing_unscaled().(id) |
| 124 | } |
| 125 | |
| 126 | #[inline] |
| 127 | fn kern_unscaledrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]kern_unscaled().(&self, first: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#, second: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#) -> f32 { |
| 128 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..kern_unscaledrust-analyzer cargo ab_glyph 0.2.32 font/Font#kern_unscaled().(first, second) |
| 129 | } |
| 130 | |
| 131 | #[inline] |
| 132 | fn outlinerust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]outline().(&self, glyph: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Outlinerust-analyzer cargo ab_glyph 0.2.32 outlined/Outline#> { |
| 133 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..outlinerust-analyzer cargo ab_glyph 0.2.32 font/Font#outline().(glyph) |
| 134 | } |
| 135 | |
| 136 | #[inline] |
| 137 | fn glyph_countrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]glyph_count().(&self) -> usize { |
| 138 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..glyph_countrust-analyzer cargo ab_glyph 0.2.32 font/Font#glyph_count().() |
| 139 | } |
| 140 | |
| 141 | #[inline] |
| 142 | fn codepoint_idsrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]codepoint_ids().(&self) -> craterust-analyzer cargo ab_glyph 0.2.32 crate/::CodepointIdIterrust-analyzer cargo ab_glyph 0.2.32 codepoint_ids/CodepointIdIter#<'_> { |
| 143 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..codepoint_idsrust-analyzer cargo ab_glyph 0.2.32 font/Font#codepoint_ids().() |
| 144 | } |
| 145 | |
| 146 | #[inline] |
| 147 | fn glyph_raster_image2rust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]glyph_raster_image2().(&self, id: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#, size: u16) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<v2rust-analyzer cargo ab_glyph 0.2.32 glyph/v2/::GlyphImagerust-analyzer cargo ab_glyph 0.2.32 glyph/v2/GlyphImage#<'_>> { |
| 148 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..glyph_raster_image2rust-analyzer cargo ab_glyph 0.2.32 font/Font#glyph_raster_image2().(id, size) |
| 149 | } |
| 150 | |
| 151 | #[inline] |
| 152 | fn glyph_svg_imagerust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]glyph_svg_image().(&self, id: GlyphIdrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphId#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<craterust-analyzer cargo ab_glyph 0.2.32 crate/::GlyphSvgrust-analyzer cargo ab_glyph 0.2.32 glyph/GlyphSvg#<'_>> { |
| 153 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..glyph_svg_imagerust-analyzer cargo ab_glyph 0.2.32 font/Font#glyph_svg_image().(id) |
| 154 | } |
| 155 | |
| 156 | #[inline] |
| 157 | fn font_datarust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][Font]font_data().(&self) -> &[u8] { |
| 158 | self.0rust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc#0..font_datarust-analyzer cargo ab_glyph 0.2.32 font/Font#font_data().() |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<FontVecrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontVec#> for FontArcrust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc# { |
| 163 | #[inline] |
| 164 | fn fromrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<FontVec>`]from().(font: FontVecrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontVec#) -> Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<FontVec>`] { |
| 165 | Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<FontVec>`]::newrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc]new().(font) |
| 166 | } |
| 167 | } |
| 168 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<FontRefrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontRef#<'static>> for FontArcrust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc# { |
| 169 | #[inline] |
| 170 | fn fromrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<FontRef<'static>>`]from().(font: FontRefrust-analyzer cargo ab_glyph 0.2.32 ttfp/FontRef#<'static>) -> Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<FontRef<'static>>`] { |
| 171 | Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<FontRef<'static>>`]::newrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc]new().(font) |
| 172 | } |
| 173 | } |
| 174 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Fontrust-analyzer cargo ab_glyph 0.2.32 font/Font# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static>> for FontArcrust-analyzer cargo ab_glyph 0.2.32 font_arc/FontArc# { |
| 175 | #[inline] |
| 176 | fn fromrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<Arc<dyn Font + Send + Sync + 'static>>`]from().(font: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<dyn Fontrust-analyzer cargo ab_glyph 0.2.32 font/Font# + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + Syncrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sync# + 'static>) -> Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<Arc<dyn Font + Send + Sync + 'static>>`] { |
| 177 | Selfrust-analyzer cargo ab_glyph 0.2.32 font_arc/impl#[FontArc][`From<Arc<dyn Font + Send + Sync + 'static>>`](font) |
| 178 | } |
| 179 | } |