Skip to content

Commit

Permalink
Fix docs warning, move private functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpunch committed Nov 10, 2024
1 parent e410077 commit 88d391f
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions lib/mudbrick/font.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
defmodule Mudbrick.Font do
@moduledoc false

@type t :: %__MODULE__{
descendant: Mudbrick.Indirect.Object.t(),
encoding: atom(),
Expand Down Expand Up @@ -41,6 +39,7 @@ defmodule Mudbrick.Font do
alias Mudbrick.Object
alias Mudbrick.Stream

@doc false
def new(opts) do
case Keyword.fetch(opts, :parsed) do
{:ok, parsed} ->
Expand All @@ -52,8 +51,10 @@ defmodule Mudbrick.Font do
end
end

@doc false
def type!(s), do: Map.fetch!(%{"Type0" => :Type0}, s)

@doc false
def add_objects(doc, fonts) do
{doc, font_objects, _id} =
for {human_name, font_opts} <- fonts, reduce: {doc, %{}, 0} do
Expand Down Expand Up @@ -86,6 +87,27 @@ defmodule Mudbrick.Font do
{doc, font_objects}
end

@doc false
def width(%Font{parsed: nil}, _size, _text) do
raise Font.NotMeasured, "Built-in fonts aren't alignable yet"
end

def width(_font, _size, "") do
0
end

def width(font, size, text) do
{glyph_ids, _positions} = OpenType.layout_text(font.parsed, text)

for id <- glyph_ids, reduce: 0 do
acc ->
glyph_width = Enum.at(font.parsed.glyphWidths, id)
width_in_points = glyph_width / 1000 * size

acc + width_in_points
end
end

defp add_font_file(doc, contents) do
doc
|> Document.add(
Expand Down Expand Up @@ -146,26 +168,6 @@ defmodule Mudbrick.Font do
end)
end

def width(%Font{parsed: nil}, _size, _text) do
raise Font.NotMeasured, "Built-in fonts aren't alignable yet"
end

def width(_font, _size, "") do
0
end

def width(font, size, text) do
{glyph_ids, _positions} = OpenType.layout_text(font.parsed, text)

for id <- glyph_ids, reduce: 0 do
acc ->
glyph_width = Enum.at(font.parsed.glyphWidths, id)
width_in_points = glyph_width / 1000 * size

acc + width_in_points
end
end

defimpl Mudbrick.Object do
def from(font) do
Object.from(
Expand Down

0 comments on commit 88d391f

Please sign in to comment.