file-parser/OpenFontFormat/erl/tables/head.erl

46 lines
1.4 KiB
Erlang
Raw Normal View History

2024-05-03 21:04:21 +10:00
-module(head).
-export([parse_head_table/1]).
-include("sizes.hrl").
-import(read_utils, [read_fixed/1, read_long_datetime/1]).
parse_head_table(
<<1:16, 0:16,
FontRendition:?FIXED_SIZE/binary,
CheckSumAdjustment:32,
MagicNumber:32,
Flags:16/bits,
UnitsPerEm:16,
Created:?DATETIME_SIZE/binary,
Modified:?DATETIME_SIZE/binary,
XMin:16/signed,
YMin:16/signed,
XMax:16/signed,
YMax:16/signed,
MacStyle:16/bits,
LowestRecPPEM:16,
FontDirectionHint:16/signed,
IndexToLocFormat:16/signed,
GlyphDataFormat:16/signed>>) ->
case MagicNumber == 16#5F0F3CF5 of false -> throw({invalid_magic_number, MagicNumber}); true -> ok end,
case lists:member(IndexToLocFormat, [0, 1]) of false -> throw({invalid_index_to_loc_format, IndexToLocFormat}); true -> ok end,
case GlyphDataFormat == 0 of false -> throw({invalid_glyph_data_format, GlyphDataFormat}); true -> ok end,
[
{major_version, 1},
{minor_version, 0},
{font_revision, read_fixed(FontRendition)},
{check_sum_adjustment, CheckSumAdjustment},
{flags, Flags},
{units_per_em, UnitsPerEm},
{created, read_long_datetime(Created)},
{modified, read_long_datetime(Modified)},
{x_min, XMin},
{y_min, YMin},
{x_max, XMax},
{y_max, YMax},
{mac_style, MacStyle},
{lowest_rec_ppem, LowestRecPPEM},
{font_direction_hint, FontDirectionHint},
{index_to_loc_format, IndexToLocFormat},
{glyph_data_format, GlyphDataFormat}
].