3 * Copyright 2020, Gary Wong <gtw@gnu.org>
5 * This file is part of FPC-III.
7 * FPC-III is a free hardware design: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * FPC-III is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with FPC-III. If not, see <https://www.gnu.org/licenses/>.
26 #include FT_FREETYPE_H
28 unsigned char font
[ 0x80 ][ 0x20 ][ 0x10 ]; /* cccccccyyyyyxxxx */
30 void draw_bitmap( int n
, FT_Bitmap
* bitmap
, FT_Int x
, FT_Int y
) {
33 FT_Int x_max
= x
+ bitmap
->width
;
34 FT_Int y_max
= y
+ bitmap
->rows
;
36 for( i
= x
, p
= 0; i
< x_max
; i
++, p
++ ) {
37 for ( j
= y
, q
= 0; j
< y_max
; j
++, q
++ ) {
38 if ( i
< 0 || j
< 0 || i
>= 0x10 || j
>= 0x20 )
41 font
[ n
][ j
][ i
] = bitmap
->buffer
[ q
* bitmap
->width
+ p
] >> 4;
46 void show_font( void ) {
51 for( c
= 0; c
< 0x80; c
++ )
52 for( y
= 0; y
< 0x20; y
++ ) {
53 for( x
= 0; x
< 0x10; x
++ )
54 putchar( font
[ c
][ y
][ x
] > 7 ? '#' : ' ' );
62 for( p
= &font
[ 0 ][ 0 ][ 0 ]; p
< &font
[ 0x80 ][ 0 ][ 0 ]; p
++ )
66 extern int main( int argc
, char *argv
[] ) {
75 fprintf( stderr
, "usage: %s font\n", argv
[ 0 ] );
81 FT_Init_FreeType( &library
);
82 FT_New_Face( library
, filename
, 0, &face
);
84 FT_Set_Char_Size( face
, 27 * 64, 0, 72, 0 );
88 for( i
= 0x21; i
< 0x7F; i
++ ) {
89 if( FT_Load_Char( face
, i
, FT_LOAD_RENDER
) )
92 draw_bitmap( i
, &slot
->bitmap
, slot
->bitmap_left
,
93 0x18 - slot
->bitmap_top
);
96 for( y
= 0; y
< 0x20; y
++ )
97 for( x
= 0; x
< 0x10; x
++ )
98 font
[ 0x01 ][ y
][ x
] = x
^ y
? 0x0 : 0xF;
100 for( y
= 0; y
< 0x20; y
++ )
101 for( x
= 0; x
< 0x20; x
++ ) {
104 if( ( x
+ 1 ) * ( x
+ 1 ) + ( y
+ 1 ) * ( y
+ 1 ) < 0x400 )
106 else if( x
* x
+ y
* y
>= 0x400 )
113 for( dx
= 0; dx
< 4; dx
++ )
114 for( dy
= 0; dy
< 4; dy
++ )
115 fill
+= ( ( x
* 4 + dx
) * ( x
* 4 + dx
) +
116 ( y
* 4 + dy
) * ( y
* 4 + dy
) < 0x4000 );
122 font
[ 2 + ( x
< 0x10 ) ][ 0x1F - y
][ 0x0F - ( x
& 0x0F ) ] = fill
;
123 font
[ 4 + ( x
>= 0x10 ) ][ 0x1F - y
][ x
& 0x0F ] = fill
;
124 font
[ 6 + ( x
< 0x10 ) ][ y
][ 0x0F - ( x
& 0x0F ) ] = fill
;
125 font
[ 8 + ( x
>= 0x10 ) ][ y
][ x
& 0x0F ] = fill
;
128 for( y
= 0; y
<= 0x10; y
++ )
129 for( x
= 0x07; x
<= 0x08; x
++ ) {
130 font
[ 0x0A ][ y
][ x
] = 0x0F;
131 font
[ 0x0D ][ y
][ x
] = 0x0F;
132 font
[ 0x0E ][ y
][ x
] = 0x0F;
133 font
[ 0x14 ][ y
][ x
] = 0x0F;
134 font
[ 0x15 ][ y
][ x
] = 0x0F;
135 font
[ 0x16 ][ y
][ x
] = 0x0F;
136 font
[ 0x18 ][ y
][ x
] = 0x0F;
139 for( y
= 0x0F; y
< 0x20; y
++ )
140 for( x
= 0x07; x
<= 0x08; x
++ ) {
141 font
[ 0x0B ][ y
][ x
] = 0x0F;
142 font
[ 0x0C ][ y
][ x
] = 0x0F;
143 font
[ 0x0E ][ y
][ x
] = 0x0F;
144 font
[ 0x14 ][ y
][ x
] = 0x0F;
145 font
[ 0x15 ][ y
][ x
] = 0x0F;
146 font
[ 0x17 ][ y
][ x
] = 0x0F;
147 font
[ 0x18 ][ y
][ x
] = 0x0F;
150 for( x
= 0; x
<= 0x08; x
++ )
151 for( y
= 0x0F; y
<= 0x10; y
++ ) {
152 font
[ 0x0A ][ y
][ x
] = 0x0F;
153 font
[ 0x0B ][ y
][ x
] = 0x0F;
154 font
[ 0x0E ][ y
][ x
] = 0x0F;
155 font
[ 0x11 ][ y
][ x
] = 0x0F;
156 font
[ 0x15 ][ y
][ x
] = 0x0F;
157 font
[ 0x16 ][ y
][ x
] = 0x0F;
158 font
[ 0x17 ][ y
][ x
] = 0x0F;
161 for( x
= 0x07; x
< 0x10; x
++ )
162 for( y
= 0x0F; y
<= 0x10; y
++ ) {
163 font
[ 0x0C ][ y
][ x
] = 0x0F;
164 font
[ 0x0D ][ y
][ x
] = 0x0F;
165 font
[ 0x0E ][ y
][ x
] = 0x0F;
166 font
[ 0x11 ][ y
][ x
] = 0x0F;
167 font
[ 0x14 ][ y
][ x
] = 0x0F;
168 font
[ 0x16 ][ y
][ x
] = 0x0F;
169 font
[ 0x17 ][ y
][ x
] = 0x0F;
172 font
[ 0x1E ][ 0x0F ][ 0x07 ] = 0x0F;
173 font
[ 0x1E ][ 0x0F ][ 0x08 ] = 0x0F;
174 font
[ 0x1E ][ 0x10 ][ 0x07 ] = 0x0F;
175 font
[ 0x1E ][ 0x10 ][ 0x08 ] = 0x0F;
177 for( y
= 0; y
< 0x20; y
++ )
178 for( x
= 0; x
< 0x10; x
++ )
179 font
[ 0x7F ][ y
][ x
] = y
>> 1;
183 FT_Done_Face( face
);
184 FT_Done_FreeType( library
);