deweese 02/05/02 12:05:44
Modified: samples/tests/spec/text textAnchor2.svg
sources/org/apache/batik/gvt/renderer
StrokingTextPainter.java
Added: samples/tests/spec/text textOnPath2.svg
test-references/org/apache/batik/transcoder/image .cvsignore
Log:
1) New text on a path test that checks embedded test on a path with
startOffsets and text-anchors with multiple trailing tspans.
2) Adjusted textAnchor2.svg for new textChunking alg.
3) _Greatly_ simplified final layout code for text (same results)
Revision Changes Path
1.2 +31 -27 xml-batik/samples/tests/spec/text/textAnchor2.svg
Index: textAnchor2.svg
===================================================================
RCS file: /home/cvs/xml-batik/samples/tests/spec/text/textAnchor2.svg,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- textAnchor2.svg 6 Dec 2001 08:13:47 -0000 1.1
+++ textAnchor2.svg 2 May 2002 19:05:44 -0000 1.2
@@ -14,7 +14,7 @@
<!-- Tests text-anchor on multiple text chunks on single tspan element -->
<!-- -->
<!-- @author [EMAIL PROTECTED] -->
-<!-- @version $Id: textAnchor2.svg,v 1.1 2001/12/06 08:13:47 vhardy Exp $ -->
+<!-- @version $Id: textAnchor2.svg,v 1.2 2002/05/02 19:05:44 deweese Exp $ -->
<!-- ====================================================================== -->
<?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?>
@@ -34,20 +34,24 @@
<rect x="75" y="150" width="300" height="40" style="fill:#eee; stroke:black" />
<text x="90" y="64" style="fill:white;font-size:14">x attribute define new
text chunks</text>
<g style="stroke:crimson; fill:none">
- <line x1="150" y1="70" x2="150" y2="190" />
- <line x1="190" y1="70" x2="190" y2="190" />
- <line x1="230" y1="70" x2="230" y2="190" />
- <line x1="270" y1="70" x2="270" y2="190" />
- <line x1="310" y1="70" x2="310" y2="190" />
+ <line x1="145" y1="70" x2="145" y2="190" />
+ <line x1="185" y1="70" x2="185" y2="190" />
+ <line x1="225" y1="70" x2="225" y2="190" />
+ <line x1="265" y1="70" x2="265" y2="190" />
+ <line x1="305" y1="70" x2="305" y2="190" />
</g>
</g>
-<g transform="translate(0 150)">
- <rect x="75" y="50" width="300" height="20" style="fill:black; stroke:black"
/>
- <rect x="75" y="70" width="300" height="40" style="fill:#eee; stroke:black" />
- <rect x="75" y="110" width="300" height="40" style="fill:white; stroke:black"
/>
- <rect x="75" y="150" width="300" height="40" style="fill:#eee; stroke:black" />
- <text x="90" y="64" style="fill:white;font-size:14">y attribute define new
text chunks</text>
+<g transform="translate(0 150)" stroke="black" >
+ <rect x="75" y="50" width="300" height="20" style="fill:black" />
+ <rect x="75" y="70" width="300" height="40" style="fill:#eee" />
+ <rect x="75" y="110" width="300" height="40" style="fill:white" />
+ <rect x="75" y="150" width="300" height="40" style="fill:#eee" />
+ <text x="90" y="64" style="fill:white;stroke:none;font-size:14"
+ >y attribute does not define new text chunk</text>
+ <g style="stroke:crimson; fill:none">
+ <line x1="225" y1="70" x2="225" y2="190" />
+ </g>
</g>
<g transform="translate(0 300)">
@@ -57,11 +61,11 @@
<rect x="75" y="150" width="300" height="40" style="fill:#eee; stroke:black" />
<text x="90" y="64" style="fill:white;font-size:14">x & y attributes
define new text chunks</text>
<g style="stroke:crimson; fill:none">
- <line x1="150" y1="70" x2="150" y2="190" />
- <line x1="190" y1="70" x2="190" y2="190" />
- <line x1="230" y1="70" x2="230" y2="190" />
- <line x1="270" y1="70" x2="270" y2="190" />
- <line x1="310" y1="70" x2="310" y2="190" />
+ <line x1="145" y1="70" x2="145" y2="190" />
+ <line x1="185" y1="70" x2="185" y2="190" />
+ <line x1="225" y1="70" x2="225" y2="190" />
+ <line x1="265" y1="70" x2="265" y2="190" />
+ <line x1="305" y1="70" x2="305" y2="190" />
</g>
</g>
@@ -69,23 +73,23 @@
<!-- x attribute defines new text chunks -->
<!-- ################################################################# -->
-<text transform="translate(150 94)"><tspan x="0 40 80 120 160"
style="text-anchor:start">Batik</tspan></text>
-<text transform="translate(150 134)"><tspan x="0 40 80 120 160"
style="text-anchor:middle">Batik</tspan></text>
-<text transform="translate(150 174)"><tspan x="0 40 80 120 160"
style="text-anchor:end">Batik</tspan></text>
+<text transform="translate(145 94)"><tspan x="0 40 80 120 160"
style="text-anchor:start">Batik</tspan></text>
+<text transform="translate(145 134)"><tspan x="0 40 80 120 160"
style="text-anchor:middle">Batik</tspan></text>
+<text transform="translate(145 174)"><tspan x="0 40 80 120 160"
style="text-anchor:end">Batik</tspan></text>
<!-- ################################################################# -->
-<!-- y attribute defines new text chunks -->
+<!-- y attribute does not define new text chunk -->
<!-- ################################################################# -->
-<text transform="translate(210 240)"><tspan y="0 10 0 10 0"
style="text-anchor:start">Batik</tspan></text>
-<text transform="translate(210 280)"><tspan y="0 10 0 10 0"
style="text-anchor:middle">Batik</tspan></text>
-<text transform="translate(210 320)"><tspan y="0 10 0 10 0"
style="text-anchor:end">Batik</tspan></text>
+<text transform="translate(225 240)"><tspan y="0 10 0 10 0"
style="text-anchor:start">Batik</tspan></text>
+<text transform="translate(225 280)"><tspan y="0 10 0 10 0"
style="text-anchor:middle">Batik</tspan></text>
+<text transform="translate(225 320)"><tspan y="0 10 0 10 0"
style="text-anchor:end">Batik</tspan></text>
<!-- ################################################################# -->
<!-- both x and y attributes define new text chunks -->
<!-- ################################################################# -->
-<text transform="translate(150 390)"><tspan x="0 40 80 120 160" y="0 10 0 10 0"
style="text-anchor:start">Batik</tspan></text>
-<text transform="translate(150 430)"><tspan x="0 40 80 120 160" y="0 10 0 10 0"
style="text-anchor:middle">Batik</tspan></text>
-<text transform="translate(150 470)"><tspan x="0 40 80 120 160" y="0 10 0 10 0"
style="text-anchor:end">Batik</tspan></text>
+<text transform="translate(145 390)"><tspan x="0 40 80 120 160" y="0 10 0 10 0"
style="text-anchor:start">Batik</tspan></text>
+<text transform="translate(145 430)"><tspan x="0 40 80 120 160" y="0 10 0 10 0"
style="text-anchor:middle">Batik</tspan></text>
+<text transform="translate(145 470)"><tspan x="0 40 80 120 160" y="0 10 0 10 0"
style="text-anchor:end">Batik</tspan></text>
</g>
1.1 xml-batik/samples/tests/spec/text/textOnPath2.svg
Index: textOnPath2.svg
===================================================================
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!-- ====================================================================== -->
<!-- Copyright (C) The Apache Software Foundation. All rights reserved. -->
<!-- -->
<!-- This software is published under the terms of the Apache Software -->
<!-- License version 1.1, a copy of which has been included with this -->
<!-- distribution in the LICENSE file. -->
<!-- ====================================================================== -->
<?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
id="body" width="450" height="500" viewBox="0 0 450 500">
<title>Text on Path with trailing <tspan></title>
<text class="title" x="50%" y="40"
>Text on Path with trailing <tspan></text>
<rect fill="black" stroke="black" x="30" y="50" width="390" height="20"/>
<rect fill="white" stroke="black" x="30" y="70" width="390" height="120"/>
<text x="40" y="64" fill="white" font-size="14"
>Text with embedded textPath and multiple trailing tspan</text>
<rect fill="black" stroke="black" x="30" y="195" width="390" height="20"/>
<rect fill="white" stroke="black" x="30" y="215" width="390" height="120"/>
<text x="40" y="209" fill="white" font-size="14"
>textPath has startOffset="10%"</text>
<rect fill="black" stroke="black" x="30" y="340" width="390" height="20"/>
<rect fill="white" stroke="black" x="30" y="360" width="390" height="120"/>
<text x="40" y="354" fill="white" font-size="14"
>textPath with startOffset and text-anchor</text>
<g transform="translate(40, 185)" >
<path id="path" style="fill:none; stroke:blue;"
d="M100 0 c0 -125 140 -125 140 0"/>
<text x="10" y="0" fill="black">This is simple<textPath
fill="crimson" xlink:href="#path" startOffset="0%"
>text on a path<tspan fill="orange" dy="-10"
>with nested</tspan><tspan fill="green" dy="10"
> tspan</tspan></textPath
> xxx <tspan fill="blue" dx="10"
>all with </tspan> different links.</text>
</g>
<g transform="translate(40, 330)" >
<path id="path" style="fill:none; stroke:blue;"
d="M100 0 c0 -125 140 -125 140 0"/>
<text x="10" y="0" fill="black">This is simple<textPath
fill="crimson" xlink:href="#path" startOffset="10%"
>text on a path<tspan fill="orange" dy="-10"
>with nested</tspan><tspan fill="green" dy="10"
> tspan</tspan></textPath
> xxx <tspan fill="blue" dx="10"
>all with </tspan> different links.</text>
</g>
<g transform="translate(40, 475)" >
<path id="path" style="fill:none; stroke:blue;"
d="M100 0 c0 -125 140 -125 140 0"/>
<text x="10" y="0" fill="black">This is simple<textPath
fill="crimson" xlink:href="#path"
startOffset="75%" text-anchor="middle"
>text on a path<tspan fill="orange" dy="-10"
>with nested</tspan><tspan fill="green" dy="10"
> tspan</tspan></textPath
> xxx <tspan fill="blue" dx="10"
>all with </tspan> different links.</text>
</g>
</svg>
1.35 +42 -78
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.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- StrokingTextPainter.java 30 Apr 2002 19:08:48 -0000 1.34
+++ StrokingTextPainter.java 2 May 2002 19:05:44 -0000 1.35
@@ -61,7 +61,7 @@
* @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator
*
* @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
- * @version $Id: StrokingTextPainter.java,v 1.34 2002/04/30 19:08:48 deweese Exp $
+ * @version $Id: StrokingTextPainter.java,v 1.35 2002/05/02 19:05:44 deweese Exp $
*/
public class StrokingTextPainter extends BasicTextPainter {
@@ -603,8 +603,11 @@
if (aci.current() == CharacterIterator.DONE)
return null;
- Point2D advance = new Point2D.Float(0,0);
- boolean isChunkStart = true;
+ // we now lay all aci's out at 0,0 then move them
+ // when we adjust the chunk offsets.
+ Point2D.Float offset = new Point2D.Float(0,0);
+ Point2D.Float advance = new Point2D.Float(0,0);
+ boolean isChunkStart = true;
TextSpanLayout layout = null;
do {
int start = aci.getRunStart(extendedAtts);
@@ -618,10 +621,6 @@
subCharMap[i] = charMap[i+start-begin];
}
- Point2D.Float offset;
- offset = new Point2D.Float((float)advance.getX(),
- (float)advance.getY());
-
layout = getTextLayoutFactory().createTextLayout
(runaci, subCharMap, offset, fontRenderContext);
textRuns.add(new TextRun(layout, runaci, isChunkStart));
@@ -630,9 +629,9 @@
Point2D layoutAdvance = layout.getAdvance2D();
// System.out.println("layoutAdv: " + layoutAdvance);
- advance = new Point2D.Float
- ((float) (advance.getX()+layoutAdvance.getX()),
- (float) (advance.getY()+layoutAdvance.getY()));
+ advance.x += (float)layoutAdvance.getX();
+ advance.y += (float)layoutAdvance.getY();
+
++endChunk;
if (aci.setIndex(end) == CharacterIterator.DONE) break;
isChunkStart = false;
@@ -766,42 +765,38 @@
Float runY = (Float) runaci.getAttribute(YPOS);
TextPath textPath = (TextPath) runaci.getAttribute(TEXTPATH);
+ // The point that the next peice of normal text should be
+ // layed out from, only used for normal text not text on a path.
float absX = (float)location.getX();
float absY = (float)location.getY();
- float advX = 0;
- float advY = 0;
+ // TextPath Shift used to account for startOffset.
float tpShiftX = 0;
float tpShiftY = 0;
- float shiftX = 0;
- float shiftY = 0;
-
- if (textPath == null) {
- // Of course X and Y override all that...
- if ((runX != null) && (!runX.isNaN()))
- absX = runX.floatValue();
- if ((runY != null) && (!runY.isNaN()))
- absY = runY.floatValue();
+ // Of course X and Y override that...
+ if ((runX != null) && (!runX.isNaN())) {
+ absX = runX.floatValue();
+ tpShiftX = absX;
+ }
+
+ if ((runY != null) && (!runY.isNaN())) {
+ absY = runY.floatValue();
+ tpShiftY = absY;
+ }
+
+ // Factor in text-anchor in writing direction.
+ // Ignore tpShift in non-writing direction.
+ if (vertical) {
+ absY += dy;
+ tpShiftY += dy;
+ tpShiftX = 0;
} else {
- absX = 0;
- absY = 0;
- // Only use the x or y in writing direction...
- if (vertical) {
- if ((runY != null) && (!runY.isNaN())) {
- absY = runY.floatValue();
- tpShiftY = absY;
- }
- } else {
- if ((runX != null) && (!runX.isNaN())) {
- absX = runX.floatValue();
- tpShiftX = absX;
- }
- }
+ absX += dx;
+ tpShiftX += dx;
+ tpShiftY = 0;
}
- // System.out.println("ABS: [" + absX + "," + absY + "]");
- float retX = absX;
- float retY = absY;
+ // System.out.println("ABS: [" + absX + "," + absY + "]");
for (int n=chunk.begin; n<chunk.end; ++n) {
r = (TextRun) textRuns.get(n);
layout = r.getLayout();
@@ -809,56 +804,25 @@
runaci.first();
textPath = (TextPath) runaci.getAttribute(TEXTPATH);
- Point2D offset = layout.getOffset();
- // System.out.println("Offset1: " + offset);
- // System.out.println("Shift: [" + shiftX + "," + shiftY + "]");
- if (textPath != null) {
- // For text path use relative values.
- absX = tpShiftX;
- absY = tpShiftY;
-
- shiftX = 0;
- shiftY = 0;
- }
- if (layout.isVertical()) {
- float adj = (float)((offset.getY()-shiftY)*yScale);
- offset = new Point2D.Float((float)absX,
- (float)absY+adj+dy);
- } else {
- float adj = (float)((offset.getX()-shiftX)*xScale);
- offset = new Point2D.Float((float)absX+adj+dx,
- (float)absY);
- }
- // System.out.println("Offset2: " + offset);
- layout.setOffset(offset);
-
if (textPath == null) {
+ layout.setOffset(new Point2D.Float(absX, absY));
+
Point2D ladv = layout.getAdvance2D();
- retX = (float)(offset.getX()+ladv.getX());
- retY = (float)(offset.getY()+ladv.getY());
- if (vertical)
- absX += ladv.getX();
- else
- absY += ladv.getY();
+ absX += ladv.getX();
+ absY += ladv.getY();
} else {
+ layout.setOffset(new Point2D.Float(tpShiftX, tpShiftY));
+
Point2D ladv = layout.getAdvance2D();
- advX += (float)ladv.getX();
- advY += (float)ladv.getY();
- shiftX = advX;
- shiftY = advY;
- if (vertical)
- tpShiftX += (float)ladv.getX();
- else
- tpShiftY += (float)ladv.getY();
+ tpShiftX += (float)ladv.getX();
+ tpShiftY += (float)ladv.getY();
ladv = layout.getTextPathAdvance();
absX = (float)ladv.getX();
absY = (float)ladv.getY();
- retX = absX;
- retY = absY;
}
}
- return new Point2D.Float(retX, retY);
+ return new Point2D.Float(absX, absY);
}
/**
1.1
xml-batik/test-references/org/apache/batik/transcoder/image/.cvsignore
Index: .cvsignore
===================================================================
candidate-reference
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]