Skip to content

Commit 101219d

Browse files
committed
Updated font names, char index code
1 parent cd71e48 commit 101219d

35 files changed

Lines changed: 5226 additions & 5180 deletions

README.md

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,39 @@ Developed on Espressif ESP-IDF toolchain, debugged seperately on Eclipse CDT.
66

77
## Fonts
88

9-
| Num | Description | Size | Norm |
10-
|-----|-------------|------|------|
11-
|0 | bitocra |4x7 |ascii|
12-
|1 | bitocra |6x11 |iso8859 1|
13-
|2 | bitocra |7x13 |iso8859 1|
14-
|3 | glcd |5x7|
15-
|4 | roboto |8pt|
16-
|5 | roboto |10pt|
17-
|6 | tahoma |10x11 |
18-
|7 | terminus |6x12 |iso8859 1|
19-
|8 | terminus |8x14 |iso8859 1|
20-
|9 | terminus |10x18 |iso8859 1|
21-
|10 | terminus |11x22 |iso8859 1|
22-
|11 | terminus |12x24 |iso8859 1|
23-
|12 | terminus |14x28 |iso8859 1|
24-
|13 | terminus |16x32 |iso8859 1|
25-
|14 | terminus bold |8x14 |iso8859 1|
26-
|15 | terminus bold |10x18 |iso8859 1|
27-
|16 | terminus bold |11x22 |iso8859 1|
28-
|17 | terminus bold |12x24 |iso8859 1|
29-
|18 | terminus bold |14x28 |iso8859 1|
30-
|19 | terminus bold |16x32 |iso8859 1|
31-
9+
The fonts are grouped by character set, with the custom _GLCD5x7_ font always included and first.
10+
11+
The character sets to be compiled into the library are defined in _fonts.h_. Depending on the active charactersets, the index of a particular font may change. If all are chosen, these are the available fonts:
12+
13+
| Num | Description | Size | Char Set |
14+
|-----|-------------|------|----------|
15+
|0| glcd_5x7|5x7|
16+
|1| bitocra_4x7_ascii|4x7|ascii|
17+
|2| roboto_8pt_ascii|8x11|ascii|
18+
|3| roboto_10pt_ascii|11x14|ascii|
19+
|4| tahoma_8pt_ascii|10x11|ascii|
20+
|5| bitocra_6x11_iso8859_1|6x11|iso8859_1|
21+
|6| bitocra_7x13_iso8859_1|7x13|iso8859_1|
22+
|7| terminus_6x12_iso8859_1|6x12|iso8859_1|
23+
|8| terminus_8x14_iso8859_1|8x14|iso8859_1|
24+
|9| terminus_10x18_iso8859_1|10x18|iso8859_1|
25+
|10| terminus_11x22_iso8859_1|11x22|iso8859_1|
26+
|11| terminus_12x24_iso8859_1|12x24|iso8859_1|
27+
|12| terminus_14x28_iso8859_1|14x28|iso8859_1|
28+
|13| terminus_16x32_iso8859_1|16x32|iso8859_1|
29+
|14| terminus_bold_8x14_iso8859_1|8x14|iso8859_1|
30+
|15| terminus_bold_10x18_iso8859_1|10x18|iso8859_1|
31+
|16| terminus_bold_11x22_iso8859_1|11x22|iso8859_1|
32+
|17| terminus_bold_12x24_iso8859_1|12x24|iso8859_1|
33+
|18| terminus_bold_14x28_iso8859_1|14x28|iso8859_1|
34+
|19| terminus_bold_16x32_iso8859_1|16x32|iso8859_1|
35+
|20| terminus_6x12_koi8_r|6x12|koi8_r|
36+
|21| terminus_8x14_koi8_r|8x14|koi8_r|
37+
|22| terminus_14x28_koi8_r|14x28|koi8_r|
38+
|23| terminus_16x32_koi8_r|16x32|koi8_r|
39+
|24| terminus_bold_8x14_koi8_r|8x14|koi8_r|
40+
|25| terminus_bold_14x28_koi8_r|14x28|koi8_r|
41+
|26| terminus_bold_16x32_koi8_r|16x32|koi8_r|
3242

3343
## Features
3444

