Skip to content

Commit

Permalink
Read some composite glyph data
Browse files Browse the repository at this point in the history
  • Loading branch information
wezm committed Apr 27, 2022
1 parent b551f96 commit 74a6f67
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
7 changes: 6 additions & 1 deletion formats/data/opentype/woff2/SFNT-TTF-Composite.snap
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,12 @@ stdout = '''
x_max = 4514,
y_max = 1434,
},
data = {},
data = {
flags = 4135,
glyphIndex = 7,
argument1 = 3453,
argument2 = 0,
},
},
],
},
Expand Down
28 changes: 27 additions & 1 deletion formats/opentype.fathom
Original file line number Diff line number Diff line change
Expand Up @@ -1066,13 +1066,39 @@ let simple_glyph = fun (number_of_contours : U16) => {
// or int16 <- uint8,
};

let args_are_signed = fun (flags : U16) =>
(u16_neq (u16_and flags 0x0002) 0);

let arg_format = fun (flags : U16) =>
match (u16_neq (u16_and flags 0x0001) 0) {
// If the bit is set the arguments are 16-bit
true => match (args_are_signed flags) {
true => s16be,
false => u16be,
},
// Otherwise they are 8-bit
false => match (args_are_signed flags) {
true => s8,
false => u8,
},
};

/// # Composite glyph description
///
/// ## References
///
/// - [Microsoft's OpenType Spec: Glyph Headers](https://docs.microsoft.com/en-us/typography/opentype/spec/glyf#composite-glyph-description)
/// - [Apple's TrueType Reference Manual: The `'loca'` table](https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6glyf.html)
let composite_glyph = unknown_table; // TODO
let composite_glyph = {
/// component flag
flags <- u16be,
/// glyph index of component
glyphIndex <- u16be,
/// x-offset for component or point number; type depends on bits 0 and 1 in component flags
argument1 <- arg_format flags,
/// y-offset for component or point number; type depends on bits 0 and 1 in component flags
argument2 <- arg_format flags,
};

/// # TrueType glyph
let glyph = {
Expand Down
18 changes: 17 additions & 1 deletion formats/opentype.snap
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,23 @@ let simple_glyph : _ = fun number_of_contours => {
instruction_length <- u16be,
instructions <- array16 instruction_length u8,
};
let composite_glyph : _ = unknown_table;
let args_are_signed : _ = fun flags => u16_neq (u16_and flags 0x2) 0;
let arg_format : _ = fun flags => match (u16_neq (u16_and flags 0x1) 0) {
false => match (args_are_signed flags) {
false => u8,
true => s8,
},
true => match (args_are_signed flags) {
false => u16be,
true => s16be,
},
};
let composite_glyph : _ = {
flags <- u16be,
glyphIndex <- u16be,
argument1 <- arg_format flags,
argument2 <- arg_format flags,
};
let glyph : _ = {
header <- glyph_header,
data <- match (s16_lt header.number_of_contours 0) {
Expand Down

0 comments on commit 74a6f67

Please sign in to comment.