开发者

How are diacriticals represented in a font and typed in a Java app?

I'm writing a simulation of an old computer console typewriter that had one unusual feature: "flagged digits." A flagged digit is a digit with a ho开发者_高级运维rizontal bar above it, and you typed it by pressing the FLG key, which typed the horizontal bar but did not advance the carriage, followed by pressing a digit key.

When outputting a flagged digit, the typewriter used the same two-stroke process.

Since the "flag" is like a diacritical (e.g. the tilde in ñ), I'm imagining that I may be able to treat it as such, binding it to its own unique key rather than option-n (as you do on Mac).

I hope to be able to construct the font from scanning old printouts (ribbon cross-hatching and all!). But I don't know what's involved in defining a diacritical mark or whether it's possible to output a textual character without "advancing the carriage."

Fontography (if that's a word) is wicked complicated, so I'm hoping someone versed in the subject might be able to point me to the relevant topics.


Java uses Unicode. Some of the diacritical-marked characters have their own character. But there is also the option of overstrike diacritics, which effectively have zero width. Examples here and here.

To represent these in output, you need to have the right font in place.

As for representing them in your source code, though Java can in principle include any Unicode character in the source code, in common practice this is not done. Instead, Unicode escapes (e.g. \ucc81) are used, or non-ASCII characters are read from an outside source.

If what you want to do is create a font, that's not related to Java. You'll want the right tools for that, like FontCreator or FontLab. These fonts must then be installed in the OS from which Java will reference them. though loading them in Java is also possible.


Add unicode 0305 after the number in the text you are rendering:

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

public class MacronTest {

  public static void main(String[] args) {
    JFrame jframe = new JFrame();
    JLabel label = new JLabel();
    jframe.add(label);
    jframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    label.setText("1\u0305");
    jframe.setVisible(true);
  }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