You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Henryk Hecht <ml...@hhecht.e4ward.com> on 2011/06/10 02:28:46 UTC

text-anchor: middle bug?

There appears to be a rather unusual bug in font handling under newer JDKs 
with squiggle, and I am somewhat at a loss to guess what's actually 
happening.  Below is a pseudo-minimal test case.  Effectively, the problem 
appears to be that under some circumstances, text-anchor: middle does not 
work, and instead aligns the text somewhat in the text-advance direction 
of where it ought to be; specifically, in the figure below, the line 
should bisect all three tspans, but fails to do so for the second of them.

I'm presently seeing this error on Sun, er, Oracle Java 1.6.0_25-b06 on 
opensuse 11.3 (Linux).  The error does not occur with an antiquated 
1.5.0_22-b03 JDK I've lying around.  Nor does it occur with firefox, 
opera, or inkscape (though the latter doesn't seem to support @dy).  I've 
not yet been able to test on windows.  Both Batik 1.6 and 1.7 behave 
identically.

Significantly, the error in alignment only occurs if some text in the same 
font has previously (document order, I assume) been used: deleting the 
first text element, or changing its font (or the font of the second 
element) causes the problem to vanish.  So long as the fonts are kept the 
same however, the problem seems to occur with all fonts that I've tested 
with.

If there are additional text elements, they will all exhibit this problem. 
If a text element contains additional tspans, all but the last will be 
shifted.

I don't know how text-anchor: middle is implemented in Batik, and it seems 
it isn't easy to find out, but perhaps Batik (or the newer versions of the 
JDK) is caching some incorrect information-AWT font metrics perhaps? 
Really, I'm just guessing-I hope that someone with greater expertise might 
be able to produce a better guess.

I've not had a chance to look at it systematically, but it seems as though 
the misaligned tspans are approximately (but not quite) aligned on the 
middle of the text excluding the last word; effectively left-aligned when 
there is only a single word.  Perhaps the behavior of a collection changed 
between JDKs 1.5 and 1.6 (or became buggy), and a fencepost error has 
developed as a result?  Again, this is only a guess.

---cut
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg"
      version="1.1">
   <text
       style="font-family: Arial; font-size: 14; text-anchor: middle;"
       x="50"
       y="20">
     <tspan x="50">Sample Text</tspan>
   </text>
   <text
       style="font-family: Arial; font-size: 14; text-anchor: middle;"
       x="50"
       y="50">
     <tspan x="50">More Sample</tspan>
     <tspan dy="1em" x="50">Text</tspan>
   </text>
   <line x1="50" y1="0" x2="50" y2="70" stroke="black" stroke-width=".5"/>
</svg>
---cut

-- 
HH

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


Re: text-anchor: middle bug?

Posted by Helder Magalhães <he...@gmail.com>.
Hi Henryk,


> Effectively, the problem
> appears to be that under some circumstances, text-anchor: middle does not
> work, and instead aligns the text somewhat in the text-advance direction of
> where it ought to be; specifically, in the figure below, the line should
> bisect all three tspans, but fails to do so for the second of them.
[...]
> If a text element contains additional tspans, all but the last will be
> shifted.

Humm... Could this be the same as bug 49736 [1]? The whitespace
removal workaround should help confirming it.


Cheers,
 Helder


[1] https://issues.apache.org/bugzilla/show_bug.cgi?id=49736

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


Re: text-anchor: middle bug?

Posted by Cameron McCormack <ca...@mcc.id.au>.
Cameron McCormack:
> I’m just downloading an earlier 1.6 JRE to verify.

So it looks to me that the bug shows up with 1.6.0_24 but not with
1.6.0_23.  Unfortunately I don’t have the time at the moment to track
down whether there Batik is incorrectly using the AWT font/text stuff
when text-anchor is in use, or whether it is a bug in the JRE.

-- 
Cameron McCormack ≝ http://mcc.id.au/

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


Re: text-anchor: middle bug?

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Henryk.

Henryk Hecht:
> There appears to be a rather unusual bug in font handling under
> newer JDKs with squiggle, and I am somewhat at a loss to guess
> what's actually happening.
> …
> I don't know how text-anchor: middle is implemented in Batik, and it
> seems it isn't easy to find out, but perhaps Batik (or the newer
> versions of the JDK) is caching some incorrect information-AWT font
> metrics perhaps? Really, I'm just guessing-I hope that someone with
> greater expertise might be able to produce a better guess.

I think you are right that there must be something that has changed in
the JRE to result in this bug.  I just fired up Batik on Windows, which
I hadn’t done for a while, and with the JRE that is on there (1.6.0_24)
I too encounter the problem.  I’m just downloading an earlier 1.6 JRE to
verify.

-- 
Cameron McCormack ≝ http://mcc.id.au/

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