use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class DrawOutput method processPdf.
private void processPdf(Collection<Image> images, OutputStream stream, DrawLayout layout) throws OutputException {
PDFDocumentGraphics2D g2d;
try {
g2d = new PDFDocumentGraphics2D();
g2d.setGraphicContext(new GraphicContext());
FopFactory fopFactory = PdfTransformer.createFopFactory();
FOUserAgent userAgent = fopFactory.newFOUserAgent();
FontConfig fc = userAgent.getRendererConfig(MimeConstants.MIME_PDF, new PDFRendererConfigParser()).getFontInfoConfig();
FontManager fontManager = fopFactory.getFontManager();
DefaultFontConfigurator fontInfoConfigurator = new DefaultFontConfigurator(fontManager, null, false);
List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fc);
FontInfo fontInfo = new FontInfo();
FontSetup.setup(fontInfo, fontInfoList, userAgent.getResourceResolver(), fontManager.isBase14KerningEnabled());
g2d.setFontInfo(fontInfo);
g2d.setFont(new Font("SansCondensed", Font.PLAIN, g2d.getFont().getSize()));
List<Dimension> sizes = this.getSizes(images, g2d);
Dimension size = this.getTotalSize(sizes, layout);
g2d.setupDocument(stream, size.width, size.height);
this.drawImages(sizes, images, g2d, layout);
g2d.finish();
} catch (IOException | FOPException e) {
throw new OutputException(e.getMessage(), e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class DrawOutput method processPng.
private void processPng(Collection<Image> images, OutputStream stream, DrawLayout layout) throws OutputException {
BufferedImage testImg = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
List<Dimension> sizes = this.getSizes(images, testImg.createGraphics());
Dimension size = this.getTotalSize(sizes, layout);
BufferedImage img = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = img.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, size.width, size.height);
this.drawImages(sizes, images, g2d, layout);
try {
ImageIO.write(img, "png", stream);
} catch (IOException e) {
throw new OutputException(e.getMessage(), e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class PdfTransformer method write.
public FormattingResults write(OutputStream os, InputStream is, URIResolver resolver) throws OutputException {
FopFactory fopFactory = getFopFactory(resolver);
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, fopFactory.newFOUserAgent(), os);
Transformer transformer = factory.newTransformer();
Source src = new StreamSource(is);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
return fop.getResults();
} catch (FOPException | TransformerException e) {
throw new OutputException("Error transformation exception", e);
}
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class CirculationView method draw.
@Override
public void draw(Dimension size, File outputFile, Type type) throws OutputException {
// ignore dimension - it is fixed for the circulation output
OutputFactory factory = OutputFactory.newInstance("draw");
Output output = factory.createOutput("circulations");
Tuple<Integer> limits = this.getLimits();
List<TrainsCycle> circulations = this.getCirculations();
CirculationDrawParams cdParams = new CirculationDrawParams(circulations).setFrom(limits.first).setTo(limits.second).setWidthInChars(stepWidth).setZoom(zoom).setColors(drawColors);
output.write(output.getAvailableParams().setParam(Output.PARAM_OUTPUT_FILE, outputFile).setParam(Output.PARAM_TRAIN_DIAGRAM, diagram).setParam(DrawParams.CD_PARAMS, Arrays.asList(cdParams)).setParam(DrawParams.OUTPUT_TYPE, type == Type.SVG ? FileOutputType.SVG : FileOutputType.PNG));
}
use of net.parostroj.timetable.output2.OutputException in project grafikon by jub77.
the class XmlEndPositionsOutput method writeTo.
@Override
protected void writeTo(OutputParams params, OutputStream stream, TrainDiagram diagram) throws OutputException {
try {
// extract positions
PositionsExtractor pe = new PositionsExtractor(diagram);
List<Position> engines = pe.getEndPositions(diagram.getEngineCycleType().getCycles(), null);
List<Position> trainUnits = pe.getEndPositions(diagram.getTrainUnitCycleType().getCycles(), null);
EndPositions ep = new EndPositions();
ep.setEnginesPositions(engines);
ep.setTrainUnitsPositions(trainUnits);
JAXBContext context = JAXBContext.newInstance(EndPositions.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, this.getCharset().name());
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
Writer writer = new OutputStreamWriter(stream, this.getCharset());
m.marshal(ep, writer);
} catch (Exception e) {
throw new OutputException(e);
}
}
Aggregations