java processing replaces unicode char to square - java

I'm developing a java project with eclipse v2021-3, with the software processing v3.5.4, and I want to put unicode characters as a text on my screen.
I can do that and have positive results with no problem, just by doing this:
#Override
public void mousePressed(PApplet p) {
p.text("\u2196", 10, 10); // "\u2196" code for arrow top-left
}
But whenever I try to change the textSize:
p.textSize(10);
It turns all the unicode characters into squares, despite the size I choose.
https://prnt.sc/12pykgs -> this is a screenshot of before and after I scale the text.
In my work colleague is also working with eclipse and processing in her computer and she can do this without any problems, and I've looked for help on the forums and I haven't found anything.
Thank you in advance if you can help me with this problem! :)

Host OS configuration problem, not a programming problem
Likely not a Java programming problem, nor a problem with Eclipse. Likely a problem related to font problems on your particular computer.
See similar code run live on IdeOne.com.
String input = "\u2196" ;
System.out.println( input ) ;
↖
Code point U+2196 in hex (8,598 decimal) is NORTH WEST ARROW.
You should be seeing this character if your display app is running on a computer offering a font with a defined glyph. If none of the available fonts has such a glyph, you will get a fall-back glyph such as empty box.

Related

Unicode arrow character prints on Mac but not Windows

I have a Java program that is meant to print a Unicode LEFTWARDS ARROW character, ←:
public class test {
public static void main(String[] args) {
System.out.print("\u2190");
}
}
When I run this program in Eclipse on a Mac computer, the console prints the proper arrow symbol, ←. However, when I run the exact same code on a Windows 10 machine, the Unicode character prints as a question mark, ?.
I also tried printing an arrow character in a C++ program on my Windows computer, and got the same Unicode rendering problem.
I don't know when this stopped working and if it is a recent Windows update that is causing the character to not display properly, but I do know that this code used to work and doesn't anymore.
Any ideas as to why this code is not rendering the correct Unicode character on Windows?
Update
To address #ElliotFrisch's comment, I checked which font my Eclipse console is using, and it is using Consolas. I opened the font Character Map in Control Panel, and Consolas does seem to have a leftwards arrow, U+2190 character:
I also tried changing the font to different common fonts like Times New Roman, Calibri, Cambria and Arial, but none of those printed the correct arrow character.

ANSI character not working for eclipse console on Ubuntu Linux

I am fairly new to Java and need your help. I am trying to change the color of the text in Eclipse console on run-time. I referred to one of the posts and tried to follow that. But the output shows a box of unicode escape character and the color of the text remains unchanged.
public static void main(String[] args)
{
System.out.println((char)27 + "[31mTest red color");
}
OUTPUT:
|00|
|1B| [31mTest red color
Notes:
For output, I couldn't upload the image so i have typed [001B].
The console uses UTF-8 encoding.
UPDATE
Following the comment from Jarrod for possible duplication of the question, here is my update -
The question is mainly for ANSI character not working and not for text color, so i have updated the question.
Eclipse does not support ANSI escape characters out of the box.
You have to install a plugin for that: https://marketplace.eclipse.org/content/ansi-escape-console

libGDX, printing non-western fonts

I'm in the middle of finishing my libGDX android game and I have problems with making localizations.
I want my game to be localized in Polish, English, Arabic and Chinese. To do this, I'm using libgdx I18NBundle which works perfectly fine. I have no problems with the former 2, they print very well with my BitmapFont(I've made it through Hiero).
I have completely no idea how to render the latter 2. Hiero doesn't seem to be capable of generating bitmaps from non-western fonts, and trying Gdx freetype extension left me even more confused(printing western symbols didn't work - another characters where showing and when I was trying to print Chinese/Arabic characters all I got was blank space).
Here's the second part of the question. Let's assume that I/we managed to achieve working font rendering. It's quite obvious that I'm going to need 3 fonts(Polish/English, Chinese and Arabic). I have to somehow detect system's language and then load proper font. Loading proper font doesn't seem like a big problem, the problem is, how I could detect the language(not whole locale).
Hiero generates bitmap font for non-western fonts. I generated several Cyrillic bitmap fonts for my games. And I tried several arabic fonts from this page just now - all work pretty well. Probably you should ask another question with more detailed description of your problems with Hiero.
You can use method Locale.getDefault().getLanguage() (more info here) in your AndroidLauncher class to get current language on device at runtime.
Then your should decide what language from your localizations you will use and pass this info to the main game class.
protected void onCreate (Bundle savedInstanceState) {
...
String sysLang = Locale.getDefault().getLanguage();
String i18nLang;
if ((sysLang == "en") || (sysLang == "de")) {
i18nLang = "en";
} else if (...) {...}
initialize(new MyGame(i18nLang), config);
}
If you select the font file manually, it will work. Apparently the non-western fonts in the default System list won't work in Hiero.

Why does JavaFX add extra spacing between letters when using the Text component and how do I fix it?

I'm trying to use the text component of JavaFX to do some nice headline typography in my application. How ever the letters in the text are not spaced evenly. For example in the word "visiting", the "iting" part seems disconnected from the first part.
In the sample image I'm using Arial but this kind of bad spacing happens with every font I tried.
This only happens when "gray" anti-aliasing is used (-fx-font-smoothing-type: gray;). One obvious solution would be to change -fx-font-smoothing-type to lcd, but that would result in the text having jagged edges.
The only thing remotely mentioning something like this is the jira issue RT-14187, but that seem to have been resolved in javafx 8 (jre 8).

Print unique ascii characters in eclipse console

Kind of a strange question but... here it goes.
Recently my application threw an IOException that the text only had a clubs symbol in it (like the suit in cards) I know this is probably because there was a number in there that was cast to a char and printed to the screen, and I've found where that might have happened. The only problem is, I can't recreate it in eclipse because the eclipse console doesn't want to print those characters for me. All I get are boxes.
I figure this is an encoding issue or something but I need eclipse to print out those characters just like the windows console would. Is there a setting I can change to do this?
The respective Unicode character is U+2663. Just print "\u2663" and you should be fine. This has nothing to do with ASCII, though.
If you get boxes it may also be a font issue. If the font you selected for the console view in Eclipse does not have a glyph for that code point you'll get boxes, usually. The character might still correctly printed, though. Usually monospaced fonts have that character, though, since it was historically part of the glyphs for the control characters below character code 32 (not that control characters ever had the intention of a visual appearance, but well, they could be in the screen buffer, so someone thought it would be a good idea to display them as well).

Categories

Resources