New line detection is mechanism that allows control over text width. New line character indicates that everything that appears after it should be printed out in next line. Text provider sometimes wants to be able to manually decide where the next line should be added, in order to create nicely formatted text. Still, automatic line detection implementation is needed, so texts of different width will be printed out properly (i.e. only on provided text area) on screens of different size and resolution.
In order to implement methods that allow new line detection with respect of user defined paragraphs new String variable is needed to hold formatted text. When new text is being set applications parse through it checking each character. Using information provided by font mapping file application width of each character in the string that is supposed to be printed out, can be counted. If it reaches character which width, added to previously considered chars width, exceeds maximum width of text area for given screen it needs to put an extra new line character in this place. In order to make texts readable closes white character should be found among previously parsed characters and replaced with a new line sign. After that width of whole text should be rested and the process should continue till end of the string. Also, reaching new line indicator character in text that is being parsed means that new line should be created in similar manner, and parsed line width should be reset. As a result application will get text with new line signs placed instead of white signs where needed, which can be used later to create lines array.
The same method can be used when system fonts are used in application but the source of the information won’t be font mapping file, but java’s system Font class.
Thursday, 20 November 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment