You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by nnaass <al...@gmail.com> on 2008/02/19 06:59:05 UTC

Re: Determining available fonts?

I was looking for a solution for this problem then I solved it and I want to
post it :

fonts = new Vector<String>();

// Get all font family names
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontNames[] = ge.getAvailableFontFamilyNames();


// Iterate the font family names
for (int i = 0; i < fontNames.length; i++) {
	Font f=new Font(fontNames[i],Font.PLAIN,10);
    if (f.canDisplayUpTo("zxcvbnmasdfghjklqwertyuiop")==-1)
    	fonts.add(fontNames[i]);
	
}
System.out.println(fonts.toString());

///////////////////////////////////////

The trick is to check if the font can display all characters. 
(f.canDisplayUpTo("zxcvbnmasdfghjklqwertyuiop")==-1) // if true, it will
return -1
 
This will remove the junk fonts. 

Please note that this is not solution about the space in the font name such
as "Wingdings 3" you need to double quat them like this font-family=" '
Wingdings 3 ' " <-- to make it clear but it should be
font-family="'Wingdings 3'" .

Hope this will help somebody...

Alaa ,


Bishop, Michael W. CONTR J9C880 wrote:
> 
> For my application, I poll the local system for a list of fonts:
>  
> String[] fontNames =
> GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
>  
> Most work in Batik.  Some, however, (like Wingdings) do not.  Is there a
> way to determine which fonts are available for Batik to render?  I know
> this is dependent on the system, so I'm looking for a runtime solution
> that can evaluate whether or not a system font is usable by Batik.
>  
> Michael Bishop
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Determining-available-fonts--tp12038730p15554276.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org