Skip to content

Commit

Permalink
Object.from/1 -> Object.to_iodata/1
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpunch committed Nov 17, 2024
1 parent bc85d11 commit 3dbe280
Show file tree
Hide file tree
Showing 37 changed files with 74 additions and 74 deletions.
8 changes: 4 additions & 4 deletions lib/mudbrick.ex
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ defmodule Mudbrick do
output =
doc
|> text_block(writes, fetch_font(doc, opts))
|> TextBlock.Output.from()
|> TextBlock.Output.to_iodata()

output.operations ++ ops
end)
Expand Down Expand Up @@ -331,7 +331,7 @@ defmodule Mudbrick do

context
|> ContentStream.update_operations(fn ops ->
Path.Output.from(path).operations ++ ops
Path.Output.to_iodata(path).operations ++ ops
end)
end

Expand All @@ -344,7 +344,7 @@ defmodule Mudbrick do
end

def render(doc) do
Mudbrick.Object.from(doc)
Mudbrick.Object.to_iodata(doc)
end

@doc false
Expand All @@ -364,7 +364,7 @@ defmodule Mudbrick do
end

def join(list, separator) do
Enum.map_join(list, separator, &Mudbrick.Object.from/1)
Enum.map_join(list, separator, &Mudbrick.Object.to_iodata/1)
end

