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 bi...@apache.org on 2001/02/27 14:05:57 UTC

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

billh       01/02/27 05:05:57

  Modified:    sources/org/apache/batik/gvt/text
                        ConcreteTextLayoutFactory.java
                        GVTAttributedCharacterIterator.java
                        GlyphLayout.java
  Log:
  Changes to GlyphLayout to support new SVG WG definition of textLength
  when lengthAdjust="default" or "spacing".
  
  Revision  Changes    Path
  1.5       +3 -1      xml-batik/sources/org/apache/batik/gvt/text/ConcreteTextLayoutFactory.java
  
  Index: ConcreteTextLayoutFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/ConcreteTextLayoutFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConcreteTextLayoutFactory.java	2001/02/05 11:59:44	1.4
  +++ ConcreteTextLayoutFactory.java	2001/02/27 13:05:57	1.5
  @@ -33,7 +33,7 @@
    *
    * @see org.apache.batik.gvt.text.TextSpanLayout
    * @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
  - * @version $Id: ConcreteTextLayoutFactory.java,v 1.4 2001/02/05 11:59:44 billh Exp $
  + * @version $Id: ConcreteTextLayoutFactory.java,v 1.5 2001/02/27 13:05:57 billh Exp $
    */
   public class ConcreteTextLayoutFactory implements TextLayoutFactory {
   
  @@ -77,6 +77,8 @@
                   GVTAttributedCharacterIterator.TextAttribute.ROTATION);
           glyphPositionKeys.add(
                   GVTAttributedCharacterIterator.TextAttribute.BASELINE_SHIFT);
  +        glyphPositionKeys.add(
  +                GVTAttributedCharacterIterator.TextAttribute.TEXTPATH);
           glyphPositionKeys.retainAll(keys);
           if (glyphPositionKeys.isEmpty()) {
               return new TextLayoutAdapter(new TextLayout(aci, frc), offset, aci);
  
  
  
  1.11      +5 -1      xml-batik/sources/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java
  
  Index: GVTAttributedCharacterIterator.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/GVTAttributedCharacterIterator.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- GVTAttributedCharacterIterator.java	2001/02/05 11:59:44	1.10
  +++ GVTAttributedCharacterIterator.java	2001/02/27 13:05:57	1.11
  @@ -30,7 +30,7 @@
    * SVGAttributedCharacterIterator.TextAttributes.
    *
    * @author <a href="mailto:bill.haneman@ireland.sun.com">Bill Haneman</a>
  - * @version $Id: GVTAttributedCharacterIterator.java,v 1.10 2001/02/05 11:59:44 billh Exp $
  + * @version $Id: GVTAttributedCharacterIterator.java,v 1.11 2001/02/27 13:05:57 billh Exp $
    */
   
   public interface GVTAttributedCharacterIterator extends
  @@ -302,6 +302,10 @@
            */
           public final static TextAttribute WORD_SPACING =
                                             new TextAttribute("WORD_SPACING");
  +
  +        /** Path along which text is to be laid out */
  +        public final static TextAttribute TEXTPATH =
  +                                          new TextAttribute("TEXTPATH");
   
           /** Font variant to be used for this character span.
            * @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator.TextAttribute#SMALL_CAPS
  
  
  
  1.8       +75 -5     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- GlyphLayout.java	2001/02/05 11:59:46	1.7
  +++ GlyphLayout.java	2001/02/27 13:05:57	1.8
  @@ -21,6 +21,7 @@
   import java.awt.geom.Rectangle2D;
   import java.awt.geom.AffineTransform;
   import java.awt.geom.GeneralPath;
  +import java.awt.geom.PathIterator;
   import java.awt.geom.Point2D;
   import java.text.AttributedCharacterIterator;
   import java.text.CharacterIterator;
  @@ -35,7 +36,7 @@
    * @see org.apache.batik.gvt.TextSpanLayout.
    *
    * @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
  - * @version $Id: GlyphLayout.java,v 1.7 2001/02/05 11:59:46 billh Exp $
  + * @version $Id: GlyphLayout.java,v 1.8 2001/02/27 13:05:57 billh Exp $
    */
   public class GlyphLayout implements TextSpanLayout {
   
  @@ -75,6 +76,7 @@
           this.transform = null;
           doExplicitGlyphLayout(false);
           adjustTextSpacing();
  +        doPathLayout();
           computeGlyphLogicalBounds();
       }
   
  @@ -131,6 +133,7 @@
           this.gv.performDefaultLayout();
           doExplicitGlyphLayout(true);
           adjustTextSpacing();
  +        doPathLayout();
           computeGlyphLogicalBounds();
       }
   
  @@ -573,6 +576,69 @@
           return new Font(aci.getAttributes());
       }
   
  +    protected void doPathLayout() {
  +
  +        aci.first();
  +        Shape path =  (Shape) aci.getAttribute(
  +               GVTAttributedCharacterIterator.TextAttribute.TEXTPATH);
  +        if (path != null) {
  +            System.out.println("Performing text layout");
  +            PathIterator pi = path.getPathIterator(new AffineTransform());
  +            int numGlyphs = gv.getNumGlyphs();
  +            double coords[] = new double[6];
  +            double tx = 0d;
  +            double dx = 0d;
  +            double dy = 0d;
  +            pi.currentSegment(coords);
  +            double x = coords[0];
  +            double y = coords[1];
  +            double d;
  +            for (int i=0; i<numGlyphs; ++i) {
  +                // XXX: TODO: generalize to vertical
  +                d = glyphPositions[i].getX();
  +                if (pi.isDone()) System.out.println("Done already??? "+i+"; tx="+tx);
  +                while (!pi.isDone()) {
  +                    switch(pi.currentSegment(coords)) {
  +                    case PathIterator.SEG_MOVETO:
  +                    case PathIterator.SEG_LINETO:
  +                        System.out.println("SEG MOVE/LINE "+i);
  +                        break;
  +                    case PathIterator.SEG_QUADTO:
  +                        System.out.println("QUAD "+i);
  +                        break;
  +                    case PathIterator.SEG_CUBICTO:
  +                        System.out.println("CUBIC "+i);
  +                       break;
  +                    default:
  +                        ;
  +                    }
  +                    dx = coords[0] - x;
  +                    dy = coords[1] - y;
  +                    if (dx!=0d || dy!=0d) tx += Math.sqrt(dx*dx+dy*dy);
  +                    if (tx < d) {
  +                        x = coords[0];
  +                        y = coords[1];
  +                        pi.next();
  +                    } else {
  +                        break;
  +                    }
  +                }
  +                if (tx != 0d) {
  +                    System.out.println("d="+d+"; tx="+tx+"; dx="+dx+"; x="+x);
  +                    x += (d/tx)*(dx);
  +                    y += (d/tx)*(dy);
  +                    tx -= d; // keep remainder...
  +                }
  +                glyphPositions[i] = new Point2D.Float(
  +                                (float) x,
  +                                (float) (y+glyphPositions[i].getY()));
  +                gv.setGlyphPosition(i, glyphPositions[i]);
  +                System.out.println("Placed glyph "+i+" at "+
  +                                   new Point2D.Float((float) x, (float) y));
  +            }
  +        }
  +    }
  +
       protected void adjustTextSpacing() {
   
           aci.first();
  @@ -644,7 +710,11 @@
               float xscale = 1f;
               float yscale = 1f;
               if (!isVertical()) {
  -                xscale = length.floatValue()/(float) gv.getVisualBounds().getWidth();
  +                float lastCharWidth = 
  +                    (float) (gv.getGlyphMetrics(
  +                        gv.getNumGlyphs()-1).getBounds2D().getWidth());
  +                xscale = (length.floatValue()-lastCharWidth)/
  +                         (float) (gv.getVisualBounds().getWidth()-lastCharWidth);
               } else {
                   yscale = length.floatValue()/(float) gv.getVisualBounds().getHeight();
               }
  @@ -861,7 +931,7 @@
                   curr_y_pos += gp[i*2 + 1]-gp[i*2 - 1];
               }
   
  -	    // ox and oy are origin adjustments for each glyph,
  +            // ox and oy are origin adjustments for each glyph,
               // computed on the basis of baseline-shifts, etc.
               float ox = 0f;
               float oy = 0f;
  @@ -870,7 +940,7 @@
                   GVTAttributedCharacterIterator.TextAttribute.BASELINE_SHIFT);
               if (baseline != null) {
                   if (baseline instanceof Integer) {
  -    	            if (baseline==TextAttribute.SUPERSCRIPT_SUPER) {
  +                    if (baseline==TextAttribute.SUPERSCRIPT_SUPER) {
                           baselineAdjust = baselineAscent*0.5f;
                       } else if (baseline==TextAttribute.SUPERSCRIPT_SUB) {
                           baselineAdjust = -baselineAscent*0.5f;
  @@ -887,7 +957,7 @@
               glyphPositions[i] = new Point2D.Float(curr_x_pos+ox,curr_y_pos+oy);
               gv.setGlyphPosition(i, glyphPositions[i]);
               if (rotation != null && !rotation.isNaN()) {
  -                gv.setGlyphTransform(i, 
  +                gv.setGlyphTransform(i,
                       AffineTransform.getRotateInstance(
                           (double)rotation.floatValue()));
               }