Hi Thomas,
On 29 Aug 2007 at 7:21, [EMAIL PROTECTED] wrote:
> "Matthew Darlison" <[EMAIL PROTECTED]> wrote on 08/29/2007 07:02:44 AM:
> > > "Matthew Darlison" <[EMAIL PROTECTED]> wrote on 08/29/2007 05:56:36 AM:
> > >
> > > > TextLayout stextLayout = slbm.nextLayout(swrappingWidth);
> > > > stextLayout.draw(g2, sx, sy);
>
> > On 29 Aug 2007 at 6:21, [EMAIL PROTECTED] wrote:
>
> > > I'm guessing that the LineBreakMeasurer is setting a
> > > bunch of attributes on the attribute string that it passes
> > > to the Graphics2D to draw.
>
> > I've just tried with all of the commented out, and I'm seeing no
> > change... could the font itself make a difference...?
>
> Then I suspect that the TextLayout class draws the string
> using a GlyphVector which is impossible to map back to chars.
> You can test this by adding print statements in the Graphics2D.
That would figure... printing the TextLayout.toString() yields:
[EMAIL PROTECTED]:0, len:16, cstart:0, clen:31,
chars:"50 61 72 74 6e 65 72 20 77 68 6f 20 68 61 73 20", level:0,
flags:0,font:java.awt.Font[family=Dialog,name=Dialog,style=plain,size=12],
frc:[EMAIL PROTECTED],
cm:[EMAIL PROTECTED]
> Unfortunately I think this means that you will need to change the
> way you wrap text if you want to preserve the text as text...
I think I have a workaround... not tested it much yet, but it produces
text in SVG and the EPS version transformed form that by Inkscape is
excellent... basically by letting the TextLayout do all the work, and
then grabbing its values, I can use the drawString method, and get
text...
String slabel = "String of variable length";
AttributedString sas = new AttributedString(slabel);
g2.setFont(getCapFont());
AttributedCharacterIterator saci = sas.getIterator();
FontRenderContext sfrc = g2.getFontRenderContext();
LineBreakMeasurer slbm = new LineBreakMeasurer(saci, sfrc);
float swrappingWidth = (this.getXDimension()/4)-offsetunit;
float sx = offsetunit;
float sy = rowcentre1 -offsetunit;
int sstartchar =0;
while (slbm.getPosition() < saci.getEndIndex()) {
TextLayout stextLayout = slbm.nextLayout(swrappingWidth);
System.err.println("!! "+stextLayout.toString());
sy += stextLayout.getAscent();
//stextLayout.draw(g2, sx, sy);
g2.drawString(slabel.substring(sstartchar, slbm.getPosition()),
sx, sy);
sstartchar = slbm.getPosition();
sy += stextLayout.getDescent() + stextLayout.getLeading();
sx = offsetunit;
}
So far this seems to work... unless I've missed somehting obvious..?! ;-)
> Do any of the other output formats manage to preserve
> the text as text?
Apparently not - I'd got as far as Java > SVG > EPS, and EMF using the
freehep toolkit... the workaround preserves text in EPS too, assuming
inkscape isn't told to substitute outlines... illutrator gets confused by
the font names, but seems to make a sensible substitution.
Many thanks for your assistance!
Yours,
Matthew
--
"Mr. Matthew Darlison BA MA" <[EMAIL PROTECTED]>
Senior Research Fellow, Clinical & Applied Bioinformatics
UCL Centre for Health Informatics and Multiprofessional Education (CHIME)
WHO Collaborating Centre for the Community Control of Inherited Disorders
APoGI on the Web at http://www.chime.ucl.ac.uk/APoGI/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]