-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spread content stream modules into files
- Loading branch information
1 parent
db96bf3
commit 5e20a2a
Showing
10 changed files
with
161 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule Mudbrick.ContentStream.BT do | ||
@moduledoc false | ||
defstruct [] | ||
|
||
def open({_doc, content_stream} = context) do | ||
context | ||
|> Mudbrick.ContentStream.add(%__MODULE__{}) | ||
|> Mudbrick.ContentStream.add(content_stream.value.current_base_td) | ||
|> Mudbrick.ContentStream.add(content_stream.value.current_tf) | ||
|> Mudbrick.ContentStream.add(content_stream.value.current_tl) | ||
end | ||
|
||
defimpl Mudbrick.Object do | ||
def from(_), do: ["BT"] | ||
end | ||
end | ||
|
||
defmodule Mudbrick.ContentStream.ET do | ||
@moduledoc false | ||
defstruct [] | ||
|
||
def remove(context) do | ||
Mudbrick.ContentStream.update_operations(context, fn [%__MODULE__{} | operations] -> | ||
operations | ||
end) | ||
end | ||
|
||
defimpl Mudbrick.Object do | ||
def from(_), do: ["ET"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Mudbrick.ContentStream.Cm do | ||
@moduledoc false | ||
defstruct scale: {0, 0}, | ||
skew: {0, 0}, | ||
position: {0, 0} | ||
|
||
defimpl Mudbrick.Object do | ||
def from(%Mudbrick.ContentStream.Cm{ | ||
scale: {x_scale, y_scale}, | ||
skew: {x_skew, y_skew}, | ||
position: {x_translate, y_translate} | ||
}) do | ||
[ | ||
Mudbrick.join([x_scale, x_skew, y_skew, y_scale, x_translate, y_translate]), | ||
" cm" | ||
] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Mudbrick.ContentStream.Do do | ||
@moduledoc false | ||
defstruct [:image] | ||
|
||
defimpl Mudbrick.Object do | ||
def from(operator) do | ||
[ | ||
Mudbrick.Object.from(operator.image.resource_identifier), | ||
" Do" | ||
] | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Mudbrick.ContentStream.QPush do | ||
@moduledoc false | ||
defstruct [] | ||
|
||
defimpl Mudbrick.Object do | ||
def from(_), do: ["q"] | ||
end | ||
end | ||
|
||
defmodule Mudbrick.ContentStream.QPop do | ||
@moduledoc false | ||
defstruct [] | ||
|
||
defimpl Mudbrick.Object do | ||
def from(_), do: ["Q"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Mudbrick.ContentStream.Rg do | ||
@moduledoc false | ||
defstruct [:r, :g, :b] | ||
|
||
def new(opts) do | ||
if Enum.any?(opts, fn {_k, v} -> | ||
v < 0 or v > 1 | ||
end) do | ||
raise Mudbrick.ContentStream.InvalidColour, | ||
"tuple must be made of floats or integers between 0 and 1" | ||
end | ||
|
||
struct!(__MODULE__, opts) | ||
end | ||
|
||
defimpl Mudbrick.Object do | ||
def from(%Mudbrick.ContentStream.Rg{r: r, g: g, b: b}) do | ||
[[r, g, b] |> Enum.map_join(" ", &to_string/1), " rg"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Mudbrick.ContentStream.Tf do | ||
@moduledoc false | ||
defstruct [:font, :size] | ||
|
||
def current!(content_stream) do | ||
content_stream.value.current_tf || raise Mudbrick.Font.NotSet, "No font chosen" | ||
end | ||
|
||
defimpl Mudbrick.Object do | ||
def from(tf) do | ||
[ | ||
Mudbrick.Object.from(tf.font.resource_identifier), | ||
" ", | ||
to_string(tf.size), | ||
" Tf" | ||
] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Mudbrick.ContentStream.Tj do | ||
@moduledoc false | ||
defstruct font: nil, | ||
operator: "Tj", | ||
text: nil | ||
end | ||
|
||
defmodule Mudbrick.ContentStream.Apostrophe do | ||
@moduledoc false | ||
defstruct font: nil, | ||
operator: "'", | ||
text: nil | ||
end | ||
|
||
defimpl Mudbrick.Object, for: [Mudbrick.ContentStream.Tj, Mudbrick.ContentStream.Apostrophe] do | ||
def from(op) do | ||
if op.font.descendant && String.length(op.text) > 0 do | ||
{glyph_ids_decimal, _positions} = | ||
OpenType.layout_text(op.font.parsed, op.text) | ||
|
||
glyph_ids_hex = Enum.map(glyph_ids_decimal, &Mudbrick.to_hex/1) | ||
|
||
["<", glyph_ids_hex, "> ", op.operator] | ||
else | ||
[Mudbrick.Object.from(op.text), " ", op.operator] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Mudbrick.ContentStream.TL do | ||
@moduledoc false | ||
defstruct [:leading] | ||
|
||
defimpl Mudbrick.Object do | ||
def from(tl) do | ||
[to_string(tl.leading), " TL"] | ||
end | ||
end | ||
end |