author | wenzelm |
Sun, 10 Nov 2024 12:33:20 +0100 | |
changeset 81420 | d25a241502c1 |
parent 81419 | b242c7603e08 |
child 81421 | 8c1680ac4160 |
permissions | -rw-r--r-- |
81416 | 1 |
/* Title: Pure/GUI/rich_text.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Support for rendering of rich text, based on individual messages (XML.Elem). |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
10 |
import javax.swing.JComponent |
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
11 |
|
81418 | 12 |
import scala.collection.mutable |
13 |
||
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
14 |
|
81416 | 15 |
object Rich_Text { |
81420 | 16 |
/* margin */ |
17 |
||
18 |
def make_margin(metric: Font_Metric, margin: Int, limit: Int = -1): Int = { |
|
19 |
val m = (margin * metric.average).toInt |
|
20 |
(if (limit < 0) m else m min limit) max 20 |
|
21 |
} |
|
22 |
||
23 |
def component_margin(metric: Font_Metric, component: JComponent): Int = |
|
24 |
make_margin(metric, (component.getWidth.toDouble / metric.average_width).toInt) |
|
25 |
||
26 |
||
27 |
/* format */ |
|
28 |
||
81416 | 29 |
def command( |
30 |
body: XML.Body = Nil, |
|
31 |
id: Document_ID.Command = Document_ID.none, |
|
32 |
results: Command.Results = Command.Results.empty |
|
33 |
): Command = { |
|
34 |
val source = XML.content(body) |
|
35 |
val markups = Command.Markups.init(Markup_Tree.from_XML(body)) |
|
36 |
Command.unparsed(source, id = id, results = results, markups = markups) |
|
37 |
} |
|
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
38 |
|
81418 | 39 |
def format( |
40 |
msgs: List[XML.Elem], |
|
41 |
margin: Double, |
|
42 |
metric: Font_Metric, |
|
43 |
results: Command.Results |
|
44 |
) : List[Command] = { |
|
45 |
val result = new mutable.ListBuffer[Command] |
|
46 |
for (msg <- msgs) { |
|
47 |
if (result.nonEmpty) { |
|
48 |
result += command(body = Pretty.Separator, id = Document_ID.make()) |
|
49 |
} |
|
50 |
val body = Pretty.formatted(List(msg), margin = margin, metric = metric) |
|
81419 | 51 |
result += command(body = body, id = Protocol_Message.get_serial(msg)) |
81418 | 52 |
|
53 |
Exn.Interrupt.expose() |
|
54 |
} |
|
55 |
result.toList |
|
56 |
} |
|
81416 | 57 |
} |