📄 rasterfont.c
字号:
//*****************************************************************************
//
// rasterfont.c - An 8x8 numeric raster font and a 24x32 raster font.
//
// Copyright (c) 2006-2007 Luminary Micro, Inc. All rights reserved.
//
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. Any use in violation
// of the foregoing restrictions may subject the user to criminal sanctions
// under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 220 of sw01246.
//
//*****************************************************************************
#include "rasterfont.h"
//*****************************************************************************
//
//! \page ui_rasterfont_intro Introduction
//!
//! A 24x32 raster font is used for drawing text on the LCD. In order to
//! reduce the space used by the font, a simple compression scheme is used on
//! the font data. Additionally, a 8x8 raster font with just the ten numbers
//! ("0" through "9") is also provided in an uncompressed form.
//!
//! The compression scheme for the font data treats the thirty-two scan lines
//! of the font glyph as if they were connected side-by-side. Therefore,
//! pixels from the end of one scan line can be combined with pixels from the
//! beginning of the next scan line when compressing. The encoded format of
//! font data is as follows:
//!
//! - A non-zero byte encodes up to 15 consecutive zero pixels followed by up
//! to 15 consecutive one pixels. The upper nibble contains the number of
//! zero pixels and the lower nibble contains the number of one pixels. So,
//! for example, <tt>0x12</tt> means that there is a single zero pixel
//! followed by two one pixels.
//!
//! - A zero byte indicates a literal encoding. The next byte determines the
//! size and type of the literal. The lower seven bits of the next byte
//! specifies the number of bytes in the literal encoding (referred to as N).
//! If the upper bit of the next byte is set, then the third byte is repeated
//! N times. If the upper bit is not set, then the N following bytes are
//! directly copied from the encoded data to the font glyph.
//!
//! The literal encoding method is only valid when the previous number of
//! encoded pixels is a power of eight; in other words, a whole number of bytes
//! must have been previously output so that the literal encoding is directly
//! output without having to shift within bytes. The repeated byte literal
//! encoding is very useful for the several scan lines worth of zero pixels
//! that is present is most of the glyphs. The direct copy literal encoding
//! is useful for highly detailed portions of glyphs that would otherwise
//! become much larger if encoded with the non-zero byte format.
//!
//! As an example, consider the following font glyph (for a non-existant
//! character, and much smaller than 24x32 to make it easier to discuss):
//!
//! \verbatim
//! ....xxxxxxxx....
//! ....xxxxxxxx....
//! ......xxxx......
//! .......xx.......
//! ................
//! ................
//! ................
//! ................
//! \endverbatim
//!
//! The compressed version of this glyph would be as follows, with an
//! explanation of each byte or byte sequence:
//!
//! - 0x48: The first scan line starts with four zero pixels followed by eight
//! one pixels.
//!
//! - 0x88: The first scan line ends with four zero pixels and the second scan
//! starts with four zero pixels, resulting in eight consecutive zero
//! pixels. This is followed by eight one pixels on the second scan
//! line.
//!
//! - 0xa4: Four zero pixels at the end of the second scan line plus six zero
//! pixels at the beginning of the third scan line, followed by four
//! one pixels on the third scan line.
//!
//! - 0xd2: Six zero pixels at the end of the third scan line plus seven zero
//! pixels at the beginning of the fourth scan line, followed by two
//! one pixels on the fourth scan line.
//!
//! - 0x70: Seven zero pixels at the end of the fourth scan line and no one
//! pixels. This brings the number of encoded pixels to sixty-four, a
//! multiple of eight, which allows a literal encoding to follow.
//!
//! - 0x00 0x88 0x00: Eight bytes of zero to encode the final four scan lines
//! of the glyph.
//!
//! This results in an eight byte compressed font glyph, compared to the
//! sixteen bytes required to describe the uncompressed 16x8 array.
//!
//! While being simplistic, this encoding method provides very effective
//! results. Since the font has three or four pixel wide strokes, and the
//! ASCII character set has a small number of strokes per character, the
//! non-zero byte encoding format can effectively encode most occurrences of
//! non-zero pixels and the repeated byte encoding format can effectively
//! encode the large run of zero pixels at the bottom of most glyphs.
//!
//! The compress utility (the source of which is in
//! <tt>ui_micro/compress.c</tt>) contains the uncompressed font data plus the
//! routines to compress it into the format required here. If the font glyphs
//! need to be changed, the uncompressed version can be modified, the program
//! rebuilt, and the output of the program (i.e. the compressed font data) can
//! be pasted into the file containing the raster font. Rebuilding the
//! compress program is as simple as "gcc -o compress compress.c" (or similar
//! for a non-GNU toolchain), using a compiler that produces code that runs on
//! the build machine, not on the Cortex-M3 microcontroller. When run, it will
//! output the compressed font data on \<stdout\> and output any error messages
//! on \<stderr\>.
//!
//! The array containing the compressed raster fonts is contained in
//! <tt>ui_micro/rasterfont.c</tt>, with <tt>ui_micro/rasterfont.h</tt>
//! containing the API definitions for use by the remainder of the application.
//
//*****************************************************************************
//*****************************************************************************
//
//! \defgroup ui_rasterfont_api Definitions
//! @{
//
//*****************************************************************************
//*****************************************************************************
//
//! An array of 8x8 font glyphs for ASCII characters 48 through 57 (i.e. '0'
//! through '9'). This is used for displaying the table position in diagnostic
//! mode.
//
//*****************************************************************************
const unsigned char g_pucFont8x8[] =
{
//
// '0'
//
0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0x00,
//
// '1'
//
0x10, 0x30, 0x50, 0x10, 0x10, 0x10, 0x7c, 0x00,
//
// '2'
//
0x7c, 0x82, 0x02, 0x0c, 0x30, 0x40, 0xfe, 0x00,
//
// '3'
//
0x7c, 0x82, 0x02, 0x1c, 0x02, 0x82, 0x7c, 0x00,
//
// '4'
//
0x82, 0x82, 0x82, 0xfe, 0x02, 0x02, 0x02, 0x00,
//
// '5'
//
0xfe, 0x80, 0x80, 0xfc, 0x02, 0x82, 0x7c, 0x00,
//
// '6'
//
0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c, 0x00,
//
// '7'
//
0x7e, 0x02, 0x04, 0x08, 0x10, 0x10, 0x10, 0x00,
//
// '8'
//
0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c, 0x00,
//
// '9'
//
0x7c, 0x82, 0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00
};
//*****************************************************************************
//
//! An array of 24x32 font glyphs for ASCII characters 32 through 127, plus
//! some additional glyphs the following on-screen elements:
//!
//! - #FONT_CHAR_LMI: Luminary Micro logo
//! - #FONT_CHAR_ARM: ARM logo
//! - #FONT_CHAR_RUN: Run
//! - #FONT_CHAR_Abc: Abc logo
//! - #FONT_CHAR_ABC: ABC logo
//! - #FONT_CHAR_abc: abc logo
//! - #FONT_CHAR_CURSOR: Block cursor
//! - #FONT_CHAR_BACKSPACE: Backspace
//! - #FONT_CHAR_UP: Up arrow
//! - #FONT_CHAR_DEMO1: Demo 1
//! - #FONT_CHAR_DEMO2: Demo 2
//! - #FONT_CHAR_DEMO3: Demo 3
//! - #FONT_CHAR_DEMO4: Demo 4
//! - #FONT_CHAR_DEMO5: Demo 5
//! - #FONT_CHAR_DEMO6: Demo 6
//! - #FONT_CHAR_PEN: Pen
//! - #FONT_CHAR_ROUTER_25: Router, 25 mil
//! - #FONT_CHAR_ROUTER_50: Router, 50 mil
//! - #FONT_CHAR_ROUTER_75: Router, 75 mil
//! - #FONT_CHAR_ROUTER_100: Router, 100 mil
//
//*****************************************************************************
const unsigned char * const g_ppucFont24x32[] =
{
//
// ' '
//
(unsigned char *)
"\003\000\340\000",
//
// '!'
//
(unsigned char *)
"\060\243\360\143\360\143\360\143\360\143\360\143\360\143\360\143\360\143"
"\360\143\360\143\360\143\360\161\360\201\360\201\360\201\360\201\360\201"
"\100\000\210\000\043\360\143\360\143\060\000\234\000",
//
// '"'
//
(unsigned char *)
"\025\163\063\363\063\363\063\363\063\363\063\363\063\363\063\360\021\121"
"\020\000\311\000",
//
// '#'
//
(unsigned char *)
"\062\223\103\343\103\324\063\343\103\343\103\343\103\237\002\177\002\177"
"\002\263\103\343\103\324\064\323\103\343\103\277\002\177\002\177\002\223"
"\103\343\103\343\103\343\064\323\103\343\103\040\000\234\000",
//
// '$'
//
(unsigned char *)
"\073\226\360\032\334\264\042\043\263\062\063\243\062\063\243\062\360\023"
"\062\360\044\022\360\047\360\071\360\070\360\050\360\022\044\360\022\064"
"\362\103\203\102\103\203\102\103\204\062\064\224\042\044\274\332\360\027"
"\360\102\060\000\231\000",
//
// '%'
//
(unsigned char *)
"\103\064\223\150\143\163\043\143\143\103\103\163\103\103\163\103\063\203"
"\103\063\203\103\043\223\103\043\243\043\043\267\063\324\063\064\343\030"
"\263\043\043\244\023\103\223\043\103\204\043\103\203\063\103\163\103\103"
"\163\103\103\143\143\043\163\150\143\224\100\000\233\000",
//
// '&'
//
(unsigned char *)
"\064\225\360\070\371\344\064\323\123\323\123\323\123\343\063\360\027\360"
"\046\360\046\360\047\360\024\043\343\123\063\143\163\023\163\163\023\163"
"\205\203\223\224\204\224\127\234\023\232\043\266\121\100\000\233\000",
//
// '\''
//
(unsigned char *)
"\023\243\360\143\360\143\360\143\360\143\360\143\360\143\360\161\100\000"
"\311\000",
//
// '('
//
(unsigned char *)
"\074\342\360\142\360\142\360\143\360\142\360\143\360\142\360\143\360\143"
"\360\143\360\123\360\143\360\143\360\143\360\143\360\143\360\143\360\143"
"\360\143\360\163\360\143\360\143\360\163\360\143\360\162\360\163\360\162"
"\360\202\360\202\000\212\000",
//
// ')'
//
(unsigned char *)
"\075\202\360\202\360\202\360\163\360\162\360\163\360\162\360\163\360\143"
"\360\143\360\163\360\143\360\143\360\143\360\143\360\143\360\143\360\143"
"\360\143\360\123\360\143\360\143\360\123\360\143\360\142\360\143\360\142"
"\360\142\360\142\140\000\212\000",
//
// '*'
//
(unsigned char *)
"\032\262\360\162\360\162\360\063\022\023\352\360\026\360\104\360\106\360"
"\043\043\360\041\101\020\000\303\000",
//
// '+'
//
(unsigned char *)
"\040\000\215\000\043\360\143\360\143\360\143\360\143\360\143\377\237\237"
"\363\360\143\360\143\360\143\360\143\360\143\060\000\250\000",
//
// ','
//
(unsigned char *)
"\026\000\275\000\043\360\143\360\143\360\162\360\162\360\162\360\161\360"
"\162\100\000\215\000",
//
// '-'
//
(unsigned char *)
"\011\000\247\000\171\371\371\000\261\000",
//
// '.'
//
(unsigned char *)
"\014\000\275\000\043\360\143\360\143\060\000\234\000",
//
// '/'
//
(unsigned char *)
"\061\342\360\162\360\142\360\162\360\162\360\142\360\162\360\162\360\143"
"\360\142\360\162\360\143\360\142\360\162\360\162\360\142\360\162\360\162"
"\360\142\360\162\360\162\360\143\360\142\160\000\234\000",
//
// '0'
//
(unsigned char *)
"\056\226\360\032\334\265\105\243\203\243\203\224\204\203\243\203\243\203"
"\243\203\243\203\243\203\243\203\243\203\243\203\243\203\243\223\203\243"
"\203\245\105\274\332\360\026\020\000\234\000",
//
// '1'
//
(unsigned char *)
"\060\342\360\143\360\124\360\105\360\047\360\030\364\043\362\103\360\143"
"\360\143\360\143\360\143\360\143\360\143\360\143\360\143\360\143\360\143"
"\360\143\360\143\360\143\360\143\360\143\000\234\000",
//
// '2'
//
(unsigned char *)
"\055\207\373\315\264\124\243\204\223\223\360\143\360\143\360\143\360\123"
"\360\143\360\123\360\123\360\123\360\123\360\104\360\104\360\103\360\123"
"\360\123\360\156\237\237\120\000\233\000",
//
// '3'
//
(unsigned char *)
"\056\226\360\032\334\264\124\244\164\223\223\360\143\360\124\360\104\360"
"\027\360\047\360\050\360\144\360\144\360\143\360\143\360\143\203\243\204"
"\203\244\144\274\332\360\026\020\000\234\000",
//
// '4'
//
(unsigned char *)
"\064\362\360\143\360\124\360\105\360\105\360\066\360\043\023\360\024\023"
"\360\023\043\363\063\343\103\343\103\323\123\303\143\263\163\277\001\217"
"\001\217\001\360\063\360\143\360\143\360\143\360\143\160\000\233\000",
//
// '5'
//
(unsigned char *)
"\053\155\275\275\243\360\143\360\143\360\143\360\143\045\342\031\276\245"
"\144\223\223\360\163\360\143\360\143\360\143\360\143\203\224\204\203\244"
"\144\255\332\367\020\000\234\000",
//
// '6'
//
(unsigned char *)
"\055\246\360\032\334\264\124\244\164\223\223\223\360\123\360\143\066\303"
"\031\276\246\124\224\204\203\243\203\243\203\243\203\243\223\223\223\203"
"\264\124\274\332\360\026\020\000\234\000",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -