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, 15 December 2008
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
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.
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.
Labels:
documentation,
new line detection,
scrolling,
text,
textBox
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.
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.
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.
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.
Wednesday, 19 November 2008
TextBox
Since text area is always limited and has very specific boundaries within application screen it’s easy to define an instance of text box element – an area inside which given text appears. Text box main features are its width and height, because text placed in given text box is not allowed to appear outside of it (see provided image for reference). Knowing height and width of each character printed out in textbox a general set of rules for text placement within a box can be created. While considering TextBox as a class, developer needs to think about main features that should be provided for game designer: positioning of text box on the screen, positioning of the text inside text box, smart new line detection, meaning both automatic detection and user defined new paragraph detection, smart text scrolling, and text scrolling indicators, text box look and feel parameters, meaning background colour, text area background colour, border colour, scrolling indicators style and text font.

Text Box diagram - simple image showing the idea implemented in mobilePack.

Text Box diagram - simple image showing the idea implemented in mobilePack.
Progress info
GameTextBox class and new line detection mechanism were added. Some of text management mechanics were covered in new version of project document.
There is 0.0.4 version of project documentation avaliable here.
There is 0.0.4 version of project documentation avaliable here.
Project info
MobilePack is a j2me project that is suppsed to provied both sources and information for any developer starting to work on java mobile applications, especially games. It contains a documentation that covers all aspects of game creation and set of packages of classes usefull when creating a game. All sources are designed and impelemented by me, based on my expirience as java games developer. The final product will be a set of game classess, a pdf document and a sample game showing implemented mechanics.
Purpose of this blog is to show progress of works, and publish some of the materials from documentations so they will be easily accesible by everybody. Current documentation can be find in development section of my home webpage.
Purpose of this blog is to show progress of works, and publish some of the materials from documentations so they will be easily accesible by everybody. Current documentation can be find in development section of my home webpage.
Subscribe to:
Posts (Atom)
