Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-502

[PATCH] Awt measuring/rendering problems

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Resolution: Fixed
    • 0.20.4
    • None
    • renderer/awt
    • None
    • Operating System: All
      Platform: PC
    • 14657

    Description

      The AWT Renderer and its subclass Print renderer (lives in the PrintStarter)
      sizes text
      incorrectly at certain zoom scalings. It is especially with
      bold text. The problem shows up
      differently with jre 1.3.x and 1.4.x

      The solution requires two actions:
      1) to enable the
      Rendering Hint - FractionalMetrics
      2) to use getStringBounds to obtain the size of a
      character
      rather than charWidth.

      3 files in package ...fop.render.awt are affected,
      AWTRenderer,
      AWTFontMetrics, and FontSetup.

      Diff file follows below

      'best
      -
      Ralph LaChance

      Index: xml-
      fop/src/org/apache/fop/render/awt/AWTFontMetrics.java
      ===================================================================
      RCS
      file: /home/cvspublic/xml-
      fop/src/org/apache/fop/render/awt/AWTFontMetrics.java,v
      retrieving revision
      1.3.2.3
      diff -u -r1.3.2.3 AWTFontMetrics.java
      — xml-
      fop/src/org/apache/fop/render/awt/AWTFontMetrics.java 8 Nov 2002 10:25:27 -
      0000 1.3.2.3
      +++ xml-fop/src/org/apache/fop/render/awt/AWTFontMetrics.java 18 Nov
      2002 22:41:37 -0000
      @@ -177,14 +177,26 @@
      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: xml-
      fop/src/org/apache/fop/render/awt/AWTRenderer.java
      ===================================================================
      RCS
      file: /home/cvspublic/xml-
      fop/src/org/apache/fop/render/awt/AWTRenderer.java,v
      retrieving revision
      1.38.2.9
      diff -u -r1.38.2.9 AWTRenderer.java
      — xml-
      fop/src/org/apache/fop/render/awt/AWTRenderer.java 8 Nov 2002 10:25:27 -
      0000 1.38.2.9
      +++ xml-fop/src/org/apache/fop/render/awt/AWTRenderer.java 18 Nov 2002
      22:41:38 -0000
      @@ -15,6 +15,7 @@
      import org.apache.fop.render.AbstractRenderer;

      import org.apache.fop.render.pdf.*;
      import org.apache.fop.svg.*;
      +import
      org.apache.fop.render.pdf.*;
      import org.apache.fop.viewer.*;

      import
      org.w3c.dom.svg.*;
      @@ -373,6 +374,11 @@

      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,7 +865,13 @@
      int oldPageNumber = pageNumber;

      graphics =
      (Graphics2D)g;

      • Page aPage = (Page)pageList.get(pageIndex);
        +
        + // Nov 18, 2002 -
        [aml/rlc] eliminates layout problems at various scaling
        +
        + graphics.setRenderingHint
        (RenderingHints.KEY_FRACTIONALMETRICS,
        +
        RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        +
        + Page aPage =
        (Page)pageList.elementAt(pageIndex);
        renderPage(aPage);
        graphics = oldGraphics;

      Index: xml-
      fop/src/org/apache/fop/render/awt/FontSetup.java
      ===================================================================
      RCS
      file: /home/cvspublic/xml-
      fop/src/org/apache/fop/render/awt/FontSetup.java,v
      retrieving revision
      1.3.2.4
      diff -u -r1.3.2.4 FontSetup.java
      — xml-
      fop/src/org/apache/fop/render/awt/FontSetup.java 8 Nov 2002 10:25:27 -
      0000 1.3.2.4
      +++ xml-fop/src/org/apache/fop/render/awt/FontSetup.java 18 Nov 2002
      22:41:38 -0000
      @@ -19,8 +19,8 @@
      // Java
      import java.awt.Font;
      import
      java.awt.Graphics2D;
      -import java.util.List;
      -import java.net.URL;
      +import
      java.awt.RenderingHints ;
      +import java.util.Vector;

      /**

      • sets up the AWT fonts. It
        is similar to
        @@ -46,8 +46,8 @@
      • 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 {
        @@ -55,6 +55,12 @@
        FontMetricsMapper
        metric;

      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:

      Attachments

        1. 14657.diff.txt
          5 kB
          Ralph LaChance

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            fop-dev@xmlgraphics.apache.org fop-dev
            ralph_lachance@compuserve.com Ralph LaChance
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment