Skip to content

Commit bbef004

Browse files
committed
Set leading when changing font
1 parent 4ab2a16 commit bbef004

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

lib/mudbrick.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,20 @@ defmodule Mudbrick do
4545
end
4646

4747
def font({_document, content_stream_object} = context, user_identifier, opts) do
48+
import ContentStream
49+
4850
case Map.fetch(content_stream_object.value.page.fonts, user_identifier) do
4951
{:ok, font} ->
50-
ContentStream.add(
51-
context,
52+
context
53+
|> add(
5254
ContentStream.Tf,
5355
Keyword.put(
5456
opts,
5557
:font,
5658
font.value
5759
)
5860
)
61+
|> add(ContentStream.TL, leading: Keyword.fetch!(opts, :size) * 1.2)
5962

6063
:error ->
6164
raise Font.Unregistered, "Unregistered font: #{user_identifier}"
@@ -90,7 +93,6 @@ defmodule Mudbrick do
9093
[first_part | parts] = String.split(text, "\n")
9194

9295
context
93-
|> add(ContentStream.TL, leading: tf.size * 1.2)
9496
|> add(ContentStream.Tj, font: tf.font, text: first_part)
9597
|> then(fn context ->
9698
for part <- parts, reduce: context do

test/mudbrick/content_stream_test.exs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ defmodule Mudbrick.ContentStreamTest do
3232
""")
3333

3434
assert content_stream.value.operations
35-
|> render(3) ==
35+
|> render(2) ==
3636
"""
37-
12.0 TL
3837
(a) Tj
3938
(b) '\
4039
"""
@@ -56,9 +55,8 @@ defmodule Mudbrick.ContentStreamTest do
5655
""")
5756

5857
assert content_stream.value.operations
59-
|> render(3) ==
58+
|> render(2) ==
6059
"""
61-
12.0 TL
6260
<00A5> Tj
6361
<00B4> '\
6462
"""

test/mudbrick/font_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ defmodule Mudbrick.FontTest do
3939
(black and ) Tj
4040
q
4141
1.0 0.0 0.0 rg
42-
12.0 TL
4342
(red) Tj
4443
(text) '
4544
Q

test/mudbrick_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ defmodule MudbrickTest do
9595
stream
9696
BT
9797
/F2 100 Tf
98-
300 400 Td
9998
120.0 TL
99+
300 400 Td
100100
(hello, world!) Tj
101101
/F1 10 Tf
102-
0 -24 Td
103102
12.0 TL
103+
0 -24 Td
104104
(a new line!) Tj
105105
ET
106106
endstream

0 commit comments

Comments
 (0)