]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Improved AWT Font-measuring/rendering (see bug #14657)
authorChristian Geisert <chrisg@apache.org>
Mon, 25 Nov 2002 17:01:48 +0000 (17:01 +0000)
committerChristian Geisert <chrisg@apache.org>
Mon, 25 Nov 2002 17:01:48 +0000 (17:01 +0000)
Submitted by: Ralph LaChance <Ralph_LaChance@compuserve.com>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195627 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
src/org/apache/fop/render/awt/AWTFontMetrics.java
src/org/apache/fop/render/awt/AWTRenderer.java
src/org/apache/fop/render/awt/FontSetup.java

diff --git a/CHANGES b/CHANGES
index 4902fb3789634338bb9a6c03be498e67782b2ec4..164ce79ff264262ba7703f0190a2215dd7ae6212 100644 (file)
--- 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 <Ralph_LaChance@compuserve.com>
 - Updated examples/fo files to remove all errors and warnings during build
   Submitted by: Manuel Mall <mm@arcus.com.au> (see bug #13867)
 - Perfomance tuning (reduced object creation etc.) (see bug #14103)
index 4c787f535408006a9a72f8400821c7f03778edb6..17205394456c4a85b9787cd7c57571cb403153e5 100644 (file)
@@ -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;
     }
 
     /**
index 72f0b831fc5b44a9117fe79b618d56dfbe7086c5..bd3a4f223673979642203b0910e728727d650c21 100644 (file)
@@ -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;
index cbecb2000f59d947c3645b8ef9a0da7730da2a52..702d3466c256b4807a23ea02aae367557a6923cf 100644 (file)
@@ -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