1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use postscript;
use postscript::compact1::FontSet;
use std::io::{Read, Seek};
use truetype::{self, Result, Tag};
use truetype::{
CharMapping, FontHeader, GlyphData, GlyphMapping, HorizontalHeader, HorizontalMetrics,
MaximumProfile, NamingTable, PostScript, WindowsMetrics,
};
use crate::{GlyphDefinition, GlyphPositioning, GlyphSubstitution};
pub trait Table<'l>: Sized {
#[doc(hidden)]
type Parameter;
#[doc(hidden)]
fn tag() -> Tag;
#[doc(hidden)]
fn take<T>(tape: &mut T, parameter: Self::Parameter) -> Result<Self>
where
T: Read + Seek;
}
macro_rules! table {
(@one $tag:expr => opentype::$kind:ident()) => (
table! { @one $tag => truetype::$kind() }
);
(@one $tag:expr => $scope:ident::$kind:ident()) => (
impl Table<'static> for $kind {
type Parameter = ();
#[inline]
fn tag() -> Tag { Tag(*$tag) }
#[inline]
fn take<T>(tape: &mut T, _: Self::Parameter) -> Result<Self>
where T: Read + Seek
{
$scope::Tape::take(tape)
}
}
);
(@one $tag:expr => $scope:ident::$kind:ident(..)) => (
impl<'l> Table<'l> for $kind {
type Parameter = <$kind as $scope::Walue<'l>>::Parameter;
#[inline]
fn tag() -> Tag { Tag(*$tag) }
#[inline]
fn take<T>(tape: &mut T, parameter: Self::Parameter) -> Result<Self>
where T: Read + Seek
{
$scope::Tape::take_given(tape, parameter)
}
}
);
($($tag:expr => $scope:ident::$kind:ident($($parameter:tt)*),)+) => (
$(table! { @one $tag => $scope::$kind($($parameter)*) })+
);
}
table! {
b"CFF " => postscript::FontSet(),
b"GDEF" => opentype::GlyphDefinition(),
b"GPOS" => opentype::GlyphPositioning(),
b"GSUB" => opentype::GlyphSubstitution(),
b"OS/2" => truetype::WindowsMetrics(),
b"cmap" => truetype::CharMapping(),
b"glyf" => truetype::GlyphData(..),
b"head" => truetype::FontHeader(),
b"hhea" => truetype::HorizontalHeader(),
b"hmtx" => truetype::HorizontalMetrics(..),
b"loca" => truetype::GlyphMapping(..),
b"maxp" => truetype::MaximumProfile(),
b"name" => truetype::NamingTable(),
b"post" => truetype::PostScript(),
}