5f0fd3b4e0759e04869c8b876c893bf9f838d87d
3 #define STB_IMAGE_IMPLEMENTATION
4 #include "submodules/stb/stb_image.h"
6 void vg_build_font_face_run( vg_font_face
*face
,
7 char first
, char last
, i16 x
, i16 y
)
9 u32 count
= (u32
)last
- (u32
)first
;
10 for( u32 i
=0; i
<=count
; i
++ )
12 u32 index
= (u32
)first
+ i
;
13 face
->map
[index
].x
= x
+(i
*face
->cw
);
14 face
->map
[index
].y
= y
;
18 void vg_build_write_font_face( FILE *fp
, vg_font_face
*face
)
20 fprintf( fp
, "vg_font_face %s = {\n", face
->name
);
21 fprintf( fp
, " .name=\"%s\",\n", face
->name
);
22 fprintf( fp
, " .cw=%hd,.ch=%hd,\n", face
->cw
,face
->ch
);
23 fprintf( fp
, " .sx=%hd,.sy=%hd,\n", face
->sx
,face
->sy
);
24 fprintf( fp
, " .baseline=%hd,\n", face
->baseline
);
25 fprintf( fp
, " .map={\n" );
29 for( u32 i
=0; i
<256; i
++ )
31 if( face
->map
[i
].x
|| face
->map
[i
].y
)
33 chars
+= fprintf( fp
, "[%u]={%hd,%hd},",
34 i
, face
->map
[i
].x
, face
->map
[i
].y
);
44 fprintf( fp
, "\n}};\n\n" );
47 void vg_build_font_sheet( FILE *fp
, char *name
, const char *source
)
50 unsigned char *data
= stbi_load( source
, &x
, &y
, &n
, 4 );
54 vg_error( "Couldn't open source file\n" );
58 fprintf( fp
, "vg_font_sheet %s = {\n", name
);
59 fprintf( fp
, " .w=%d, .h=%d,\n", x
,y
);
60 fprintf( fp
, " .bitmap={\n" );
63 u32 pixel
= 0, chars
= 0;
67 for( int b
= 31; b
>= 0; b
-- )
69 buff
|= data
[pixel
*4]>128?0x1<<b
:0;
72 if( pixel
>= pixel_max
)
79 chars
+= fprintf( fp
, "%#x,", buff
);
87 fprintf( fp
, "\n}};\n" );
91 void vg_build_default_font(void)
93 FILE *fp
= fopen( "vg/vg_default_font.gc", "w" );
94 vg_build_font_sheet( fp
, "vg_default_font_sheet",
95 "vg/src/fonts/vg_font_thin_3.png" );
98 .name
= "vgf_default_small",
103 vg_build_font_face_run( &small
, '!', '/', 8, 0 );
104 vg_build_font_face_run( &small
, '[', '`', 128,0 );
105 vg_build_font_face_run( &small
, '{', '~', 176,0 );
106 vg_build_font_face_run( &small
, ':', '@', 208,0 );
107 vg_build_font_face_run( &small
, 'A', 'Z', 0, 14 );
108 vg_build_font_face_run( &small
, 'a', 'z', 0, 28 );
109 vg_build_font_face_run( &small
, '0', '9', 208,14 );
110 vg_build_write_font_face( fp
, &small
);
114 .name
= "vgf_default_large",
119 vg_build_font_face_run( &large
, '!', '/', 12, 56 );
120 vg_build_font_face_run( &large
, '[', '`', 192,56 );
121 vg_build_font_face_run( &large
, '{', '~', 264,56 );
122 vg_build_font_face_run( &large
, ':', '@', 324,56 );
123 vg_build_font_face_run( &large
, 'A', 'Z', 0, 77 );
124 vg_build_font_face_run( &large
, 'a', 'z', 0, 98 );
125 vg_build_font_face_run( &large
, '0', '9', 312,77 );
126 vg_build_write_font_face( fp
, &large
);
130 .name
= "vgf_default_title",
135 vg_build_font_face_run( &title
, '!', '/', 24, 140 );
136 vg_build_font_face_run( &title
, '[', '_', 384,140 );
137 vg_build_font_face_run( &title
, '`', '`', 0, 182 );
138 vg_build_font_face_run( &title
, '{', '~', 24, 182 );
139 vg_build_font_face_run( &title
, ':', '@', 120,182 );
140 vg_build_font_face_run( &title
, 'A', 'U', 0, 224 );
141 vg_build_font_face_run( &title
, 'V', 'Z', 0, 308 );
142 vg_build_font_face_run( &title
, 'a', 'u', 0, 266 );
143 vg_build_font_face_run( &title
, 'v', 'z', 0, 350 );
144 vg_build_font_face_run( &title
, '0', '9', 120,308 );
145 vg_build_write_font_face( fp
, &title
);