deweese     01/11/29 15:11:02

  Modified:    sources/org/apache/batik/gvt/renderer
                        StrokingTextPainter.java
               sources/org/apache/batik/gvt/text GlyphLayout.java
  Log:
  Fixed Text Anchor on tspan.
  PR: 4809
  
  Revision  Changes    Path
  1.24      +82 -99    
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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- StrokingTextPainter.java  2001/11/15 14:20:58     1.23
  +++ StrokingTextPainter.java  2001/11/29 23:11:02     1.24
  @@ -60,7 +60,7 @@
    * @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator
    *
    * @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
  - * @version $Id: StrokingTextPainter.java,v 1.23 2001/11/15 14:20:58 vhardy Exp $
  + * @version $Id: StrokingTextPainter.java,v 1.24 2001/11/29 23:11:02 deweese Exp $
    */
   public class StrokingTextPainter extends BasicTextPainter {
   
  @@ -160,9 +160,8 @@
   
           // create text runs for each chunk and add them to the list
           textRuns = new ArrayList();
  -        TextChunk chunk;
  +        TextChunk chunk, prevChunk=null;
           int beginChunk = 0;
  -        Point2D lastChunkAdvance = new Point2D.Float(0,0);
           int currentChunk = 0;
           do {
            // Text Chunks contain one or more TextRuns, which they create from
  @@ -174,7 +173,7 @@
                                    chunkCharMaps[currentChunk],
                                    textRuns,
                                    beginChunk, 
  -                                 lastChunkAdvance);
  +                                 prevChunk);
            
               // Adjust according to text-anchor property value
               chunkACIs[currentChunk].first();
  @@ -182,8 +181,8 @@
                   adjustChunkOffsets(textRuns, chunk.advance, 
                                      chunk.begin, chunk.end);
                   beginChunk = chunk.end;
  -                lastChunkAdvance = chunk.advance;
               }
  +            prevChunk = chunk;
               currentChunk++;
            
           } while (chunk != null && currentChunk < chunkACIs.length);
  @@ -265,107 +264,88 @@
                                      int [] charMap,
                                      List textRuns,
                                      int beginChunk,
  -                                   Point2D lastChunkAdvance) {
  +                                   TextChunk prevChunk) {
           int endChunk = beginChunk;
  -        AttributedCharacterIterator runaci;
  -        boolean inChunk = true;
  -        Point2D advance = lastChunkAdvance;
  -        Point2D location = node.getLocation();
           int begin = aci.getIndex();
  -        if (aci.current() != CharacterIterator.DONE) {
  -            int chunkStartIndex = aci.getIndex();
  -
  -            // find out if this chunck is the start or end of a text
  -            // path chunck if it is, then we ignore any previous
  -            // advance
  -            TextPath chunkTextPath = (TextPath) aci.getAttribute
  -                (GVTAttributedCharacterIterator.TextAttribute.TEXTPATH);
  -            TextPath prevChunkTextPath = null;
  -            if (chunkStartIndex > 0) {
  -                aci.setIndex(chunkStartIndex-1);
  -                prevChunkTextPath = (TextPath) aci.getAttribute
  -                    (GVTAttributedCharacterIterator.TextAttribute.TEXTPATH);
  -                aci.setIndex(chunkStartIndex);
  -            }
  -
  -            if (prevChunkTextPath != chunkTextPath) {
  -                advance = new Point2D.Float(0,0);
  -            }
  -
  -            boolean isChunkStart = true;
  -            TextPath prevTextPath = null;
  -            Point2D prevTextPathAdvance = null;
  -            do {
  +        // System.out.println("New Chunk");
  +        if (aci.current() == CharacterIterator.DONE) 
  +            return null;
   
  -                int start = aci.getRunStart(extendedAtts);
  -                int end   = aci.getRunLimit(extendedAtts);
  +        Point2D advance = new Point2D.Float(0,0);
  +        Point2D location;
  +        if (prevChunk == null) {
  +            location = node.getLocation();
  +        } else {
  +            location = new Point2D.Float
  +                ((float)(prevChunk.absLoc.getX()+prevChunk.advance.getX()),
  +                 (float)(prevChunk.absLoc.getY()+prevChunk.advance.getY()));
  +        }
   
  -                runaci = new AttributedCharacterSpanIterator(aci, start, end);
  +        boolean  isChunkStart        = true;
  +        TextPath prevTextPath        = null;
  +        Point2D  prevTextPathAdvance = null;
  +        do {
  +            int start = aci.getRunStart(extendedAtts);
  +            int end   = aci.getRunLimit(extendedAtts);
   
  -                runaci.first();
  +            AttributedCharacterIterator runaci;
  +            runaci = new AttributedCharacterSpanIterator(aci, start, end);
  +            runaci.first();
   
  -                Float runX = (Float) runaci.getAttribute
  -                 (GVTAttributedCharacterIterator.TextAttribute.X);
  +            Float runX = (Float) runaci.getAttribute
  +                (GVTAttributedCharacterIterator.TextAttribute.X);
   
  -                Float runY = (Float) runaci.getAttribute
  -                 (GVTAttributedCharacterIterator.TextAttribute.Y);
  +            Float runY = (Float) runaci.getAttribute
  +                (GVTAttributedCharacterIterator.TextAttribute.Y);
   
  -                TextPath textPath =  (TextPath) runaci.getAttribute
  -                 (GVTAttributedCharacterIterator.TextAttribute.TEXTPATH);
  -             
  -                inChunk = ((isChunkStart) || 
  -                        ((runX == null || runX.isNaN()) &&
  -                         (runY == null || runY.isNaN())));
  +            TextPath textPath =  (TextPath) runaci.getAttribute
  +                (GVTAttributedCharacterIterator.TextAttribute.TEXTPATH);
                
  -                // do additional check for the start/end of a textPath
  -                if (prevTextPath == null && textPath != null && !isChunkStart) {
  -                    inChunk = false;
  -                }
  -
  -                if (inChunk) {
  -                    Point2D offset;
  -                    if (textPath == null) {
  -                        if (prevTextPath != null && prevTextPathAdvance != null) {
  -                            // this text is directly after some text on a path
  -                            offset = new 
Point2D.Float((float)prevTextPathAdvance.getX(),
  -                                                       
(float)prevTextPathAdvance.getY());
  -                        } else {
  -                            offset = new Point2D.Float(
  -                                (float) (location.getX()+advance.getX()),
  -                                (float) (location.getY()+advance.getY()));
  -                        }
  -                    } else {
  -                        // is on a text path so ignore the text node's location
  -                        offset = new Point2D.Float((float)advance.getX(),
  -                                                   (float)advance.getY());
  -                    }
  -                    
  -                    int [] subCharMap = new int[end-start];
  -                    for (int i=0; i<subCharMap.length; i++) {
  -                        subCharMap[i] = charMap[i+start-begin];
  -                    }
  -                    TextSpanLayout layout = getTextLayoutFactory().
  -                        createTextLayout(runaci, subCharMap, 
  -                                         offset, fontRenderContext);
  -                    TextRun run = new TextRun(layout, runaci, isChunkStart);
  -                    textRuns.add(run);
  -                    Point2D layoutAdvance = layout.getAdvance2D();
  -                    advance = new Point2D.Float(
  -                       (float) (advance.getX()+layoutAdvance.getX()),
  -                       (float) (advance.getY()+layoutAdvance.getY()));
  -                    ++endChunk;
  -                    prevTextPath = textPath;
  -                    prevTextPathAdvance = layout.getTextPathAdvance();
  -                    if (aci.setIndex(end) == CharacterIterator.DONE) break;
  +            Point2D offset;
  +            if (textPath == null) {
  +                if ((prevTextPath != null) && 
  +                    (prevTextPathAdvance != null)) {
  +                    // this text is directly after some text on a path
  +                    offset = new Point2D.Float
  +                        ((float)prevTextPathAdvance.getX(),
  +                         (float)prevTextPathAdvance.getY());
                   } else {
  -                    aci.setIndex(start);
  +                    offset = new Point2D.Float(
  +                                               (float) 
(location.getX()+advance.getX()),
  +                                               (float) 
(location.getY()+advance.getY()));
                   }
  -                isChunkStart = false;
  -            } while (inChunk);
  -            return new TextChunk(beginChunk, endChunk, advance);
  -        } else {
  -            return null;
  -        }
  +            } else {
  +                // is on a text path so ignore the text node's location
  +                offset = new Point2D.Float((float)advance.getX(),
  +                                           (float)advance.getY());
  +            }
  +                    
  +            int [] subCharMap = new int[end-start];
  +            for (int i=0; i<subCharMap.length; i++) {
  +                subCharMap[i] = charMap[i+start-begin];
  +            }
  +            TextSpanLayout layout = getTextLayoutFactory().
  +                createTextLayout(runaci, subCharMap, 
  +                                 offset, fontRenderContext);
  +            TextRun run = new TextRun(layout, runaci, isChunkStart);
  +            textRuns.add(run);
  +            Point2D layoutAdvance = layout.getAdvance2D();
  +            if (isChunkStart)
  +                location = layout.getOffset();
  +
  +            // System.out.println("layoutAdv: " + layoutAdvance);
  +
  +            advance = new Point2D.Float(
  +                                        (float) 
(advance.getX()+layoutAdvance.getX()),
  +                                        (float) 
(advance.getY()+layoutAdvance.getY()));
  +            ++endChunk;
  +            prevTextPath = textPath;
  +            prevTextPathAdvance = layout.getTextPathAdvance();
  +            if (aci.setIndex(end) == CharacterIterator.DONE) break;
  +            isChunkStart = false;
  +        } while (true);
  +        // System.out.println("Adv: " + advance);
  +        return new TextChunk(beginChunk, endChunk, location, advance);
       }
   
   
  @@ -579,10 +559,8 @@
                                       Point2D advance,
                                       int beginChunk, 
                                       int endChunk) {
  -
  -        for (int n=beginChunk; n<endChunk; ++n) {
  -            TextRun r = (TextRun) textRuns.get(n);
   
  +        TextRun r = (TextRun) textRuns.get(beginChunk);
               int anchorType = r.getAnchorType();
               float dx = 0f;
               float dy = 0f;
  @@ -601,6 +579,8 @@
                   // leave untouched
               }
   
  +        for (int n=beginChunk; n<endChunk; ++n) {
  +            r = (TextRun) textRuns.get(n);
               TextSpanLayout layout = r.getLayout();
               Point2D        offset = layout.getOffset();
   
  @@ -1373,10 +1353,13 @@
           public int begin;
           public int end;
           public Point2D advance;
  +        public Point2D absLoc;
   
  -        public TextChunk(int begin, int end, Point2D advance) {
  +        public TextChunk(int begin, int end, Point2D absLoc, Point2D advance) {
               this.begin = begin;
               this.end = end;
  +            this.absLoc  = new Point2D.Float((float) absLoc.getX(),
  +                                             (float) absLoc.getY());
               this.advance = new Point2D.Float((float) advance.getX(),
                                                (float) advance.getY());
           }
  
  
  
  1.29      +4 -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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- GlyphLayout.java  2001/11/09 15:32:57     1.28
  +++ GlyphLayout.java  2001/11/29 23:11:02     1.29
  @@ -42,7 +42,7 @@
    * @see org.apache.batik.gvt.text.TextSpanLayout
    *
    * @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
  - * @version $Id: GlyphLayout.java,v 1.28 2001/11/09 15:32:57 deweese Exp $
  + * @version $Id: GlyphLayout.java,v 1.29 2001/11/29 23:11:02 deweese Exp $
    */
   public class GlyphLayout implements TextSpanLayout {
   
  @@ -1227,7 +1227,6 @@
       protected Point2D doSpacing(Float kern,
                                   Float letterSpacing,
                                   Float wordSpacing) {
  -
           boolean autoKern = true;
           boolean doWordSpacing = false;
           boolean doLetterSpacing = false;
  @@ -1516,6 +1515,8 @@
                  GVTAttributedCharacterIterator.TextAttribute.TEXTPATH);
   
           int numGlyphs = gv.getNumGlyphs();
  +        // System.out.println("NumGlyphs: " + numGlyphs);
  +
           float[] gp = new float[numGlyphs*2];
           gp = (float[]) gv.getGlyphPositions(0, numGlyphs, gp).clone();
           float init_x_pos = (float) offset.getX();
  @@ -1742,10 +1743,10 @@
               firstChar = false;
           }
   
  +        offset  = new Point2D.Float(init_x_pos, init_y_pos);
           advance = new Point2D.Float((float) (curr_x_pos - offset.getX()),
                                       (float) (curr_y_pos - offset.getY()));
   
  -        offset = new Point2D.Float(init_x_pos, init_y_pos);
       }
   
   }
  
  
  

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

Reply via email to