@@ -29,28 +29,19 @@ defmodule Mudbrick.TextBlock.Output do
2929
3030 # first line, first part
3131 defp reduce_parts ( output , % Line { parts: [ part ] } , _operator , :first_line ) do
32- add_part ( output , part , Tj )
32+ Output . add_part ( output , part , Tj )
3333 end
3434
3535 # subsequent line, first part
3636 defp reduce_parts ( output , % Line { parts: [ part ] } , _operator , nil ) do
37- add_part ( output , part , Apostrophe )
37+ Output . add_part ( output , part , Apostrophe )
3838 end
3939
4040 defp reduce_parts ( output , % Line { parts: [ part | parts ] } = line , operator , line_kind ) do
4141 output
42- |> add_part ( part , operator )
42+ |> Output . add_part ( part , operator )
4343 |> reduce_parts ( % { line | parts: parts } , Tj , line_kind )
4444 end
45-
46- def add_part ( output , part , operator ) do
47- output
48- |> Output . with_font (
49- struct! ( operator , font: part . font || output . font , text: part . text ) ,
50- part
51- )
52- |> Output . colour ( part . colour )
53- end
5445 end
5546
5647 defmodule RightAlign do
@@ -76,20 +67,14 @@ defmodule Mudbrick.TextBlock.Output do
7667 end
7768
7869 defp reduce_parts ( output , % Line { parts: [ part ] } ) do
79- add_part ( output , part )
70+ Output . add_part ( output , part , Tj )
8071 end
8172
8273 defp reduce_parts ( output , % Line { parts: [ part | parts ] } = line ) do
8374 output
84- |> add_part ( part )
75+ |> Output . add_part ( part , Tj )
8576 |> reduce_parts ( % { line | parts: parts } )
8677 end
87-
88- def add_part ( output , part ) do
89- output
90- |> Output . with_font ( % Tj { font: part . font || output . font , text: part . text } , part )
91- |> Output . colour ( part . colour )
92- end
9378 end
9479
9580 def from (
@@ -100,16 +85,13 @@ defmodule Mudbrick.TextBlock.Output do
10085 position: { x , y }
10186 } = tb
10287 ) do
103- output =
104- % __MODULE__ { font: font , font_size: font_size }
105- |> end_block ( )
106- |> LeftAlign . reduce_lines ( tb . lines )
107- |> add ( % Td { tx: x , ty: y } )
108- |> add ( % TL { leading: leading ( tb ) } )
109- |> add ( % Tf { font: font , size: font_size } )
110- |> start_block ( )
111-
112- output . operations
88+ % __MODULE__ { font: font , font_size: font_size }
89+ |> end_block ( )
90+ |> LeftAlign . reduce_lines ( tb . lines )
91+ |> add ( % Td { tx: x , ty: y } )
92+ |> add ( % TL { leading: leading ( tb ) } )
93+ |> add ( % Tf { font: font , size: font_size } )
94+ |> start_block ( )
11395 end
11496
11597 def from (
@@ -119,21 +101,27 @@ defmodule Mudbrick.TextBlock.Output do
119101 font_size: font_size
120102 } = tb
121103 ) do
122- output =
123- % __MODULE__ { font: font , font_size: font_size }
124- |> RightAlign . reduce_lines ( tb . lines , fn output , text , line ->
125- right_offset ( output , tb , text , line )
126- end )
127- |> add ( % TL { leading: leading ( tb ) } )
128- |> add ( % Tf { font: font , size: font_size } )
129-
130- output . operations
104+ % __MODULE__ { font: font , font_size: font_size }
105+ |> RightAlign . reduce_lines ( tb . lines , fn output , text , line ->
106+ right_offset ( output , tb , text , line )
107+ end )
108+ |> add ( % TL { leading: leading ( tb ) } )
109+ |> add ( % Tf { font: font , size: font_size } )
131110 end
132111
133112 def add ( % __MODULE__ { } = output , op ) do
134113 Map . update! ( output , :operations , & [ op | & 1 ] )
135114 end
136115
116+ def add_part ( output , part , operator ) do
117+ output
118+ |> with_font (
119+ struct! ( operator , font: part . font || output . font , text: part . text ) ,
120+ part
121+ )
122+ |> colour ( part . colour )
123+ end
124+
137125 def with_font ( output , op , part ) do
138126 if part . font == nil or output . font == part . font do
139127 add ( output , op )
0 commit comments