private DefaultConfiguration generateFontTripletConfig(String name, String style, String weight) { DefaultConfiguration tripletConfig = new DefaultConfiguration("font-triplet"); tripletConfig.setAttribute("name", name); tripletConfig.setAttribute("style", style); tripletConfig.setAttribute("weight", weight); return tripletConfig; }
/** * Checks that the <code>serializeToFile</code> method closes the output stream when it is done. */ public void testSerializeToFile() throws Exception { DefaultConfiguration config = new DefaultConfiguration("root", ""); config.setAttribute("attribute", "value"); File file = new File(testDirectory, "DefaultConfigurationSerializerTestCase.xml"); DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer(); serializer.serializeToFile(file, config); // // This will not work if the serializeToFile method keeps the stream open. // assertTrue(testDirectory.renameTo(testDirectory2)); assertTrue(testDirectory2.renameTo(testDirectory)); file.delete(); }
@SuppressWarnings({"unchecked"}) private DefaultConfiguration buildFontsConfig() { DefaultConfiguration fontsConfig = new DefaultConfiguration("fonts"); // did not work for me :( // if ( environment.getFontDirectories() != null ) { // for ( File fontDirectory : environment.getFontDirectories() ) { // DefaultConfiguration fontDirectoryElement = new DefaultConfiguration( "directory" ); // fontDirectoryElement.setValue( fontDirectory.getAbsolutePath() ); // fontsConfig.addChild( fontDirectoryElement ); // } // } // this code is mostly copied from // http://dev.plutext.org/trac/docx4j/browser/trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/Conversion.java // // Thanks to Jason Harrop from the fop-user list (and who wrote that code) for pointing it out for (EmbedFontInfo embedFontInfo : locateEmbedFontInfos()) { DefaultConfiguration fontConfig = new DefaultConfiguration("font"); fontsConfig.addChild(fontConfig); fontConfig.setAttribute("embed-url", embedFontInfo.getEmbedFile()); if (embedFontInfo.getSubFontName() != null) { fontConfig.setAttribute("sub-font", embedFontInfo.getSubFontName()); } FontTriplet triplet = (FontTriplet) embedFontInfo.getFontTriplets().get(0); fontConfig.addChild( generateFontTripletConfig(triplet.getName(), triplet.getStyle(), triplet.getWeight())); fontConfig.addChild(generateFontTripletConfig(triplet.getName(), "normal", "bold")); fontConfig.addChild(generateFontTripletConfig(triplet.getName(), "italic", "bold")); fontConfig.addChild(generateFontTripletConfig(triplet.getName(), "italic", "normal")); } if (componentRegistry.getConfiguration().isAutoDetectFontsEnabled()) { DefaultConfiguration autoDetect = new DefaultConfiguration("auto-detect"); fontsConfig.addChild(autoDetect); } return fontsConfig; }
private DefaultConfiguration buildFopConfiguration() { DefaultConfiguration fopUserConfiguration = new DefaultConfiguration("fop"); fopUserConfiguration.setAttribute("version", "1.0"); DefaultConfiguration strictConfig = new DefaultConfiguration("strict-configuration"); strictConfig.setValue(true); fopUserConfiguration.addChild(strictConfig); DefaultConfiguration renderersConfig = new DefaultConfiguration("renderers"); fopUserConfiguration.addChild(renderersConfig); DefaultConfiguration pdfRendererConfig = new DefaultConfiguration("renderer"); pdfRendererConfig.setAttribute("mime", "application/pdf"); renderersConfig.addChild(pdfRendererConfig); pdfRendererConfig.addChild(buildFontsConfig()); dumpUserConfigToFile(fopUserConfiguration); return fopUserConfiguration; }