From 8c1aba3f976127d33ec50b67d760f56364c08487 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki <jeremias@apache.org> Date: Mon, 28 May 2007 14:31:24 +0000 Subject: Bugzilla #41831: - Add support font auto-detection (easier font configuration) including a font cache to speed up the auto-detection process. - Refactoring of the configuration code: All Avalon configuration stuff is extracted into separate "Configurator" classes. - Refactoring of the FOURIResolver. Submitted by: Adrian Cumiskey <fop-dev.at.cumiskey.com> Changes to the patch by jeremias during the review: - Font cache simplified (Java object serialization instead of XML), functionality fixed and moved to the fonts.package. - Relocated default cache file location to user directory. - Fixed the font configuration for PDFDocumentGraphics2D/PDFTranscoder that got lost with the patch. - Fixed a problem with having a non-file URL as font base URL. - Simplified RendererContextInfo stuff to make it easier to understand. - Fixed handling of Type 1 fonts in auto-detection. - Reduced verbosity of font-related log output. - Updated Jakarta Commons IO to version 1.3.1 (the patch depends on it) - Various javadocs improvements git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@542237 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/pdf/PDFRendererConfigurator.java | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java (limited to 'src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java') diff --git a/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java new file mode 100644 index 000000000..5c5894d3b --- /dev/null +++ b/src/java/org/apache/fop/render/pdf/PDFRendererConfigurator.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* $Id: $ */ + +package org.apache.fop.render.pdf; + +import java.util.List; +import java.util.Map; + +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.FOUserAgent; +import org.apache.fop.pdf.PDFAMode; +import org.apache.fop.pdf.PDFFilterList; +import org.apache.fop.pdf.PDFXMode; +import org.apache.fop.render.PrintRendererConfigurator; +import org.apache.fop.render.Renderer; +import org.apache.fop.util.LogUtil; + +/** + * PDF renderer configurator + */ +public class PDFRendererConfigurator extends PrintRendererConfigurator { + + /** + * Default constructor + * @param userAgent user agent + */ + public PDFRendererConfigurator(FOUserAgent userAgent) { + super(userAgent); + } + + /** + * Configure the PDF renderer. + * Get the configuration to be used for pdf stream filters, + * fonts etc. + * @param renderer pdf renderer + * @throws FOPException fop exception + */ + public void configure(Renderer renderer) throws FOPException { + Configuration cfg = super.getRendererConfig(renderer); + if (cfg != null) { + PDFRenderer pdfRenderer = (PDFRenderer)renderer; + //PDF filters + try { + Map filterMap = buildFilterMapFromConfiguration(cfg); + if (filterMap != null) { + pdfRenderer.setFilterMap(filterMap); + } + } catch (ConfigurationException e) { + LogUtil.handleException(log, e, false); + } + + super.configure(renderer); + + String s = cfg.getChild(PDFRenderer.PDF_A_MODE, true).getValue(null); + if (s != null) { + pdfRenderer.setAMode(PDFAMode.valueOf(s)); + } + s = cfg.getChild(PDFRenderer.PDF_X_MODE, true).getValue(null); + if (s != null) { + pdfRenderer.setXMode(PDFXMode.valueOf(s)); + } + s = cfg.getChild(PDFRenderer.KEY_OUTPUT_PROFILE, true).getValue(null); + if (s != null) { + pdfRenderer.setOutputProfileURI(s); + } + } + } + + /** + * Builds a filter map from an Avalon Configuration object. + * @param cfg the Configuration object + * @return Map the newly built filter map + * @throws ConfigurationException if a filter list is defined twice + */ + public static Map buildFilterMapFromConfiguration(Configuration cfg) + throws ConfigurationException { + Map filterMap = new java.util.HashMap(); + Configuration[] filterLists = cfg.getChildren("filterList"); + for (int i = 0; i < filterLists.length; i++) { + Configuration filters = filterLists[i]; + String type = filters.getAttribute("type", null); + Configuration[] filt = filters.getChildren("value"); + List filterList = new java.util.ArrayList(); + for (int j = 0; j < filt.length; j++) { + String name = filt[j].getValue(); + filterList.add(name); + } + + if (type == null) { + type = PDFFilterList.DEFAULT_FILTER; + } + + if (!filterList.isEmpty() && log.isDebugEnabled()) { + StringBuffer debug = new StringBuffer("Adding PDF filter"); + if (filterList.size() != 1) { + debug.append("s"); + } + debug.append(" for type ").append(type).append(": "); + for (int j = 0; j < filterList.size(); j++) { + if (j != 0) { + debug.append(", "); + } + debug.append(filterList.get(j)); + } + log.debug(debug.toString()); + } + + if (filterMap.get(type) != null) { + throw new ConfigurationException("A filterList of type '" + + type + "' has already been defined"); + } + filterMap.put(type, filterList); + } + return filterMap; + } +} -- cgit v1.2.3