Commit: 32c07faf12c515721157ff6f2aa612c48f514f4c
Parent: fc1113ca25feced0272057ea921e9a45eecadcea
Author: Randy Palamar
Date: Wed, 7 Aug 2024 06:25:28 -0600
reimplement export_font logic in gen_incs
It is unlikely that such a patch will be accepted upstream so just
keep the simplified logic locally.
Diffstat:
5 files changed, 100 insertions(+), 277 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
@@ -17,10 +17,6 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install libxkbcommon-dev xorg-dev libwayland-dev ninja-build
- - name: Configure Git
- run: |
- git config --global user.email "fu@githubci.com"
- git config --global user.name "F U"
- uses: actions/checkout@v4
- name: Build
run: ./build.sh
@@ -45,12 +41,6 @@ jobs:
update: true
install: git mingw-w64-${{matrix.env}}-${{matrix.cc}}
pacboy: ninja:p cmake:p
-
- - name: Configure Git
- run: |
- git config --global user.email "fu@githubci.com"
- git config --global user.name "F U"
-
- uses: actions/checkout@v4
- name: Build
run: ./build.sh
diff --git a/.gitmodules b/.gitmodules
@@ -1,4 +1,3 @@
[submodule "external/raylib"]
path = external/raylib
url = https://github.com/raysan5/raylib.git
- ignore = all
diff --git a/build.sh b/build.sh
@@ -18,7 +18,6 @@ if [ "$system_raylib" ]; then
else
if [ ! -f external/lib/libraylib.a ]; then
git submodule update --init --checkout --depth=1 external/raylib
- git -C external/raylib am --keep-non-patch --whitespace=nowarn "$PWD"/external/*.patch
cmake --install-prefix="${PWD}/external" \
-G "Ninja" -B external/raylib/build -S external/raylib \
-D CMAKE_INSTALL_LIBDIR=lib -D CMAKE_BUILD_TYPE="Release" \
diff --git a/external/0001-rtext-add-ExportFontAsCodeEx.patch b/external/0001-rtext-add-ExportFontAsCodeEx.patch
@@ -1,253 +0,0 @@
-From a466c6cf1f47620aa6ecdea19636c561879e9649 Mon Sep 17 00:00:00 2001
-From: Randy Palamar <randy@rnpnr.xyz>
-Date: Mon, 5 Aug 2024 12:07:33 -0600
-Subject: [PATCH] [rtext] add ExportFontAsCodeEx()
-
-ExportFontAsCode() loads image data from a font that is already
-uploaded to the GPU; this means that it requires a full graphics
-context/window. ExportFontAsCodeEx() loads the relevant font data
-into an atlas itself without ever creating a texture. This makes
-it possible to export font data as part of a build step when
-compiling a project when there is no GPU present (e.g. github CI).
-
-One minor change is that ExportFontAsCode() no longer converts the
-name to PascalCase. Its up to the user to pass the name in in that
-format if they want it.
----
- src/raylib.h | 1 +
- src/rtext.c | 126 +++++++++++++++++++++++++++++++++++++--------------
- 2 files changed, 93 insertions(+), 34 deletions(-)
-
-diff --git a/src/raylib.h b/src/raylib.h
-index 1cf34f00..c62d1909 100644
---- a/src/raylib.h
-+++ b/src/raylib.h
-@@ -1452,6 +1452,7 @@ RLAPI Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, in
- RLAPI void UnloadFontData(GlyphInfo *glyphs, int glyphCount); // Unload font chars info data (RAM)
- RLAPI void UnloadFont(Font font); // Unload font from GPU memory (VRAM)
- RLAPI bool ExportFontAsCode(Font font, const char *fileName); // Export font as code file, returns true on success
-+RLAPI bool ExportFontAsCodeEx(const char *fontFileName, const char *outputFileName, int fontSize, int *codepoints, int codepointCount); // Export font as code file with extra parameters; returns true on success
-
- // Text drawing functions
- RLAPI void DrawFPS(int posX, int posY); // Draw current FPS
-diff --git a/src/rtext.c b/src/rtext.c
-index 755b15ef..a3d31028 100644
---- a/src/rtext.c
-+++ b/src/rtext.c
-@@ -953,20 +953,19 @@ void UnloadFont(Font font)
- }
- }
-
--// Export font as code file, returns true on success
--bool ExportFontAsCode(Font font, const char *fileName)
-+
-+static bool
-+WriteOutputFontAsCode(Font font, Image atlas, const char *fileName)
- {
-- bool success = false;
--
--#ifndef TEXT_BYTES_PER_LINE
-- #define TEXT_BYTES_PER_LINE 20
--#endif
--
-- #define MAX_FONT_DATA_SIZE 1024*1024 // 1 MB
--
- // Get file name from path
-- char fileNamePascal[256] = { 0 };
-- strncpy(fileNamePascal, TextToPascal(GetFileNameWithoutExt(fileName)), 256 - 1);
-+ char baseFileName[256] = { 0 };
-+ strncpy(baseFileName, GetFileNameWithoutExt(fileName), 256 - 1);
-+
-+ #ifndef TEXT_BYTES_PER_LINE
-+ #define TEXT_BYTES_PER_LINE 20
-+ #endif
-+
-+ #define MAX_FONT_DATA_SIZE 1024*1024
-
- // NOTE: Text data buffer size is estimated considering image data size in bytes
- // and requiring 6 char bytes for every byte: "0x00, "
-@@ -994,9 +993,8 @@ bool ExportFontAsCode(Font font, const char *fileName)
-
- // Support font export and initialization
- // NOTE: This mechanism is highly coupled to raylib
-- Image image = LoadImageFromTexture(font.texture);
-- if (image.format != PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA) TRACELOG(LOG_WARNING, "Font export as code: Font image format is not GRAY+ALPHA!");
-- int imageDataSize = GetPixelDataSize(image.width, image.height, image.format);
-+ if (atlas.format != PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA) TRACELOG(LOG_WARNING, "Font export as code: Font image format is not GRAY+ALPHA!");
-+ int imageDataSize = GetPixelDataSize(atlas.width, atlas.height, atlas.format);
-
- // Image data is usually GRAYSCALE + ALPHA and can be reduced to GRAYSCALE
- //ImageFormat(&image, PIXELFORMAT_UNCOMPRESSED_GRAYSCALE);
-@@ -1009,13 +1007,13 @@ bool ExportFontAsCode(Font font, const char *fileName)
-
- // Compress font image data
- int compDataSize = 0;
-- unsigned char *compData = CompressData((const unsigned char *)image.data, imageDataSize, &compDataSize);
-+ unsigned char *compData = CompressData((const unsigned char *)atlas.data, imageDataSize, &compDataSize);
-
- // Save font image data (compressed)
-- byteCount += sprintf(txtData + byteCount, "#define COMPRESSED_DATA_SIZE_FONT_%s %i\n\n", TextToUpper(fileNamePascal), compDataSize);
-+ byteCount += sprintf(txtData + byteCount, "#define COMPRESSED_DATA_SIZE_FONT_%s %i\n\n", TextToUpper(baseFileName), compDataSize);
- byteCount += sprintf(txtData + byteCount, "// Font image pixels data compressed (DEFLATE)\n");
- byteCount += sprintf(txtData + byteCount, "// NOTE: Original pixel data simplified to GRAYSCALE\n");
-- byteCount += sprintf(txtData + byteCount, "static unsigned char fontData_%s[COMPRESSED_DATA_SIZE_FONT_%s] = { ", fileNamePascal, TextToUpper(fileNamePascal));
-+ byteCount += sprintf(txtData + byteCount, "static unsigned char fontData_%s[COMPRESSED_DATA_SIZE_FONT_%s] = { ", baseFileName, TextToUpper(baseFileName));
- for (int i = 0; i < compDataSize - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%02x,\n " : "0x%02x, "), compData[i]);
- byteCount += sprintf(txtData + byteCount, "0x%02x };\n\n", compData[compDataSize - 1]);
- RL_FREE(compData);
-@@ -1023,14 +1021,14 @@ bool ExportFontAsCode(Font font, const char *fileName)
- // Save font image data (uncompressed)
- byteCount += sprintf(txtData + byteCount, "// Font image pixels data\n");
- byteCount += sprintf(txtData + byteCount, "// NOTE: 2 bytes per pixel, GRAY + ALPHA channels\n");
-- byteCount += sprintf(txtData + byteCount, "static unsigned char fontImageData_%s[%i] = { ", fileNamePascal, imageDataSize);
-+ byteCount += sprintf(txtData + byteCount, "static unsigned char fontImageData_%s[%i] = { ", baseFileName, imageDataSize);
- for (int i = 0; i < imageDataSize - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%02x,\n " : "0x%02x, "), ((unsigned char *)imFont.data)[i]);
- byteCount += sprintf(txtData + byteCount, "0x%02x };\n\n", ((unsigned char *)imFont.data)[imageDataSize - 1]);
- #endif
-
- // Save font recs data
- byteCount += sprintf(txtData + byteCount, "// Font characters rectangles data\n");
-- byteCount += sprintf(txtData + byteCount, "static Rectangle fontRecs_%s[%i] = {\n", fileNamePascal, font.glyphCount);
-+ byteCount += sprintf(txtData + byteCount, "static Rectangle fontRecs_%s[%i] = {\n", baseFileName, font.glyphCount);
- for (int i = 0; i < font.glyphCount; i++)
- {
- byteCount += sprintf(txtData + byteCount, " { %1.0f, %1.0f, %1.0f , %1.0f },\n", font.recs[i].x, font.recs[i].y, font.recs[i].width, font.recs[i].height);
-@@ -1042,7 +1040,7 @@ bool ExportFontAsCode(Font font, const char *fileName)
- // it could be generated from image and recs
- byteCount += sprintf(txtData + byteCount, "// Font glyphs info data\n");
- byteCount += sprintf(txtData + byteCount, "// NOTE: No glyphs.image data provided\n");
-- byteCount += sprintf(txtData + byteCount, "static GlyphInfo fontGlyphs_%s[%i] = {\n", fileNamePascal, font.glyphCount);
-+ byteCount += sprintf(txtData + byteCount, "static GlyphInfo fontGlyphs_%s[%i] = {\n", baseFileName, font.glyphCount);
- for (int i = 0; i < font.glyphCount; i++)
- {
- byteCount += sprintf(txtData + byteCount, " { %i, %i, %i, %i, { 0 }},\n", font.glyphs[i].value, font.glyphs[i].offsetX, font.glyphs[i].offsetY, font.glyphs[i].advanceX);
-@@ -1050,8 +1048,8 @@ bool ExportFontAsCode(Font font, const char *fileName)
- byteCount += sprintf(txtData + byteCount, "};\n\n");
-
- // Custom font loading function
-- byteCount += sprintf(txtData + byteCount, "// Font loading function: %s\n", fileNamePascal);
-- byteCount += sprintf(txtData + byteCount, "static Font LoadFont_%s(void)\n{\n", fileNamePascal);
-+ byteCount += sprintf(txtData + byteCount, "// Font loading function: %s\n", baseFileName);
-+ byteCount += sprintf(txtData + byteCount, "static Font LoadFont_%s(void)\n{\n", baseFileName);
- byteCount += sprintf(txtData + byteCount, " Font font = { 0 };\n\n");
- byteCount += sprintf(txtData + byteCount, " font.baseSize = %i;\n", font.baseSize);
- byteCount += sprintf(txtData + byteCount, " font.glyphCount = %i;\n", font.glyphCount);
-@@ -1059,11 +1057,11 @@ bool ExportFontAsCode(Font font, const char *fileName)
- byteCount += sprintf(txtData + byteCount, " // Custom font loading\n");
- #if defined(SUPPORT_COMPRESSED_FONT_ATLAS)
- byteCount += sprintf(txtData + byteCount, " // NOTE: Compressed font image data (DEFLATE), it requires DecompressData() function\n");
-- byteCount += sprintf(txtData + byteCount, " int fontDataSize_%s = 0;\n", fileNamePascal);
-- byteCount += sprintf(txtData + byteCount, " unsigned char *data = DecompressData(fontData_%s, COMPRESSED_DATA_SIZE_FONT_%s, &fontDataSize_%s);\n", fileNamePascal, TextToUpper(fileNamePascal), fileNamePascal);
-- byteCount += sprintf(txtData + byteCount, " Image imFont = { data, %i, %i, 1, %i };\n\n", image.width, image.height, image.format);
-+ byteCount += sprintf(txtData + byteCount, " int fontDataSize_%s = 0;\n", baseFileName);
-+ byteCount += sprintf(txtData + byteCount, " unsigned char *data = DecompressData(fontData_%s, COMPRESSED_DATA_SIZE_FONT_%s, &fontDataSize_%s);\n", baseFileName, TextToUpper(baseFileName), baseFileName);
-+ byteCount += sprintf(txtData + byteCount, " Image imFont = { data, %i, %i, 1, %i };\n\n", atlas.width, atlas.height, atlas.format);
- #else
-- byteCount += sprintf(txtData + byteCount, " Image imFont = { fontImageData_%s, %i, %i, 1, %i };\n\n", styleName, image.width, image.height, image.format);
-+ byteCount += sprintf(txtData + byteCount, " Image imFont = { fontImageData_%s, %i, %i, 1, %i };\n\n", styleName, atlas.width, atlas.height, atlas.format);
- #endif
- byteCount += sprintf(txtData + byteCount, " // Load texture from image\n");
- byteCount += sprintf(txtData + byteCount, " font.texture = LoadTextureFromImage(imFont);\n");
-@@ -1079,25 +1077,23 @@ bool ExportFontAsCode(Font font, const char *fileName)
- byteCount += sprintf(txtData + byteCount, " // Copy glyph recs data from global fontRecs\n");
- byteCount += sprintf(txtData + byteCount, " // NOTE: Required to avoid issues if trying to free font\n");
- byteCount += sprintf(txtData + byteCount, " font.recs = (Rectangle *)malloc(font.glyphCount*sizeof(Rectangle));\n");
-- byteCount += sprintf(txtData + byteCount, " memcpy(font.recs, fontRecs_%s, font.glyphCount*sizeof(Rectangle));\n\n", fileNamePascal);
-+ byteCount += sprintf(txtData + byteCount, " memcpy(font.recs, fontRecs_%s, font.glyphCount*sizeof(Rectangle));\n\n", baseFileName);
-
- byteCount += sprintf(txtData + byteCount, " // Copy font glyph info data from global fontChars\n");
- byteCount += sprintf(txtData + byteCount, " // NOTE: Required to avoid issues if trying to free font\n");
- byteCount += sprintf(txtData + byteCount, " font.glyphs = (GlyphInfo *)malloc(font.glyphCount*sizeof(GlyphInfo));\n");
-- byteCount += sprintf(txtData + byteCount, " memcpy(font.glyphs, fontGlyphs_%s, font.glyphCount*sizeof(GlyphInfo));\n\n", fileNamePascal);
-+ byteCount += sprintf(txtData + byteCount, " memcpy(font.glyphs, fontGlyphs_%s, font.glyphCount*sizeof(GlyphInfo));\n\n", baseFileName);
- #else
- byteCount += sprintf(txtData + byteCount, " // Assign glyph recs and info data directly\n");
- byteCount += sprintf(txtData + byteCount, " // WARNING: This font data must not be unloaded\n");
-- byteCount += sprintf(txtData + byteCount, " font.recs = fontRecs_%s;\n", fileNamePascal);
-- byteCount += sprintf(txtData + byteCount, " font.glyphs = fontGlyphs_%s;\n\n", fileNamePascal);
-+ byteCount += sprintf(txtData + byteCount, " font.recs = fontRecs_%s;\n", baseFileName);
-+ byteCount += sprintf(txtData + byteCount, " font.glyphs = fontGlyphs_%s;\n\n", baseFileName);
- #endif
- byteCount += sprintf(txtData + byteCount, " return font;\n");
- byteCount += sprintf(txtData + byteCount, "}\n");
-
-- UnloadImage(image);
--
- // NOTE: Text data size exported is determined by '\0' (NULL) character
-- success = SaveFileText(fileName, txtData);
-+ bool success = SaveFileText(fileName, txtData);
-
- RL_FREE(txtData);
-
-@@ -1107,6 +1103,68 @@ bool ExportFontAsCode(Font font, const char *fileName)
- return success;
- }
-
-+// Export font as code file, returns true on success
-+bool ExportFontAsCode(Font font, const char *fileName)
-+{
-+ Image atlas = LoadImageFromTexture(font.texture);
-+ bool success = WriteOutputFontAsCode(font, atlas, fileName);
-+ UnloadImage(atlas);
-+ return success;
-+}
-+
-+// Export font as code file with extra parameters; returns true on success
-+bool ExportFontAsCodeEx(const char *fontFileName, const char *outputFileName, int fontSize, int *codepoints, int codepointCount)
-+{
-+ int dataSize = 0;
-+ unsigned char *fileData = LoadFileData(fontFileName, &dataSize);
-+
-+ if (fileData == NULL) {
-+ TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export font as code", fontFileName);
-+ return false;
-+ }
-+
-+ Font font = {0};
-+ font.baseSize = fontSize;
-+ font.glyphCount = (codepointCount > 0)? codepointCount : 95;
-+
-+ char fileExtLower[16] = { 0 };
-+ strncpy(fileExtLower, TextToLower(GetFileExtension(fontFileName)), 16 - 1);
-+
-+#if defined(SUPPORT_FILEFORMAT_TTF)
-+ if (TextIsEqual(fileExtLower, ".ttf") ||
-+ TextIsEqual(fileExtLower, ".otf"))
-+ {
-+ font.glyphs = LoadFontData(fileData, dataSize, font.baseSize, codepoints, font.glyphCount, FONT_DEFAULT);
-+ }
-+#endif
-+#if defined(SUPPORT_FILEFORMAT_BDF)
-+ if (TextIsEqual(fileExtLower, ".bdf"))
-+ {
-+ font.glyphs = LoadFontDataBDF(fileData, dataSize, codepoints, font.glyphCount, &font.baseSize);
-+ }
-+#endif
-+
-+ Image atlas;
-+#if defined(SUPPORT_FILEFORMAT_TTF) || defined(SUPPORT_FILEFORMAT_BDF)
-+ if (font.glyphs != NULL) {
-+ font.glyphPadding = FONT_TTF_DEFAULT_CHARS_PADDING;
-+ atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize, font.glyphPadding, 0);
-+ } else {
-+ TRACELOG(LOG_WARNING, "FILEIO: [%s] Failed to export font as code", fontFileName);
-+ }
-+#endif
-+
-+ bool success = false;
-+ if (font.glyphs != NULL) {
-+ success = WriteOutputFontAsCode(font, atlas, outputFileName);
-+ UnloadFileData(fileData);
-+ UnloadFontData(font.glyphs, font.glyphCount);
-+ UnloadImage(atlas);
-+ }
-+
-+ return success;
-+}
-+
- // Draw current FPS
- // NOTE: Uses default font
- void DrawFPS(int posX, int posY)
---
-2.44.0
-
diff --git a/gen_incs.c b/gen_incs.c
@@ -4,6 +4,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "config.h"
@@ -12,7 +13,7 @@
typedef struct {uint8_t *data; ptrdiff_t len;} s8;
static s8
-read_whole_file(char *name, s8 mem)
+read_whole_file(char *name, s8 *mem)
{
s8 res = {0};
FILE *fp = fopen(name, "r");
@@ -26,13 +27,17 @@ read_whole_file(char *name, s8 mem)
res.len = ftell(fp);
rewind(fp);
- if (mem.len < res.len) {
+ if (mem->len < res.len) {
fputs("Not enough space for reading file!\n", stdout);
exit(1);
}
- res.data = mem.data;
+ res.data = mem->data;
fread(res.data, res.len, 1, fp);
fclose(fp);
+
+ mem->data += res.len;
+ mem->len -= res.len;
+
return res;
}
@@ -51,6 +56,90 @@ get_line(s8 *s)
return res;
}
+/* NOTE: modified from raylib */
+static void
+export_font_as_code(char *font_path, char *output_name, int font_size, s8 mem)
+{
+ s8 raw = read_whole_file(font_path, &mem);
+ Font font = {0};
+ font.baseSize = font_size;
+ font.glyphCount = 95;
+ font.glyphPadding = 4;
+
+ font.glyphs = LoadFontData(raw.data, raw.len, font.baseSize, 0, font.glyphCount, FONT_DEFAULT);
+ if (font.glyphs == NULL) {
+ printf("Failed to load font data: %s\n", font_path);
+ exit(1);
+ }
+
+ Image atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize,
+ font.glyphPadding, 0);
+
+ FILE *fp = fopen(output_name, "w");
+ if (fp == NULL) {
+ printf("Failed to open output font file: %s\n", output_name);
+ exit(1);
+ }
+
+ char suffix[256];
+ strncpy(suffix, GetFileNameWithoutExt(output_name), 256 - 1);
+
+ #define TEXT_BYTES_PER_LINE 16
+
+ int image_data_size = GetPixelDataSize(atlas.width, atlas.height, atlas.format);
+ int comp_data_size = 0;
+ unsigned char *comp_data = CompressData(atlas.data, image_data_size, &comp_data_size);
+
+ // Save font image data (compressed)
+ fprintf(fp, "#define COMPRESSED_DATA_SIZE_FONT_%s %i\n\n", TextToUpper(suffix), comp_data_size);
+ fprintf(fp, "// Font image pixels data compressed (DEFLATE)\n");
+ fprintf(fp, "// NOTE: Original pixel data simplified to GRAYSCALE\n");
+ fprintf(fp, "static unsigned char fontData_%s[COMPRESSED_DATA_SIZE_FONT_%s] = { ", suffix, TextToUpper(suffix));
+ for (int i = 0; i < comp_data_size - 1; i++) fprintf(fp, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%02x,\n " : "0x%02x, "), comp_data[i]);
+ fprintf(fp, "0x%02x };\n\n", comp_data[comp_data_size - 1]);
+ RL_FREE(comp_data);
+
+ // Save font recs data
+ fprintf(fp, "// Font characters rectangles data\n");
+ fprintf(fp, "static Rectangle fontRecs_%s[%i] = {\n", suffix, font.glyphCount);
+ for (int i = 0; i < font.glyphCount; i++)
+ fprintf(fp, " { %1.0f, %1.0f, %1.0f , %1.0f },\n", font.recs[i].x, font.recs[i].y, font.recs[i].width, font.recs[i].height);
+ fprintf(fp, "};\n\n");
+
+ // Save font glyphs data
+ // NOTE: Glyphs image data not saved (grayscale pixels), it could be generated from image and recs
+ fprintf(fp, "// Font glyphs info data\n");
+ fprintf(fp, "// NOTE: No glyphs.image data provided\n");
+ fprintf(fp, "static GlyphInfo fontGlyphs_%s[%i] = {\n", suffix, font.glyphCount);
+ for (int i = 0; i < font.glyphCount; i++)
+ fprintf(fp, " { %i, %i, %i, %i, { 0 }},\n", font.glyphs[i].value, font.glyphs[i].offsetX, font.glyphs[i].offsetY, font.glyphs[i].advanceX);
+ fprintf(fp, "};\n\n");
+
+ // Custom font loading function
+ fprintf(fp, "// Font loading function: %s\n", suffix);
+ fprintf(fp, "static Font LoadFont_%s(void)\n{\n", suffix);
+ fprintf(fp, " Font font = { 0 };\n\n");
+ fprintf(fp, " font.baseSize = %i;\n", font.baseSize);
+ fprintf(fp, " font.glyphCount = %i;\n", font.glyphCount);
+ fprintf(fp, " font.glyphPadding = %i;\n\n", font.glyphPadding);
+ fprintf(fp, " // Custom font loading\n");
+ fprintf(fp, " // NOTE: Compressed font image data (DEFLATE), it requires DecompressData() function\n");
+ fprintf(fp, " int fontDataSize_%s = 0;\n", suffix);
+ fprintf(fp, " unsigned char *data = DecompressData(fontData_%s, COMPRESSED_DATA_SIZE_FONT_%s, &fontDataSize_%s);\n", suffix, TextToUpper(suffix), suffix);
+ fprintf(fp, " Image imFont = { data, %i, %i, 1, %i };\n\n", atlas.width, atlas.height, atlas.format);
+ fprintf(fp, " // Load texture from image\n");
+ fprintf(fp, " font.texture = LoadTextureFromImage(imFont);\n");
+ fprintf(fp, " UnloadImage(imFont); // Uncompressed data can be unloaded from memory\n\n");
+ fprintf(fp, " // Assign glyph recs and info data directly\n");
+ fprintf(fp, " // WARNING: This font data must not be unloaded\n");
+ fprintf(fp, " font.recs = fontRecs_%s;\n", suffix);
+ fprintf(fp, " font.glyphs = fontGlyphs_%s;\n\n", suffix);
+ fprintf(fp, " return font;\n");
+ fprintf(fp, "}\n");
+
+ fclose(fp);
+}
+
int
main(void)
{
@@ -58,15 +147,14 @@ main(void)
s8 smem = {.data = mem, .len = sizeof(mem)};
SetTraceLogLevel(LOG_NONE);
- {
+ int font_sizes[] = { FONT_SIZE, FONT_SIZE/2 };
+ for (int i = 0; i < sizeof(font_sizes)/sizeof(*font_sizes); i++) {
s8 tmem = smem;
- int font_sizes[] = { FONT_SIZE, FONT_SIZE/2 };
- for (int i = 0; i < sizeof(font_sizes)/sizeof(*font_sizes); i++) {
- snprintf((char *)tmem.data, tmem.len, "lora_sb_%d_inc.h", i);
- if (!ExportFontAsCodeEx("assets/Lora-SemiBold.ttf", (char *)tmem.data,
- font_sizes[i], 0, 0))
- printf("Failed to export font: %s\n", (char *)tmem.data);
- }
+ s8 rmem = smem;
+ size_t tlen = snprintf((char *)tmem.data, tmem.len, "lora_sb_%d_inc.h", i);
+ rmem.len -= (tlen + 1);
+ rmem.data += (tlen + 1);
+ export_font_as_code("assets/Lora-SemiBold.ttf", (char *)tmem.data, font_sizes[i], rmem);
}
FILE *out_file = fopen("external/include/shader_inc.h", "w");
@@ -75,7 +163,7 @@ main(void)
return 1;
}
- s8 shader_data = read_whole_file(HSV_LERP_SHADER_NAME, smem);
+ s8 shader_data = read_whole_file(HSV_LERP_SHADER_NAME, &smem);
s8 s = shader_data;
/* NOTE: skip over license notice */
s8 line = get_line(&s);