Mercurial > repos > blastem
annotate nuklear_ui/font_web.c @ 2688:b42f00a3a937 default tip
Fix default target. Ensure m68k.h and z80.h are built before anything else when no dep info is available
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 31 Mar 2025 21:06:18 -0700 |
parents | 537a2f3b880d |
children |
rev | line source |
---|---|
2629
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <stdint.h> |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdio.h> |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stdlib.h> |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include <stddef.h> |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "sfnt.h" |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "../util.h" |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 uint8_t *default_font(uint32_t *size_out) |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 sfnt_container *sfnt = NULL; |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 FILE *f = fopen("DroidSans.ttf", "rb"); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 if (!f) { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 fprintf(stderr, "Failed to open font file DroidSans.ttf\n"); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 return NULL; |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 } |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 long size = file_size(f); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 uint8_t *buffer = malloc(size); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 if (size != fread(buffer, 1, size, f)) { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 fprintf(stderr, "Failed to read font file\n"); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 goto cleanup; |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 } |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 fclose(f); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 f = NULL; |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 sfnt = load_sfnt(buffer, size); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 if (!sfnt) { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 fprintf(stderr, "File does not contain SFNT resources\n"); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 goto cleanup; |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 for (uint8_t j = 0; j < sfnt->num_fonts; j++) |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 if (sfnt_has_truetype_glyphs(sfnt->tables + j)) { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 return sfnt_flatten(sfnt->tables + j, size_out); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 } |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 fprintf(stderr, "Font %s in file doesn't have TrueType glyphs\n", sfnt_name(sfnt->tables + j, SFNT_POSTSCRIPT)); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 } |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 cleanup: |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 if (sfnt) { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 sfnt_free(sfnt); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } else { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 free(buffer); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 if (f) { |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 fclose(f); |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 } |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 return NULL; |
537a2f3b880d
Add font_web.c that was missed on a previous commit
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 } |