import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
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;
= (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) {
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);
//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());
}
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;
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
try {
baseURL = new File(sourcefile.getAbsolutePath()).
- getParentFile().toURL().toExternalForm();
+ getParentFile().toURI().toURL().toExternalForm();
} catch (Exception e) {
baseURL = "";
}
+ 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) {
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");
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());
}
}
}
} 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
} 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);
}
<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>
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
this.methodName = methodName;
this.severity = severity;
}
-
+
/**
* Adds a method parameter.
* @param param the method parameter
public void addParameter(Parameter param) {
this.params.add(param);
}
-
+
/**
* Adds a method parameter.
* @param type the type of the parameter
* @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
public void setMethodName(String name) {
this.methodName = name;
}
-
+
/**
* Returns the event method name
* @return the event name
public String getMethodName() {
return this.methodName;
}
-
+
/**
* Sets the event's severity level.
* @param severity the severity
public void setSeverity(EventSeverity severity) {
this.severity = severity;
}
-
+
/**
* Returns the event's severity level.
* @return the severity
public EventSeverity getSeverity() {
return this.severity;
}
-
+
/**
* Returns an unmodifiable list of parameters for this event method.
* @return the list of parameters
public List getParameters() {
return Collections.unmodifiableList(this.params);
}
-
+
/**
* Sets the primary exception class for this event method. Note: Not all event methods throw
* exceptions!
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.
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
this.type = type;
this.name = name;
}
-
+
/**
* Returns the parameter type.
* @return the parameter type
public Class getType() {
return this.type;
}
-
+
/**
* Returns the parameter name.
* @return the parameter name
/** {@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);
}
-
+
}
}
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import org.apache.commons.io.IOUtils;
+
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
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>)
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
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();
throw new IOException(e.getMessage());
} catch (SAXException e) {
throw new IOException(e.getMessage());
+ } finally {
+ IOUtils.closeQuietly(out);
}
}
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
public String getInterfaceName() {
return this.interfaceName;
}
-
+
/**
* Sets the fully qualified interface name of the event producer.
* @param name the fully qualified interface name
public void setInterfaceName(String name) {
this.interfaceName = name;
}
-
+
/**
* Adds a model instance of an event method.
* @param method the event method model
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
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>)
/** {@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);
}
-
+
}
// 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);
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;
* 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.
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;
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();
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);
// 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;
}
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);
}
* 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.
package org.apache.fop.fonts;
-import java.awt.Graphics2D;
import java.net.MalformedURLException;
import javax.xml.transform.Source;
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
}
/**
- * 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);
}
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: "
*/
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: "
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;
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();
* 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.
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 {
*/
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);
}
/**
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;
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;
/** {@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} */
--- /dev/null
+/*
+ * 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;
+ }
+
+}
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;
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;
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;
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 "
* 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.
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
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++;
// 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);
}
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;
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} */
* 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.
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;
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;
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);
}
/**
//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;
at.translate(currentIPPosition, currentBPPosition);
at.translate(block.getXOffset(), block.getYOffset());
at.translate(0, block.getSpaceBefore());
-
+
if (!at.isIdentity()) {
saveGraphicsState();
concatenateTransformationMatrix(mptToPt(at));
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
//Establish a new coordinate system
AffineTransform at = new AffineTransform();
at.translate(currentIPPosition, currentBPPosition);
-
+
if (!at.isIdentity()) {
saveGraphicsState();
concatenateTransformationMatrix(mptToPt(at));
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.
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
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");
}
//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) {
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();
}
*/
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()]);
* 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.
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;
/**
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);