equal
deleted
inserted
replaced
16 import org.jfree.chart.JFreeChart |
16 import org.jfree.chart.JFreeChart |
17 |
17 |
18 import com.lowagie.text.pdf.{PdfWriter, BaseFont, FontMapper, DefaultFontMapper} |
18 import com.lowagie.text.pdf.{PdfWriter, BaseFont, FontMapper, DefaultFontMapper} |
19 |
19 |
20 |
20 |
21 object Graphics_File |
21 object Graphics_File { |
22 { |
|
23 /* PNG */ |
22 /* PNG */ |
24 |
23 |
25 def write_png( |
24 def write_png( |
26 file: JFile, paint: Graphics2D => Unit, width: Int, height: Int, dpi: Int = 72): Unit = |
25 file: JFile, |
27 { |
26 paint: Graphics2D => Unit, |
|
27 width: Int, |
|
28 height: Int, |
|
29 dpi: Int = 72 |
|
30 ): Unit = { |
28 val scale = dpi / 72.0f |
31 val scale = dpi / 72.0f |
29 val w = (width * scale).round |
32 val w = (width * scale).round |
30 val h = (height * scale).round |
33 val h = (height * scale).round |
31 |
34 |
32 val img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB) |
35 val img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB) |
40 } |
43 } |
41 |
44 |
42 |
45 |
43 /* PDF */ |
46 /* PDF */ |
44 |
47 |
45 private def font_mapper(): FontMapper = |
48 private def font_mapper(): FontMapper = { |
46 { |
|
47 val mapper = new DefaultFontMapper |
49 val mapper = new DefaultFontMapper |
48 for (entry <- Isabelle_Fonts.fonts()) { |
50 for (entry <- Isabelle_Fonts.fonts()) { |
49 val params = new DefaultFontMapper.BaseFontParameters(File.platform_path(entry.path)) |
51 val params = new DefaultFontMapper.BaseFontParameters(File.platform_path(entry.path)) |
50 params.encoding = BaseFont.IDENTITY_H |
52 params.encoding = BaseFont.IDENTITY_H |
51 params.embedded = true |
53 params.embedded = true |
53 mapper.putName(entry.name, params) |
55 mapper.putName(entry.name, params) |
54 } |
56 } |
55 mapper |
57 mapper |
56 } |
58 } |
57 |
59 |
58 def write_pdf(file: JFile, paint: Graphics2D => Unit, width: Int, height: Int): Unit = |
60 def write_pdf(file: JFile, paint: Graphics2D => Unit, width: Int, height: Int): Unit = { |
59 { |
|
60 import com.lowagie.text.{Document, Rectangle} |
61 import com.lowagie.text.{Document, Rectangle} |
61 |
62 |
62 using(new BufferedOutputStream(new FileOutputStream(file)))(out => |
63 using(new BufferedOutputStream(new FileOutputStream(file)))(out => { |
63 { |
|
64 val document = new Document() |
64 val document = new Document() |
65 try { |
65 try { |
66 document.setPageSize(new Rectangle(width.toFloat, height.toFloat)) |
66 document.setPageSize(new Rectangle(width.toFloat, height.toFloat)) |
67 val writer = PdfWriter.getInstance(document, out) |
67 val writer = PdfWriter.getInstance(document, out) |
68 document.open() |
68 document.open() |