def write_png(
file: JFile,
paint: Graphics2D => Unit,
width: Int,
height: Int,
dpi: Int = 72
): Unit = { val scale = dpi / 72.0f val w = (width * scale).round val h = (height * scale).round
val img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB) val gfx = img.createGraphics try {
gfx.scale(scale, scale)
paint(gfx)
ImageIO.write(img, "png", file)
} finally { gfx.dispose }
}
/* PDF */
privatedef font_mapper(): FontMapper = { val mapper = new DefaultFontMapper for (entry <- Isabelle_Fonts.fonts()) { val params = new DefaultFontMapper.BaseFontParameters(File.platform_path(entry.path))
params.encoding = BaseFont.IDENTITY_H
params.embedded = true
params.ttfAfm = entry.bytes.make_array
mapper.putName(entry.name, params)
}
mapper
}
def write_pdf(file: JFile, paint: Graphics2D => Unit, width: Int, height: Int): Unit = { import com.lowagie.text.{Document, Rectangle}
using(new BufferedOutputStream(new FileOutputStream(file))) { out => val document = new Document() try {
document.setPageSize(new Rectangle(width.toFloat, height.toFloat)) val writer = PdfWriter.getInstance(document, out)
document.open()
val cb = writer.getDirectContent() val tp = cb.createTemplate(width.toFloat, height.toFloat) val gfx = tp.createGraphics(width.toFloat, height.toFloat, font_mapper())
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.