|
Hi!
I'm trying to layout a (single) line of text with
some extra space between each glyph
similar to kerning an entire string
with some extra space between the letters, the method
I had hoped would work was to use an
AttributedString with the TextAttribute.WIDTH
attribute set to TextAttribute.WIDTH_EXTENDED
but the result doesn't seem to
reflect this :-( (jdk1.2.2) the textlayout still does not have the extra
space
between the glyphs :(
// Tab positions is a List of AttributedString
(s)
// as is an AttributedString with
TextAttribute.WIDTH_EXTENDED applied across the entire string.
LineBreakMeasurer measurer = new LineBreakMeasurer(as.getIterator(),new
FontRenderContext(null,true, true));
List shapes = new ArrayList(1); Iterator
iterator = tabPositions.iterator();
while(iterator.hasNext() ) { int position = ((Integer)iterator.next()).intValue(); TextLayout layout = measurer.nextLayout(rightmargin-horizontalPos, position+1,false); if( layout != null ) { AffineTransform xform = AffineTransform.getTranslateInstance(horizontalPos,0); Shape s = layout.getOutline(xform); horizontalPos += layout.getAdvance(); horizontalPos = getNextTabPosition(tabStops,horizontalPos); shapes.add(s); } } // We now have an array of perfectly aligned shapes. GeneralPath textBlock = new GeneralPath(); iterator = shapes.iterator(); while(iterator.hasNext() ) { Shape s = (Shape)iterator.next(); textBlock.append(s, false); // Do not connect lines } (btw - those of you who have looked into the GLF's
TextLayer code will recognise alot of this :-)))
Can anyone recommend a way to add kerning
between the glyphs, or a different method of measuring lines where I
can
advance the line by a little more?
Cheers
James Gardner
|
