Thread View: borland.public.jbuilder.java.api
1 messages
1 total messages
Started by GUI-Majician
Fri, 23 Apr 2004 13:25
Font Glyphs to AnimationStrip, Need Constant Size
Author: GUI-Majician
Date: Fri, 23 Apr 2004 13:25
Date: Fri, 23 Apr 2004 13:25
57 lines
2973 bytes
2973 bytes
I have a unique problem. I need to get images of font characters into an
animation strip. The animation strip is necessary for performance reasons.
Just printing chars as strings is way too slow. I am trying to use
GlyphVector to do this. The problem is in the SIZE of the individual
glyphs. There doesn't seem to be any consistency in the size of the
character glyphs and I need them all to be the same size to work in an
animation strip. I have tried to use the GlyphVector.getLogicalBounds(),
GlyphVector.getVisualBounds(), and the equivalent methods for the individual
glyphs, but those methods return illogical results. For example visual
bounds has a larger width but logical bounds has a larger height, aargh!
That make no sense at all and I can't find any documentation anywhere.
I am thinking of using a BufferedImageOp (RescaleOp) but I have no
consistent glyph size for the scale factor.
Does anybody know an easy way to do this?
Thanks.
Here is the code if you want to look at it:
// chars is an array of char
public void saveGlyphs( Graphics2D g2d )
{
FontRenderContext frc = g2d.getFontRenderContext();
GlyphVector gv = g2d.getFont().createGlyphVector( frc, chars );
Rectangle2D glyphLBounds = gv.getLogicalBounds();
int w = (int)Math.ceil( glyphLBounds.getWidth() );
int h = (int)Math.ceil( glyphLBounds.getHeight() );
if ( (h <= 0) || (w <= 0) )
{
g2d.drawString( "Font Size Bad: " + curFont.getFontName(), 20, 100);
return;
}
BufferedImage bi = new BufferedImage( w, h, BufferedImage.TYPE_INT_RGB );
Graphics2D big = bi.createGraphics();
big.setColor( textColor );
big.drawGlyphVector( gv, 0.0f, -(float)glyphLBounds.getY() );
*** BufferedImageOp bop = getScaledBOP( (float)glyphLBounds.getHeight() );
*** g2d.drawImage( bi, bop, 10, 100 );
big.dispose();
String filename = curFont.getFontName() + ".jpg";
try
{
javax.imageio.ImageIO.write( bi, "jpg", new File( "src/justatest/images",
filename ) );
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads