| author | wenzelm |
| Tue, 06 Jan 2015 23:56:13 +0100 | |
| changeset 59312 | c4b9b04bfc6d |
| parent 59302 | 4d985afc0565 |
| child 59384 | c75327a34960 |
| 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 |
||
12 |
import java.awt.{Font, RenderingHints}
|
|
13 |
import java.awt.font.FontRenderContext |
|
14 |
||
15 |
||
16 |
object Metrics |
|
17 |
{
|
|
18 |
val rendering_hints: RenderingHints = |
|
19 |
new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON) |
|
20 |
||
21 |
val font_render_context: FontRenderContext = |
|
22 |
new FontRenderContext(null, true, false) |
|
23 |
||
24 |
def apply(font: Font): Metrics = new Metrics(font) |
|
25 |
||
26 |
val default: Metrics = apply(new Font("Helvetica", Font.PLAIN, 12))
|
|
27 |
} |
|
28 |
||
29 |
class Metrics private(val font: Font) |
|
30 |
{
|
|
31 |
def string_bounds(s: String) = font.getStringBounds(s, Metrics.font_render_context) |
|
32 |
private val mix = string_bounds("mix")
|
|
33 |
val space_width = string_bounds(" ").getWidth
|
|
34 |
def char_width: Double = mix.getWidth / 3 |
|
35 |
def height: Double = mix.getHeight |
|
36 |
def ascent: Double = font.getLineMetrics("", Metrics.font_render_context).getAscent
|
|
37 |
def gap: Double = mix.getWidth |
|
| 59293 | 38 |
def pad_x: Double = char_width * 1.5 |
39 |
def pad_y: Double = char_width |
|
| 59290 | 40 |
|
|
59302
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
41 |
def dummy_width2: Double = (pad_x / 2).ceil |
|
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
42 |
|
| 59290 | 43 |
def box_width2(node: Graph_Display.Node): Double = |
| 59293 | 44 |
((string_bounds(node.toString).getWidth + pad_x) / 2).ceil |
|
59302
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
45 |
|
|
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
46 |
def box_width2(vertex: Layout.Vertex): Double = |
|
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
47 |
vertex match {
|
|
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
48 |
case Layout.Node(node) => box_width2(node) |
|
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
49 |
case _: Layout.Dummy => dummy_width2 |
|
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59293
diff
changeset
|
50 |
} |
| 59290 | 51 |
def box_gap: Double = gap.ceil |
52 |
def box_height(n: Int): Double = (char_width * 1.5 * (5 max n)).ceil |
|
53 |
} |
|
54 |