author | wenzelm |
Fri, 01 Apr 2022 23:19:12 +0200 | |
changeset 75394 | 42267c650205 |
parent 75393 | 87ebf5a50283 |
child 75906 | 2167b9e3157a |
permissions | -rw-r--r-- |
59441 | 1 |
/* Title: Tools/Graphview/graph_file.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
File system operations for graph output. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.graphview |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
import java.io.{File => JFile} |
|
13 |
import java.awt.{Color, Graphics2D} |
|
14 |
||
15 |
||
75393 | 16 |
object Graph_File { |
17 |
def write(file: JFile, graphview: Graphview): Unit = { |
|
59459 | 18 |
val box = graphview.bounding_box() |
59441 | 19 |
val w = box.width.ceil.toInt |
20 |
val h = box.height.ceil.toInt |
|
21 |
||
75393 | 22 |
def paint(gfx: Graphics2D): Unit = { |
61176 | 23 |
gfx.setColor(graphview.background_color) |
59441 | 24 |
gfx.fillRect(0, 0, w, h) |
25 |
gfx.translate(- box.x, - box.y) |
|
59460 | 26 |
graphview.paint(gfx) |
59441 | 27 |
} |
28 |
||
29 |
val name = file.getName |
|
71601 | 30 |
if (name.endsWith(".png")) Graphics_File.write_png(file, paint, w, h) |
31 |
else if (name.endsWith(".pdf")) Graphics_File.write_pdf(file, paint, w, h) |
|
59441 | 32 |
else error("Bad type of file: " + quote(name) + " (.png or .pdf expected)") |
33 |
} |
|
59443
5b552b4f63a5
support for off-line graph output, without GUI thread;
wenzelm
parents:
59441
diff
changeset
|
34 |
|
75393 | 35 |
def write(options: Options, file: JFile, graph: Graph_Display.Graph): Unit = { |
59443
5b552b4f63a5
support for off-line graph output, without GUI thread;
wenzelm
parents:
59441
diff
changeset
|
36 |
val the_options = options |
59462 | 37 |
val graphview = |
38 |
new Graphview(graph.transitive_reduction_acyclic) { def options = the_options } |
|
59459 | 39 |
graphview.update_layout() |
59443
5b552b4f63a5
support for off-line graph output, without GUI thread;
wenzelm
parents:
59441
diff
changeset
|
40 |
|
59459 | 41 |
write(file, graphview) |
59443
5b552b4f63a5
support for off-line graph output, without GUI thread;
wenzelm
parents:
59441
diff
changeset
|
42 |
} |
72573 | 43 |
|
44 |
def make_pdf(options: Options, graph: Graph_Display.Graph): Bytes = |
|
75394 | 45 |
Isabelle_System.with_tmp_file("graph", ext = "pdf") { graph_file => |
72573 | 46 |
write(options, graph_file.file, graph) |
47 |
Bytes.read(graph_file) |
|
75394 | 48 |
} |
59441 | 49 |
} |