From: Christian Geisert Date: Mon, 25 Nov 2002 17:01:48 +0000 (+0000) Subject: Improved AWT Font-measuring/rendering (see bug #14657) X-Git-Tag: fop-0_20_5rc~36 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=811674be7e48fc89b52d12be590e7de6bec60013;p=xmlgraphics-fop.git Improved AWT Font-measuring/rendering (see bug #14657) Submitted by: Ralph LaChance git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195627 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 4902fb378..164ce79ff 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ ============================================================================== Done since 0.20.4 release +- Improved AWT Font-measuring/rendering (see bug #14657) + Submitted by: Ralph LaChance - Updated examples/fo files to remove all errors and warnings during build Submitted by: Manuel Mall (see bug #13867) - Perfomance tuning (reduced object creation etc.) (see bug #14103) diff --git a/src/org/apache/fop/render/awt/AWTFontMetrics.java b/src/org/apache/fop/render/awt/AWTFontMetrics.java index 4c787f535..172053944 100644 --- a/src/org/apache/fop/render/awt/AWTFontMetrics.java +++ b/src/org/apache/fop/render/awt/AWTFontMetrics.java @@ -177,14 +177,26 @@ public class AWTFontMetrics { public int width(int i, String family, int style, int size) { int w; setFont(family, style, size); + + // Nov 18, 2002, aml/rlc + // measure character width using getStringBounds for better results + + char [] ac = new char [1]; + ac [0] = (char)i; + + double dWidth = fmt.getStringBounds (ac, 0, 1, graphics).getWidth() * FONT_FACTOR; + + // The following was left in based on this comment from the past (may be vestigial) + // 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); - return w; + + if (i <=32) { + dWidth = dWidth * 1.4; + } + + return (int) dWidth; } /** diff --git a/src/org/apache/fop/render/awt/AWTRenderer.java b/src/org/apache/fop/render/awt/AWTRenderer.java index 72f0b831f..bd3a4f223 100644 --- a/src/org/apache/fop/render/awt/AWTRenderer.java +++ b/src/org/apache/fop/render/awt/AWTRenderer.java @@ -373,6 +373,11 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable graphics = pageImage.createGraphics(); + // Nov 18, 2002 - [aml/rlc] eliminates layout problems at various scaling + + graphics.setRenderingHint (RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); + transform(graphics, scaleFactor, 0); drawFrame(); @@ -859,6 +864,12 @@ public class AWTRenderer extends AbstractRenderer implements Printable, Pageable int oldPageNumber = pageNumber; graphics = (Graphics2D)g; + + // Nov 18, 2002 - [aml/rlc] eliminates layout problems at various scaling + + graphics.setRenderingHint (RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); + Page aPage = (Page)pageList.get(pageIndex); renderPage(aPage); graphics = oldGraphics; diff --git a/src/org/apache/fop/render/awt/FontSetup.java b/src/org/apache/fop/render/awt/FontSetup.java index cbecb2000..702d3466c 100644 --- a/src/org/apache/fop/render/awt/FontSetup.java +++ b/src/org/apache/fop/render/awt/FontSetup.java @@ -20,6 +20,7 @@ import org.apache.fop.apps.FOPException; import java.awt.Font; import java.awt.Graphics2D; import java.util.List; +import java.awt.RenderingHints ; import java.net.URL; /** @@ -46,8 +47,8 @@ public class FontSetup { * triplets for lookup * * @param fontInfo the font info object to set up - * @param graphics Graphics2D to work on - * @throws FOPException in case of an error during font setup + * @param parent needed, since a live AWT component is needed + * to get a valid java.awt.FontMetrics object */ public static void setup(FontInfo fontInfo, Graphics2D graphics) throws FOPException { @@ -56,6 +57,12 @@ public class FontSetup { MessageHandler.logln("setting up fonts"); + // Nov 18, 2002 - [aml/rlc] eliminates layout problems at various scaling + + graphics.setRenderingHint (RenderingHints.KEY_FRACTIONALMETRICS, + RenderingHints.VALUE_FRACTIONALMETRICS_ON); + + /* * available java fonts are: * Serif - bold, normal, italic, bold-italic