Ejemplo n.º 1
0
  @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;
  }
Ejemplo n.º 2
0
  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;
  }