@@ -65,8 +75,6 @@ In paged display bitmap such as that in the SD1306, to rasterize a 5-bit high ch
6575
uint8_t y = 21;
6676
uint8_t page = y / 8;
6777
std::string s = "@test";
68-
69-
7078
7179
7280
/*
@@ -91,7 +99,6 @@ In paged display bitmap such as that in the SD1306, to rasterize a 5-bit high ch
9199
*oled++ |= *d++;
92100
}
93101
}
94-
95102
```
96103

97104
Integration and use can be seen in [ESP32-SSD1306-Driver](https://github.com/technosf/ESP32-SSD1306-Driver)
@@ -104,7 +111,7 @@ Thinking about what could be added:
104111

105112
## Versions
106113

107-
* _1.0.0_ First release with 20 fonts, verticle and horizontal rasterization, position offset
114+
* _1.0.0_ First release with 27 fonts, verticle and horizontal rasterization, position offset
108115
* _0.1.0_ Initial commit and pre-release
109116

110117

@@ -114,7 +121,6 @@ This repo is a fork of [Baoshi's ESP-I2C-OLED repo](https://github.com/baoshi/ES
114121

115122
Looking through the various forks of the SSD1306 and similar drivers, you find plenty of font bitmaps you can you, such as the set from [ubirch](https://github.com/ubirch/esp32-i2c-ssd1306-oled) I've also borrowed here.
116123

117-
118124
## License
119125

120126
Raster-Font - Copyright 2019 technosf [http://github.com/technosf]

main/Font_Manager.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
See the License for the specific language governing permissions and limitations under the License.
1717
*/
1818

19+
#include <stdio.h>
20+
1921
#include "Font_Manager.h"
2022

21-
Font_Manager::Font_Manager( uint8_t fontindex, Raster raster ) : m_raster { raster}
23+
Font_Manager::Font_Manager( uint8_t fontindex, Raster raster )
2224
{
2325
m_font = fonts [ fontindex ]; // Err out if out of bounds
24-
// m_raster = raster;
26+
m_raster = raster;
2527
}
2628

2729
uint8_t Font_Manager::fontcount()
@@ -50,6 +52,7 @@ uint8_t Font_Manager::font_height()
5052
return ( m_font->height );
5153
}
5254

55+
5356
uint8_t Font_Manager::font_c()
5457
{
5558
return ( m_font->c );
@@ -67,31 +70,36 @@ uint16_t Font_Manager::measure_string( std::string str )
6770
c = *i;
6871
// we always have space in the font set
6972
if ( ( c < m_font->char_start ) || ( c > m_font->char_end ) ) c = ' ';
70-
c = c - m_font->char_start; // c now become index to tables
73+
c = c - m_font->char_start;
7174
w += m_font->char_descriptors [ c ].width;
7275
if ( *i ) w += m_font->c;
7376
}
7477

78+
7579
return w;
7680
}
7781

78-
Font_Manager::bitmap Font_Manager::rasterize( std::string str, uint16_t offset )
82+
Font_Manager::bitmap Font_Manager::rasterize( std::string str, uint16_t bitoffset )
7983
{
80-
bitmap scan( m_raster, measure_string( str ), m_font->height, offset );
84+
bitmap scan( m_raster, measure_string( str ), m_font->height, bitoffset );
8185

8286
for ( char& c : str )
8387
{
88+
if ( ( c < m_font->char_start ) || ( c > m_font->char_end ) ) c = ' ';
89+
c = c - m_font->char_start;
8490
raster( c, scan );
8591
};
8692

8793
return scan;
8894
}
8995

90-
Font_Manager::bitmap Font_Manager::rasterize( unsigned char c, uint16_t offset )
96+
Font_Manager::bitmap Font_Manager::rasterize( unsigned char c, uint16_t bitoffset )
9197
{
9298
if ( ( c < m_font->char_start ) || ( c > m_font->char_end ) ) c = ' ';
99+
c = c - m_font->char_start;
100+
101+
bitmap scan( m_raster, m_font->char_descriptors [ c ].width, m_font->height, bitoffset );
93102

94-
bitmap scan( m_raster, m_font->char_descriptors [ c ].width, m_font->height, offset );
95103
raster( c, scan );
96104
return scan;
97105
}
@@ -102,14 +110,20 @@ void Font_Manager::raster( unsigned char c, bitmap& bm )
102110
const uint8_t * bitmap = m_font->bitmap + char_desc.offset; // Pointer to L-R bitmap
103111
uint8_t horizontal_read_bytes = 1 + ( ( char_desc.width - 1 ) / 8 ); // Bytes to read for horizontal
104112
uint8_t* data; // Data byte placement
105-
uint8_t linecoefficient { 1 };
106-
if ( bm.raster == TBLR ) linecoefficient = 8; // For vertical raster, each line is 1/8th shift
107-
uint8_t shiftright = bm.xpoint % 8; // Number of bits to shift right on placement
113+
uint8_t shiftright { 0 };
114+
uint8_t linecoefficient { 8 }; // TBLR default
115+
uint8_t rowcoefficient { 1 }; // TBLR default
116+
if ( bm.raster == LRTB )
117+
{
118+
shiftright = bm.xpoint % 8; // Number of bits to shift right on placement
119+
linecoefficient = 1; // For vertical raster, each line is 1/8th shift
120+
rowcoefficient = 8;
121+
}
108122

