Allowing Hindi fonts in html text area - java

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

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.

getting square emoticons instead of actual emoticons

I am working a java chat application and I am adding emoticons by replacing the emoticon shortcut, like :) ,with ◕‿◕ . Its not an image that I am replacing it with but simple text. Now the problem that I am facing is that sometimes I get just Square boxes instead of the actual thing that I want. I am making these images/texts in MS Word by converting the unicode to the actual image. I am also using various online resources to get these images/text.
Can anyone tell me how to get rid of the boxes and get the actual text.
My encoding is in UTF-8 and my font is also set to monospaced.
Your unicode-character is probably not supported by your font. Either the font implements the character as a box, or the operating system / font-renderer draws a box instead of the glyph.
I would say the Font used in your application just cannot show some chars. Find one which font really can and use it there.
Font has boolean canDisplay(char c) method which you can use.
See also the doc about font

How to use images in SWT Text field?

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

English characters don't show up when entering text with Urdu fonts in Swing

This is similar to my own previous question, but that solution didn't work here.
As mentioned in the previous question, I'm working on a cross platform(Windows/Ubuntu) application that has to transliterate English into one of several official Indian languages. The application has a custom input method, and typing in English and pressing space will transliterate the typed text into the specific local language. Urdu is different from the others in being right to left, like Arabic/Hebrew.
I managed to find an open licensed Urdu font that has both English and Urdu glyphs, but when I type characters in English, nothing shows up.
I don't understand whether it's a font painting issue, or related to the input method. So far, if I disable the custom input method (InputMethod.dispatchEvent() ) for this language, I am able to see the English text (but of course no transliteration takes place).
My findings:
Change font to one of Windows' built in Arabic fonts - same result.
Instead of using ComponentOrientation to align text in the text field, I used setHorizontalAlignment for when the locale is Urdu. Same result.
Decompiled the JDK's default input method provider on Windows (sun.awt.windows.WInputMethod). Here I see the dispatchEvent() makes a native call to the OS for handling IME. I can't do that here.
Found a custom IM for Hebrew - my version of dispatchEvent() is essentially the same.
Stepped through code for JTextField in Eclipse - wasn't able to find anything in the AbstractDocument and subclasses. The AbstractDocument.insertUpdate() method checks for and updates bidirectional text input, but there wasn't anything else significant.
I'm unable to understand what happens after the dispatchEvent() call. The characters are being registered, i.e. the transliteration engine is able to detect the typed characters and process them, but they just don't show up on screen.
Workaround
If I let the text field's orientation be as it is for regular left to right languages, I can see the English text. However, this would not be acceptable to an Urdu speaking user.
Can someone point me in the right direction?
I set the locale to ur_IN.
Sadly, ur_IN is not among the supported locales; I only see en_IN and hi_IN. In the example cited, I used the following code to get the image below:
spinner.setLocale(new Locale("hi", "IN"));

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