Hi,
I tried to use Japanese font in my Pivot class, but these fonts are
displayed as empty boxes.
How do we support these Japanese fonts localization?
There are actually a few issues to set up Japanese fonts in Linux.
Since I'm using SuSE 11.3, and Sun's jdk(not the default JVM od SuSE(open
souce JDK)), I needed to install Japanese fonts(sazanami-gothic.ttf,
sazanami-mincho.ttf, and execute the SuSEconfig -module fonts to create new
properties file: fontconfig.SuSE.properties under /usr/lib64/jvm/jre/lib,
and copied it to Sun's JDK directory(/usr/java/jdk1.6.0_22/jre/lib as well
as creating links to these ttf fonts file under jre/lib/fonts).
This setting allowed to use Japanese fonts in Applet in chrome, and swing
from eclipse, also in the window frame of Pivot application. But in the main
window content, the proper Japanese fonts are not used and they are
displayed as empty boxes.
In the Pivot site, there is an explanation to use French character in Pivot
using BXML file, but how can we use Japanese character in a label (for
instance) ?
Following codes are the program I used to test this issue. There I just used
a Japanese text in the string.(konnichiwa means hello)
The similar codes in Swing can display the Japanese character properly
without extra setting.
Is it possible to use Japanese fonts in Pivot ??
--------
public class _Hello implements Application {
private Window window = null;
@Override
public void startup(Display display, Map<String, String> properties)
throws Exception {
final Object obj = create();
if (obj instanceof Window) {;
window = (Window)obj;
} else if (obj instanceof Component) {
window = new Window();
window.setContent((Component)obj);
window.setTitle("hello.bxml");
} else {
System.out.println("getComponent returned object with type:
"+obj.getClass());
}
window.open(display);
}
@Override
public boolean shutdown(boolean optional) {
if (window != null) {
window.close();
}
return false;
}
@Override
public void suspend() {
}
@Override
public void resume() {
}
public static void main(String[] args) {
DesktopApplicationContext.main(_Hello.class, args);
}
static Window create() throws Exception {
return new Window() {{
final Map<String, Object> namespace = new HashMap<String,
Object>();
setTitle("こんにちは BXML!"); // this is displayed properly
setMaximized(true);
setContent(new Label() {{
// setText("Hello BXML!");
setText("こんにちは BXML!"); // the Japanese fonts are not used
properly, they are displayed as empty boxes.
setStyles("{font:'Arial bold 24', color:'#ff0000',
horizontalAlignment:'center', verticalAlignment:'center'}");
}}); // INSTANCE, name: <Label>
// CodeEmitterRuntime.initialize(this, namespace);
}};
}
}
-----------------------
This is a swing sample code which display Japanese fonts properly.
public class SwingLabelDemo extends JPanel {
public SwingLabelDemo() {
super(new GridLayout(3,1)); //3 rows, 1 column
JLabel label1, label2, label3;
ImageIcon icon = createImageIcon("images/middle.gif",
"a pretty but meaningless splat");
//Create the first label.
label1 = new JLabel("Image and Text",
icon,
JLabel.CENTER);
//Set the position of its text, relative to its icon:
label1.setVerticalTextPosition(JLabel.BOTTOM);
label1.setHorizontalTextPosition(JLabel.CENTER);
//Create the other labels.
label2 = new JLabel("日本語つかえる");
label3 = new JLabel(icon);
//Create tool tips, for the heck of it.
label1.setToolTipText("A label containing both image and text");
label2.setToolTipText("A label containing only text");
label3.setToolTipText("A label containing only an image");
//Add the labels.
add(label1);
add(label2);
add(label3);
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path,
String description) {
java.net.URL imgURL = SwingLabelDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("SwingLabelDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
SwingLabelDemo newContentPane = new SwingLabelDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
--
Cheers,
calathus