author | wenzelm |
Mon, 04 Nov 2024 20:55:01 +0100 | |
changeset 81340 | 30f7eb65d679 |
parent 75393 | 87ebf5a50283 |
child 81343 | b5b0c398cdec |
permissions | -rw-r--r-- |
59290 | 1 |
/* Title: Tools/Graphview/metrics.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Physical metrics for layout and painting. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.graphview |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
81340 | 12 |
import java.awt.Font |
59384 | 13 |
import java.awt.geom.Rectangle2D |
59290 | 14 |
|
15 |
||
75393 | 16 |
object Metrics { |
59290 | 17 |
def apply(font: Font): Metrics = new Metrics(font) |
81340 | 18 |
val default: Metrics = apply(Font_Metric.default.font) |
59290 | 19 |
} |
20 |
||
81340 | 21 |
class Metrics private(font: Font) extends Font_Metric(font = font) { |
22 |
val ascent: Double = font.getLineMetrics("", context).getAscent |
|
59290 | 23 |
|
81340 | 24 |
def gap: Double = (average_width * 3).ceil |
59302
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
25 |
|
81340 | 26 |
def dummy_size2: Double = (average_width / 2).ceil |
59384 | 27 |
|
28 |
def node_width2(lines: List[String]): Double = |
|
81340 | 29 |
((lines.foldLeft(0.0)({ case (w, s) => w max string_width(s) }) + 2 * average_width) / 2).ceil |
59302
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
30 |
|
59384 | 31 |
def node_height2(num_lines: Int): Double = |
81340 | 32 |
((height.ceil * (num_lines max 1) + average_width) / 2).ceil |
59384 | 33 |
|
34 |
def level_height2(num_lines: Int, num_edges: Int): Double = |
|
35 |
(node_height2(num_lines) + gap) max (node_height2(1) * (num_edges max 5)) |
|
59290 | 36 |
} |