How to use images in SWT Text field? - java

I'm creating a chat like application with SWT. My application uses StyledText and Text for taking input and displaying it to user. Is there a way I can insert emoticons (images) into the text field?

There are Unicode characters for Emoticons (starting with Unicode 6.0) so you don't need to use images for this provided you have a font which supports them 😀
The Unicode characters are in the range U+1F600..U+1F64F, more information on the characters see here

Related

Emoji inside Whatsapp chat

I am having a Whatsapp chat txt file inside of which emojis have been replaced by such text------> "���"
I want to convert that text to specifics emojis. How can I do that and use it inside a java application?
As #Abhishek pointed out, you need to use a different type of encoding. Whatsapp does backup with UTF-8 converting the emoticons into string representations. If you want to see the real emoji, you will have to use Unicode instead. Unicode contains sections which specify emoji as "characters". They're regular characters, you only need a font which can display them. Also see the Unicode Emoji FAQ.
In a text file, characters are basically encoded as numbers in the form of bytes. To display those visually on a computer screen you need a font which contains the visual glyph to render this character. Since the process is always numeric identifier → font → visible glyph, it should be pretty obvious that a "character" can be anything visual, including emoji or any other image.
Maybe all you need is a a font which contains the visual glyph to render these characters. See this for reference.

Allowing Hindi fonts in html text area

I have a desktop application in java that converts from literal hindi text to corresponding english translitration. I am using jTextArea in desktop application. Now I want to make a web application for doing the same. My end goal is to have two text areas in html in one of which I can type hindi characters and in other one would show translitration result in english characters at the same time. For Hindi I want to use kruti dev font and Times new roman for english.
Take a look at Cufon: http://cufon.shoqolate.com/generate/
Keep in mind any license issues regarding font usage before making use of a font.
If you want a safe approach, try and find a font you're happy with here: https://www.google.com/fonts

Android: Character appearing as a box

I have an app displaying Japanese characters but for some reason, the tilde (~) character is displaying as a box (which looks like this, but one character: []).
This is after i apply the text to a TextView. I got the text from a JSON string.
The thing that disturbs me is, aren't Java strings unicode? Anyone know what i need to fix?
characters = getCharacterFromJSON();
// set character
TextView charTextView = (TextView)findViewById(R.id.characterView);
charTextView.setText(characters);
// Ack! all my ~'s are []!
EDIT: it's not a tilde(~), it's a japanese character (〜), which indicates these characters are a suffix. It's still not showing though.
Most probably a font issue. The default font that comes with most Android devices doesn't properly support all Japanese characters: some kanji are shown using the Chinese glyph, more obscure characters are not displayed at all (boxes). You have a few options:
if this is for your own use, and you have are rooted phone, install the DroidSansJapanese.ttf font (copy to /system/fonts)
if it's an app you want to distribute, bundle the font in assets, and set your text views to use it

Printing Unicode characters in java

I'm developing a Sinhala-English Unicode translator on Java. When I print a Unicode character in a JTextPane, it only shows a blank box. But when I copy that box to the notepad in windows it shows me the letter.
The problem is that Java not showing the Unicode characters instead windows.
How can I fix this problem ?
It's likely that the font you are using in your JTextPane does not fully support the Unicode range that you are trying to display. Try setting the text area's font to something more Unicode-friendly (see the row labeled "Sinhala (80: 0D80–0DFF)").

how to manage formatting of text when read a save file?

i have a java applet application in which i use rich text area . i write URDU the national language of PAKISTAN. i managed to do so with uni codes. the problem is, when i write urdu in text area and select a font and color for each line it do all of this but when i save this file using UTF-8 encoding and then open it again it shows all text formatted as i choose format of last line.
my requirement is to open file as it is saved. i mean each file should have same formatting as i done before saving.
I'm still suffering with this problem even after bounty can any one help! dated 07-06-2010.
See, when you actually format text using some font and color, it will generate some RTF/HTML code right? You should try to get the RTF/HTML of the text area so that all your formatting can be saved in a file.
Basically all its a text file, so you need to get it with all code right?
Check this link for RTF formatted text saving mechanism.
Java JTextPane RTF Save
Also check HTMLEditorKit for more info.
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/html/HTMLEditorKit.html
thanks.
UTF-8 is an assignment of codes to characters. For convenience a decision was made that the lowest 127 codes are the same in ASCII and UTF-8. For all characters the codes differ.
UTF-8 Fonts have a character map (cmap) which assigned unicode code to their glyphs. There are very few fonts that cover large portions of the unicode range (Arial Unicode and Gentium i know, there are some others), and to get full coverage in a rendering solution, you have to mix fonts.
To be able to display arbitray Unicode texts, you therefore have to create a set of fonts with one as the default font and fallback fonts for the unicode characters that are not contained the default font. Back to Java and your Textpane: If you select a font for a given part of text in your Textpane, this only means that to render the text glyph are used from the selected font. But the text itself is not associated with the font in any means.
So you have two options:
You don't just store the UTF-8 text,
but also information about the
selected font, or
more interesting:
You store the text simply as UTF-8
and apply fonts after loading the
text into your textpanel!

Categories