Monday, 15 December 2008

Font Manager and mapping files

Font's used in mobile applications are stored in images saved in format that supports transparency (.png, .gif). After identifying a character that needed to be printed out, application needs to locate a set of pixels that is a graphical representation of given character.
Additional mapping file provided with a font image, that contains list of all mapped characters, their sizes and positions in the image file allows application quick access to all information. Font Manager is needed to give developer chance to use any font image to generate mapping file, and use both of those sources in the mobile application
Implementation of fontManager implementation is a simple swing based GUI application, that allows user to generate mapping file for given font image file.
It allows to load image, zoom it and scroll through it acordingly, separate each sign by border that determines it's size and position in the image, information that is later on stored in generated .map file.

First phase of implementation - application that allows user to load,display and scroll through image is finished.

Monday, 24 November 2008

Graphical font implementation

Firs approach of graphical font implementation is ready and working. FontMapping class derived from MappingClass utility class, Font class responsible for each character display and simple Character class with all parameters needed for proper display of char were added. The class structure and proper documentation will be presented after full implementation will be provided.

Friday, 21 November 2008

Text "pseudo-class-diagram"

Simplified class diagram of text classes created so far

Classes used with TextBox

In code representation of lines Vector collection should be placed in separate class. TextArray instance which is strictly connected with used text box object, has parse method that creates Vector container of all lines, and getLine(int i) method that gives text box access to needed String variables. It’s created when text box is created, and right after that first parsing is called, so the array is ready to be printed out whenever text box is ready for it. Text box, object that is responsible only for display will simply get each line of its text array and print it out on the screen.

To allow text scrolling another class is needed. Scrolling class, which is also tightly connected with given text box, is responsible for all calculations connected with scrolling elements. From text box point of view its purpose is to give indexes of first and last line displayed inside text box. Scrolling class deals with all height and index moving calculations and produces just those two numbers that are used by textbox to get proper lines from TextArray.

Thursday, 20 November 2008

New line separator

It's not good practice to rely on "\n" as a new line indicator while parsing input coming from resources file. The problem is in the fact that not all systems are using it as a line separator. You may end up with white spaces at the end of input lines, or even missing other new line indicators and not counting them in at all. Deciding to use one, easily recognizable indicator for all files is the best thing to deal with this problem, it gives project consistency and it's easy to recognize and use by other developers. And what's most important it will work with files created on different machines with different OS.

MobilePack uses "|" character as line separator.

Text scrolling inside text box

New line detection mechanics described before can be easily used in class implementation to perform first text formatting, and prepare new version of String containing text – one with new line indicators (“|”) placed at end of each displayed line. But to make really flexible tool for text management some kind of indexed array of lines should be prepared to allow user determine order and manner in which each line is shown.
Having parsed String containing text with added new line indicators in proper places an array like that can be easily constructed. Another loop on all characters is needed, and this time when application meets new line indicator it should create new instance of String – a line, starting where the previous line ended. This String can be added than to a Vector collection object, which will keep all lines nicely indexed and in order. Having such a Vector representation of all lines in texts allows implementation of scrolling mechanism.
Its main idea is simple – determine how many lines can be displayed in a text box at one time, check whether given text is too long, if it is, scrolling will be needed. Display first n lines that can fit into text area, and set currentStartLine indicator to point at first line. If navigation button action is detected (for example DOWN), increment currentStartLine indicator and display lines from currentStartLine indicator to currentStartLine indicator + n.

New line detection

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.