| author | wenzelm |
| Sun, 10 Nov 2024 12:15:31 +0100 | |
| changeset 81417 | 964b85e04f1f |
| parent 81416 | 206dd586f3d7 |
| child 81418 | de8dbdadda76 |
| 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 |
|
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
12 |
|
| 81416 | 13 |
object Rich_Text {
|
14 |
def command( |
|
15 |
body: XML.Body = Nil, |
|
16 |
id: Document_ID.Command = Document_ID.none, |
|
17 |
results: Command.Results = Command.Results.empty |
|
18 |
): Command = {
|
|
19 |
val source = XML.content(body) |
|
20 |
val markups = Command.Markups.init(Markup_Tree.from_XML(body)) |
|
21 |
Command.unparsed(source, id = id, results = results, markups = markups) |
|
22 |
} |
|
|
81417
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
23 |
|
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
24 |
def make_margin(metric: Font_Metric, margin: Int, limit: Int = -1): Int = {
|
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
25 |
val m = (margin * metric.average).toInt |
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
26 |
(if (limit < 0) m else m min limit) max 20 |
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
27 |
} |
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
28 |
|
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
29 |
def component_margin(metric: Font_Metric, component: JComponent): Int = |
|
964b85e04f1f
clarified margin operations (again, reverting 4794576828df);
wenzelm
parents:
81416
diff
changeset
|
30 |
make_margin(metric, (component.getWidth.toDouble / metric.average_width).toInt) |
| 81416 | 31 |
} |