jeremias    2003/01/08 05:58:25

  Modified:    src/org/apache/fop/render/awt AWTFontMetrics.java
                        FontMetricsMapper.java FontSetup.java
  Log:
  Adjustments for the font refactoring
  Lots of Javadocs
  Fixed Checkstyle errors
  
  Revision  Changes    Path
  1.5       +27 -27    xml-fop/src/org/apache/fop/render/awt/AWTFontMetrics.java
  
  Index: AWTFontMetrics.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/awt/AWTFontMetrics.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AWTFontMetrics.java       9 Nov 2001 11:32:41 -0000       1.4
  +++ AWTFontMetrics.java       8 Jan 2003 13:58:25 -0000       1.5
  @@ -1,32 +1,22 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
   
   package org.apache.fop.render.awt;
   
  -// FOP
  -import org.apache.fop.layout.FontInfo;
  -import org.apache.fop.layout.FontDescriptor;
  -import org.apache.fop.layout.FontState;
  -
   // Java
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import java.awt.Component;
   import java.awt.Font;
  -import java.awt.Graphics;
   import java.awt.Graphics2D;
   import java.awt.geom.Rectangle2D;
   import java.awt.FontMetrics;
  -import java.awt.font.FontRenderContext;
   import java.awt.font.TextLayout;
   
   /**
    * This is a FontMetrics to be used  for AWT  rendering.
  - * It  instanciates a font, depening on famil and style
  + * It  instanciates a font, depening on family and style
    * values. The java.awt.FontMetrics for this font is then
    * created to be used for the actual measurement.
    * Since layout is word by word and since it is expected that
  @@ -89,13 +79,12 @@
       /**
        * Temp graphics object needed to get the font metrics
        */
  -    Graphics2D graphics;
  +    private Graphics2D graphics;
   
       /**
        * Constructs a new Font-metrics.
  -     * @param parent  an temp graphics object - this is needed  so
  -     * that we can get an instance of
  -     * java.awt.FontMetrics
  +     * @param graphics a temp graphics object - this is needed  so
  +     * that we can get an instance of java.awt.FontMetrics
        */
       public AWTFontMetrics(Graphics2D graphics) {
           this.graphics = graphics;
  @@ -104,15 +93,16 @@
       /**
        * Determines the font ascent of the Font described by this
        * FontMetrics object
  -     * @param family font family (jave name) to use
  -     * @param style font style (jave def.) to use
  +     * @param family font family (java name) to use
  +     * @param style font style (java def.) to use
  +     * @param size font size
        * @return ascent in milliponts
        */
       public int getAscender(String family, int style, int size) {
           setFont(family, style, size);
           // return (int)(FONT_FACTOR * fmt.getAscent());
   
  -        // workaround for sun bug on FontMetric.getAscent()
  +        // workaround for sun bug on FontMetrics.getAscent()
           // http://developer.java.sun.com/developer/bugParade/bugs/4399887.html
           int realAscent = fmt.getAscent()
                            - (fmt.getDescent() + fmt.getLeading());
  @@ -122,6 +112,10 @@
   
       /**
        * The size of a capital letter measured from the font's baseline
  +     * @param family font family
  +     * @param style font style
  +     * @param size font size
  +     * @return capital height in millipoints
        */
       public int getCapHeight(String family, int style, int size) {
           // currently just gets Ascent value but maybe should use
  @@ -134,6 +128,7 @@
        * FontMetrics object
        * @param family font family (jave name) to use
        * @param style font style (jave def.) to use
  +     * @param size font size
        * @return descent in milliponts
        */
       public int getDescender(String family, int style, int size) {
  @@ -146,6 +141,7 @@
        * FontMetrics object
        * @param family font family (jave name) to use
        * @param style font style (jave def.) to use
  +     * @param size font size
        * @return font height in milliponts
        */
       public int getXHeight(String family, int style, int size) {
  @@ -159,7 +155,8 @@
        * @param  i the character for which to get the width
        * @param family font family (jave name) to use
        * @param style font style (jave def.) to use
  -     * @param size the of the font
  +     * @param size font size
  +     * @return character width in millipoints
        */
       public int width(int i, String family, int style, int size) {
           int w;
  @@ -167,10 +164,11 @@
           // the output seems to look a little better if the
           // space is rendered larger than given by
           // the FontMetrics object
  -        if (i <= 32)
  +        if (i <= 32) {
               w = (int)(1.4 * fmt.charWidth(i) * FONT_FACTOR);
  -        else
  +        } else {
               w = (int)(fmt.charWidth(i) * FONT_FACTOR);
  +        }
           return w;
       }
   
  @@ -179,6 +177,8 @@
        * characters
        * @param family font family (jave name) to use
        * @param style font style (jave def.) to use
  +     * @param size font size
  +     * @return array of character widths in millipoints
        */
       public int[] getWidths(String family, int style, int size) {
           int i;
  @@ -199,6 +199,7 @@
        * whether it is a new one
        * @param family font family (jave name) to use
        * @param style font style (jave def.) to use
  +     * @param size font size
        * @return true if the font was changed, false otherwise
        */
       private boolean setFont(String family, int style, int size) {
  @@ -212,12 +213,13 @@
               fmt = graphics.getFontMetrics(f1);
               changed = true;
           } else {
  -            if ((this.style != style) ||!this.family.equals(family)
  +            if ((this.style != style) || !this.family.equals(family)
                       || this.size != s) {
                   if (family.equals(this.family)) {
                       f1 = f1.deriveFont(style, (float)s);
  -                } else
  +                } else {
                       f1 = new Font(family, style, s);
  +                }
                   fmt = graphics.getFontMetrics(f1);
                   changed = true;
               }
  @@ -249,8 +251,6 @@
        * @return font with the desired characeristics.
        */
       public java.awt.Font getFont(String family, int style, int size) {
  -        Font f;
  -
           setFont(family, style, size);
           return f1;
           /*
  
  
  
  1.6       +53 -43    xml-fop/src/org/apache/fop/render/awt/FontMetricsMapper.java
  
  Index: FontMetricsMapper.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/awt/FontMetricsMapper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FontMetricsMapper.java    25 Oct 2002 09:29:47 -0000      1.5
  +++ FontMetricsMapper.java    8 Jan 2003 13:58:25 -0000       1.6
  @@ -1,33 +1,30 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
   
   package org.apache.fop.render.awt;
   
  -// FOP
  -import org.apache.fop.layout.FontInfo;
  -import org.apache.fop.layout.FontDescriptor;
  -import org.apache.fop.layout.FontState;
  -
   // Java
  -import java.util.Enumeration;
  -import java.util.Hashtable;
   import java.awt.Graphics2D;
  -import java.awt.Font;
  +import java.util.Map;
  +
  +// FOP
  +import org.apache.fop.fonts.FontMetrics;
  +import org.apache.fop.fonts.FontType;
   
   
   /**
  - * This class implements org.apache.fop.layout.FontMetric and
  + * This class implements org.apache.fop.layout.FontMetrics and
    * is added to the hash table in FontInfo. It  deferes the
    * actual calculation of the metrics to
    * AWTFontMetrics.  It only keeps the java name and
    * style as member varibles
    */
   
  -public class FontMetricsMapper implements org.apache.fop.layout.FontMetric {
  +public class FontMetricsMapper implements FontMetrics {
   
       /**
        * The first and last non space-character
  @@ -57,85 +54,98 @@
        * Constructs a new Font-metrics.
        * @param family the family name of the font (java value)
        * @param style the java type style value of the font
  -     * @param parent  an AWT component - this is needed  so
  -     * that we can get an instance of
  -     * java.awt.FontMetrics
  +     * @param graphics a Graphics2D object - this is needed  so
  +     * that we can get an instance of java.awt.FontMetrics
        */
       public FontMetricsMapper(String family, int style, Graphics2D graphics) {
           this.family = family;
           this.style = style;
  -        if (metric == null)
  +        if (metric == null) {
               metric = new AWTFontMetrics(graphics);
  +        }
       }
   
       /**
  -     * Determines the font ascent of the Font described by this
  -     * FontMetrics object
  -     * @return ascent in milliponts
  +     * @see org.apache.fop.layout.FontMetrics#getFontName()
  +     */
  +    public String getFontName() {
  +        return family;
  +    }
  +
  +    /**
  +     * @see org.apache.fop.layout.FontMetrics#getFontType()
  +     */
  +    public FontType getFontType() {
  +        return FontType.OTHER;
  +    }
  +    
  +    /**
  +     * @see org.apache.fop.layout.FontMetrics#getAscender(int)
        */
       public int getAscender(int size) {
           return metric.getAscender(family, style, size);
       }
   
  -
       /**
  -     * The size of a capital letter measured from the font's baseline
  +     * @see org.apache.fop.layout.FontMetrics#getCapHeight(int)
        */
       public int getCapHeight(int size) {
           return metric.getCapHeight(family, style, size);
       }
   
       /**
  -     * Determines the font descent of the Font described by this
  -     * FontMetrics object
  -     * @return descent in milliponts
  +     * @see org.apache.fop.layout.FontMetrics#getDescender(int)
        */
       public int getDescender(int size) {
           return metric.getDescender(family, style, size);
       }
   
       /**
  -     * Determines the typical font height of this
  -     * FontMetrics object
  -     * @return font height in milliponts
  +     * @see org.apache.fop.layout.FontMetrics#getXHeight(int)
        */
       public int getXHeight(int size) {
           return metric.getXHeight(family, style, size);
       }
   
  -
  -    public int getFirstChar() {
  -        return FIRST_CHAR;
  -    }
  -
  -    public int getLastChar() {
  -        return LAST_CHAR;
  -    }
  -
       /**
  -     * return width (in 1/1000ths of point size) of character at
  -     * code point i.
  +     * @see org.apache.fop.layout.FontMetrics#getWidth(int, int)
        */
  -    public int width(int i, int size) {
  +    public int getWidth(int i, int size) {
           return metric.width(i, family, style, size);
       }
   
   
       /**
  -     * return width (in 1/1000ths of point size) of all character
  +     * @see org.apache.fop.layout.FontMetrics#getWidths()
        */
  -    public int[] getWidths(int size) {
  -        return metric.getWidths(family, style, size);
  +    public int[] getWidths() {
  +        return metric.getWidths(family, style, AWTFontMetrics.FONT_SIZE);
       }
   
       /**
        * Gets a Font instance  of the Font that this
        * FontMetrics describes in the desired size.
  +     * @param size font size
        * @return font with the desired characeristics.
        */
  -    public Font getFont(int size) {
  +    public java.awt.Font getFont(int size) {
           return metric.getFont(family, style, size);
       }
  +
  +    /**
  +     * @see org.apache.fop.layout.FontMetrics#getKerningInfo()
  +     */
  +    public Map getKerningInfo() {
  +        return java.util.Collections.EMPTY_MAP;
  +    }
  +
  +    /**
  +     * @see org.apache.fop.layout.FontMetrics#hasKerningInfo()
  +     */
  +    public boolean hasKerningInfo() {
  +        return false;
  +    }
  +
   
   }
   
  
  
  
  1.6       +8 -13     xml-fop/src/org/apache/fop/render/awt/FontSetup.java
  
  Index: FontSetup.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/render/awt/FontSetup.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FontSetup.java    23 Jul 2002 11:06:51 -0000      1.5
  +++ FontSetup.java    8 Jan 2003 13:58:25 -0000       1.6
  @@ -1,6 +1,6 @@
   /*
    * $Id$
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
  @@ -9,32 +9,27 @@
   
   // FOP
   import org.apache.fop.layout.FontInfo;
  -import org.apache.fop.layout.FontDescriptor;
   
   // Java
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import java.awt.Font;
   import java.awt.Graphics2D;
   
   /**
  - * sets up the AWT fonts. It is similar to
  + * Sets up the AWT fonts. It is similar to
    * org.apache.fop.render.pdf.FontSetup.
    * Assigns the font (with metrics) to internal names like "F1" and
  - * assigns family-style-weight triplets to the fonts
  + * assigns family-style-weight triplets to the fonts.
    */
   public class FontSetup {
   
   
       /**
  -     * sets up the font info object.
  +     * Sets up the font info object.
        *
  -     * adds metrics for basic fonts and useful family-style-weight
  -     * triplets for lookup
  +     * Adds metrics for basic fonts and useful family-style-weight
  +     * triplets for lookup.
        *
        * @param fontInfo the font info object to set up
  -     * @param parent needed, since a live AWT component is needed
  -     * to get a valid java.awt.FontMetrics object
  +     * @param graphics needed for acces to font metrics
        */
       public static void setup(FontInfo fontInfo, Graphics2D graphics) {
           FontMetricsMapper metric;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to