Commit 80fe7502 by Timothée Floure

Fix size of binary bitmap values

parent db5a1110
......@@ -21,19 +21,32 @@ defmodule BDF.Char do
parse_header tail, Map.merge(map, new)
end
defp pad_binary(bin, len) do
unless byte_size(bin) < len do
bin
else
String.duplicate(<<0x0>>, byte_size(bin)) <> bin
end
end
def parse(lines) do
{head, ["BITMAP"|bitmap_raw]} = Enum.split_while(
lines,
fn (l) -> not String.starts_with?(l, "BITMAP") end
)
bitmap = Enum.map(
bitmap_values = Enum.map(
bitmap_raw, fn (str) ->
{int ,_} = Integer.parse(str, 16)
<<int::size(4)-unit(8)>>
<<int::integer>>
end
)
bitmap_max_size = bitmap_values
|> Enum.reduce(0, fn(x, acc) -> max(byte_size(x), acc) end)
bitmap = bitmap_values
|> Enum.map(&pad_binary(&1, bitmap_max_size))
struct %Char{bitmap: bitmap}, parse_header(head)
end
end
......@@ -97,5 +97,4 @@ defmodule BDF.Parser do
to_bits(bits, [b|acc])
end
defp to_bits(<<>>, acc), do: acc |> Enum.reverse
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment