I am developing a java game and I need characters, such as monsters and doors etc. I am trying to include them with the help of chars and unicode. However, some chars, such as a key, '\u26BF', do not show up properly in the terminal of the game, but rather as a box. Do I need to import some special fonts or how else would I solve this problem?
GNU Unifont is reported as containing this Glyph. As it comes under the GNU public licence it is not subject to any licence fee.
Home page: http://unifoundry.com/unifont.html
It has TrueType, which should work wiht Java.
Like people already pointed out in the comments sections, you will have to use another font containing those special characeters.
The font you are using seems to not support those characters, you can download any other font containing those character(s). The character 'u26BF' is a square box in some default fonts (source).
You can find different fonts and even try them out on DaFont and, like #SubOptimal warned you, check the licenses also before you download & use it.
Related
I need to render the below String on a JTable cell. How do we do this?
testä漢字1ગુજરાતી2
Update:
Looks like my question is not clear. The above string is a name of file. Need to display this and many other file names in JTable. Data comes dynamically. I may need a custom renderer to display this string exactly same. Currently, this displays junk characters. Simply changing the table Font from Calibri to MS Gothic, I can see the chinese characters, but not indic letters. But, as the data comes dynamically, we won't be knowing what font to use.
So, want to know if there is way so that I can check the string programmatically and render the string with different fonts as appropriate.
The simplest solution would be to use a font which is more complete. I believe the DejaVu family is decent, others may be able to suggest better. The Oracle manual suggests that the logical fonts Dialog, DialogInput, Monospaced, Serif and SansSerif are also likely to be more complete. Potentially they could map to multiple underlying fonts depending on the specific characters which need to be rendered. Oracle also mentions the Lucidia family which is distributed with Oracle's JRE as another possibility which is fairly complete, though it doesn't have Chinese, Korean or Japanese characters.
A more convoluted solution would be to run Character.UnicodeBlock.of(c) on the characters in each string, assemble a Set<Character.UnicodeBlock> and guess which font is most appropriate based on the blocks present in the string, or even write a custom renderer to render each character (or sequence of characters) with a font appropriate to the Unicode block they belong to. Unicode blocks tend to be categorized according to the script they contain.
I'm working on an app where User should be able to input some text which contains both English and Persian(Same as Arabic: almost same characters and written from right to left ).
Currently i'm using fonts like Courier New which supports both languages but it looks really Ugly. I Want to use some better looking fonts, but these fonts only support one of these languages and show nonsense characters for the other language. So i need to use them based on text language.
So generally how can I make Java components (especially swing.JTextField, swing.JListBox and swing.JTextComponent) accept two fonts and switch appropriately to have a good looking GUI?
Edit: Here is an example of what i need. Let say user should input something like (FPGA استفاده از ) and all of it in a single swing.JTextField. It means (Using FPGA) and FPGA is an abbreviation, so there is no Persian translation. I need to set a font with a better look and all fonts which support Unicode are ugly for the Persian part.
Now if I set font to something like Times New Roman ,which only supports Latin, then Persian characters would show as empty squares. also if i set font to something like B Nazanin ,which only supports Persian, then Latin characters would show as empty squares. How can I have both fonts in a single Java component in the same time.
InputContext context = InputContext.getInstance();
if(context.getLocale().toString().equals("en_GB")){
.setFont(*font for english keyboard*);
}
else if(context.getLocale().toString().equals("fa_IR")){
.setFont(*font for persian keyboard*);
}
I am trying to create pdf documents using iText (version 5.4.0) in a java web application and I have come across an issue with fonts.
The web application is multi-lingual, and so users may save information into the system in various languages (eg. english, french, lithuanian, chinese, japanese, arabic, etc.).
When I tried to configure the pdf to output some sample japanese text it didn't show up, so I started following the examples in the official "iText in Action" book. The problem I have encountered is that when I try and configure a font with BaseFont.IDENTITY_H encoding I get the following error:
java.nio.charset.UnsupportedCharsetException: Identity-H
at java.nio.charset.Charset.forName(Charset.java:505)
at com.itextpdf.text.pdf.PdfEncodings.convertToBytes(PdfEncodings.java:186)
at com.itextpdf.text.pdf.Type1Font.<init>(Type1Font.java:276)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:692)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:615)
at com.itextpdf.text.pdf.BaseFont.createFont(BaseFont.java:450)
Nothing in the book or searching Google mentions this issue.
Any suggestions as to what I might have missed?
As you probably understood from the answers from two Michaels, you made the wrong assumption that the standard Type 1 font Times Roman and IDENTITY_H are compatible. You'll have to change the font if you want to use IDENTITY_H, or change the encoding if you want to use a standard Type 1 font (in which case using BaseFont.EMBEDDED doesn't make sense because standard Type 1 fonts are never embedded). I'm sorry if I didn't mention this in my book. I thought it was kind of trivial. One can deduct it from what I wrote about composite fonts.
I don't think there's any one encoding that works for all languages, with font embedding. For example, you'd assume that choosing the UTF-8 encoding, with font embedding set to true will embed the font, but it doesn't.
I find myself having to do this, because I don't know the language of the text ahead of time:
try {
// Try to embed the font.
// This doesn't work for type 1 fonts.
return FontFactory.getFont(fontFace, BaseFont.IDENTITY_H,
true, fontSize, fontStyle, textColor);
} catch (ExceptionConverter e) {
return FontFactory.getFont(fontFace, "UTF-8", true,
fontSize, fontStyle, textColor);
}
(The exception class may be different since I'm using an older version of iText -- 2.1.)
As with a lot of iText stuff, this is poorly documented, and makes the easy stuff unnecessarily hard.
I want to write a java program to print Unicode characters. I want to detect and not print Unknown/Unassigned CHaracters (which are shown by a rectangular). I have tried "isDefined" and "isISOControl" from "Character" class, but it does not work.
Does anybody know the solution? it will be a big help for me.
Thanks.
The characters that are shown as a rectangle (on Windows) are ones that aren't available in the font you're using. While you could filter out a lot of them by filtering out undefined and control characters, it's entirely possible that the problem you're running into is that your font doesn't support certain ranges of valid characters (which is typical -- very few fonts define glyphs for all defined Unicode characters).
If your goal is really to remove characters that render as a rectangle, you can use the canDisplay method in Font.
I have a small Java application that has a JTextArea where the user enters text. I would like to add spell checking capabilities to this component similar to the way that Microsoft Word does it, i.e. misspelled words are underlined and a popup menu with corrections is displayed when the user right clicks on the underlined word. Are there any open source libraries for adding this functionality to JTextAreas?
You could implement your own spell checker using a dictionary (can get quite large depending on languages you support), then distance metrics are calculated from the words in the text box to the dictionary. Underlining can be done using font styling, there as applet based sample here.
Jaspell is a Java implementation of the popular Aspell. In there are some explantions of the search algorithms used.
As mentioned previously Jazzy is also great and IBM provides a nice tutorial.
I haven't tried this before, but I came across it a little while ago: http://sourceforge.net/projects/jazzy/