aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2006-05-10 13:45:46 +0000
committerJeremias Maerki <jeremias@apache.org>2006-05-10 13:45:46 +0000
commit0af60bb3783baacbef97cbf7eb7f67fbe9896841 (patch)
treec5e67d83804d875f209ebe01db8e2ed9b3c4f3b8 /src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
parente98e4a82127082d77e073e8d72f17231d5e5b9c1 (diff)
downloadxmlgraphics-fop-0af60bb3783baacbef97cbf7eb7f67fbe9896841.tar.gz
xmlgraphics-fop-0af60bb3783baacbef97cbf7eb7f67fbe9896841.zip
Important improvements for the Java2DRenderer:
Support for letter- and word-spacing which also enables justified text. Fix for font metric access. Fractional metrics was off. charWidth() only returned integers. Removed the obscure 1.4 factor (Thanks to Chris Dail for the hint!) Dispose of Graphics2D instance if no longer used to free up resources. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@405763 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java')
-rw-r--r--src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java b/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
index 724fda81d..5cba0d5e9 100644
--- a/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
+++ b/src/java/org/apache/fop/render/java2d/Java2DFontMetrics.java
@@ -189,17 +189,17 @@ public class Java2DFontMetrics {
public int width(int i, String family, int style, int size) {
int w;
setFont(family, style, size);
- // the output seems to look a little better if the
- // space is rendered larger than given by
- // the FontMetrics object
- if (i <= 32) {
- w = (int)(1.4 * fmt.charWidth(i) * FONT_FACTOR);
- } else {
- w = (int)(fmt.charWidth(i) * FONT_FACTOR);
- }
+ w = internalCharWidth(i) * 1000;
return w;
}
+ private int internalCharWidth(int i) {
+ //w = (int)(fmt.charWidth(i) * 1000); //Not accurate enough!
+ char[] ch = {(char)i};
+ Rectangle2D rect = fmt.getStringBounds(ch, 0, 1, this.graphics);
+ return (int)Math.round(rect.getWidth() * 1000);
+ }
+
/**
* Return widths (in 1/1000ths of point size) of all
* characters
@@ -216,7 +216,7 @@ public class Java2DFontMetrics {
}
setFont(family, style, size);
for (i = 0; i < 256; i++) {
- width[i] = FONT_FACTOR * fmt.charWidth(i);
+ width[i] = 1000 * internalCharWidth(i);
}
return width;
}
@@ -234,6 +234,7 @@ public class Java2DFontMetrics {
boolean changed = false;
Rectangle2D rect;
TextLayout layout;
+ //TODO this seems bad. It rounds font sizes down to the next integer value (=pt)
int s = (int)(size / 1000f);
if (f1 == null) {