Le mar 25/03/2003 � 00:28, Doug Felt [CONTRACTOR] a �crit :
> > Thanks! Modifying the position of each glyph in the GlyphVector works
> > perfectly! At first I didn't though that this was practical, because the
> > GlyphVector seems to encode positions as Point2D: it seemed to me that
> > the final position of each glyph was already encoded in there. But I
> > poked around and apparently the default layout is purely linear: the Y
> > value is always 0.
> > 
> > Best Regards,
> > David Garnier
> 
> David:
> 
> GlyphVector.performDefaultLayout puts each glyph at the position + advance of 
> the previous glyph.  For fonts without rotation, the y advance is 0.  As long as 
> you are working with non-complex text (e.g. no reordering, combining marks, or 
> ligature formation) tweaking the positions will be fine.  You just need to 
> really know what kind of text you are working on.  For general text, you have to 
> go through the full bidi analysis and layout process that TextLayout can 
> perform, taking a shortcut through Font.createGlyphVector can produce 
> next-to-worthless text.
> 
> Tracking would be handy for some folks, file an RFE if you want this feature.  
> It would have to be filed pretty soon, and need some votes for it to get 
> attention in the right places and make the next major release.  RFE's are always 
> welcome in any case.
> 
> I'm not sure why the glyphs are 'too far apart', though.  FractionalMetrics 
> should help for some cases.  It might be the font you are using.  It might be 
> the framework you are using imposing its own tracking (from one email it sounded 
> like you were using Vincent Hardy's graphics framework, but I'm not familiar 
> with the implementation).  It might, um, even be a bug.  Without a test case its 
> difficult to tell.  If you think it might be a bug, please submit a bug report.
> 
> Doug

First, thanks for you detailed answer. Indeed Vincent Hardy's TextStroke
class, but it doesn't depend on anything from its framework, it's just
plain j2SE. It's a tad late over here, so here is just a quick snippet.
I'm using the following code to manipulate the glyphVector (I just
hacked my current code to include your comments):

        glyphVector = font.createGlyphVector(new FontRenderContext(null, true,
true), "Too_much_space");
        //        glyphVector.performDefaultLayout();

        // manipulating the Glyph Vector in order to pack more letters
in a shape.

        float currentPosition = 0;
        Point2D point = null;
        nGlyphs = glyphVector.getNumGlyphs();

        for (int i = 0; i < nGlyphs; i++) {
            //first set the position of the current glyph
            point = glyphVector.getGlyphPosition(i);
            GlyphMetrics metrics = glyphVector.getGlyphMetrics(i);

            point.setLocation(currentPosition, RAISING);
            // Then move move it to a better position
            glyphVector.setGlyphPosition(i, point);
          currentPosition +=metrics.getAdvance();
        }

Font should be "sansserif" (I'm not sure I'm doing this correctly).

You will notice the commented out performDefaultLayout().

In this setup, there is still too much space between letters. A sample
is attached. I'm thinking that maybe TextStroke is modifying the
GlyphVector behing my back.

Best Regards,
David Garnier
-- 
David Garnier <[EMAIL PROTECTED]>

<<attachment: pic.gif>>

Attachment: signature.asc
Description: PGP signature

Reply via email to