33 lines
1.4 KiB
Erlang
33 lines
1.4 KiB
Erlang
|
-module(ttf_parser).
|
||
|
-export([read/1]).
|
||
|
|
||
|
-import(font_directory, [parse_font_directory/1]).
|
||
|
-import(table, [parse_table/4]).
|
||
|
|
||
|
parse_at_table_directory(File, TableDirectory, TableTag, Info) ->
|
||
|
TableDirectoryEntry = proplists:get_value(TableTag, TableDirectory),
|
||
|
Offset = proplists:get_value(offset, TableDirectoryEntry),
|
||
|
Length = proplists:get_value(length, TableDirectoryEntry),
|
||
|
<<_:Offset/binary, Table:Length/binary, _/binary>> = File,
|
||
|
parse_table(TableTag, Table, Length, Info).
|
||
|
parse_at_table_directory(File, TableDirectory, TableTag) -> parse_at_table_directory(File, TableDirectory, TableTag, {}).
|
||
|
|
||
|
read(Filename) ->
|
||
|
{ok, File} = file:read_file(Filename),
|
||
|
FontDirectory = parse_font_directory(File),
|
||
|
TableDirectory = proplists:get_value(table_directory, FontDirectory),
|
||
|
|
||
|
FontHeader = parse_at_table_directory(File, TableDirectory, head),
|
||
|
HorizontalHeader = parse_at_table_directory(File, TableDirectory, hhea),
|
||
|
MaximumProfile = parse_at_table_directory(File, TableDirectory, maxp),
|
||
|
HorizontalMetrics = parse_at_table_directory(File, TableDirectory, hmtx, [
|
||
|
{number_of_h_metrics, proplists:get_value(number_of_h_metrics, HorizontalHeader)},
|
||
|
{num_glyphs, proplists:get_value(num_glyphs, MaximumProfile)}
|
||
|
]),
|
||
|
[
|
||
|
{font_header, FontHeader},
|
||
|
{horizontal_header, HorizontalHeader},
|
||
|
{maximum_profile, MaximumProfile},
|
||
|
{horizontal_metrics, HorizontalMetrics}
|
||
|
].
|