* 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();
* 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);
}
* 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);
}
/**
* 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
* 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);