...
 
defmodule BDF.Font do
alias BDF.Parser
defstruct [:format, :font, :size, :font_bounding_box, :metrics_set,
:properties, :chars]
......@@ -9,7 +11,7 @@ defmodule BDF.Font do
|> Enum.map(&(encode(font, &1)))
|> Enum.zip
|> Enum.map(&Tuple.to_list(&1))
|> Enum.map(&Enum.reduce(&1, <<>>, fn (x, acc) -> x <> acc end))
|> Enum.map(&Enum.reduce(&1, <<>>, fn (x, acc) -> acc <> x end))
end
def encode(font, char) do
......@@ -19,9 +21,21 @@ defmodule BDF.Font do
{bbw, bbh, bbxoffx, bbxoffy} = char.bbx
bitmap = char |> Map.get(:bitmap)
|> Enum.chunk_every(round(bbw / 4))
|> Enum.map(&Enum.reduce(&1, <<>>, fn (x, acc) -> x <> acc end))
|> Enum.chunk_every(round(bbw / 8))
|> Enum.map(&Enum.reduce(&1, <<>>, fn (x, acc) -> acc <> x end))
bitmap
end
def prettyprint(char) do
Enum.map(
char, fn (l) ->
Parser.to_bits(l) |> Enum.map(
fn (bit) ->
if bit == 1, do: IO.write("#"), else: IO.write(" ")
end)
IO.write "\n"
end)
:ok
end
end
......@@ -91,4 +91,11 @@ defmodule BDF.Parser do
|> struct(properties)
|> struct(chars)
end
def to_bits(bin) when is_binary(bin), do: to_bits(bin, [])
defp to_bits(<<b :: size(1), bits :: bitstring>>, acc) when is_bitstring(bits) do
to_bits(bits, [b|acc])
end
defp to_bits(<<>>, acc), do: acc |> Enum.reverse
end