2014년 12월 9일 화요일

Help in displaying Unicode text from a Unicode text file


I am trying to develop an AI2 app where it can read an unicode text file and display it on the screen.
I prepared the unicode text by saving from MS Word in 'Unicode' text form. I also opened up in word and it recognizes it as a unicode text.
However, when I set my textBox text to that was read from the file (using File component), many characters are not showing right.
I tried the font style of the textbox to sans, sans-serif, mono-style, etc, but all shows different different funny characters. 
Wondering if any one can help me in the right direction.
I am attaching the unicode.txt file.


--
I suspect your text file might not be in UTF-8, do not use the Unicode setting in Notepad..   I think that will work with the File component but can not check that now.

What you can do immediately  is just highlight the text, then drag and drop it on to a blank text box (like the one at the top of the image.

 If you do that, your text in a label will be identical to the text in the Text box if you connect     Label1.text   to    the Text box.

Does that give you the correct characters?     I'll check with the File component later and make sure UTF-8 is the issue


Edit:   Are you coding using WIFI or the emulator.   The emulator does not support some of the characters, so you get 'funny' characters replacing the characters you desire.
However, running your file on my device, I get the correct text.   Please try running your code on your device.  Do the correct characters show up?

--
Thank you for the response..
I tried the idea you gave.. exactly.
I attached a snap shot of my try..
But it is still displaying some square characters. Also I tried the font of the textbox to serif, San Serif, etc and the results varied but nothing is perfect. 
After more investigation I found out that the unicode characters I have can be displayed perfectly only by 'Balaram' font. But the serious limitation is that in AI2 I do not know how to use any custom font other than the ones supported.
It will be very helpful if you can suggest a way to use a custom font for the textbox or label in the AI2.



--
@Raj .... send me the text in your example  "anarpita .....     just a few lines, some containing the incorrect box character when displayed in the label.   I'll try the text on my device.    It appears from your screen capture you are trying this one an emulator?  That is what you are showing in the image you posted.

I will say this again, I think the reason you see the 'box' is  the text will NOT display properly in the emulator .. because the emulator may not have the required text font installed on your PC (or the emulator does not have access to it).   A device can only display text  properly if the correct fonts are present and the font might be on your phone or tablet and might display properly there.

1)   Please send the text here .... just post it here ...not in blocks. I will try the text on my Android. I hope there will be no 'blocks' on my tablet.
2)  Please try running that block of code on YOUR Android, not in the emulator and see what happens.

This is  what Google says about the language fonts available on Android devices:  http://developer.android.com/training/basics/supporting-devices/languages.html   The key phrase is "Android loads the appropriate resources according to the locale settings of the device at run time"

I suspect the code may display properly in your device and possibly both devices.    Do you want to try?  

--
Thank you for helping me out...
I tried on my Android before and it also displayed the same.. But I am going to try downloading the fonts needed. 
I am not sure what should be the 'locale' to set on the Android when using the those unicode fonts.
While I am going to try on an Android phone, here is the text below as you have suggested.
THANK YOU!

anarpita-carīṁ cirāt karuṇayāvatīrṇaḥ kalau
samarpayitum unnatojjvala-rasāṁ sva-bhakti-śriyam
hariḥ puraṭa-sundara-dyuti-kadamba sandīpitaḥ
sadā hṛdaya-kandare sphuratu vaḥ śacī-nandanaḥ (1)
Śrīla Rūpa Gosvāmī’s Śri Vidagdha-mādhava (1st act, 2nd verse)
Śrī Caitanya-caritāmṛta (Ādi-līlā 1.4)

May Śrī Śacīnandana Gaurahari, resplendent with the radiance of molten gold, be forever manifest within the innermost core of your heart. He has descended in the age of Kali out of causeless mercy to bestow that which had not been revealed for millions of eons—unnatojjvala-rasa, the most elevated, brilliant devotional service in paramour love.

-- Raj,  here are two images, the lower image is on the emulator.  As expected, some letters do not reproduce.  The second image (at the top) is from my Tablet.   I think it reproduces the text properly.


I'm in the USA and the OS version is 4.2.2.  What you see might be OS dependent.    Possibly loading additional fonts may help you to get your app to display properly.

--
Wow! Fantastic!
Thank you Steve!

My Android version is 4.1.1 (way old!) and is so nice that it works on 4.2.2 the one you have. 
I am also in USA. I will upgrade the os version or install the custom font. 
I heard that the calibre font displays these characters nicely and in fact the unicode txt file I sent earlier was in that font.

--

댓글 없음:

댓글 쓰기