diff --git a/lib/mudbrick.ex b/lib/mudbrick.ex index ba4409e..1f97da6 100644 --- a/lib/mudbrick.ex +++ b/lib/mudbrick.ex @@ -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() diff --git a/test/mudbrick_test.exs b/test/mudbrick_test.exs index 6460056..3f80eb4 100644 --- a/test/mudbrick_test.exs +++ b/test/mudbrick_test.exs @@ -3,6 +3,8 @@ defmodule MudbrickTest do import Mudbrick + alias Mudbrick.Page + test "playground" do assert new( compress: true, @@ -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), @@ -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!") @@ -74,7 +76,7 @@ defmodule MudbrickTest do a new line!\ """) - |> page(size: :a4) + |> page(size: Page.size(:a4)) |> render() |> to_string() == """ diff --git a/test/predicates_test.exs b/test/predicates_test.exs index c025eb8..8e2b593 100644 --- a/test/predicates_test.exs +++ b/test/predicates_test.exs @@ -3,12 +3,13 @@ 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" @@ -16,20 +17,20 @@ defmodule Mbc.PredicatesTest do |> 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 @@ -46,7 +47,7 @@ defmodule Mbc.PredicatesTest do ] } ) - |> page(size: :letter) + |> page() |> font(:helvetica, size: 100) |> text( "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWhello, world!WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" @@ -68,7 +69,7 @@ defmodule Mbc.PredicatesTest do ] } ) - |> page(size: :letter) + |> page() |> font(:helvetica, size: 100) |> text("hello, world!") |> render() diff --git a/test/text_test.exs b/test/text_test.exs index d79e13c..859a219 100644 --- a/test/text_test.exs +++ b/test/text_test.exs @@ -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) @@ -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 @@ -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₂") @@ -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()