Skip to content

Commit

Permalink
Page size option must be a {w,h} tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpunch committed Oct 21, 2024
1 parent ac0d734 commit 66d4d0d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
5 changes: 2 additions & 3 deletions lib/mudbrick.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ defmodule Mudbrick do
def page(doc, opts) do
Page.add(
doc,
Keyword.update(
Keyword.put_new(
opts,
:size,
Page.size(:a4),
&Page.size(&1)
Page.size(:a4)
)
)
|> contents()
Expand Down
8 changes: 5 additions & 3 deletions test/mudbrick_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule MudbrickTest do

import Mudbrick

alias Mudbrick.Page

test "playground" do
assert new(
compress: true,
Expand All @@ -11,7 +13,7 @@ defmodule MudbrickTest do
flower: [file: TestHelper.flower()]
}
)
|> page(size: :letter)
|> page(size: Page.size(:letter))
|> image(
:flower,
scale: Mudbrick.Page.size(:letter),
Expand Down Expand Up @@ -65,7 +67,7 @@ defmodule MudbrickTest do
]
}
)
|> page(size: :letter)
|> page(size: Page.size(:letter))
|> text_position(300, 400)
|> font(:helvetica, size: 100)
|> text("hello, world!")
Expand All @@ -74,7 +76,7 @@ defmodule MudbrickTest do
a new line!\
""")
|> page(size: :a4)
|> page(size: Page.size(:a4))
|> render()
|> to_string() ==
"""
Expand Down
21 changes: 11 additions & 10 deletions test/predicates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ defmodule Mbc.PredicatesTest do

import Mudbrick
import Mudbrick.Predicates
import TestHelper

describe "with direct glyph encoding" do
test "with compression, can assert/refute that a piece of text appears" do
raw_pdf =
new(compress: true, fonts: %{bodoni: [file: TestHelper.bodoni()]})
|> page(size: :letter)
new(compress: true, fonts: %{bodoni: [file: bodoni()]})
|> page()
|> font(:bodoni, size: 100)
|> text(
"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWhello, CO₂!WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"
)
|> render()
|> IO.iodata_to_binary()

assert raw_pdf |> has_text?("hello, CO₂!", in_font: TestHelper.bodoni())
refute raw_pdf |> has_text?("good morning!", in_font: TestHelper.bodoni())
assert raw_pdf |> has_text?("hello, CO₂!", in_font: bodoni())
refute raw_pdf |> has_text?("good morning!", in_font: bodoni())
end

test "without compression, can assert/refute that a piece of text appears" do
raw_pdf =
new(fonts: %{bodoni: [file: TestHelper.bodoni()]})
|> page(size: :letter)
new(fonts: %{bodoni: [file: bodoni()]})
|> page()
|> font(:bodoni, size: 100)
|> text("hello, world!")
|> render()

assert raw_pdf |> has_text?("hello, world!", in_font: TestHelper.bodoni())
refute raw_pdf |> has_text?("good morning!", in_font: TestHelper.bodoni())
assert raw_pdf |> has_text?("hello, world!", in_font: bodoni())
refute raw_pdf |> has_text?("good morning!", in_font: bodoni())
end
end

Expand All @@ -46,7 +47,7 @@ defmodule Mbc.PredicatesTest do
]
}
)
|> page(size: :letter)
|> page()
|> font(:helvetica, size: 100)
|> text(
"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWhello, world!WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW"
Expand All @@ -68,7 +69,7 @@ defmodule Mbc.PredicatesTest do
]
}
)
|> page(size: :letter)
|> page()
|> font(:helvetica, size: 100)
|> text("hello, world!")
|> render()
Expand Down
8 changes: 4 additions & 4 deletions test/text_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ defmodule Mudbrick.TextTest do
_text2
] =
new(fonts: %{bodoni: [file: TestHelper.bodoni()]})
|> page(size: :letter)
|> page()
|> font(:bodoni, size: 14)
|> text("hi")
|> text_position(200, 700)
Expand All @@ -100,7 +100,7 @@ defmodule Mudbrick.TextTest do
"200 700 Td"
] =
new(fonts: %{bodoni: [file: TestHelper.bodoni()]})
|> page(size: :letter)
|> page()
|> text_position(200, 700)
|> operations()
end
Expand Down Expand Up @@ -265,7 +265,7 @@ defmodule Mudbrick.TextTest do
test "converts Tj text to the assigned font's glyph IDs in hex" do
assert ["<001100550174> Tj"] =
new(fonts: %{bodoni: [file: TestHelper.bodoni()]})
|> page(size: :letter)
|> page()
|> font(:bodoni, size: 24)
|> text_position(0, 700)
|> text("CO₂")
Expand All @@ -275,7 +275,7 @@ defmodule Mudbrick.TextTest do

test "copes with trailing newlines in CID font text" do
assert new(fonts: %{bodoni: [file: TestHelper.bodoni()]})
|> page(size: :letter)
|> page()
|> font(:bodoni, size: 13)
|> text("\n")
|> render()
Expand Down

0 comments on commit 66d4d0d

Please sign in to comment.