26 lines
827 B
Erlang
26 lines
827 B
Erlang
|
-module(hmtx).
|
||
|
-export([parse_hmtx_table/1]).
|
||
|
|
||
|
-include("sizes.hrl").
|
||
|
|
||
|
-define(LONG_HOR_METRIC_SIZE, (?U16+?I16)).
|
||
|
|
||
|
parse_long_hor_metric(<<AdvanceWidth:16, Lsb:16/signed, Rest/binary>>) ->
|
||
|
[[
|
||
|
{advance_width, AdvanceWidth},
|
||
|
{lsb, Lsb}
|
||
|
] | parse_long_hor_metric(Rest)];
|
||
|
parse_long_hor_metric(<<>>) -> [].
|
||
|
|
||
|
parse_left_side_bearing(<<LeftSideBearing:16/unsigned, Rest/binary>>) ->
|
||
|
[LeftSideBearing | parse_left_side_bearing(Rest)];
|
||
|
parse_left_side_bearing(<<>>) -> [].
|
||
|
|
||
|
parse_hmtx_table(
|
||
|
<<NumberOfHMetrics:16, NumGlyphs:16, %% <<NumberOfHMetrics:16, NumGlyphs:16, <<Data>>>>
|
||
|
HMetrics:(NumberOfHMetrics*?LONG_HOR_METRIC_SIZE)/binary,
|
||
|
LeftSideBearing:((NumGlyphs-NumberOfHMetrics)*?I16)/binary
|
||
|
>>) -> [
|
||
|
{h_metrics, parse_long_hor_metric(HMetrics)},
|
||
|
{left_side_bearing, parse_left_side_bearing(LeftSideBearing)}
|
||
|
].
|