Search in sources :

Example 1 with FontManager

use of org.apache.fop.fonts.FontManager 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);
    }
}
Also used : EmbedFontInfo(org.apache.fop.fonts.EmbedFontInfo) GraphicContext(org.apache.xmlgraphics.java2d.GraphicContext) PDFRendererConfigParser(org.apache.fop.render.pdf.PDFRendererConfig.PDFRendererConfigParser) FOUserAgent(org.apache.fop.apps.FOUserAgent) FontConfig(org.apache.fop.fonts.FontConfig) PDFDocumentGraphics2D(org.apache.fop.svg.PDFDocumentGraphics2D) FopFactory(org.apache.fop.apps.FopFactory) Dimension(java.awt.Dimension) IOException(java.io.IOException) FontManager(org.apache.fop.fonts.FontManager) Font(java.awt.Font) FOPException(org.apache.fop.apps.FOPException) OutputException(net.parostroj.timetable.output2.OutputException) EmbedFontInfo(org.apache.fop.fonts.EmbedFontInfo) FontInfo(org.apache.fop.fonts.FontInfo) DefaultFontConfigurator(org.apache.fop.fonts.DefaultFontConfigurator)

Aggregations

Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 IOException (java.io.IOException)1 OutputException (net.parostroj.timetable.output2.OutputException)1 FOPException (org.apache.fop.apps.FOPException)1 FOUserAgent (org.apache.fop.apps.FOUserAgent)1 FopFactory (org.apache.fop.apps.FopFactory)1 DefaultFontConfigurator (org.apache.fop.fonts.DefaultFontConfigurator)1 EmbedFontInfo (org.apache.fop.fonts.EmbedFontInfo)1 FontConfig (org.apache.fop.fonts.FontConfig)1 FontInfo (org.apache.fop.fonts.FontInfo)1 FontManager (org.apache.fop.fonts.FontManager)1 PDFRendererConfigParser (org.apache.fop.render.pdf.PDFRendererConfig.PDFRendererConfigParser)1 PDFDocumentGraphics2D (org.apache.fop.svg.PDFDocumentGraphics2D)1 GraphicContext (org.apache.xmlgraphics.java2d.GraphicContext)1