Skip to content

Commit 2fb01f7

Browse files
authored
Use fontations for shape planning (#8)
Replaces the ttf-parser code for script, langsys and feature lookup. GSUB/GPOS is now fully fontations.
1 parent cdb55cc commit 2fb01f7

File tree

6 files changed

+287
-90
lines changed

6 files changed

+287
-90
lines changed

src/hb/face.rs

+13-49
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ use core_maths::CoreFloat;
44

55
use crate::hb::paint_extents::hb_paint_extents_context_t;
66
use ttf_parser::gdef::GlyphClass;
7-
use ttf_parser::opentype_layout::LayoutTable;
87
use ttf_parser::{GlyphId, RgbaColor};
98

109
use super::buffer::GlyphPropsFlags;
1110
use super::fonta;
1211
use super::ot_layout::TableIndex;
13-
use super::ot_layout_common::{PositioningTable, SubstitutionTable};
1412
use crate::Variation;
1513

1614
/// A font face handle.
@@ -21,22 +19,6 @@ pub struct hb_font_t<'a> {
2119
pub(crate) units_per_em: u16,
2220
pixels_per_em: Option<(u16, u16)>,
2321
pub(crate) points_per_em: Option<f32>,
24-
pub(crate) gsub: Option<SubstitutionTable<'a>>,
25-
pub(crate) gpos: Option<PositioningTable<'a>>,
26-
}
27-
28-
impl<'a> AsRef<ttf_parser::Face<'a>> for hb_font_t<'a> {
29-
#[inline]
30-
fn as_ref(&self) -> &ttf_parser::Face<'a> {
31-
&self.ttfp_face
32-
}
33-
}
34-
35-
impl<'a> AsMut<ttf_parser::Face<'a>> for hb_font_t<'a> {
36-
#[inline]
37-
fn as_mut(&mut self) -> &mut ttf_parser::Face<'a> {
38-
&mut self.ttfp_face
39-
}
4022
}
4123

4224
impl<'a> core::ops::Deref for hb_font_t<'a> {
@@ -48,13 +30,6 @@ impl<'a> core::ops::Deref for hb_font_t<'a> {
4830
}
4931
}
5032

51-
impl<'a> core::ops::DerefMut for hb_font_t<'a> {
52-
#[inline]
53-
fn deref_mut(&mut self) -> &mut Self::Target {
54-
&mut self.ttfp_face
55-
}
56-
}
57-
5833
impl<'a> hb_font_t<'a> {
5934
/// Creates a new `Face` from data.
6035
///
@@ -67,28 +42,10 @@ impl<'a> hb_font_t<'a> {
6742
units_per_em: face.units_per_em(),
6843
pixels_per_em: None,
6944
points_per_em: None,
70-
gsub: face.tables().gsub.map(SubstitutionTable::new),
71-
gpos: face.tables().gpos.map(PositioningTable::new),
7245
ttfp_face: face,
7346
})
7447
}
7548

76-
/// Creates a new [`Face`] from [`ttf_parser::Face`].
77-
///
78-
/// Data will be referenced, not owned.
79-
pub fn from_face(face: ttf_parser::Face<'a>) -> Self {
80-
let font = fonta::Font::new(face.raw_face().data, 0).unwrap();
81-
hb_font_t {
82-
font,
83-
units_per_em: face.units_per_em(),
84-
pixels_per_em: None,
85-
points_per_em: None,
86-
gsub: face.tables().gsub.map(SubstitutionTable::new),
87-
gpos: face.tables().gpos.map(PositioningTable::new),
88-
ttfp_face: face,
89-
}
90-
}
91-
9249
// TODO: remove
9350
/// Returns face’s units per EM.
9451
#[inline]
@@ -124,7 +81,7 @@ impl<'a> hb_font_t<'a> {
12481
/// Sets font variations.
12582
pub fn set_variations(&mut self, variations: &[Variation]) {
12683
for variation in variations {
127-
self.set_variation(variation.tag, variation.value);
84+
self.ttfp_face.set_variation(variation.tag, variation.value);
12885
}
12986
self.font.set_coords(self.ttfp_face.variation_coordinates());
13087
}
@@ -338,17 +295,24 @@ impl<'a> hb_font_t<'a> {
338295
}
339296
}
340297

341-
pub(crate) fn layout_table(&self, table_index: TableIndex) -> Option<&LayoutTable<'a>> {
298+
pub(crate) fn layout_table(
299+
&self,
300+
table_index: TableIndex,
301+
) -> Option<fonta::ot::LayoutTable<'a>> {
342302
match table_index {
343-
TableIndex::GSUB => self.gsub.as_ref().map(|table| &table.inner),
344-
TableIndex::GPOS => self.gpos.as_ref().map(|table| &table.inner),
303+
TableIndex::GSUB => Some(fonta::ot::LayoutTable::Gsub(
304+
self.font.ot.gsub.as_ref()?.table.clone(),
305+
)),
306+
TableIndex::GPOS => Some(fonta::ot::LayoutTable::Gpos(
307+
self.font.ot.gpos.as_ref()?.table.clone(),
308+
)),
345309
}
346310
}
347311

348312
pub(crate) fn layout_tables(
349313
&self,
350-
) -> impl Iterator<Item = (TableIndex, &LayoutTable<'a>)> + '_ {
351-
TableIndex::iter().filter_map(move |idx| self.layout_table(idx).map(|table| (idx, table)))
314+
) -> impl Iterator<Item = (TableIndex, fonta::ot::LayoutTable<'a>)> + '_ {
315+
TableIndex::iter().filter_map(move |idx| Some((idx, self.layout_table(idx)?)))
352316
}
353317
}
354318

src/hb/fonta/font.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ impl<'a> Font<'a> {
5454
pub(crate) fn set_coords(&mut self, coords: &[NormalizedCoordinate]) {
5555
self.coords.clear();
5656
if !coords.is_empty() && !coords.iter().all(|coord| coord.get() == 0) {
57+
self.coords.extend(
58+
coords
59+
.iter()
60+
.map(|coord| NormalizedCoord::from_bits(coord.get())),
61+
);
5762
let ivs = self.ivs.take().or_else(|| self.ot.item_variation_store());
58-
if ivs.is_some() {
59-
self.coords.extend(
60-
coords
61-
.iter()
62-
.map(|coord| NormalizedCoord::from_bits(coord.get())),
63-
);
64-
}
6563
self.ivs = ivs;
6664
} else {
6765
self.ivs = None;

0 commit comments

Comments
 (0)