You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by vh...@apache.org on 2001/05/16 03:32:13 UTC

cvs commit: xml-batik/sources/org/apache/batik/gvt/text GlyphLayout.java

vhardy      01/05/15 18:32:13

  Modified:    sources/org/apache/batik/bridge SVGBridgeExtension.java
               sources/org/apache/batik/gvt/font AWTGVTGlyphVector.java
                        FontFamilyResolver.java
               sources/org/apache/batik/gvt/renderer
                        StrokingTextPainter.java
               sources/org/apache/batik/gvt/text GlyphLayout.java
  Log:
  Fixed SVG Font issues.
  
  Revision  Changes    Path
  1.2       +2 -0      xml-batik/sources/org/apache/batik/bridge/SVGBridgeExtension.java
  
  Index: SVGBridgeExtension.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGBridgeExtension.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SVGBridgeExtension.java	2001/05/03 22:10:42	1.1
  +++ SVGBridgeExtension.java	2001/05/16 01:31:55	1.2
  @@ -168,5 +168,7 @@
   
           ctx.putBridge(new SVGAltGlyphElementBridge());
   
  +        ctx.putBridge(new SVGTextPathElementBridge());
  +
       }
   }
  
  
  
  1.4       +18 -7     xml-batik/sources/org/apache/batik/gvt/font/AWTGVTGlyphVector.java
  
  Index: AWTGVTGlyphVector.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/font/AWTGVTGlyphVector.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AWTGVTGlyphVector.java	2001/05/14 16:45:46	1.3
  +++ AWTGVTGlyphVector.java	2001/05/16 01:31:58	1.4
  @@ -29,7 +29,7 @@
    * This is a wrapper class for a java.awt.font.GlyphVector instance.
    *
    * @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
  - * @version $Id: AWTGVTGlyphVector.java,v 1.3 2001/05/14 16:45:46 tkormann Exp $
  + * @version $Id: AWTGVTGlyphVector.java,v 1.4 2001/05/16 01:31:58 vhardy Exp $
    */
   public final class AWTGVTGlyphVector implements GVTGlyphVector {
   
  @@ -48,6 +48,7 @@
       private Shape[] glyphLogicalBounds;
       private boolean[] glyphVisible;
       private GeneralPath outline;
  +    private Rectangle2D logicalBounds;
   
       /**
        * Creates and new AWTGVTGlyphVector from the specified GlyphVector
  @@ -58,6 +59,7 @@
           gvtFont = font;
           int numGlyphs = glyphVector.getNumGlyphs();
           outline = null;
  +        logicalBounds = null;
           glyphTransforms = new AffineTransform[numGlyphs];
           defaultGlyphPositions = new Point2D.Float[numGlyphs];
           glyphOutlines = new Shape[numGlyphs];
  @@ -246,12 +248,17 @@
        *  Returns the logical bounds of this GlyphVector.
        */
       public Rectangle2D getLogicalBounds() {
  -        Shape outline = getOutline();
  -        Rectangle2D bounds = outline.getBounds2D();
  -        Point2D firstPos = getGlyphPosition(0);
  -        bounds.setRect(bounds.getX()-firstPos.getX(), bounds.getY()-firstPos.getY(),
  -                            bounds.getWidth(), bounds.getHeight());
  -        return bounds;
  +        if (logicalBounds == null) {
  +            GeneralPath logicalBoundsPath = new GeneralPath();
  +            for (int i = 0; i < getNumGlyphs(); i++) {
  +                Shape glyphLogicalBounds = getGlyphLogicalBounds(i);
  +                if (glyphLogicalBounds != null) {
  +                    logicalBoundsPath.append(glyphLogicalBounds, false);
  +                }
  +            }
  +            logicalBounds = logicalBoundsPath.getBounds2D();
  +        }
  +        return logicalBounds;
       }
   
       /**
  @@ -305,6 +312,7 @@
       public void performDefaultLayout() {
           awtGlyphVector.performDefaultLayout();
           outline = null;
  +        logicalBounds = null;
           for (int i = 0; i < getNumGlyphs(); i++) {
               defaultGlyphPositions[i] = getGlyphPosition(i);
               glyphTransforms[i] = null;
  @@ -320,6 +328,7 @@
       public void setGlyphPosition(int glyphIndex, Point2D newPos) {
           awtGlyphVector.setGlyphPosition(glyphIndex, newPos);
           outline = null;
  +        logicalBounds = null;
           glyphVisualBounds[glyphIndex] = null;
           glyphLogicalBounds[glyphIndex] = null;
           glyphOutlines[glyphIndex] = null;
  @@ -331,6 +340,7 @@
       public void setGlyphTransform(int glyphIndex, AffineTransform newTX) {
           glyphTransforms[glyphIndex] = newTX;
           outline = null;
  +        logicalBounds = null;
           glyphVisualBounds[glyphIndex] = null;
           glyphLogicalBounds[glyphIndex] = null;
           glyphOutlines[glyphIndex] = null;
  @@ -342,6 +352,7 @@
       public void setGlyphVisible(int glyphIndex, boolean visible) {
           glyphVisible[glyphIndex] = visible;
           outline = null;
  +        logicalBounds = null;
           glyphVisualBounds[glyphIndex] = null;
           glyphLogicalBounds[glyphIndex] = null;
           glyphOutlines[glyphIndex] = null;
  
  
  
  1.2       +29 -1     xml-batik/sources/org/apache/batik/gvt/font/FontFamilyResolver.java
  
  Index: FontFamilyResolver.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/font/FontFamilyResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FontFamilyResolver.java	2001/04/29 08:22:54	1.1
  +++ FontFamilyResolver.java	2001/05/16 01:32:00	1.2
  @@ -10,14 +10,17 @@
   
   import java.util.Map;
   import java.util.HashMap;
  +import java.util.Collection;
   import java.awt.GraphicsEnvironment;
   import java.util.StringTokenizer;
  +import java.util.Iterator;
  +import java.util.Vector;
   
   /**
    * The is a utility class that is used for resolving UnresolvedFontFamilies.
    *
    * @author <a href="mailto:bella.robinson@cmis.csiro.au">Bella Robinson</a>
  - * @version $Id: FontFamilyResolver.java,v 1.1 2001/04/29 08:22:54 dino Exp $
  + * @version $Id: FontFamilyResolver.java,v 1.2 2001/05/16 01:32:00 vhardy Exp $
    */
   public class FontFamilyResolver {
   
  @@ -33,6 +36,9 @@
        */
       protected final static Map fonts = new HashMap(11);
   
  +    protected final static Vector awtFontFamilies = new Vector();
  +    protected final static Vector awtFonts = new Vector();
  +
       /**
        * This sets up the list of available fonts.
        */
  @@ -65,6 +71,17 @@
               }
               fonts.put(fontNameWithoutSpaces, fontNames[i]);
           }
  +
  +        Collection fontValues = fonts.values();
  +        Iterator iter = fontValues.iterator();
  +        while(iter.hasNext()) {
  +            String fontFamily = (String)iter.next();
  +            AWTFontFamily awtFontFamily = new AWTFontFamily(fontFamily);
  +            awtFontFamilies.add(awtFontFamily);
  +            AWTGVTFont font = new AWTGVTFont(fontFamily, 0, 12);
  +            awtFonts.add(font);
  +        }
  +
       }
   
       /**
  @@ -106,6 +123,17 @@
           }
   
           return resolvedFontFamily;
  +    }
  +
  +    public static GVTFontFamily getFamilyThatCanDisplay(char c) {
  +        for (int i = 0; i < awtFontFamilies.size(); i++) {
  +            AWTFontFamily fontFamily = (AWTFontFamily)awtFontFamilies.get(i);
  +            AWTGVTFont font = (AWTGVTFont)awtFonts.get(i);
  +            if (font.canDisplay(c)) {
  +                return fontFamily;
  +            }
  +        }
  +        return null;
       }
   
   }
  
  
  
  1.6       +12 -8     xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java
  
  Index: StrokingTextPainter.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StrokingTextPainter.java	2001/05/14 16:46:31	1.5
  +++ StrokingTextPainter.java	2001/05/16 01:32:04	1.6
  @@ -50,7 +50,7 @@
    * @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator
    *
    * @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
  - * @version $Id: StrokingTextPainter.java,v 1.5 2001/05/14 16:46:31 tkormann Exp $
  + * @version $Id: StrokingTextPainter.java,v 1.6 2001/05/16 01:32:04 vhardy Exp $
    */
   public class StrokingTextPainter extends BasicTextPainter {
   
  @@ -275,7 +275,7 @@
               }
   
               // create a list of fonts of the correct size
  -            Float fontSizeFloat = (Float)as.getIterator().getAttribute(TextAttribute.SIZE);
  +            Float fontSizeFloat = (Float)runaci.getAttributes().get(TextAttribute.SIZE);
               float fontSize = 12;
               if (fontSizeFloat != null) {
                   fontSize = fontSizeFloat.floatValue();
  @@ -337,8 +337,16 @@
               // assign the first font to any chars haven't alreay been assigned
               for (int i = 0; i < runaciLength; i++) {
                   if (!fontAssigned[i]) {
  -                    as.addAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT,
  -                                   gvtFonts.get(0), start+i, start+i+1);
  +                    GVTFontFamily fontFamily = FontFamilyResolver.getFamilyThatCanDisplay(runaci.setIndex(start+i));
  +                    if (fontFamily != null) {
  +                        GVTFont font = fontFamily.deriveFont(fontSize, runaci);
  +                        as.addAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT,
  +                                   font, start+i, start+i+1);
  +                    } else {
  +                        // no available fonts can display it, just use the first font in the list
  +                        as.addAttribute(GVTAttributedCharacterIterator.TextAttribute.GVT_FONT,
  +                                        gvtFonts.get(0), start+i, start+i+1);
  +                    }
                   }
               }
               if (aci.setIndex(end) == aci.DONE) {
  @@ -1023,7 +1031,3 @@
   
       }
   }
  -
  -
  -
  -
  
  
  
  1.12      +3 -3      xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java
  
  Index: GlyphLayout.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- GlyphLayout.java	2001/05/14 16:47:04	1.11
  +++ GlyphLayout.java	2001/05/16 01:32:09	1.12
  @@ -46,7 +46,7 @@
    * @see org.apache.batik.gvt.TextSpanLayout.
    *
    * @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
  - * @version $Id: GlyphLayout.java,v 1.11 2001/05/14 16:47:04 tkormann Exp $
  + * @version $Id: GlyphLayout.java,v 1.12 2001/05/16 01:32:09 vhardy Exp $
    */
   public class GlyphLayout implements TextSpanLayout {
   
  @@ -581,7 +581,7 @@
   
           // need to move the underline a bit lower,
           // not sure if this is correct behaviour or not
  -        y += underlineThickness;
  +        y += underlineThickness*1.5;
   
           Stroke underlineStroke =
               new BasicStroke(underlineThickness);
  @@ -940,7 +940,7 @@
           int i=0;
           float baselineAscent = isVertical() ?
                                  (float) gv.getLogicalBounds().getWidth() :
  -                               (float) gv.getLogicalBounds().getHeight();
  +                              (metrics.getAscent() + Math.abs(metrics.getDescent()));
   
           int numGlyphs = gv.getNumGlyphs();
           float[] gp = new float[numGlyphs*2];
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org