@doc """
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/catalog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ defmodule Mudbrick.Catalog do
end

defimpl Mudbrick.Object do
def from(catalog) do
Mudbrick.Object.from(%{
def to_iodata(catalog) do
Mudbrick.Object.to_iodata(%{
Type: :Catalog,
Metadata: catalog.metadata.ref,
Pages: catalog.page_tree.ref
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/content_stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Mudbrick.ContentStream do
end

defimpl Mudbrick.Object do
def from(content_stream) do
def to_iodata(content_stream) do
Mudbrick.Stream.new(
compress: content_stream.compress,
data: [
Expand All @@ -58,7 +58,7 @@ defmodule Mudbrick.ContentStream do
|> Mudbrick.join("\n")
]
)
|> Mudbrick.Object.from()
|> Mudbrick.Object.to_iodata()
end
end
end
4 changes: 2 additions & 2 deletions lib/mudbrick/content_stream/bt_et.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Mudbrick.ContentStream.BT do
defstruct []

defimpl Mudbrick.Object do
def from(_), do: ["BT"]
def to_iodata(_), do: ["BT"]
end
end

Expand All @@ -12,6 +12,6 @@ defmodule Mudbrick.ContentStream.ET do
defstruct []

defimpl Mudbrick.Object do
def from(_), do: ["ET"]
def to_iodata(_), do: ["ET"]
end
end
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/cm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Mudbrick.ContentStream.Cm do
end

defimpl Mudbrick.Object do
def from(%Mudbrick.ContentStream.Cm{
def to_iodata(%Mudbrick.ContentStream.Cm{
scale: {x_scale, y_scale},
skew: {x_skew, y_skew},
position: {x_translate, y_translate}
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/content_stream/do.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ defmodule Mudbrick.ContentStream.Do do
defstruct [:image]

defimpl Mudbrick.Object do
def from(operator) do
def to_iodata(operator) do
[
Mudbrick.Object.from(operator.image.resource_identifier),
Mudbrick.Object.to_iodata(operator.image.resource_identifier),
" Do"
]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/l.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Mudbrick.ContentStream.L do
defstruct [:coords]

defimpl Mudbrick.Object do
def from(%Mudbrick.ContentStream.L{coords: {x, y}}) do
def to_iodata(%Mudbrick.ContentStream.L{coords: {x, y}}) do
Enum.map_intersperse([x, y, "l"], " ", &to_string/1)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/m.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Mudbrick.ContentStream.M do
defstruct [:coords]

defimpl Mudbrick.Object do
def from(%Mudbrick.ContentStream.M{coords: {x, y}}) do
def to_iodata(%Mudbrick.ContentStream.M{coords: {x, y}}) do
Enum.map_intersperse([x, y, "m"], " ", &to_string/1)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/content_stream/q.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Mudbrick.ContentStream.QPush do
defstruct []

defimpl Mudbrick.Object do
def from(_), do: ["q"]
def to_iodata(_), do: ["q"]
end
end

Expand All @@ -12,6 +12,6 @@ defmodule Mudbrick.ContentStream.QPop do
defstruct []

defimpl Mudbrick.Object do
def from(_), do: ["Q"]
def to_iodata(_), do: ["Q"]
end
end
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/re.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Mudbrick.ContentStream.Re do
defstruct [:lower_left, :dimensions]

defimpl Mudbrick.Object do
def from(%Mudbrick.ContentStream.Re{lower_left: {x, y}, dimensions: {width, height}}) do
def to_iodata(%Mudbrick.ContentStream.Re{lower_left: {x, y}, dimensions: {width, height}}) do
Enum.map_intersperse([x, y, width, height, "re"], " ", &to_string/1)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/content_stream/rg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ defmodule Mudbrick.ContentStream.Rg do
end

defimpl Mudbrick.Object do
def from(%Mudbrick.ContentStream.Rg{stroking: false, r: r, g: g, b: b}) do
def to_iodata(%Mudbrick.ContentStream.Rg{stroking: false, r: r, g: g, b: b}) do
[[r, g, b] |> Enum.map_join(" ", &to_string/1), " rg"]
end

def from(%Mudbrick.ContentStream.Rg{stroking: true, r: r, g: g, b: b}) do
def to_iodata(%Mudbrick.ContentStream.Rg{stroking: true, r: r, g: g, b: b}) do
[[r, g, b] |> Enum.map_join(" ", &to_string/1), " RG"]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/s.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Mudbrick.ContentStream.S do
defstruct []

defimpl Mudbrick.Object do
def from(_op) do
def to_iodata(_op) do
["S"]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/t_star.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ defmodule Mudbrick.ContentStream.TStar do
defstruct []

defimpl Mudbrick.Object do
def from(_), do: ["T*"]
def to_iodata(_), do: ["T*"]
end
end
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/td.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Mudbrick.ContentStream.Td do
end

defimpl Mudbrick.Object do
def from(td) do
def to_iodata(td) do
[td.tx, td.ty, "Td"]
|> Enum.map(&to_string/1)
|> Enum.intersperse(" ")
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/content_stream/tf.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ defmodule Mudbrick.ContentStream.Tf do
defstruct [:font, :size]

defimpl Mudbrick.Object do
def from(tf) do
def to_iodata(tf) do
[
Mudbrick.Object.from(tf.font.resource_identifier),
Mudbrick.Object.to_iodata(tf.font.resource_identifier),
" ",
to_string(tf.size),
" Tf"
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/content_stream/tj.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ defmodule Mudbrick.ContentStream.TJ do
text: nil

defimpl Mudbrick.Object do
def from(%Mudbrick.ContentStream.TJ{text: ""}) do
def to_iodata(%Mudbrick.ContentStream.TJ{text: ""}) do
[]
end

def from(op) do
def to_iodata(op) do
[
"[ ",
Mudbrick.Font.kerned(op.font, op.text)
Expand Down
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/tl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Mudbrick.ContentStream.TL do
defstruct [:leading]

defimpl Mudbrick.Object do
def from(tl) do
def to_iodata(tl) do
[to_string(tl.leading), " TL"]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mudbrick/content_stream/w.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Mudbrick.ContentStream.W do
defstruct [:width]

defimpl Mudbrick.Object do
def from(w) do
def to_iodata(w) do
[to_string(w.width), " w"]
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/font.ex
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ defmodule Mudbrick.Font do
end

defimpl Mudbrick.Object do
def from(font) do
Object.from(%{
def to_iodata(font) do
Object.to_iodata(%{
Type: :Font,
BaseFont: font.name,
Subtype: font.type,
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/font/cid_font.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ defmodule Mudbrick.Font.CIDFont do
end

defimpl Mudbrick.Object do
def from(cid_font) do
Mudbrick.Object.from(%{
def to_iodata(cid_font) do
Mudbrick.Object.to_iodata(%{
Type: :Font,
Subtype: cid_font.type,
BaseFont: cid_font.font_name,
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/font/cmap.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Mudbrick.Font.CMap do
end

defimpl Mudbrick.Object do
def from(cmap) do
def to_iodata(cmap) do
pairs =
cmap.parsed.gid2cid
|> Enum.map(fn {gid, cid} ->
Expand Down Expand Up @@ -47,7 +47,7 @@ defmodule Mudbrick.Font.CMap do
"""
]

