Skip to content

Commit

Permalink
Add MATH table.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifengx authored Sep 27, 2022
1 parent 6d34ac6 commit 88aaffa
Show file tree
Hide file tree
Showing 7 changed files with 920 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Cargo.lock
.directory
.DS_Store
.vscode
.idea
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ std = []
# Enables variable fonts support. Increases binary size almost twice.
# Includes avar, CFF2, fvar, gvar, HVAR, MVAR and VVAR tables.
variable-fonts = []
# Enables GDEF, GPOS and GSUB tables.
# Enables GDEF, GPOS, GSUB and MATH tables.
opentype-layout = []
# Enables ankr, feat, format1 subtable in kern, kerx, morx and trak tables.
apple-layout = []
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ There are roughly three types of TrueType tables:
| `HVAR` table ||| |
| `kern` table || ~ (only 0) | ~ (only 0) |
| `kerx` table || | |
| `MATH` table || | |
| `maxp` table ||||
| `morx` table || | |
| `MVAR` table ||| |
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub use os2::{Weight, Width, ScriptMetrics, Style};
pub use tables::CFFError;
pub use tables::{cmap, kern, sbix, maxp, hmtx, name, os2, loca, svg, vorg, post, head, hhea, glyf};
pub use tables::{cff1 as cff, vhea, cbdt, cblc};
#[cfg(feature = "opentype-layout")] pub use tables::{gdef, gpos, gsub};
#[cfg(feature = "opentype-layout")] pub use tables::{gdef, gpos, gsub, math};
#[cfg(feature = "apple-layout")] pub use tables::{ankr, feat, kerx, morx, trak};
#[cfg(feature = "variable-fonts")] pub use tables::{cff2, avar, fvar, gvar, hvar, mvar};

Expand Down Expand Up @@ -680,6 +680,7 @@ pub struct RawFaceTables<'a> {
#[cfg(feature = "opentype-layout")] pub gdef: Option<&'a [u8]>,
#[cfg(feature = "opentype-layout")] pub gpos: Option<&'a [u8]>,
#[cfg(feature = "opentype-layout")] pub gsub: Option<&'a [u8]>,
#[cfg(feature = "opentype-layout")] pub math: Option<&'a [u8]>,

#[cfg(feature = "apple-layout")] pub ankr: Option<&'a [u8]>,
#[cfg(feature = "apple-layout")] pub feat: Option<&'a [u8]>,
Expand Down Expand Up @@ -730,6 +731,7 @@ pub struct FaceTables<'a> {
#[cfg(feature = "opentype-layout")] pub gdef: Option<gdef::Table<'a>>,
#[cfg(feature = "opentype-layout")] pub gpos: Option<opentype_layout::LayoutTable<'a>>,
#[cfg(feature = "opentype-layout")] pub gsub: Option<opentype_layout::LayoutTable<'a>>,
#[cfg(feature = "opentype-layout")] pub math: Option<math::Table<'a>>,

#[cfg(feature = "apple-layout")] pub ankr: Option<ankr::Table<'a>>,
#[cfg(feature = "apple-layout")] pub feat: Option<feat::Table<'a>>,
Expand Down Expand Up @@ -841,6 +843,8 @@ impl<'a> Face<'a> {
b"GPOS" => tables.gpos = table_data,
#[cfg(feature = "opentype-layout")]
b"GSUB" => tables.gsub = table_data,
#[cfg(feature = "opentype-layout")]
b"MATH" => tables.math = table_data,
#[cfg(feature = "variable-fonts")]
b"HVAR" => tables.hvar = table_data,
#[cfg(feature = "variable-fonts")]
Expand Down Expand Up @@ -963,6 +967,7 @@ impl<'a> Face<'a> {
#[cfg(feature = "opentype-layout")] gdef: raw_tables.gdef.and_then(gdef::Table::parse),
#[cfg(feature = "opentype-layout")] gpos: raw_tables.gpos.and_then(opentype_layout::LayoutTable::parse),
#[cfg(feature = "opentype-layout")] gsub: raw_tables.gsub.and_then(opentype_layout::LayoutTable::parse),
#[cfg(feature = "opentype-layout")] math: raw_tables.math.and_then(math::Table::parse),

#[cfg(feature = "apple-layout")] ankr: raw_tables.ankr
.and_then(|data| ankr::Table::parse(maxp.number_of_glyphs, data)),
Expand Down
6 changes: 6 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,12 @@ impl<'a> Stream<'a> {
data.get(offset..)
}

#[allow(dead_code)]
#[inline]
pub(crate) fn parse_at_offset16<T: FromSlice<'a>>(&mut self, data: &'a [u8]) -> Option<T> {
self.read_at_offset16(data).and_then(T::parse)
}

#[allow(dead_code)]
#[inline]
pub(crate) fn read_at_offset32(&mut self, data: &'a [u8]) -> Option<&'a [u8]> {
Expand Down
Loading

0 comments on commit 88aaffa

Please sign in to comment.