Hello,
I have a japanese TrueType font for Windows NT (which is not the
standard
Microsoft japanese font as you can't install those fonts on a
german/english system) that we want to use to display japanese text.
If I use TextLayout objects with this font on a german/english NT 4.0
(SP3)
system, I only get the latin characters of that font shown, and all the
japanese
characters are just empty boxes (although "canDisplay()" returns true
for most
of the characters I want to show). If I use the same font and same
program (see below) on a japanese NT 4.0 (SP1) system, all japanese
characters
appear, even if I don't change the font.properties file to
font.properties.ja
of the runtime.Why isn't it working on a german/english NT system?
I used a Windows NT native program that displays all characters of a
font
and this worked on both system (english/japanese).
Any ideas?
Too play around with fonts, I attached a little program, that lists all
fonts found in a listbox. If you click on one,the characters 32-300 and
10000-35000 (if displayable) are shown.
It consumes a lot of memory (about 40Mb) for the BufferedImage the text
is written too, and
it is slow, so take your time. And its a hack as well.
Regards,
Knut
--
Knut H. Meyer Phone: +49-711/13353-44 FAX:
+49-711/1335353
Email: [EMAIL PROTECTED]
D A N E T - IS GmbH Waldburgstrasse 17 - 19, D-70563 Stuttgart
import java.awt.*;
import java.awt.image.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class FontTest
{
public static int width = 600;
public static int height = 10000;
public static String fontName;
public static JList fontList;
public static BufferedImage buffer;
public static Graphics2D graphics ;
public static JPanel panel;
public static void showFont(String name)
{
if(buffer == null)
{
buffer = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
graphics = buffer.createGraphics();
}
graphics.setBackground(Color.white);
graphics.setColor(Color.black);
graphics.clearRect(0, 0, width, height);
Font f = new Font(name, Font.PLAIN,20);
Font f2 = new Font("Monospaced", Font.PLAIN,8);
System.err.println("Loaded font=" + f.getFontName());
graphics.setFont(f);
StringBuffer str = new StringBuffer();
int x = 10;
int y = 50;
for(int i = 32; i<300; i++)
{
/* if(f.canDisplay((char)i))
{*/
char c[] = new char[1];
c[0] = (char)i;
graphics.setFont(f);
FontRenderContext frc = graphics.getFontRenderContext();
TextLayout l = new TextLayout(new String(c), f, frc);
l.draw(graphics, x, y);
int h = i;
String nr = String.valueOf(h);
graphics.setFont(f2);
TextLayout l2 = new TextLayout(nr, f2, frc);
l2.draw(graphics, x, y+ l.getAscent()+10);
x += l.getAdvance() + 10;
if(x > width)
{
x = 10;
y += l.getAscent()+10+30;
}
//System.err.println("can display "+ i);
/*}*/
}
for(int i = 10000; i<35000; i++)
{
if(f.canDisplay((char)i))
{
char c[] = new char[1];
c[0] = (char)i;
graphics.setFont(f);
FontRenderContext frc = graphics.getFontRenderContext();
TextLayout l = new TextLayout(new String(c), f, frc);
l.draw(graphics, x, y);
int h = i;
String nr = String.valueOf(h);
graphics.setFont(f2);
TextLayout l2 = new TextLayout(nr, f2, frc);
l2.draw(graphics, x, y+ l.getAscent()+10);
x += l.getAdvance() + 10;
if(x > width)
{
x = 10;
y += l.getAscent()+10+30;
}
//System.err.println("can display "+ i);
}
}
panel.repaint();
}
public static void main(String argv[])
{
buffer = null;
// ui stuff
WindowListener listener = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
javax.swing.JFrame frame = new javax.swing.JFrame("Font Test");
frame.setBackground(Color.white);
frame.getContentPane().setLayout(new BorderLayout());
System.err.println("loading fonts");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font[] flist = ge.getAllFonts();
String fontNames[] = new String[flist.length];
for(int i = 0; i < flist.length; i++)
{
StringBuffer aName = new StringBuffer();
aName.append(flist[i].getFontName());
/*
//append unicode escape sequences for font name representation
aName.append("(");
for(int j = 0; j < flist[i].getFontName().length(); j++)
{
int c = flist[i].getFontName().charAt(j);
if(c < 256)
aName.append((char)c);
else
{
aName.append("\\u"+Integer.toHexString(c));
}
}
aName.append(")"); */
fontNames[i] = aName.toString();
}
fontList = new JList(fontNames);
JScrollPane scrollPane = new JScrollPane(fontList);
frame.getContentPane().add("West", scrollPane);
ListSelectionListener selectionListener = new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
showFont((String)fontList.getSelectedValue());
}
};
fontList.addListSelectionListener(selectionListener);
panel = new JPanel()
{
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.setBackground(Color.white);
g2.setColor(Color.black);
g2.clearRect(0,0,getWidth(), getHeight());
if(buffer != null)
g2.drawImage(buffer, null, 1, 1);
}
public Dimension getSize(Dimension s)
{
if(s != null)
{
s.setSize(width, height);
return s;
}
else
return new Dimension(width, height);
}
public Dimension getPreferredSize()
{
return getSize(null);
}
public Dimension getPreferredScrollableViewportSize()
{
return getPreferredSize();
}
public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation,
int direction)
{
if(orientation == JScrollBar.VERTICAL)
{
return height/2;
}
else
{
return width/2;
}
}
public int getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,
int direction)
{
if(orientation == JScrollBar.VERTICAL)
{
return height / 20;
}
else
{
return width / 20;
}
}
public boolean getScrollableTracksViewportHeight()
{
if (getParent() instanceof JViewport)
{
return (((JViewport)getParent()).getHeight() >
getPreferredSize().height);
}
return false;
}
public boolean getScrollableTracksViewportWidth()
{
if (getParent() instanceof JViewport)
{
return (((JViewport)getParent()).getWidth() >
getPreferredSize().width);
}
return false;
}
public void setLocation(int x, int y)
{
super.setLocation(x,y);
revalidate();
}
public void setViewSize(Dimension dim)
{
}
};
JScrollPane scrollPane2 = new JScrollPane(panel);
frame.getContentPane().add("Center", scrollPane2);
frame.addWindowListener(listener);
frame.pack();
frame.setSize(940,640);
// display the stuff
frame.show();
}
}
// EOF