@@ -66,11 +66,11 @@ defmodule Mudbrick do
66
66
ContentStream . add ( context , ContentStream.Td , tx: x , ty: y )
67
67
end
68
68
69
- defp latest_font_operation ( content_stream ) do
69
+ defp latest_font_operation! ( content_stream ) do
70
70
Enum . find (
71
71
content_stream . value . operations ,
72
72
& match? ( % ContentStream.Tf { } , & 1 )
73
- )
73
+ ) || raise Font.NotSet , "No font chosen"
74
74
end
75
75
76
76
def text ( { _doc , content_stream } = context , text , colour: { r , g , b } ) do
@@ -79,39 +79,25 @@ defmodule Mudbrick do
79
79
|> ContentStream . add ( ContentStream.Rg , r: r , g: g , b: b )
80
80
|> text ( text )
81
81
|> ContentStream . add ( ContentStream.QPop , [ ] )
82
- |> ContentStream . add ( latest_font_operation ( content_stream ) )
82
+ |> ContentStream . add ( latest_font_operation! ( content_stream ) )
83
83
end
84
84
85
85
def text ( { _doc , content_stream } = context , text ) do
86
- case latest_font_operation ( content_stream ) do
87
- % ContentStream.Tf { size: font_size , font: font } ->
88
- [ first_part | parts ] = String . split ( text , "\n " )
89
-
90
- context
91
- |> ContentStream . add (
92
- ContentStream.TL ,
93
- leading: font_size * 1.2
94
- )
95
- |> ContentStream . add (
96
- ContentStream.Tj ,
97
- font: font ,
98
- text: first_part
99
- )
100
- |> then ( fn context ->
101
- for part <- parts , reduce: context do
102
- acc ->
103
- ContentStream . add (
104
- acc ,
105
- ContentStream.Apostrophe ,
106
- font: font ,
107
- text: part
108
- )
109
- end
110
- end )
111
-
112
- nil ->
113
- raise Font.NotSet , "No font chosen"
114
- end
86
+ import ContentStream
87
+
88
+ tf = latest_font_operation! ( content_stream )
89
+
90
+ [ first_part | parts ] = String . split ( text , "\n " )
91
+
92
+ context
93
+ |> add ( ContentStream.TL , leading: tf . size * 1.2 )
94
+ |> add ( ContentStream.Tj , font: tf . font , text: first_part )
95
+ |> then ( fn context ->
96
+ for part <- parts , reduce: context do
97
+ acc ->
98
+ add ( acc , ContentStream.Apostrophe , font: tf . font , text: part )
99
+ end
100
+ end )
115
101
end
116
102
117
103
def render ( { doc , _page } ) do
0 commit comments