109123
for ( uint8_t line = 0; line < m_font->height; line++ )
110124
{
111125
uint16_t rowdataoffset = bm.width * ( ( line + bm.heightoffset ) / linecoefficient );
112-
data = bm.data + rowdataoffset + ( bm.xpoint / 8 ); // address plus lines plus offset
126+
data = bm.data + rowdataoffset + ( bm.xpoint / rowcoefficient ); // address plus lines plus offset
113127

114128
for ( uint8_t chunk = 0; chunk < horizontal_read_bytes; chunk++ )
115129
/*

main/app_main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ void raster( char c, Font_Manager& fm, uint8_t o )
3737
printf( "0x%02x ", *d );
3838
d++;
3939
}
40-
//printf( "\n" );
4140
}
4241
printf( "\n" );
4342

main/fonts.c

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
* Created on: Jan 3, 2015
55
* Author: Baoshi
66
*/
7-
//#include "esp_common.h"
7+
88
#include "fonts.h"
9+
910
#include "font_bitocra_4x7_ascii.h"
1011
#include "font_bitocra_6x11_iso8859_1.h"
1112
#include "font_bitocra_7x13_iso8859_1.h"
1213
#include "font_glcd_5x7.h"
13-
#include "font_roboto_8pt.h"
14-
#include "font_roboto_10pt.h"
15-
#include "font_tahoma_8pt.h"
14+
#include "font_roboto_8pt_ascii.h"
15+
#include "font_roboto_10pt_ascii.h"
16+
#include "font_tahoma_8pt_ascii.h"
1617
#include "font_terminus_6x12_iso8859_1.h"
1718
#include "font_terminus_8x14_iso8859_1.h"
1819
#include "font_terminus_10x18_iso8859_1.h"
@@ -34,20 +35,48 @@
3435
#include "font_terminus_bold_14x28_koi8_r.h"
3536
#include "font_terminus_bold_16x32_koi8_r.h"
3637

37-
const font_info_t * fonts [ NUM_FONTS ] = { &_fonts_bitocra_4x7_ascii_info, &_fonts_bitocra_6x11_iso8859_1_info,
38-
&_fonts_bitocra_7x13_iso8859_1_info, &_fonts_glcd_5x7_info, &_fonts_roboto_8pt_info, &_fonts_roboto_10pt_info,
39-
&_font_tahoma_8pt_info, &_fonts_terminus_6x12_iso8859_1_info, &_fonts_terminus_8x14_iso8859_1_info,
40-
&_fonts_terminus_10x18_iso8859_1_info, &_fonts_terminus_11x22_iso8859_1_info,
41-
&_fonts_terminus_12x24_iso8859_1_info, &_fonts_terminus_14x28_iso8859_1_info,
42-
&_fonts_terminus_16x32_iso8859_1_info, &_fonts_terminus_bold_8x14_iso8859_1_info,
43-
&_fonts_terminus_bold_10x18_iso8859_1_info, &_fonts_terminus_bold_11x22_iso8859_1_info,
44-
&_fonts_terminus_bold_12x24_iso8859_1_info, &_fonts_terminus_bold_14x28_iso8859_1_info,
38+
const font_info_t * fonts [ NUM_FONTS ] = {
39+
&_fonts_glcd_5x7_info,
40+
#ifdef FONTS_ASCII
41+
#define NUM_FONTS NUM_FONTS+4
42+
/*
43+
* ascii fonts
44+
*/
45+
&_fonts_bitocra_4x7_ascii_info,
46+
&_fonts_roboto_8pt_ascii_info,
47+
&_fonts_roboto_10pt_ascii_info,
48+
&_font_tahoma_8pt_ascii_info,
49+
#endif
50+
#ifdef FONTS_ISO8859
51+
/*
52+
* iso8859_1 fonts
53+
*/
54+
&_fonts_bitocra_6x11_iso8859_1_info,
55+
&_fonts_bitocra_7x13_iso8859_1_info,
56+
&_fonts_terminus_6x12_iso8859_1_info,
57+
&_fonts_terminus_8x14_iso8859_1_info,
58+
&_fonts_terminus_10x18_iso8859_1_info,
59+
&_fonts_terminus_11x22_iso8859_1_info,
60+
&_fonts_terminus_12x24_iso8859_1_info,
61+
&_fonts_terminus_14x28_iso8859_1_info,
62+
&_fonts_terminus_16x32_iso8859_1_info,
63+
&_fonts_terminus_bold_8x14_iso8859_1_info,
64+
&_fonts_terminus_bold_10x18_iso8859_1_info,
65+
&_fonts_terminus_bold_11x22_iso8859_1_info,
66+
&_fonts_terminus_bold_12x24_iso8859_1_info,
67+
&_fonts_terminus_bold_14x28_iso8859_1_info,
4568
&_fonts_terminus_bold_16x32_iso8859_1_info,
46-
// &_fonts_terminus_6x12_koi8_r_info,
47-
// &_fonts_terminus_8x14_koi8_r_info,
48-
// &_fonts_terminus_14x28_koi8_r_info,
49-
// &_fonts_terminus_16x32_koi8_r_info,
50-
// &_fonts_terminus_bold_8x14_koi8_r_info,
51-
// &_fonts_terminus_bold_14x28_koi8_r_info,
52-
// &_fonts_terminus_bold_16x32_koi8_r_info
53-
};
69+
#endif
70+
#ifdef FONTS_KOI8
71+
/*
72+
* koi8_r fonts
73+
*/
74+
&_fonts_terminus_6x12_koi8_r_info,
75+
&_fonts_terminus_8x14_koi8_r_info,
76+
&_fonts_terminus_14x28_koi8_r_info,
77+
&_fonts_terminus_16x32_koi8_r_info,
78+
&_fonts_terminus_bold_8x14_koi8_r_info,
79+
&_fonts_terminus_bold_14x28_koi8_r_info,
80+
&_fonts_terminus_bold_16x32_koi8_r_info
81+
#endif
82+
};

main/fonts/font_bitocra_4x7_ascii.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,7 @@ static const uint8_t _fonts_bitocra_4x7_ascii_bitmaps [] = {
881881
0x00, /* ........ */
882882
};
883883

884-
const font_char_desc_t _fonts_bitocra_4x7_ascii_descriptors [] = {
885-
{ 0x00, 0x0000 }, /* Dummy */
884+
const font_char_desc_t _fonts_bitocra_4x7_ascii_descriptors [] = {
886885
{ 0x04, 0x0000 }, /* Index: 0x00, char: \x20 */
887886
{ 0x04, 0x0007 }, /* Index: 0x01, char: \x21 */
888887
{ 0x04, 0x000e }, /* Index: 0x02, char: \x22 */

main/fonts/font_bitocra_6x11_iso8859_1.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,8 +2929,7 @@ static const uint8_t _fonts_bitocra_6x11_iso8859_1_bitmaps [] = {
29292929
0x00, /* ........ */
29302930
};
29312931

2932-
const font_char_desc_t _fonts_bitocra_6x11_iso8859_1_descriptors [] = {
2933-
{ 0x00, 0x0000 }, /* Dummy */
2932+
const font_char_desc_t _fonts_bitocra_6x11_iso8859_1_descriptors [] = {
29342933
{ 0x06, 0x0000 }, /* Index: 0x00, char: \x20 */
29352934
{ 0x06, 0x000b }, /* Index: 0x01, char: \x21 */
29362935
{ 0x06, 0x0016 }, /* Index: 0x02, char: \x22 */
@@ -3158,7 +3157,7 @@ const font_char_desc_t _fonts_bitocra_6x11_iso8859_1_descriptors [] = {
31583157
};
31593158

31603159
const font_info_t _fonts_bitocra_6x11_iso8859_1_info = { //
3161-
.name = "bitocra_4x7_ascii", //
3160+
.name = "bitocra_6x11_iso8859_1", //
31623161
.height = 11, /* Character height */
31633162
.c = 0, /* C */
31643163
.char_start = 32, /* Start character */

main/fonts/font_bitocra_7x13_iso8859_1.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,8 +3377,7 @@ static const uint8_t _fonts_bitocra_7x13_iso8859_1_bitmaps [] = {
33773377
0xf8, /* #####... */
33783378
};
33793379

3380-
const font_char_desc_t _fonts_bitocra_7x13_iso8859_1_descriptors [] = {
3381-
{ 0x00, 0x0000 }, /* Dummy */
3380+
const font_char_desc_t _fonts_bitocra_7x13_iso8859_1_descriptors [] = {
33823381
{ 0x07, 0x0000 }, /* Index: 0x00, char: \x20 */
33833382
{ 0x07, 0x000d }, /* Index: 0x01, char: \x21 */
33843383
{ 0x07, 0x001a }, /* Index: 0x02, char: \x22 */

0 commit comments

Comments
 (0)