xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Alvarez <Felix.Alva...@mathworks.com>
Subject Custom Font's Without Font Paths
Date Fri, 02 Nov 2012 15:07:43 GMT
Hi,
  I'm trying to use the FOP API purely from java in order to generate PDFs, PS, and EPS files.
 I'm trying to get font embedding to work in each of these scenarios without using the auto-detect
configuration option because it can cause out of memory exceptions with my application.  I'm
trying to avoid duplicating the FOP auto-detect work trying to find the location of the font's
on the system so I'd prefer a way to just convert my java fonts into FOP Fonts.  I can get
 the list of needed fonts but am struggling to figure out how to convert the java fonts into
the FOP Fonts with appropriate font metrics so that I can set the FontInfo for my PDFDocumentGraphics2D
or my PSDocumentGraphics2D objects.  I've created my own createFontInfo method below which
doesn't work because it somehow needs to create the font metrics as well.

Thanks,
--Felix

    public FontInfo createFontInfo(List<Font> fontList) throws
                FOPException, IOException {
        FontInfo fontInfo = new org.apache.fop.fonts.FontInfo();
        org.apache.fop.fonts.FontManager fontManager = new org.apache.fop.fonts.FontManager();

        List fontCollections = new java.util.ArrayList();
        fontCollections.add(new Base14FontCollection(fontManager.isBase14KerningEnabled()));

        for (Font f:fontList) {
            fontInfo.addFontProperties(f.getFontName(), new String[] {
                    FontUtil.stripWhiteSpace(f.getFamily()), f.getFamily(), f.getPSName()},
                    (f.getStyle() & Font.ITALIC) != 0 ? org.apache.fop.fonts.Font.STYLE_ITALIC
:
                            org.apache.fop.fonts.Font.STYLE_NORMAL,
                    (f.getStyle() & Font.BOLD) != 0 ? org.apache.fop.fonts.Font.WEIGHT_BOLD
:
                            org.apache.fop.fonts.Font.WEIGHT_NORMAL);
        }

        fontManager.setup(fontInfo,
                (FontCollection[])fontCollections.toArray(
                        new FontCollection[fontCollections.size()]));

        return fontInfo;
    }


Mime
View raw message