diff options
author | Jeremias Maerki <jeremias@apache.org> | 2008-07-17 09:11:09 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2008-07-17 09:11:09 +0000 |
commit | 1867bcc73af7bbb10a7729ff01184a1909abbb4d (patch) | |
tree | 28f4f9508268a522c4cdd6238a74fe10fc45ba5d /src/java/org/apache/fop/render | |
parent | 7a56940e312c85dc0c0ec1a4729f990d0ff55358 (diff) | |
download | xmlgraphics-fop-1867bcc73af7bbb10a7729ff01184a1909abbb4d.tar.gz xmlgraphics-fop-1867bcc73af7bbb10a7729ff01184a1909abbb4d.zip |
fonts package must not depend on the render package. Refactored to restore that rule.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@677543 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
4 files changed, 71 insertions, 46 deletions
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/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 ed6f29ab9..1dd353b3b 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; @@ -176,7 +177,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 7ab46c24e..11366f985 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 |