How to use Dot Matrix words in low-level Interface drawing in JavaMe Development
JavaMe development of low-level interface drawing how to carry out latticework, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
[problem description] JavaMe comes with only three fonts: Font.SIZE_SMALL, Font.SIZE_MEDIA and Font.SIZE_LARGE, and the so-called Font.SIZE_LARGE is not very large. What if I want to draw fonts of other font sizes? Using the low-level interface Canvas to draw lattice words is a good choice.
[font tool]
Xiaoqi Studio
Mode: from left to right, top to bottom, horizontal 8 o'clock, left high position.
[analysis]
The so-called "dot matrix word" means that the text is made up of dot matrix. Dot matrix words have two basic properties, namely, width and height. Let's first look at an example:
As shown in figure 1, Asc5x8 represents a dot matrix word set with a width of 5 and a height of 8. A chartype character can represent 8 bits. The modeling tool actually uses binary "1" to represent the text of the lattice. Use the binary "0" to represent a non-literal blank block. With Asc5x8's "!" Take this as an example to explain:
0x20rec 0x20rec 0x20rec 0x20jr 0x00rec 0x20pr 0x00, / / -!-
The corresponding lattice is:
00100000
00100000
00100000
00100000
00100000
00000000
00100000
00000000
Notice that if you replace "1" with a pixel display and "0" with a blank block. Happens to be displayed as a "!" No. The width is 5, so one byte is fine. If the width exceeds one byte, how do you calculate how many bytes are required to represent the width? The principle is that the representation of the width must be a multiple of bytes. If the width is 9, then it is more than one byte, so it is represented by 2 bytes.
The bytes required for the summary width are calculated as follows:
N = (width-1) / 831
Width in Asc5x8 is 5. 5.
So how to calculate the height? In fact, the height does not need to be calculated, but is completed by the modeling software.
After understanding the above principle, it is very simple. Look at the code.
[code list]
Package com.token.view.components; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.game.GameCanvas Public class CustomFont {public final char font24x48[][] = // ASCII {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //-- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -!- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00, 0x00,0x78,0x00,0x00,0x78,0x00,0x00,0x78, 0x00,0x00,0x78,0x00,0x00,0x78,0x00,0x00, 0x78,0x00,0x00,0x78,0x00,0x00,0x78,0x00, 0x00,0x78,0x00,0x00,0x78,0x00,0x00,0x30, 0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00, 0x30,0x00,0x00,0x30,0x00,0x00,0x30,0x00, 0x00,0x30,0x00,0x00,0x30,0x00,0x00,0x30, 0x00,0x00,0x30,0x00,0x00,0x30,0x00,0x00, 0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x70,0x00,0x00,0xF8,0x00,0x00, 0xF8,0x00,0x00,0xF8,0x00,0x00,0x70,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // -"- 0x00,0x00,0xC0,0xC0,0x01,0xE1,0xE0,0x03, 0xE3,0xE0,0x03,0xC3,0xC0,0x07,0x87,0x80, 0x07,0x07,0x00,0x0E,0x0E,0x00,0x0C,0x0C, 0x00,0x18,0x18,0x00,0x10,0x10,0x00,0x20, 0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},... {0x07,0x80,0x00,0x1F,0xC0,0x00,0x10,0xE0, // -- 0x04,0x20,0x70,0x04,0x20,0x38,0x08,0x40, 0x1C, 0x08,0x40,0x0F,0x10,0x00,0x07,0xF0, 0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}} Public CustomFont () {} public void drawmat (GameCanvas canvas, Graphics g, char mat [], int w, int h, int x, int y, int color) {int iLGY, int y, int color) {int iLecture jpimg kmai n; n = (wmur1) / 8q1; for (jumb0; j)