equal
deleted
inserted
replaced
70 List(XML.Wrapped_Elem(markup, body1, standard_format(body2))) |
70 List(XML.Wrapped_Elem(markup, body1, standard_format(body2))) |
71 case XML.Elem(markup, body) => List(XML.Elem(markup, standard_format(body))) |
71 case XML.Elem(markup, body) => List(XML.Elem(markup, standard_format(body))) |
72 case XML.Text(text) => Library.separate(FBreak, split_lines(text).map(XML.Text)) |
72 case XML.Text(text) => Library.separate(FBreak, split_lines(text).map(XML.Text)) |
73 } |
73 } |
74 |
74 |
75 private sealed case class Text(tx: XML.Body = Nil, val pos: Double = 0.0, val nl: Int = 0) |
|
76 { |
|
77 def newline: Text = copy(tx = FBreak :: tx, pos = 0.0, nl = nl + 1) |
|
78 def string(s: String, len: Double): Text = copy(tx = XML.Text(s) :: tx, pos = pos + len) |
|
79 def blanks(wd: Int): Text = string(spaces(wd), wd.toDouble) |
|
80 def content: XML.Body = tx.reverse |
|
81 } |
|
82 |
|
83 private val margin_default = 76 |
75 private val margin_default = 76 |
84 private def metric_default(s: String) = s.length.toDouble |
76 private def metric_default(s: String) = s.length.toDouble |
85 |
77 |
86 def char_width(metrics: FontMetrics): Double = metrics.stringWidth("mix").toDouble / 3 |
78 def char_width(metrics: FontMetrics): Double = metrics.stringWidth("mix").toDouble / 3 |
87 |
79 |
93 } |
85 } |
94 |
86 |
95 def formatted(input: XML.Body, margin: Int = margin_default, |
87 def formatted(input: XML.Body, margin: Int = margin_default, |
96 metric: String => Double = metric_default): XML.Body = |
88 metric: String => Double = metric_default): XML.Body = |
97 { |
89 { |
|
90 sealed case class Text(tx: XML.Body = Nil, val pos: Double = 0.0, val nl: Int = 0) |
|
91 { |
|
92 def newline: Text = copy(tx = FBreak :: tx, pos = 0.0, nl = nl + 1) |
|
93 def string(s: String, len: Double): Text = copy(tx = XML.Text(s) :: tx, pos = pos + len) |
|
94 def blanks(wd: Int): Text = |
|
95 { |
|
96 val s = spaces(wd) |
|
97 string(s, metric(s)) |
|
98 } |
|
99 def content: XML.Body = tx.reverse |
|
100 } |
|
101 |
98 val breakgain = margin / 20 |
102 val breakgain = margin / 20 |
99 val emergencypos = margin / 2 |
103 val emergencypos = margin / 2 |
100 |
104 |
101 def content_length(tree: XML.Tree): Double = |
105 def content_length(tree: XML.Tree): Double = |
102 XML.traverse_text(List(tree))(0.0)(_ + metric(_)) |
106 XML.traverse_text(List(tree))(0.0)(_ + metric(_)) |