aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-01-07 15:06:24 +0000
committerJeremias Maerki <jeremias@apache.org>2008-01-07 15:06:24 +0000
commiteb93b9ef5345d734f6204c75e3171255833ac9f8 (patch)
tree4c57ca6576427efbdb12fb6b181b57850f5b8f51 /src/java
parent6415c9acd2fcfeb4961d53b8b5b967ad1010dceb (diff)
downloadxmlgraphics-fop-eb93b9ef5345d734f6204c75e3171255833ac9f8.tar.gz
xmlgraphics-fop-eb93b9ef5345d734f6204c75e3171255833ac9f8.zip
Bugzilla #44176:
Support for custom fonts in Java2DRenderer and derived renderers. Submitted by: Patrick Jaromin <patrick.at.jgsullivan.dot.com> Patch modified slightly by jeremias. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@609627 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java1
-rw-r--r--src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java205
-rw-r--r--src/java/org/apache/fop/render/java2d/FontMetricsMapper.java174
-rw-r--r--src/java/org/apache/fop/render/java2d/FontSetup.java115
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DRenderer.java2
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java1
-rw-r--r--src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java194
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLRenderer.java8
-rw-r--r--src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java2
9 files changed, 510 insertions, 192 deletions
diff --git a/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java b/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
index 41b05ecd7..14e6734dd 100644
--- a/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/bitmap/TIFFRendererConfigurator.java
@@ -68,5 +68,6 @@ public class TIFFRendererConfigurator extends PrintRendererConfigurator {
log.info("TIFF compression set to " + name);
}
}
+ super.configure(renderer);
}
}
diff --git a/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java b/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java
new file mode 100644
index 000000000..968ed7b71
--- /dev/null
+++ b/src/java/org/apache/fop/render/java2d/CustomFontMetricsMapper.java
@@ -0,0 +1,205 @@
+/*
+ * 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.java2d;
+
+import java.awt.Font;
+import java.awt.FontFormatException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.FontType;
+import org.apache.fop.fonts.LazyFont;
+import org.apache.fop.fonts.Typeface;
+
+/**
+ * FontMetricsMapper that delegates most methods to an underlying
+ * <tt>FontMetrics</tt> instance. This class was designed to allow
+ * the underlying <tt>java.awt.Font</tt> to be loaded from a
+ * user-configured file not registered in the current graphics environment.
+ */
+public class CustomFontMetricsMapper extends Typeface implements FontMetricsMapper {
+
+ /**
+ * Font metrics for the font this class models.
+ */
+ private Typeface typeface;
+
+ /**
+ * The font required by the Java2D renderer.
+ */
+ private java.awt.Font font;
+
+ /**
+ * Maintains the most recently requested size.
+ */
+ private float size = 1;
+
+ /**
+ * Construction of this class results in the immediate construction.
+ * of the underlying <tt>java.awt.Font</tt>
+ * @param fontMetrics
+ * @throws FontFormatException
+ * @throws IOException
+ */
+ public CustomFontMetricsMapper(final CustomFont fontMetrics)
+ throws FontFormatException, IOException {
+ this.typeface = fontMetrics;
+ initialize(fontMetrics.getEmbedFileSource());
+ }
+
+ /**
+ * Construction of this class results in the immediate construction
+ * of the underlying <tt>java.awt.Font</tt>
+ * @param fontMetrics
+ * @throws FontFormatException
+ * @throws IOException
+ */
+ public CustomFontMetricsMapper(final LazyFont fontMetrics, final Source fontSource)
+ throws FontFormatException, IOException {
+ this.typeface = fontMetrics;
+ initialize(fontSource);
+ }
+
+ private static final int TYPE1_FONT = 1; //Defined in Java 1.5
+
+ /**
+ * Loads the java.awt.Font
+ * @param source
+ * @throws FontFormatException
+ * @throws IOException
+ */
+ private void initialize(final Source source)
+ throws FontFormatException, IOException {
+ int type = Font.TRUETYPE_FONT;
+ if (FontType.TYPE1.equals(typeface.getFontType())) {
+ type = TYPE1_FONT; //Font.TYPE1_FONT; only available in Java 1.5
+ }
+
+ InputStream is = null;
+ if (source instanceof StreamSource) {
+ is = ((StreamSource) source).getInputStream();
+ } else if (source.getSystemId() != null) {
+ is = new java.net.URL(source.getSystemId()).openStream();
+ } else {
+ throw new IllegalArgumentException("No font source provided.");
+ }
+
+ this.font = Font.createFont(type, is);
+ is.close();
+
+ }
+
+ /** {@inheritDoc} */
+ public final String getEncoding() {
+ return null; //Not applicable to Java2D rendering
+ }
+
+ /** {@inheritDoc} */
+ public final boolean hasChar(final char c) {
+ return font.canDisplay(c);
+ }
+
+ /** {@inheritDoc} */
+ public final char mapChar(final char c) {
+ return typeface.mapChar(c);
+ }
+
+ /** {@inheritDoc} */
+ public final Font getFont(final int size) {
+ if (this.size == size) {
+ return font;
+ }
+
+ this.size = size / 1000f;
+ font = font.deriveFont(this.size);
+ return font;
+ }
+
+ /** {@inheritDoc} */
+ public final int getAscender(final int size) {
+ return typeface.getAscender(size);
+ }
+
+ /** {@inheritDoc} */
+ public final int getCapHeight(final int size) {
+ return typeface.getCapHeight(size);
+ }
+
+ /** {@inheritDoc} */
+ public final int getDescender(final int size) {
+ return typeface.getDescender(size);
+ }
+
+ /** {@inheritDoc} */
+ public final String getEmbedFontName() {
+ return typeface.getEmbedFontName();
+ }
+
+ /** {@inheritDoc} */
+ public final Set getFamilyNames() {
+ return typeface.getFamilyNames();
+ }
+
+ /** {@inheritDoc} */
+ public final String getFontName() {
+ return typeface.getFontName();
+ }
+
+ /** {@inheritDoc} */
+ public final FontType getFontType() {
+ return typeface.getFontType();
+ }
+
+ /** {@inheritDoc} */
+ public final String getFullName() {
+ return typeface.getFullName();
+ }
+
+ /** {@inheritDoc} */
+ public final Map getKerningInfo() {
+ return typeface.getKerningInfo();
+ }
+
+ /** {@inheritDoc} */
+ public final int getWidth(final int i, final int size) {
+ return typeface.getWidth(i, size);
+ }
+
+ /** {@inheritDoc} */
+ public final int[] getWidths() {
+ return typeface.getWidths();
+ }
+
+ /** {@inheritDoc} */
+ public final int getXHeight(final int size) {
+ return typeface.getXHeight(size);
+ }
+
+ /** {@inheritDoc} */
+ public final boolean hasKerningInfo() {
+ return typeface.hasKerningInfo();
+ }
+
+}
diff --git a/src/java/org/apache/fop/render/java2d/FontMetricsMapper.java b/src/java/org/apache/fop/render/java2d/FontMetricsMapper.java
index 19ecf1020..ff246af2b 100644
--- a/src/java/org/apache/fop/render/java2d/FontMetricsMapper.java
+++ b/src/java/org/apache/fop/render/java2d/FontMetricsMapper.java
@@ -16,183 +16,23 @@
*/
/* $Id$ */
-
-package org.apache.fop.render.java2d;
-// Java
-import java.awt.Graphics2D;
-import java.util.Map;
-import java.util.Set;
+package org.apache.fop.render.java2d;
import org.apache.fop.fonts.FontMetrics;
-import org.apache.fop.fonts.FontType;
-import org.apache.fop.fonts.Typeface;
-
/**
- * This class implements org.apache.fop.layout.FontMetrics and
- * is added to the hash table in FontInfo. It deferes the
- * actual calculation of the metrics to
- * Java2DFontMetrics. It only keeps the java name and
- * style as member varibles
+ * Adds method to retrieve the actual <tt>java.awt.Font</tt>
+ * for use by <tt>Java2DRenderer</tt>s.
*/
-
-public class FontMetricsMapper extends Typeface implements FontMetrics {
-
- /**
- * This is a Java2DFontMetrics that does the real calculation.
- * It is only one class that dynamically determines the font-size.
- */
- private static Java2DFontMetrics metric = null;
-
- /**
- * The java name of the font.
- * # Make the family name immutable.
- */
- private final String family;
-
- /**
- * The java style of the font.
- * # Make the style immutable.
- */
- private final int style;
-
- /**
- * Constructs a new Font-metrics.
- * @param family the family name of the font (java value)
- * @param style the java type style value of the font
- * @param graphics a Graphics2D object - this is needed so
- * that we can get an instance of java.awt.FontMetrics
- */
- public FontMetricsMapper(String family, int style, Graphics2D graphics) {
- this.family = family;
- this.style = style;
- if (metric == null) {
- metric = new Java2DFontMetrics(graphics);
- }
- }
-
- /** {@inheritDoc} */
- public String getFontName() {
- return family;
- }
-
- /** {@inheritDoc} */
- public String getEmbedFontName() {
- return getFontName();
- }
-
- /** {@inheritDoc} */
- public String getFullName() {
- return getFontName();
- }
-
- /** {@inheritDoc} */
- public Set getFamilyNames() {
- Set s = new java.util.HashSet();
- s.add(this.family);
- return s;
- }
-
- /**
- * {@inheritDoc}
- */
- public FontType getFontType() {
- return FontType.OTHER;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getMaxAscent(int size) {
- return metric.getMaxAscent(family, style, size);
- }
-
- /**
- * {@inheritDoc}
- */
- public int getAscender(int size) {
- return metric.getAscender(family, style, size);
- }
-
- /**
- * {@inheritDoc}
- */
- public int getCapHeight(int size) {
- return metric.getCapHeight(family, style, size);
- }
-
- /**
- * {@inheritDoc}
- */
- public int getDescender(int size) {
- return metric.getDescender(family, style, size);
- }
-
- /**
- * {@inheritDoc}
- */
- public int getXHeight(int size) {
- return metric.getXHeight(family, style, size);
- }
-
- /**
- * {@inheritDoc}
- */
- public int getWidth(int i, int size) {
- return metric.width(i, family, style, size);
- }
-
-
- /**
- * {@inheritDoc}
- */
- public int[] getWidths() {
- return metric.getWidths(family, style, Java2DFontMetrics.FONT_SIZE);
- }
+public interface FontMetricsMapper extends FontMetrics {
/**
* Gets a Font instance of the Font that this
* FontMetrics describes in the desired size.
* @param size font size
- * @return font with the desired characeristics.
- */
- public java.awt.Font getFont(int size) {
- return metric.getFont(family, style, size);
- }
-
- /**
- * {@inheritDoc}
- */
- public Map getKerningInfo() {
- return java.util.Collections.EMPTY_MAP;
- }
-
- /**
- * {@inheritDoc}
+ * @return font with the desired characteristics.
*/
- public boolean hasKerningInfo() {
- return false;
- }
-
- /** {@inheritDoc} */
- public String getEncoding() {
- return null; //Not applicable to Java2D rendering
- }
-
- /** {@inheritDoc} */
- public char mapChar(char c) {
- return c;
- }
-
- /** {@inheritDoc} */
- public boolean hasChar(char c) {
- return metric.hasChar(family, style, Java2DFontMetrics.FONT_SIZE, c);
- }
-
+ java.awt.Font getFont(int size);
+
}
-
-
-
-
-
diff --git a/src/java/org/apache/fop/render/java2d/FontSetup.java b/src/java/org/apache/fop/render/java2d/FontSetup.java
index bd53c20d7..6cdf01521 100644
--- a/src/java/org/apache/fop/render/java2d/FontSetup.java
+++ b/src/java/org/apache/fop/render/java2d/FontSetup.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.
@@ -22,14 +22,23 @@ package org.apache.fop.render.java2d;
// FOP
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
+import java.util.List;
import java.util.Set;
+import javax.xml.transform.Source;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
+import org.apache.fop.fonts.CustomFont;
+import org.apache.fop.fonts.EmbedFontInfo;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.FontLoader;
+import org.apache.fop.fonts.FontResolver;
import org.apache.fop.fonts.FontTriplet;
import org.apache.fop.fonts.FontUtil;
+import org.apache.fop.fonts.LazyFont;
/**
* Sets up the Java2D/AWT fonts. It is similar to
@@ -70,10 +79,13 @@ public class FontSetup {
* triplets for lookup.
*
* @param fontInfo the font info object to set up
- * @param graphics needed for acces to font metrics
+ * @param configuredFontList of fop config fonts
+ * @param resolver for resolving the font file URI
+ * @param graphics needed for access to font metrics
*/
- public static void setup(FontInfo fontInfo, Graphics2D graphics) {
- FontMetricsMapper metric;
+ public static void setup(FontInfo fontInfo, List configuredFontList,
+ FontResolver resolver, Graphics2D graphics) {
+ FontMetricsMapper metric;
int normal, bold, bolditalic, italic;
/*
@@ -87,47 +99,47 @@ public class FontSetup {
italic = java.awt.Font.ITALIC;
bolditalic = java.awt.Font.BOLD + java.awt.Font.ITALIC;
- metric = new FontMetricsMapper("SansSerif", normal, graphics);
+ metric = new SystemFontMetricsMapper("SansSerif", normal, graphics);
// --> goes to F1
fontInfo.addMetrics("F1", metric);
- metric = new FontMetricsMapper("SansSerif", italic, graphics);
+ metric = new SystemFontMetricsMapper("SansSerif", italic, graphics);
// --> goes to F2
fontInfo.addMetrics("F2", metric);
- metric = new FontMetricsMapper("SansSerif", bold, graphics);
+ metric = new SystemFontMetricsMapper("SansSerif", bold, graphics);
// --> goes to F3
fontInfo.addMetrics("F3", metric);
- metric = new FontMetricsMapper("SansSerif", bolditalic, graphics);
+ metric = new SystemFontMetricsMapper("SansSerif", bolditalic, graphics);
// --> goes to F4
fontInfo.addMetrics("F4", metric);
- metric = new FontMetricsMapper("Serif", normal, graphics);
+ metric = new SystemFontMetricsMapper("Serif", normal, graphics);
// --> goes to F5
fontInfo.addMetrics("F5", metric);
- metric = new FontMetricsMapper("Serif", italic, graphics);
+ metric = new SystemFontMetricsMapper("Serif", italic, graphics);
// --> goes to F6
fontInfo.addMetrics("F6", metric);
- metric = new FontMetricsMapper("Serif", bold, graphics);
+ metric = new SystemFontMetricsMapper("Serif", bold, graphics);
// --> goes to F7
fontInfo.addMetrics("F7", metric);
- metric = new FontMetricsMapper("Serif", bolditalic, graphics);
+ metric = new SystemFontMetricsMapper("Serif", bolditalic, graphics);
// --> goes to F8
fontInfo.addMetrics("F8", metric);
- metric = new FontMetricsMapper("MonoSpaced", normal, graphics);
+ metric = new SystemFontMetricsMapper("MonoSpaced", normal, graphics);
// --> goes to F9
fontInfo.addMetrics("F9", metric);
- metric = new FontMetricsMapper("MonoSpaced", italic, graphics);
+ metric = new SystemFontMetricsMapper("MonoSpaced", italic, graphics);
// --> goes to F10
fontInfo.addMetrics("F10", metric);
- metric = new FontMetricsMapper("MonoSpaced", bold, graphics);
+ metric = new SystemFontMetricsMapper("MonoSpaced", bold, graphics);
// --> goes to F11
fontInfo.addMetrics("F11", metric);
- metric = new FontMetricsMapper("MonoSpaced", bolditalic, graphics);
+ metric = new SystemFontMetricsMapper("MonoSpaced", bolditalic, graphics);
// --> goes to F12
fontInfo.addMetrics("F12", metric);
- metric = new FontMetricsMapper("Serif", normal, graphics);
+ metric = new SystemFontMetricsMapper("Serif", normal, graphics);
//"Symbol" doesn't seem to work here, but "Serif" does the job just fine. *shrug*
// --> goes to F13 and F14
fontInfo.addMetrics("F13", metric);
@@ -207,10 +219,11 @@ public class FontSetup {
fontInfo.addFontProperties("F9", "Computer-Modern-Typewriter",
"normal", Font.WEIGHT_NORMAL);
- configureInstalledAWTFonts(fontInfo, graphics, LAST_PREDEFINED_FONT_NUMBER + 1);
+ int lastNum = configureInstalledAWTFonts(fontInfo, graphics, LAST_PREDEFINED_FONT_NUMBER + 1);
+ addConfiguredFonts(fontInfo, configuredFontList, resolver, lastNum++);
}
- private static void configureInstalledAWTFonts(FontInfo fontInfo, Graphics2D graphics,
+ private static int configureInstalledAWTFonts(FontInfo fontInfo, Graphics2D graphics,
int startNumber) {
int num = startNumber;
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
@@ -250,9 +263,69 @@ public class FontSetup {
guessedStyle, guessedWeight, fontKey);
}
}
+ return num;
+
+ }
+
+ /**
+ * Add fonts from configuration file starting with internal name F<num>.
+ *
+ * @param fontInfo the font info object to set up
+ * @param fontList a list of EmbedFontInfo objects
+ * @param num starting index for internal font numbering
+ * @param resolver the font resolver
+ */
+ private static void addConfiguredFonts(FontInfo fontInfo, List fontList, FontResolver resolver, int num) {
+
+ if (fontList == null || fontList.size() < 1) {
+ log.debug("No user configured fonts found.");
+ return;
+ }
+ if (resolver == null) {
+ // Ensure that we have minimal font resolution capabilities
+ resolver = org.apache.fop.fonts.FontSetup
+ .createMinimalFontResolver();
+ }
+ String internalName = null;
+
+ for (int i = 0; i < fontList.size(); i++) {
+
+ EmbedFontInfo configFontInfo = (EmbedFontInfo) fontList.get(i);
+ String fontFile = configFontInfo.getEmbedFile();
+ internalName = "F" + num;
+ num++;
+ try {
+ FontMetricsMapper font = null;
+ String metricsUrl = configFontInfo.getMetricsFile();
+ // 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());
+ font = new CustomFontMetricsMapper(fontMetrics, fontSource);
+ } else {
+ CustomFont fontMetrics = FontLoader.loadFont(fontFile, resolver);
+ font = new CustomFontMetricsMapper(fontMetrics);
+ }
+ fontInfo.addMetrics(internalName, font);
+
+ List triplets = configFontInfo.getFontTriplets();
+ for (int c = 0; c < triplets.size(); c++) {
+ FontTriplet triplet = (FontTriplet) triplets.get(c);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Registering: " + triplet + " under " + internalName);
+ }
+ fontInfo.addFontProperties(internalName, triplet);
+ }
+ } catch (Exception e) {
+ log.warn("Unable to load custom font from file '" + fontFile + "'", e);
+ }
+ }
}
+
private static void addFontTriplet(FontInfo fontInfo, String fontName, String fontStyle,
int fontWeight, String fontKey) {
FontTriplet triplet = FontInfo.createFontKey(fontName, fontStyle, fontWeight);
@@ -261,7 +334,7 @@ public class FontSetup {
private static void addFontMetricsMapper(FontInfo fontInfo, String family, String fontKey,
Graphics2D graphics, int style) {
- FontMetricsMapper metric = new FontMetricsMapper(family, style, graphics);
+ FontMetricsMapper metric = new SystemFontMetricsMapper(family, style, graphics);
fontInfo.addMetrics(fontKey, metric);
}
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
index aa9b0337a..eededf13b 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRenderer.java
@@ -179,7 +179,7 @@ public abstract class Java2DRenderer extends AbstractPathOrientedRenderer implem
//The next line is important to get accurate font metrics!
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- FontSetup.setup(fontInfo, g);
+ FontSetup.setup(fontInfo, fontList, fontResolver, g);
}
/** {@inheritDoc} */
diff --git a/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java b/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java
index 6732a10fe..cc8d3d07f 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DRendererConfigurator.java
@@ -53,5 +53,6 @@ public class Java2DRendererConfigurator extends PrintRendererConfigurator {
java2dRenderer.setTransparentPageBackground("true".equalsIgnoreCase(value));
}
}
+ super.configure(renderer);
}
}
diff --git a/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java b/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java
new file mode 100644
index 000000000..ed7391383
--- /dev/null
+++ b/src/java/org/apache/fop/render/java2d/SystemFontMetricsMapper.java
@@ -0,0 +1,194 @@
+/*
+ * 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.java2d;
+
+// Java
+import java.awt.Graphics2D;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.fop.fonts.FontType;
+import org.apache.fop.fonts.Typeface;
+
+
+/**
+ * This class implements org.apache.fop.layout.FontMetrics and
+ * is added to the hash table in FontInfo. It deferes the
+ * actual calculation of the metrics to
+ * Java2DFontMetrics. It only keeps the java name and
+ * style as member varibles
+ */
+
+public class SystemFontMetricsMapper extends Typeface implements FontMetricsMapper {
+
+ /**
+ * This is a Java2DFontMetrics that does the real calculation.
+ * It is only one class that dynamically determines the font-size.
+ */
+ private static Java2DFontMetrics metric = null;
+
+ /**
+ * The java name of the font.
+ * # Make the family name immutable.
+ */
+ private final String family;
+
+ /**
+ * The java style of the font.
+ * # Make the style immutable.
+ */
+ private final int style;
+
+ /**
+ * Constructs a new Font-metrics.
+ * @param family the family name of the font (java value)
+ * @param style the java type style value of the font
+ * @param graphics a Graphics2D object - this is needed so
+ * that we can get an instance of java.awt.FontMetrics
+ */
+ public SystemFontMetricsMapper(String family, int style, Graphics2D graphics) {
+ this.family = family;
+ this.style = style;
+ if (metric == null) {
+ metric = new Java2DFontMetrics(graphics);
+ }
+ }
+
+ /** {@inheritDoc} */
+ public String getFontName() {
+ return family;
+ }
+
+ /** {@inheritDoc} */
+ public String getEmbedFontName() {
+ return getFontName();
+ }
+
+ /** {@inheritDoc} */
+ public String getFullName() {
+ return getFontName();
+ }
+
+ /** {@inheritDoc} */
+ public Set getFamilyNames() {
+ Set s = new java.util.HashSet();
+ s.add(this.family);
+ return s;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public FontType getFontType() {
+ return FontType.OTHER;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getMaxAscent(int size) {
+ return metric.getMaxAscent(family, style, size);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getAscender(int size) {
+ return metric.getAscender(family, style, size);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getCapHeight(int size) {
+ return metric.getCapHeight(family, style, size);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDescender(int size) {
+ return metric.getDescender(family, style, size);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getXHeight(int size) {
+ return metric.getXHeight(family, style, size);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getWidth(int i, int size) {
+ return metric.width(i, family, style, size);
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public int[] getWidths() {
+ return metric.getWidths(family, style, Java2DFontMetrics.FONT_SIZE);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public java.awt.Font getFont(int size) {
+ return metric.getFont(family, style, size);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Map getKerningInfo() {
+ return java.util.Collections.EMPTY_MAP;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean hasKerningInfo() {
+ return false;
+ }
+
+ /** {@inheritDoc} */
+ public String getEncoding() {
+ return null; //Not applicable to Java2D rendering
+ }
+
+ /** {@inheritDoc} */
+ public char mapChar(char c) {
+ return c;
+ }
+
+ /** {@inheritDoc} */
+ public boolean hasChar(char c) {
+ return metric.hasChar(family, style, Java2DFontMetrics.FONT_SIZE, c);
+ }
+
+}
+
+
+
+
+
diff --git a/src/java/org/apache/fop/render/pcl/PCLRenderer.java b/src/java/org/apache/fop/render/pcl/PCLRenderer.java
index 095c3bba7..732ce0f8f 100644
--- a/src/java/org/apache/fop/render/pcl/PCLRenderer.java
+++ b/src/java/org/apache/fop/render/pcl/PCLRenderer.java
@@ -48,8 +48,12 @@ import java.util.List;
import java.util.Map;
import java.util.Stack;
+import org.w3c.dom.Document;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.java2d.GraphicContext;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.area.Area;
@@ -86,8 +90,6 @@ import org.apache.fop.render.pcl.extensions.PCLElementMapping;
import org.apache.fop.traits.BorderProps;
import org.apache.fop.util.QName;
import org.apache.fop.util.UnitConv;
-import org.apache.xmlgraphics.java2d.GraphicContext;
-import org.w3c.dom.Document;
/**
* Renderer for the PCL 5 printer language. It also uses HP GL/2 for certain graphic elements.
@@ -182,7 +184,7 @@ public class PCLRenderer extends PrintRenderer {
//The next line is important to get accurate font metrics!
g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
- FontSetup.setup(fontInfo, g);
+ FontSetup.setup(fontInfo, fontList, fontResolver, g);
}
/**
diff --git a/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java b/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java
index 1330a46ac..03b60f316 100644
--- a/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java
+++ b/src/java/org/apache/fop/render/pcl/PCLRendererConfigurator.java
@@ -20,6 +20,7 @@
package org.apache.fop.render.pcl;
import org.apache.avalon.framework.configuration.Configuration;
+
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.render.PrintRendererConfigurator;
@@ -73,5 +74,6 @@ public class PCLRendererConfigurator extends PrintRendererConfigurator {
pclRenderer.setPJLDisabled(cfg.getChild("disable-pjl").getValueAsBoolean(false));
}
+ super.configure(renderer);
}
}