How do I control text formatting when reading a save file?

I have a java applet application in which I am using a rich text area. I write URDU the national language PAKISTAN. I managed to do this using uni codes. the problem is when I write urdu in the text area and select a font and color for each line, it does all of this, but when I save this file using UTF-8 encoding and then open it again, it displays all the text. formatted as I choose the format of the last line.

My requirement is to open the file as it is saved. I mean, each file should have the same formatting as I did before saving.

I still have this problem even after being generous can help anyone! from 07-06-2010.

+2


a source to share


2 answers


See, when you actually format the text using some font and color, will it generate some RTF / HTML code correctly? You should try to get the RTF / HTML of the textarea so that all your formatting can be saved in the file.

Basically, it's all a text file, so you need to get it with all the code?

Check this link for a mechanism to save text in RTF format.

Saving Java JTextPane RTF



Also check out HTMLEditorKit for more information.

http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/text/html/HTMLEditorKit.html

thanks.

+1


a source


UTF-8 is all about assigning codes to characters. For convenience, it was decided that the lowest 127 codes are the same in ASCII and UTF-8. The codes are different for all characters.

UTF-8 fonts have a character map (cmap) that assigns a Unicode character code to their glyphs. There are very few fonts that cover large parts of the Unicode range (Arial Unicode and Gentium, I know there are others), and to get full coverage in rendering you need to mix fonts.

To be able to display Unicode text files, you need to create a font set with one default font and fallback fonts for Unicode characters that do not contain the default font. Go back to Java and your Textpane: if you select a font for a specific portion of the text in your text area, it means the text glyphs are used to render from the selected font. But the text itself has nothing to do with the font.



So, you have two options:

  • You are not just storing the UTF-8 text, but information about the selected font or
  • more interesting: you save the text simply as UTF-8 and apply the fonts after loading the text into the text panel!
0


a source







All Articles