Mudbrick.Object.from(
Mudbrick.Object.to_iodata(
Mudbrick.Stream.new(
compress: cmap.compress,
data: data
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/font/descriptor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ defmodule Mudbrick.Font.Descriptor do
end

defimpl Mudbrick.Object do
def from(descriptor) do
Mudbrick.Object.from(%{
def to_iodata(descriptor) do
Mudbrick.Object.to_iodata(%{
Ascent: descriptor.ascent,
CapHeight: descriptor.cap_height,
Descent: descriptor.descent,
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Mudbrick.Image do
end

defimpl Mudbrick.Object do
def from(image) do
def to_iodata(image) do
Stream.new(
data: image.file,
additional_entries: %{
Expand All @@ -97,7 +97,7 @@ defmodule Mudbrick.Image do
Filter: image.filter
}
)
|> Mudbrick.Object.from()
|> Mudbrick.Object.to_iodata()
end
end
end
6 changes: 3 additions & 3 deletions lib/mudbrick/indirect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Mudbrick.Indirect do
end

defimpl Mudbrick.Object do
def from(%Ref{number: number}) do
def to_iodata(%Ref{number: number}) do
[to_string(number), " 0 R"]
end
end
Expand All @@ -34,8 +34,8 @@ defmodule Mudbrick.Indirect do
end

defimpl Mudbrick.Object do
def from(%Object{value: value, ref: ref}) do
[to_string(ref.number), " 0 obj\n", Mudbrick.Object.from(value), "\nendobj"]
def to_iodata(%Object{value: value, ref: ref}) do
[to_string(ref.number), " 0 obj\n", Mudbrick.Object.to_iodata(value), "\nendobj"]
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ defmodule Mudbrick.Page do
end

defimpl Mudbrick.Object do
def from(page) do
def to_iodata(page) do
{width, height} = page.size

Mudbrick.Object.from(
Mudbrick.Object.to_iodata(
%{
Type: :Page,
Parent: page.parent,
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/page_tree.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ defmodule Mudbrick.PageTree do
end

defimpl Mudbrick.Object do
def from(page_tree) do
Mudbrick.Object.from(%{
def to_iodata(page_tree) do
Mudbrick.Object.to_iodata(%{
Type: :Pages,
Kids: page_tree.kids,
Count: length(page_tree.kids),
Expand Down
4 changes: 2 additions & 2 deletions lib/mudbrick/path/output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ defmodule Mudbrick.Path.Output do
W
}

def from(%Mudbrick.Path{sub_paths: []}) do
def to_iodata(%Mudbrick.Path{sub_paths: []}) do
%__MODULE__{}
end

def from(%Mudbrick.Path{} = path) do
def to_iodata(%Mudbrick.Path{} = path) do
%__MODULE__{}
|> add(%QPush{})
|> then(fn output ->
Expand Down
6 changes: 3 additions & 3 deletions lib/mudbrick/serialisation/document.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ defimpl Mudbrick.Object, for: Mudbrick.Document do
alias Mudbrick.Document
alias Mudbrick.Object

def from(%Document{objects: raw_objects} = doc) do
def to_iodata(%Document{objects: raw_objects} = doc) do
header = "%PDF-2.0\n%����"
objects = raw_objects |> Enum.reverse() |> Enum.map(&Object.from/1)
objects = raw_objects |> Enum.reverse() |> Enum.map(&Object.to_iodata/1)
sections = [header | objects]

trailer =
Object.from(%{
Object.to_iodata(%{
Size: length(objects) + 1,
Root: Document.catalog(doc).ref
})
Expand Down
Loading

0 comments on commit 3dbe280

Please sign in to comment.