diff options
27 files changed, 364 insertions, 287 deletions
diff --git a/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java b/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java index 743811142..e00b05b55 100644 --- a/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java +++ b/src/codegen/java/org/apache/fop/tools/EventProducerCollectorTask.java @@ -22,6 +22,7 @@ package org.apache.fop.tools; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.OutputStream; import java.util.Iterator; import java.util.List; @@ -38,6 +39,7 @@ import javax.xml.transform.stream.StreamSource; import org.w3c.dom.Node; +import org.apache.commons.io.IOUtils; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; @@ -95,7 +97,7 @@ public class EventProducerCollectorTask extends Task { = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); //Generate fresh generated translation file as template - Source src = new StreamSource(getModelFile()); + Source src = new StreamSource(getModelFile().toURI().toURL().toExternalForm()); StreamSource xslt1 = new StreamSource( getClass().getResourceAsStream(MODEL2TRANSLATION)); if (xslt1.getInputStream() == null) { @@ -109,7 +111,7 @@ public class EventProducerCollectorTask extends Task { Node sourceDocument; if (resultExists) { //Load existing translation file into memory (because we overwrite it later) - src = new StreamSource(getTranslationFile()); + src = new StreamSource(getTranslationFile().toURI().toURL().toExternalForm()); domres = new DOMResult(); transformer = tFactory.newTransformer(); transformer.transform(src, domres); @@ -121,29 +123,38 @@ public class EventProducerCollectorTask extends Task { //Generate translation file (with potentially new translations) src = new DOMSource(sourceDocument); - Result res = new StreamResult(getTranslationFile()); - StreamSource xslt2 = new StreamSource( - getClass().getResourceAsStream(MERGETRANSLATION)); - if (xslt2.getInputStream() == null) { - throw new FileNotFoundException(MERGETRANSLATION + " not found"); - } - transformer = tFactory.newTransformer(xslt2); - transformer.setURIResolver(new URIResolver() { - public Source resolve(String href, String base) throws TransformerException { - if ("my:dom".equals(href)) { - return new DOMSource(generated); + + //The following triggers a bug in older Xalan versions + //Result res = new StreamResult(getTranslationFile()); + OutputStream out = new java.io.FileOutputStream(getTranslationFile()); + out = new java.io.BufferedOutputStream(out); + Result res = new StreamResult(out); + try { + StreamSource xslt2 = new StreamSource( + getClass().getResourceAsStream(MERGETRANSLATION)); + if (xslt2.getInputStream() == null) { + throw new FileNotFoundException(MERGETRANSLATION + " not found"); + } + transformer = tFactory.newTransformer(xslt2); + transformer.setURIResolver(new URIResolver() { + public Source resolve(String href, String base) throws TransformerException { + if ("my:dom".equals(href)) { + return new DOMSource(generated); + } + return null; } - return null; + }); + if (resultExists) { + transformer.setParameter("generated-url", "my:dom"); } - }); - if (resultExists) { - transformer.setParameter("generated-url", "my:dom"); - } - transformer.transform(src, res); - if (resultExists) { - log("Translation file updated: " + getTranslationFile()); - } else { - log("Translation file generated: " + getTranslationFile()); + transformer.transform(src, res); + if (resultExists) { + log("Translation file updated: " + getTranslationFile()); + } else { + log("Translation file generated: " + getTranslationFile()); + } + } finally { + IOUtils.closeQuietly(out); } } catch (TransformerException te) { throw new IOException(te.getMessage()); diff --git a/src/java/org/apache/fop/apps/FOURIResolver.java b/src/java/org/apache/fop/apps/FOURIResolver.java index 76b0bedd5..878a2745a 100644 --- a/src/java/org/apache/fop/apps/FOURIResolver.java +++ b/src/java/org/apache/fop/apps/FOURIResolver.java @@ -77,7 +77,7 @@ public class FOURIResolver implements javax.xml.transform.URIResolver { } File dir = new File(base); try { - base = (dir.isDirectory() ? dir.toURL() : new URL(base)).toExternalForm(); + base = (dir.isDirectory() ? dir.toURI().toURL() : new URL(base)).toExternalForm(); } catch (MalformedURLException mfue) { if (throwExceptions) { throw mfue; @@ -173,9 +173,9 @@ public class FOURIResolver implements javax.xml.transform.URIResolver { if (file.canRead() && file.isFile()) { try { if (fragment != null) { - absoluteURL = new URL(file.toURL().toExternalForm() + fragment); + absoluteURL = new URL(file.toURI().toURL().toExternalForm() + fragment); } else { - absoluteURL = file.toURL(); + absoluteURL = file.toURI().toURL(); } } catch (MalformedURLException mfue) { handleException(mfue, "Could not convert filename '" + href diff --git a/src/java/org/apache/fop/cli/InputHandler.java b/src/java/org/apache/fop/cli/InputHandler.java index f00de3c6f..4f49ea269 100644 --- a/src/java/org/apache/fop/cli/InputHandler.java +++ b/src/java/org/apache/fop/cli/InputHandler.java @@ -115,7 +115,7 @@ public class InputHandler implements ErrorListener, Renderable { try { baseURL = new File(sourcefile.getAbsolutePath()). - getParentFile().toURL().toExternalForm(); + getParentFile().toURI().toURL().toExternalForm(); } catch (Exception e) { baseURL = ""; } diff --git a/src/java/org/apache/fop/cli/Main.java b/src/java/org/apache/fop/cli/Main.java index 545aef7ff..f1a23ea46 100644 --- a/src/java/org/apache/fop/cli/Main.java +++ b/src/java/org/apache/fop/cli/Main.java @@ -66,7 +66,7 @@ public class Main { + baseDir.getAbsolutePath() + " (or below)"); } List jars = new java.util.ArrayList(); - jars.add(fopJar.toURL()); + jars.add(fopJar.toURI().toURL()); File[] files; FileFilter filter = new FileFilter() { public boolean accept(File pathname) { @@ -80,7 +80,7 @@ public class Main { files = libDir.listFiles(filter); if (files != null) { for (int i = 0, size = files.length; i < size; i++) { - jars.add(files[i].toURL()); + jars.add(files[i].toURI().toURL()); } } String optionalLib = System.getProperty("fop.optional.lib"); @@ -88,7 +88,7 @@ public class Main { files = new File(optionalLib).listFiles(filter); if (files != null) { for (int i = 0, size = files.length; i < size; i++) { - jars.add(files[i].toURL()); + jars.add(files[i].toURI().toURL()); } } } @@ -172,9 +172,9 @@ public class Main { } else { options.getInputHandler().transformTo(out); } - } finally { - IOUtils.closeQuietly(out); - } + } finally { + IOUtils.closeQuietly(out); + } // System.exit(0) called to close AWT/SVG-created threads, if any. // AWTRenderer closes with window shutdown, so exit() should not @@ -185,9 +185,9 @@ public class Main { } catch (Exception e) { if (options != null) { options.getLogger().error("Exception", e); - } - if (options.getOutputFile() != null) { - options.getOutputFile().delete(); + if (options.getOutputFile() != null) { + options.getOutputFile().delete(); + } } System.exit(1); } diff --git a/src/java/org/apache/fop/events/EventFormatter.xml b/src/java/org/apache/fop/events/EventFormatter.xml index dc9321a39..3578dc4e6 100644 --- a/src/java/org/apache/fop/events/EventFormatter.xml +++ b/src/java/org/apache/fop/events/EventFormatter.xml @@ -82,7 +82,7 @@ Any reference to it will be considered a reference to the first occurrence in th <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.rowTooTall">The contents of table-row {row} are taller than they should be (there is a block-progression-dimension or height constraint on the indicated row). Due to its contents the row grows to {effCellBPD} millipoints, but the row shouldn't get any taller than {maxCellBPD} millipoints.{{locator}}</message> <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.tableFixedAutoWidthNotSupported">table-layout="fixed" and width="auto", but auto-layout not supported => assuming width="100%".{{locator}}</message> <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.objectTooWide">The extent in inline-progression-direction (width) of a {elementName} is bigger than the available space ({effIPD}mpt > {maxIPD}mpt).{{locator}}</message> - <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.overconstrainedAdjustEndIndent">Adjusting end-indent based on overconstrained geometry rules for {elementName}.{{locator}}</message> + <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.overconstrainedAdjustEndIndent">An {elementName} {{locator}} is wider than the available room in inline-progression-dimension. Adjusting end-indent based on overconstrained geometry rules (XSL 1.1, ch. 5.3.4)</message> <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.viewportOverflow">Content overflows the viewport of an {elementName} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}}</message> <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.regionOverflow">Content overflows the viewport of the {elementName} on page {page} in block-progression direction by {amount} millipoints.{clip,if, Content will be clipped.}{{locator}}</message> <message key="org.apache.fop.layoutmgr.BlockLevelEventProducer.flowNotMappingToRegionBody">Flow "{flowName}" does not map to the region-body in page-master "{masterName}". FOP presently does not support this.{{locator}}</message> diff --git a/src/java/org/apache/fop/events/model/EventMethodModel.java b/src/java/org/apache/fop/events/model/EventMethodModel.java index 930cda53d..b9c62f8ab 100644 --- a/src/java/org/apache/fop/events/model/EventMethodModel.java +++ b/src/java/org/apache/fop/events/model/EventMethodModel.java @@ -37,12 +37,12 @@ import org.apache.xmlgraphics.util.XMLizable; public class EventMethodModel implements Serializable, XMLizable { private static final long serialVersionUID = -7548882973341444354L; - + private String methodName; private EventSeverity severity; private List params = new java.util.ArrayList(); private String exceptionClass; - + /** * Creates an new instance. * @param methodName the event method's name @@ -52,7 +52,7 @@ public class EventMethodModel implements Serializable, XMLizable { this.methodName = methodName; this.severity = severity; } - + /** * Adds a method parameter. * @param param the method parameter @@ -60,7 +60,7 @@ public class EventMethodModel implements Serializable, XMLizable { public void addParameter(Parameter param) { this.params.add(param); } - + /** * Adds a method parameter. * @param type the type of the parameter @@ -68,11 +68,11 @@ public class EventMethodModel implements Serializable, XMLizable { * @return the resulting Parameter instance */ public Parameter addParameter(Class type, String name) { - Parameter param = new Parameter(type, name); + Parameter param = new Parameter(type, name); addParameter(param); return param; } - + /** * Sets the event method name. * @param name the event name @@ -80,7 +80,7 @@ public class EventMethodModel implements Serializable, XMLizable { public void setMethodName(String name) { this.methodName = name; } - + /** * Returns the event method name * @return the event name @@ -88,7 +88,7 @@ public class EventMethodModel implements Serializable, XMLizable { public String getMethodName() { return this.methodName; } - + /** * Sets the event's severity level. * @param severity the severity @@ -96,7 +96,7 @@ public class EventMethodModel implements Serializable, XMLizable { public void setSeverity(EventSeverity severity) { this.severity = severity; } - + /** * Returns the event's severity level. * @return the severity @@ -104,7 +104,7 @@ public class EventMethodModel implements Serializable, XMLizable { public EventSeverity getSeverity() { return this.severity; } - + /** * Returns an unmodifiable list of parameters for this event method. * @return the list of parameters @@ -112,7 +112,7 @@ public class EventMethodModel implements Serializable, XMLizable { public List getParameters() { return Collections.unmodifiableList(this.params); } - + /** * Sets the primary exception class for this event method. Note: Not all event methods throw * exceptions! @@ -121,7 +121,7 @@ public class EventMethodModel implements Serializable, XMLizable { public void setExceptionClass(String exceptionClass) { this.exceptionClass = exceptionClass; } - + /** * Returns the primary exception class for this event method. This method returns null if * the event is only informational or just a warning. @@ -130,34 +130,34 @@ public class EventMethodModel implements Serializable, XMLizable { public String getExceptionClass() { return this.exceptionClass; } - + /** {@inheritDoc} */ public void toSAX(ContentHandler handler) throws SAXException { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute(null, "name", "name", "CDATA", getMethodName()); - atts.addAttribute(null, "severity", "severity", "CDATA", getSeverity().getName()); + atts.addAttribute("", "name", "name", "CDATA", getMethodName()); + atts.addAttribute("", "severity", "severity", "CDATA", getSeverity().getName()); if (getExceptionClass() != null) { - atts.addAttribute(null, "exception", "exception", "CDATA", getExceptionClass()); + atts.addAttribute("", "exception", "exception", "CDATA", getExceptionClass()); } String elName = "method"; - handler.startElement(null, elName, elName, atts); + handler.startElement("", elName, elName, atts); Iterator iter = this.params.iterator(); while (iter.hasNext()) { ((XMLizable)iter.next()).toSAX(handler); } - handler.endElement(null, elName, elName); + handler.endElement("", elName, elName); } - + /** * Represents an event parameter. */ public static class Parameter implements Serializable, XMLizable { - + private static final long serialVersionUID = 6062500277953887099L; - + private Class type; private String name; - + /** * Creates a new event parameter. * @param type the parameter type @@ -167,7 +167,7 @@ public class EventMethodModel implements Serializable, XMLizable { this.type = type; this.name = name; } - + /** * Returns the parameter type. * @return the parameter type @@ -175,7 +175,7 @@ public class EventMethodModel implements Serializable, XMLizable { public Class getType() { return this.type; } - + /** * Returns the parameter name. * @return the parameter name @@ -187,12 +187,12 @@ public class EventMethodModel implements Serializable, XMLizable { /** {@inheritDoc} */ public void toSAX(ContentHandler handler) throws SAXException { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute(null, "type", "type", "CDATA", getType().getName()); - atts.addAttribute(null, "name", "name", "CDATA", getName()); + atts.addAttribute("", "type", "type", "CDATA", getType().getName()); + atts.addAttribute("", "name", "name", "CDATA", getName()); String elName = "parameter"; - handler.startElement(null, elName, elName, atts); - handler.endElement(null, elName, elName); + handler.startElement("", elName, elName, atts); + handler.endElement("", elName, elName); } - + } } diff --git a/src/java/org/apache/fop/events/model/EventModel.java b/src/java/org/apache/fop/events/model/EventModel.java index 61e221b3b..9c11b79a3 100644 --- a/src/java/org/apache/fop/events/model/EventModel.java +++ b/src/java/org/apache/fop/events/model/EventModel.java @@ -21,6 +21,7 @@ package org.apache.fop.events.model; import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.io.Serializable; import java.util.Iterator; import java.util.Map; @@ -38,6 +39,8 @@ import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; +import org.apache.commons.io.IOUtils; + import org.apache.xmlgraphics.util.XMLizable; /** @@ -46,15 +49,15 @@ import org.apache.xmlgraphics.util.XMLizable; public class EventModel implements Serializable, XMLizable { private static final long serialVersionUID = 7468592614934605082L; - + private Map producers = new java.util.LinkedHashMap(); - + /** * Creates a new, empty event model */ public EventModel() { } - + /** * Adds the model of an event producer to the event model. * @param producer the event producer model @@ -62,7 +65,7 @@ public class EventModel implements Serializable, XMLizable { public void addProducer(EventProducerModel producer) { this.producers.put(producer.getInterfaceName(), producer); } - + /** * Returns an iterator over the contained event producer models. * @return an iterator (Iterator<EventProducerModel>) @@ -79,7 +82,7 @@ public class EventModel implements Serializable, XMLizable { public EventProducerModel getProducer(String interfaceName) { return (EventProducerModel)this.producers.get(interfaceName); } - + /** * Returns the model of an event producer with the given interface. * @param clazz the interface of the event producer @@ -88,22 +91,28 @@ public class EventModel implements Serializable, XMLizable { public EventProducerModel getProducer(Class clazz) { return getProducer(clazz.getName()); } - + /** {@inheritDoc} */ public void toSAX(ContentHandler handler) throws SAXException { AttributesImpl atts = new AttributesImpl(); String elName = "event-model"; - handler.startElement(null, elName, elName, atts); + handler.startElement("", elName, elName, atts); Iterator iter = getProducers(); while (iter.hasNext()) { ((XMLizable)iter.next()).toSAX(handler); } - handler.endElement(null, elName, elName); + handler.endElement("", elName, elName); } private void writeXMLizable(XMLizable object, File outputFile) throws IOException { - Result res = new StreamResult(outputFile); - + //These two approaches do not seem to work in all environments: + //Result res = new StreamResult(outputFile); + //Result res = new StreamResult(outputFile.toURI().toURL().toExternalForm()); + //With an old Xalan version: file:/C:/.... --> file:\C:\..... + OutputStream out = new java.io.FileOutputStream(outputFile); + out = new java.io.BufferedOutputStream(out); + Result res = new StreamResult(out); + try { SAXTransformerFactory tFactory = (SAXTransformerFactory)SAXTransformerFactory.newInstance(); @@ -120,6 +129,8 @@ public class EventModel implements Serializable, XMLizable { throw new IOException(e.getMessage()); } catch (SAXException e) { throw new IOException(e.getMessage()); + } finally { + IOUtils.closeQuietly(out); } } diff --git a/src/java/org/apache/fop/events/model/EventProducerModel.java b/src/java/org/apache/fop/events/model/EventProducerModel.java index 938609cd9..b0d334e99 100644 --- a/src/java/org/apache/fop/events/model/EventProducerModel.java +++ b/src/java/org/apache/fop/events/model/EventProducerModel.java @@ -35,18 +35,18 @@ import org.apache.xmlgraphics.util.XMLizable; public class EventProducerModel implements Serializable, XMLizable { private static final long serialVersionUID = 122267104123721902L; - + private String interfaceName; private Map methods = new java.util.LinkedHashMap(); - + /** * Creates a new instance. - * @param interfaceName the fully qualified interface name of the event producer + * @param interfaceName the fully qualified interface name of the event producer */ public EventProducerModel(String interfaceName) { this.interfaceName = interfaceName; } - + /** * Returns the fully qualified interface name of the event producer. * @return the fully qualified interface name @@ -54,7 +54,7 @@ public class EventProducerModel implements Serializable, XMLizable { public String getInterfaceName() { return this.interfaceName; } - + /** * Sets the fully qualified interface name of the event producer. * @param name the fully qualified interface name @@ -62,7 +62,7 @@ public class EventProducerModel implements Serializable, XMLizable { public void setInterfaceName(String name) { this.interfaceName = name; } - + /** * Adds a model instance of an event method. * @param method the event method model @@ -70,7 +70,7 @@ public class EventProducerModel implements Serializable, XMLizable { public void addMethod(EventMethodModel method) { this.methods.put(method.getMethodName(), method); } - + /** * Returns the model instance of an event method for the given method name. * @param methodName the method name @@ -79,7 +79,7 @@ public class EventProducerModel implements Serializable, XMLizable { public EventMethodModel getMethod(String methodName) { return (EventMethodModel)this.methods.get(methodName); } - + /** * Returns an iterator over the contained event producer methods. * @return an iterator (Iterator<EventMethodModel>) @@ -91,15 +91,15 @@ public class EventProducerModel implements Serializable, XMLizable { /** {@inheritDoc} */ public void toSAX(ContentHandler handler) throws SAXException { AttributesImpl atts = new AttributesImpl(); - atts.addAttribute(null, "name", "name", "CDATA", getInterfaceName()); + atts.addAttribute("", "name", "name", "CDATA", getInterfaceName()); String elName = "producer"; - handler.startElement(null, elName, elName, atts); + handler.startElement("", elName, elName, atts); Iterator iter = getMethods(); while (iter.hasNext()) { ((XMLizable)iter.next()).toSAX(handler); } - handler.endElement(null, elName, elName); + handler.endElement("", elName, elName); } - + } diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index 60317cf0d..e7e76176a 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -963,7 +963,7 @@ public final class FOPropertyMapping implements Constants { // font-family m = new FontFamilyProperty.Maker(PR_FONT_FAMILY); m.setInherited(true); - m.setDefault("sans-serif,Symbol,ZapfDingbats"); + m.setDefault("sans-serif"); m.addShorthand(s_generics[PR_FONT]); addPropertyMaker("font-family", m); diff --git a/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java b/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java index 521f3b81b..7711130b1 100644 --- a/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java +++ b/src/java/org/apache/fop/fo/extensions/svg/SVGElement.java @@ -92,7 +92,7 @@ public class SVGElement extends SVGObj { try { URL baseURL = new URL(getUserAgent().getBaseURL() == null - ? new java.io.File("").toURL().toExternalForm() + ? new java.io.File("").toURI().toURL().toExternalForm() : getUserAgent().getBaseURL()); if (baseURL != null) { SVGOMDocument svgdoc = (SVGOMDocument)doc; diff --git a/src/java/org/apache/fop/fonts/CustomFontCollection.java b/src/java/org/apache/fop/fonts/CustomFontCollection.java index 5e5a61189..5a0bba782 100644 --- a/src/java/org/apache/fop/fonts/CustomFontCollection.java +++ b/src/java/org/apache/fop/fonts/CustomFontCollection.java @@ -5,9 +5,9 @@ * 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. @@ -21,38 +21,35 @@ package org.apache.fop.fonts; import java.util.List; -import org.apache.fop.render.PrintRenderer; - /** * Sets up a set of custom (embedded) fonts */ public class CustomFontCollection implements FontCollection { - private PrintRenderer renderer = null; + private FontResolver fontResolver; + private List/*<EmbedFontInfo>*/ embedFontInfoList; /** - * A print renderer to configure - * @param renderer a print renderer + * Main constructor. + * @param fontResolver a font resolver + * @param customFonts the list of custom fonts */ - public CustomFontCollection(PrintRenderer renderer) { - this.renderer = renderer; + public CustomFontCollection(FontResolver fontResolver, + List/*<EmbedFontInfo>*/ customFonts) { + this.fontResolver = fontResolver; + if (this.fontResolver == null) { + //Ensure that we have minimal font resolution capabilities + this.fontResolver = FontManager.createMinimalFontResolver(); + } + this.embedFontInfoList = customFonts; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public int setup(int num, FontInfo fontInfo) { - List/*<EmbedFontInfo>*/ embedFontInfoList = renderer.getFontList(); if (embedFontInfoList == null) { return num; //No fonts to process } - FontResolver resolver = renderer.getFontResolver(); - if (resolver == null) { - //Ensure that we have minimal font resolution capabilities - resolver = FontManager.createMinimalFontResolver(); - } - String internalName = null; //FontReader reader = null; @@ -69,7 +66,7 @@ public class CustomFontCollection implements FontCollection { fontInfo.addMetrics(internalName, reader.getFont()); */ - LazyFont font = new LazyFont(embedFontInfo, resolver); + LazyFont font = new LazyFont(embedFontInfo, this.fontResolver); fontInfo.addMetrics(internalName, font); List triplets = embedFontInfo.getFontTriplets(); diff --git a/src/java/org/apache/fop/fonts/FontInfo.java b/src/java/org/apache/fop/fonts/FontInfo.java index 4e327c782..8e915588f 100644 --- a/src/java/org/apache/fop/fonts/FontInfo.java +++ b/src/java/org/apache/fop/fonts/FontInfo.java @@ -219,7 +219,7 @@ public class FontInfo { private FontTriplet fuzzyFontLookup(String family, String style, int weight, FontTriplet startKey, boolean substFont) { FontTriplet key; - String internalFontKey; + String internalFontKey = null; if (!family.equals(startKey.getName())) { key = createFontKey(family, style, weight); internalFontKey = getInternalFontKey(key); @@ -230,8 +230,10 @@ public class FontInfo { // adjust weight, favouring normal or bold key = findAdjustWeight(family, style, weight); - internalFontKey = getInternalFontKey(key); - + if (key != null) { + internalFontKey = getInternalFontKey(key); + } + if (!substFont && internalFontKey == null) { return null; } @@ -364,7 +366,8 @@ public class FontInfo { FontTriplet triplet; List tmpTriplets = new java.util.ArrayList(); for (int i = 0, c = families.length; i < c; i++) { - triplet = fontLookup(families[i], style, weight, (i >= families.length - 1)); + boolean substitutable = (i >= families.length - 1); + triplet = fontLookup(families[i], style, weight, substitutable); if (triplet != null) { tmpTriplets.add(triplet); } diff --git a/src/java/org/apache/fop/fonts/FontManager.java b/src/java/org/apache/fop/fonts/FontManager.java index c180fbcc9..b3833cf50 100644 --- a/src/java/org/apache/fop/fonts/FontManager.java +++ b/src/java/org/apache/fop/fonts/FontManager.java @@ -5,9 +5,9 @@ * 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. @@ -19,7 +19,6 @@ package org.apache.fop.fonts; -import java.awt.Graphics2D; import java.net.MalformedURLException; import javax.xml.transform.Source; @@ -27,7 +26,6 @@ import javax.xml.transform.stream.StreamSource; import org.apache.fop.fonts.FontTriplet.Matcher; import org.apache.fop.fonts.substitute.FontSubstitutions; -import org.apache.fop.render.PrintRenderer; // TODO: Refactor fonts package so major font activities (autodetection etc) // are all centrally managed and delegated from this class, also remove dependency on FopFactory @@ -144,55 +142,17 @@ public class FontManager { } /** - * Sets up the fonts on a given PrintRenderer - * @param renderer a print renderer + * Sets up the fonts on a given FontInfo object. The fonts to setup are defined by an + * array of {@code FontCollection} objects. + * @param fontInfo the FontInfo object to set up + * @param fontCollections the array of font collections/sources */ - public void setupRenderer(PrintRenderer renderer) { - FontInfo fontInfo = renderer.getFontInfo(); - + public void setup(FontInfo fontInfo, FontCollection[] fontCollections) { int startNum = 1; - // Configure base 14 fonts - org.apache.fop.fonts.base14.Base14FontCollection base14FontCollection - = new org.apache.fop.fonts.base14.Base14FontCollection(this.enableBase14Kerning); - startNum = base14FontCollection.setup(startNum, fontInfo); - - // Configure any custom font collection - org.apache.fop.fonts.CustomFontCollection customFontCollection - = new org.apache.fop.fonts.CustomFontCollection(renderer); - startNum = customFontCollection.setup(startNum, fontInfo); - - // Make any defined substitutions in the font info - getFontSubstitutions().adjustFontInfo(fontInfo); - } - - /** - * Sets up the fonts on a given PrintRenderer with Graphics2D - * @param renderer a print renderer - * @param graphics2D a graphics 2D - */ - public void setupRenderer(PrintRenderer renderer, Graphics2D graphics2D) { - FontInfo fontInfo = renderer.getFontInfo(); - - int startNum = 1; - - // setup base 14 fonts - org.apache.fop.render.java2d.Base14FontCollection base14FontCollection - = new org.apache.fop.render.java2d.Base14FontCollection(graphics2D); - - // setup any custom font collection - startNum = base14FontCollection.setup(startNum, fontInfo); - - // setup any installed fonts - org.apache.fop.render.java2d.InstalledFontCollection installedFontCollection - = new org.apache.fop.render.java2d.InstalledFontCollection(graphics2D); - startNum = installedFontCollection.setup(startNum, fontInfo); - - // setup any configured fonts - org.apache.fop.render.java2d.ConfiguredFontCollection configuredFontCollection - = new org.apache.fop.render.java2d.ConfiguredFontCollection(renderer); - startNum = configuredFontCollection.setup(startNum, fontInfo); - + for (int i = 0, c = fontCollections.length; i < c; i++) { + startNum = fontCollections[i].setup(startNum, fontInfo); + } // Make any defined substitutions in the font info getFontSubstitutions().adjustFontInfo(fontInfo); } diff --git a/src/java/org/apache/fop/hyphenation/HyphenationTree.java b/src/java/org/apache/fop/hyphenation/HyphenationTree.java index 67488c5b5..d145936c6 100644 --- a/src/java/org/apache/fop/hyphenation/HyphenationTree.java +++ b/src/java/org/apache/fop/hyphenation/HyphenationTree.java @@ -125,7 +125,7 @@ public class HyphenationTree extends TernaryTree public void loadPatterns(String filename) throws HyphenationException { File f = new File(filename); try { - InputSource src = new InputSource(f.toURL().toExternalForm()); + InputSource src = new InputSource(f.toURI().toURL().toExternalForm()); loadPatterns(src); } catch (MalformedURLException e) { throw new HyphenationException("Error converting the File '" + f + "' to a URL: " diff --git a/src/java/org/apache/fop/hyphenation/PatternParser.java b/src/java/org/apache/fop/hyphenation/PatternParser.java index b0378a40b..2edf64676 100644 --- a/src/java/org/apache/fop/hyphenation/PatternParser.java +++ b/src/java/org/apache/fop/hyphenation/PatternParser.java @@ -92,7 +92,7 @@ public class PatternParser extends DefaultHandler implements PatternConsumer { */ public void parse(File file) throws HyphenationException { try { - InputSource src = new InputSource(file.toURL().toExternalForm()); + InputSource src = new InputSource(file.toURI().toURL().toExternalForm()); parse(src); } catch (MalformedURLException e) { throw new HyphenationException("Error converting the File '" + file + "' to a URL: " diff --git a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java index d0874d626..589fb2645 100755 --- a/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java @@ -36,6 +36,7 @@ import org.apache.fop.fo.flow.InlineLevel; import org.apache.fop.fo.flow.Leader; import org.apache.fop.fo.pagination.Title; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.fo.properties.CommonFont; import org.apache.fop.fo.properties.CommonMarginInline; import org.apache.fop.fo.properties.SpaceProperty; import org.apache.fop.fonts.Font; @@ -115,9 +116,12 @@ public class InlineLayoutManager extends InlineStackingLayoutManager { InlineLevel fobj = (InlineLevel) this.fobj; int padding = 0; + FontInfo fi = fobj.getFOEventHandler().getFontInfo(); - FontTriplet[] fontkeys = fobj.getCommonFont().getFontState(fi); - font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); + CommonFont commonFont = fobj.getCommonFont(); + FontTriplet[] fontkeys = commonFont.getFontState(fi); + font = fi.getFontInstance(fontkeys[0], commonFont.fontSize.getValue(this)); + lineHeight = fobj.getLineHeight(); borderProps = fobj.getCommonBorderPaddingBackground(); inlineProps = fobj.getCommonMarginInline(); diff --git a/src/java/org/apache/fop/render/PrintRenderer.java b/src/java/org/apache/fop/render/PrintRenderer.java index 35630d628..44b0a211d 100644 --- a/src/java/org/apache/fop/render/PrintRenderer.java +++ b/src/java/org/apache/fop/render/PrintRenderer.java @@ -5,9 +5,9 @@ * 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. @@ -20,19 +20,23 @@ package org.apache.fop.render; // FOP +import java.awt.Color; +import java.awt.geom.Rectangle2D; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; + import org.apache.fop.area.Area; import org.apache.fop.area.Trait; +import org.apache.fop.fonts.CustomFontCollection; import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontManager; import org.apache.fop.fonts.FontResolver; import org.apache.fop.fonts.FontTriplet; -import org.w3c.dom.Document; - -// Java -import java.awt.Color; -import java.awt.geom.Rectangle2D; -import java.util.List; -import java.util.Map; +import org.apache.fop.fonts.base14.Base14FontCollection; /** Abstract base class of "Print" type renderers. */ public abstract class PrintRenderer extends AbstractRenderer { @@ -79,7 +83,12 @@ public abstract class PrintRenderer extends AbstractRenderer { */ public void setupFontInfo(FontInfo inFontInfo) { this.fontInfo = inFontInfo; - userAgent.getFactory().getFontManager().setupRenderer(this); + FontManager fontManager = userAgent.getFactory().getFontManager(); + FontCollection[] fontCollections = new FontCollection[] { + new Base14FontCollection(fontManager.isBase14KerningEnabled()), + new CustomFontCollection(getFontResolver(), getFontList()) + }; + fontManager.setup(getFontInfo(), fontCollections); } /** diff --git a/src/java/org/apache/fop/render/afp/AFPRenderer.java b/src/java/org/apache/fop/render/afp/AFPRenderer.java index 70dd3f458..98d2440c1 100644 --- a/src/java/org/apache/fop/render/afp/AFPRenderer.java +++ b/src/java/org/apache/fop/render/afp/AFPRenderer.java @@ -65,11 +65,9 @@ import org.apache.fop.datatypes.URISpecification; import org.apache.fop.events.ResourceEventProducer; import org.apache.fop.fo.Constants; import org.apache.fop.fo.extensions.ExtensionAttachment; +import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; -import org.apache.fop.fonts.FontTriplet; -import org.apache.fop.fonts.base14.Courier; -import org.apache.fop.fonts.base14.Helvetica; -import org.apache.fop.fonts.base14.TimesRoman; +import org.apache.fop.fonts.FontManager; import org.apache.fop.render.AbstractPathOrientedRenderer; import org.apache.fop.render.AbstractState; import org.apache.fop.render.Graphics2DAdapter; @@ -77,10 +75,7 @@ import org.apache.fop.render.RendererContext; import org.apache.fop.render.afp.extensions.AFPElementMapping; import org.apache.fop.render.afp.extensions.AFPPageSetup; import org.apache.fop.render.afp.fonts.AFPFont; -import org.apache.fop.render.afp.fonts.AFPFontInfo; -import org.apache.fop.render.afp.fonts.CharacterSet; -import org.apache.fop.render.afp.fonts.FopCharacterSet; -import org.apache.fop.render.afp.fonts.OutlineFont; +import org.apache.fop.render.afp.fonts.AFPFontCollection; import org.apache.fop.render.afp.modca.AFPConstants; import org.apache.fop.render.afp.modca.AFPDataStream; import org.apache.fop.render.afp.modca.PageObject; @@ -183,57 +178,11 @@ public class AFPRenderer extends AbstractPathOrientedRenderer { /** {@inheritDoc} */ public void setupFontInfo(FontInfo inFontInfo) { this.fontInfo = inFontInfo; - int num = 1; - if (super.embedFontInfoList != null - && super.embedFontInfoList.size() > 0) { - for (Iterator it = super.embedFontInfoList.iterator(); it.hasNext();) { - AFPFontInfo afi = (AFPFontInfo) it.next(); - AFPFont bf = (AFPFont) afi.getAFPFont(); - for (Iterator it2 = afi.getFontTriplets().iterator(); it2.hasNext();) { - FontTriplet ft = (FontTriplet) it2.next(); - this.fontInfo.addFontProperties("F" + num, ft.getName(), ft - .getStyle(), ft.getWeight()); - this.fontInfo.addMetrics("F" + num, bf); - num++; - } - } - } else { - AFPEventProducer eventProducer = AFPEventProducer.Provider - .get(getUserAgent().getEventBroadcaster()); - eventProducer.warnDefaultFontSetup(this); - } - if (this.fontInfo.fontLookup("sans-serif", "normal", 400) == null) { - CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", - "CZH200 ", 1, new Helvetica()); - AFPFont bf = new OutlineFont("Helvetica", cs); - this.fontInfo.addFontProperties("F" + num, "sans-serif", "normal", - 400); - this.fontInfo.addMetrics("F" + num, bf); - num++; - } - if (this.fontInfo.fontLookup("serif", "normal", 400) == null) { - CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", - "CZN200 ", 1, new TimesRoman()); - AFPFont bf = new OutlineFont("Helvetica", cs); - this.fontInfo.addFontProperties("F" + num, "serif", "normal", 400); - this.fontInfo.addMetrics("F" + num, bf); - num++; - } - if (this.fontInfo.fontLookup("monospace", "normal", 400) == null) { - CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", - "CZ4200 ", 1, new Courier()); - AFPFont bf = new OutlineFont("Helvetica", cs); - this.fontInfo.addFontProperties("F" + num, "monospace", "normal", - 400); - this.fontInfo.addMetrics("F" + num, bf); - num++; - } - if (this.fontInfo.fontLookup("any", "normal", 400) == null) { - FontTriplet ft = this.fontInfo.fontLookup("sans-serif", "normal", - 400); - this.fontInfo.addFontProperties(this.fontInfo - .getInternalFontKey(ft), "any", "normal", 400); - } + FontManager fontManager = userAgent.getFactory().getFontManager(); + FontCollection[] fontCollections = new FontCollection[] { + new AFPFontCollection(userAgent.getEventBroadcaster(), getFontList()) + }; + fontManager.setup(getFontInfo(), fontCollections); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java b/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java new file mode 100644 index 000000000..55953daf0 --- /dev/null +++ b/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java @@ -0,0 +1,110 @@ +/* + * 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.afp.fonts; + +import java.util.Iterator; +import java.util.List; + +import org.apache.fop.events.EventBroadcaster; +import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontCollection; +import org.apache.fop.fonts.FontInfo; +import org.apache.fop.fonts.FontTriplet; +import org.apache.fop.fonts.base14.Courier; +import org.apache.fop.fonts.base14.Helvetica; +import org.apache.fop.fonts.base14.TimesRoman; +import org.apache.fop.render.afp.AFPEventProducer; + +/** + * A base collection of AFP fonts + */ +public class AFPFontCollection implements FontCollection { + + private EventBroadcaster eventBroadcaster; + private List/*<EmbedFontInfo>*/ embedFontInfoList; + + /** + * Main constructor + * + * @param eventBroadcaster the event broadcaster + * @param embedFontInfoList the embed font info list + */ + public AFPFontCollection(EventBroadcaster eventBroadcaster, + List/*<EmbedFontInfo>*/ embedFontInfoList) { + this.eventBroadcaster = eventBroadcaster; + this.embedFontInfoList = embedFontInfoList; + } + + /** {@inheritDoc} */ + public int setup(int start, FontInfo fontInfo) { + int num = 1; + if (embedFontInfoList != null && embedFontInfoList.size() > 0) { + for (Iterator it = embedFontInfoList.iterator(); it.hasNext();) { + AFPFontInfo afi = (AFPFontInfo)it.next(); + AFPFont bf = (AFPFont)afi.getAFPFont(); + for (Iterator it2 = afi.getFontTriplets().iterator(); it2.hasNext();) { + FontTriplet ft = (FontTriplet)it2.next(); + fontInfo.addFontProperties("F" + num, ft.getName() + , ft.getStyle(), ft.getWeight()); + fontInfo.addMetrics("F" + num, bf); + num++; + } + } + } else { + AFPEventProducer eventProducer = AFPEventProducer.Provider.get(eventBroadcaster); + eventProducer.warnDefaultFontSetup(this); + } + if (fontInfo.fontLookup("sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { + CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZH200 ", + 1, new Helvetica()); + AFPFont bf = new OutlineFont("Helvetica", cs); + fontInfo.addFontProperties( + "F" + num, "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); + fontInfo.addMetrics("F" + num, bf); + num++; + } + if (fontInfo.fontLookup("serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { + CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZN200 ", + 1, new TimesRoman()); + AFPFont bf = new OutlineFont("Helvetica", cs); + fontInfo.addFontProperties("F" + num, "serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); + fontInfo.addMetrics("F" + num, bf); + num++; + } + if (fontInfo.fontLookup("monospace", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { + CharacterSet cs = new FopCharacterSet("T1V10500", "Cp500", "CZ4200 ", + 1, new Courier()); + AFPFont bf = new OutlineFont("Helvetica", cs); + fontInfo.addFontProperties( + "F" + num, "monospace", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); + fontInfo.addMetrics("F" + num, bf); + num++; + } + if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) { + FontTriplet ft = fontInfo.fontLookup( + "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); + fontInfo.addFontProperties( + fontInfo.getInternalFontKey(ft), "any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL); + num++; + } + return num; + } + +} diff --git a/src/java/org/apache/fop/render/afp/fonts/AFPFontReader.java b/src/java/org/apache/fop/render/afp/fonts/AFPFontReader.java index 77792267c..7951be26c 100644 --- a/src/java/org/apache/fop/render/afp/fonts/AFPFontReader.java +++ b/src/java/org/apache/fop/render/afp/fonts/AFPFontReader.java @@ -157,7 +157,7 @@ public final class AFPFontReader { if (url == null) { try { File file = new File(path); - url = file.toURL(); + url = file.toURI().toURL(); if (url == null) { String msg = "CharacterSet file not found for " + characterset + " in classpath: " + path; @@ -194,7 +194,7 @@ public final class AFPFontReader { log.warn(msg); } - inputStream = csfont[0].toURL().openStream(); + inputStream = csfont[0].toURI().toURL().openStream(); if (inputStream == null) { String msg = "Failed to open character set resource " + characterset; @@ -258,7 +258,7 @@ public final class AFPFontReader { if (url == null) { try { File file = new File(path); - url = file.toURL(); + url = file.toURI().toURL(); if (url == null) { String msg = "CodePage file not found for " + codePage + " in classpath: " + path; @@ -300,7 +300,7 @@ public final class AFPFontReader { log.warn(msg); } - InputStream is = codepage[0].toURL().openStream(); + InputStream is = codepage[0].toURI().toURL().openStream(); if (is == null) { String msg = "AFPFontReader:: loadCodePage(String):: code page file not found for " diff --git a/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java b/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java index 843ab8413..26d64af74 100644 --- a/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java +++ b/src/java/org/apache/fop/render/java2d/ConfiguredFontCollection.java @@ -5,9 +5,9 @@ * 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. @@ -35,7 +35,6 @@ import org.apache.fop.fonts.FontManager; import org.apache.fop.fonts.FontResolver; import org.apache.fop.fonts.FontTriplet; import org.apache.fop.fonts.LazyFont; -import org.apache.fop.render.PrintRenderer; /** * A java2d configured font collection @@ -44,37 +43,36 @@ public class ConfiguredFontCollection implements FontCollection { private static Log log = LogFactory.getLog(ConfiguredFontCollection.class); - private PrintRenderer renderer = null; + private FontResolver fontResolver; + private List/*<EmbedFontInfo>*/ embedFontInfoList; /** * Main constructor - * - * @param renderer a print renderer + * @param fontResolver a font resolver + * @param customFonts the list of custom fonts */ - public ConfiguredFontCollection(PrintRenderer renderer) { - this.renderer = renderer; + public ConfiguredFontCollection(FontResolver fontResolver, + List/*<EmbedFontInfo>*/ customFonts) { + this.fontResolver = fontResolver; + if (this.fontResolver == null) { + //Ensure that we have minimal font resolution capabilities + this.fontResolver = FontManager.createMinimalFontResolver(); + } + this.embedFontInfoList = customFonts; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public int setup(int start, FontInfo fontInfo) { - List/*<EmbedFontInfo>*/ fontList = renderer.getFontList(); - FontResolver resolver = renderer.getFontResolver(); int num = start; - if (fontList == null || fontList.size() < 1) { + if (embedFontInfoList == null || embedFontInfoList.size() < 1) { log.debug("No user configured fonts found."); return num; } - if (resolver == null) { - // Ensure that we have minimal font resolution capabilities - resolver = FontManager.createMinimalFontResolver(); - } String internalName = null; - for (int i = 0; i < fontList.size(); i++) { + for (int i = 0; i < embedFontInfoList.size(); i++) { - EmbedFontInfo configFontInfo = (EmbedFontInfo) fontList.get(i); + EmbedFontInfo configFontInfo = (EmbedFontInfo) embedFontInfoList.get(i); String fontFile = configFontInfo.getEmbedFile(); internalName = "F" + num; num++; @@ -84,11 +82,12 @@ public class ConfiguredFontCollection implements FontCollection { // If the user specified an XML-based metrics file, we'll use it // Otherwise, calculate metrics directly from the font file. if (metricsUrl != null) { - LazyFont fontMetrics = new LazyFont(configFontInfo, resolver); - Source fontSource = resolver.resolve(configFontInfo.getEmbedFile()); + LazyFont fontMetrics = new LazyFont(configFontInfo, fontResolver); + Source fontSource = fontResolver.resolve(configFontInfo.getEmbedFile()); font = new CustomFontMetricsMapper(fontMetrics, fontSource); } else { - CustomFont fontMetrics = FontLoader.loadFont(fontFile, null, true, resolver); + CustomFont fontMetrics = FontLoader.loadFont( + fontFile, null, true, fontResolver); font = new CustomFontMetricsMapper(fontMetrics); } diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java index 6fff05c29..02b809ff7 100644 --- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java +++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java @@ -69,6 +69,7 @@ import org.apache.fop.datatypes.URISpecification; import org.apache.fop.events.ResourceEventProducer; import org.apache.fop.fo.Constants; import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.Typeface; import org.apache.fop.render.AbstractPathOrientedRenderer; @@ -172,7 +173,13 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - userAgent.getFactory().getFontManager().setupRenderer(this, graphics2D); + FontCollection[] fontCollections = new FontCollection[] { + new Base14FontCollection(graphics2D), + new InstalledFontCollection(graphics2D), + new ConfiguredFontCollection(getFontResolver(), getFontList()) + }; + userAgent.getFactory().getFontManager().setup( + getFontInfo(), fontCollections); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/pcl/PCLRenderer.java b/src/java/org/apache/fop/render/pcl/PCLRenderer.java index 10d66fb4e..ff7a13ee8 100644 --- a/src/java/org/apache/fop/render/pcl/PCLRenderer.java +++ b/src/java/org/apache/fop/render/pcl/PCLRenderer.java @@ -5,9 +5,9 @@ * 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. @@ -82,6 +82,7 @@ import org.apache.fop.datatypes.URISpecification; import org.apache.fop.events.ResourceEventProducer; import org.apache.fop.fo.extensions.ExtensionElementMapping; import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontMetrics; import org.apache.fop.render.Graphics2DAdapter; @@ -89,7 +90,10 @@ import org.apache.fop.render.PrintRenderer; import org.apache.fop.render.RendererContext; import org.apache.fop.render.RendererContextConstants; import org.apache.fop.render.RendererEventProducer; +import org.apache.fop.render.java2d.Base14FontCollection; +import org.apache.fop.render.java2d.ConfiguredFontCollection; import org.apache.fop.render.java2d.FontMetricsMapper; +import org.apache.fop.render.java2d.InstalledFontCollection; import org.apache.fop.render.java2d.Java2DRenderer; import org.apache.fop.render.pcl.extensions.PCLElementMapping; import org.apache.fop.traits.BorderProps; @@ -207,7 +211,13 @@ public class PCLRenderer extends PrintRenderer { graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); - userAgent.getFactory().getFontManager().setupRenderer(this, graphics2D); + FontCollection[] fontCollections = new FontCollection[] { + new Base14FontCollection(graphics2D), + new InstalledFontCollection(graphics2D), + new ConfiguredFontCollection(getFontResolver(), getFontList()) + }; + userAgent.getFactory().getFontManager().setup( + getFontInfo(), fontCollections); } /** @@ -1035,7 +1045,7 @@ public class PCLRenderer extends PrintRenderer { //So there's some optimization potential but not otherwise PCLRenderer is a little //difficult to derive from AbstractPathOrientedRenderer. Maybe an additional layer //between PrintRenderer and AbstractPathOrientedRenderer is necessary. - + // save position and offset int saveIP = currentIPPosition; int saveBP = currentBPPosition; @@ -1045,7 +1055,7 @@ public class PCLRenderer extends PrintRenderer { at.translate(currentIPPosition, currentBPPosition); at.translate(block.getXOffset(), block.getYOffset()); at.translate(0, block.getSpaceBefore()); - + if (!at.isIdentity()) { saveGraphicsState(); concatenateTransformationMatrix(mptToPt(at)); @@ -1063,12 +1073,12 @@ public class PCLRenderer extends PrintRenderer { if (!at.isIdentity()) { restoreGraphicsState(); } - + // stacked and relative blocks effect stacking currentIPPosition = saveIP; currentBPPosition = saveBP; } - + /** {@inheritDoc} */ protected void renderFlow(NormalFlow flow) { //TODO This is the same code as in AbstractPathOrientedRenderer @@ -1083,7 +1093,7 @@ public class PCLRenderer extends PrintRenderer { //Establish a new coordinate system AffineTransform at = new AffineTransform(); at.translate(currentIPPosition, currentBPPosition); - + if (!at.isIdentity()) { saveGraphicsState(); concatenateTransformationMatrix(mptToPt(at)); @@ -1092,16 +1102,16 @@ public class PCLRenderer extends PrintRenderer { currentIPPosition = 0; currentBPPosition = 0; super.renderFlow(flow); - + if (!at.isIdentity()) { restoreGraphicsState(); } - + // stacked and relative blocks effect stacking currentIPPosition = saveIP; currentBPPosition = saveBP; } - + /** * Concatenates the current transformation matrix with the given one, therefore establishing * a new coordinate system. @@ -1225,7 +1235,7 @@ public class PCLRenderer extends PrintRenderer { renderDocument(doc, ns, pos, fo.getForeignAttributes()); } - /** + /** * Common method to render the background and borders for any inline area. * The all borders and padding are drawn outside the specified area. * @param area the inline area for which the background, border and padding is to be diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java index 145f88187..5cbd3c095 100644 --- a/src/java/org/apache/fop/tools/TestConverter.java +++ b/src/java/org/apache/fop/tools/TestConverter.java @@ -274,7 +274,7 @@ public class TestConverter { File xmlFile = new File(baseDir + "/" + xml); String baseURL = null; try { - baseURL = xmlFile.getParentFile().toURL().toExternalForm(); + baseURL = xmlFile.getParentFile().toURI().toURL().toExternalForm(); } catch (Exception e) { logger.error("Error setting base directory"); } diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java index 83217651e..da25478c3 100644 --- a/src/java/org/apache/fop/tools/anttasks/Fop.java +++ b/src/java/org/apache/fop/tools/anttasks/Fop.java @@ -444,14 +444,14 @@ class FOPTaskStarter { //Set base directory if (task.getBasedir() != null) { try { - this.baseURL = task.getBasedir().toURL().toExternalForm(); + this.baseURL = task.getBasedir().toURI().toURL().toExternalForm(); } catch (MalformedURLException mfue) { logger.error("Error creating base URL from base directory", mfue); } } else { try { if (task.getFofile() != null) { - this.baseURL = task.getFofile().getParentFile().toURL(). + this.baseURL = task.getFofile().getParentFile().toURI().toURL(). toExternalForm(); } } catch (MalformedURLException mfue) { @@ -519,11 +519,11 @@ class FOPTaskStarter { try { if (task.getRelativebase()) { - this.baseURL = f.getParentFile().toURL(). + this.baseURL = f.getParentFile().toURI().toURL(). toExternalForm(); } if (this.baseURL == null) { - this.baseURL = fs.getDir(task.getProject()).toURL(). + this.baseURL = fs.getDir(task.getProject()).toURI().toURL(). toExternalForm(); } diff --git a/src/java/org/apache/fop/tools/anttasks/RunTest.java b/src/java/org/apache/fop/tools/anttasks/RunTest.java index b11c75242..2bc13e8b2 100644 --- a/src/java/org/apache/fop/tools/anttasks/RunTest.java +++ b/src/java/org/apache/fop/tools/anttasks/RunTest.java @@ -224,11 +224,11 @@ public class RunTest extends Task { */ private URL[] createUrls(String mainJar) throws MalformedURLException { ArrayList urls = new ArrayList(); - urls.add(new File(mainJar).toURL()); + urls.add(new File(mainJar).toURI().toURL()); File[] libFiles = new File("lib").listFiles(); for (int i = 0; i < libFiles.length; i++) { if (libFiles[i].getPath().endsWith(".jar")) { - urls.add(libFiles[i].toURL()); + urls.add(libFiles[i].toURI().toURL()); } } return (URL[]) urls.toArray(new URL[urls.size()]); diff --git a/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java b/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java index 6f286a3fb..725f0d4d7 100644 --- a/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java +++ b/test/java/org/apache/fop/config/FontsSubstitutionTestCase.java @@ -5,9 +5,9 @@ * 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. @@ -23,10 +23,13 @@ import java.io.File; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.MimeConstants; +import org.apache.fop.fonts.CustomFontCollection; import org.apache.fop.fonts.Font; +import org.apache.fop.fonts.FontCollection; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontManager; import org.apache.fop.fonts.FontTriplet; +import org.apache.fop.fonts.base14.Base14FontCollection; import org.apache.fop.render.PrintRenderer; /** @@ -53,7 +56,11 @@ public class FontsSubstitutionTestCase extends FontInfo fontInfo = new FontInfo(); renderer.setupFontInfo(fontInfo); FontManager fontManager = ua.getFactory().getFontManager(); - fontManager.setupRenderer(renderer); + FontCollection[] fontCollections = new FontCollection[] { + new Base14FontCollection(fontManager.isBase14KerningEnabled()), + new CustomFontCollection(renderer.getFontResolver(), renderer.getFontList()) + }; + fontManager.setup(fontInfo, fontCollections); FontTriplet triplet = new FontTriplet("Times", "italic", Font.WEIGHT_NORMAL); String internalFontKey = fontInfo.getInternalFontKey(triplet); |