Article View: borland.public.jbuilder.java.api
Article #125Font Glyphs to AnimationStrip, Need Constant Size
From: 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();
}
}
Technical Details
Message-ID:
<4089194b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!hammer.uoregon.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,5069bb2639a16305,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2004-04-23 06:35:08 PST From: "GUI-Majician" <nospam@centurytel.net> Newsgroups: borland.public.jbuilder.java.api Subject: Font Glyphs to AnimationStrip, Need Constant Size Date: Fri, 23 Apr 2004 08:25:41 -0500 Lines: 59 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 69.29.172.225 Message-ID: <4089194b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1082726731 69.29.172.225 (23 Apr 2004 06:25:31 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!hammer.uoregon.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail