aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java')
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java b/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
index 10af3aa86..88ceb1270 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
@@ -21,12 +21,14 @@ package org.apache.fop.render.java2d;
// Java
import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.geom.Rectangle2D;
import java.awt.FontMetrics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
import java.awt.font.LineMetrics;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
+import java.awt.geom.Rectangle2D;
+import java.awt.image.BufferedImage;
import java.util.Map;
/**
@@ -110,6 +112,20 @@ public class Java2DFontMetrics {
private Graphics2D graphics;
/**
+ * Creates a Graphics2D object for the sole purpose of getting font metrics.
+ * @return a Graphics2D object
+ */
+ public static Graphics2D createFontMetricsGraphics2D() {
+ BufferedImage fontImage = new BufferedImage(100, 100,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D graphics2D = fontImage.createGraphics();
+ //The next line is important to get accurate font metrics!
+ graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
+ RenderingHints.VALUE_FRACTIONALMETRICS_ON);
+ return graphics2D;
+ }
+
+ /**
* Constructs a new Font-metrics.
* @param graphics a temp graphics object - this is needed so
* that we can get an instance of java.awt.FontMetrics