From aeab06513edd4a341fc79b528c5db169e4804494 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Tue, 9 Oct 2018 17:13:25 +0200 Subject: [PATCH] [kandinsky] Cleanup KDFont, include all characters --- .gitignore | 2 + kandinsky/fonts/rasterizer.c | 79 ++++-------------------------------- 2 files changed, 11 insertions(+), 70 deletions(-) diff --git a/.gitignore b/.gitignore index 332ec6666..cfd17d43a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,8 @@ poincare/src/simplification/demo_ruleset.h # Font related generated files. kandinsky/fonts/rasterizer +kandinsky/src/font_large.cpp +kandinsky/src/font_small.cpp # No i18n headers apps/i18n.h diff --git a/kandinsky/fonts/rasterizer.c b/kandinsky/fonts/rasterizer.c index f9f73bf8a..617bfc099 100644 --- a/kandinsky/fonts/rasterizer.c +++ b/kandinsky/fonts/rasterizer.c @@ -43,6 +43,7 @@ void writeImageToPNGFile(image_t * image, char * filename); #define CHARACTER_RANGE_START 0x20 #define CHARACTER_RANGE_END 0x7E #define CHARACTER_COUNT (CHARACTER_RANGE_END-CHARACTER_RANGE_START) +#define GLYPH_COUNT (CHARACTER_COUNT + NUMBER_OF_SYMBOLS) #define GRID_WIDTH 19 #define GRID_HEIGHT 8 @@ -192,9 +193,6 @@ int main(int argc, char * argv[]) { FILE * sourceFile = fopen(output_cpp, "w"); -#define NEW_FORMAT 1 -#if NEW_FORMAT - fprintf(sourceFile, "/* This file is auto-generated by the rasterizer */\n\n"); fprintf(sourceFile, "#include \n\n"); fprintf(sourceFile, "static constexpr KDCoordinate glyphWidth = %d;\n\n", glyph_width); @@ -205,12 +203,12 @@ int main(int argc, char * argv[]) { int sizeOfUncompressedGlyphBuffer = glyph_width * glyph_height * greyscaleBitsPerPixel/8; uint8_t * uncompressedGlyphBuffer = (uint8_t *)malloc(sizeOfUncompressedGlyphBuffer); - uint16_t glyphDataOffset[CHARACTER_COUNT+1]; - int maxGlyphDataSize = CHARACTER_COUNT* sizeOfUncompressedGlyphBuffer; + uint16_t glyphDataOffset[GLYPH_COUNT+1]; + int maxGlyphDataSize = GLYPH_COUNT* sizeOfUncompressedGlyphBuffer; uint8_t * glyphData = (uint8_t *)malloc(maxGlyphDataSize); uint16_t lastOffset = 0; - for (int character = 0; character <= CHARACTER_COUNT; character++) { + for (int character = 0; character <= GLYPH_COUNT; character++) { int characterX = (character%GRID_WIDTH * (glyph_width+grid_size)); int characterY = (character/GRID_WIDTH * (glyph_height+grid_size)); uint8_t accumulator = 0; @@ -244,16 +242,16 @@ int main(int argc, char * argv[]) { glyphDataOffset[character] = lastOffset; lastOffset += sizeOfCompressedGlyphBuffer; } - glyphDataOffset[CHARACTER_COUNT] = lastOffset; + glyphDataOffset[GLYPH_COUNT] = lastOffset; - fprintf(sourceFile, "static constexpr uint16_t glyphDataOffset[%d] = {", CHARACTER_COUNT+1); - prettyPrintArray(sourceFile, 80, 2, glyphDataOffset, CHARACTER_COUNT+1); + fprintf(sourceFile, "static constexpr uint16_t glyphDataOffset[%d] = {", GLYPH_COUNT+1); + prettyPrintArray(sourceFile, 80, 2, glyphDataOffset, GLYPH_COUNT+1); fprintf(sourceFile, "};\n\n"); size_t finalDataSize = lastOffset; - size_t initialDataSize = CHARACTER_COUNT * glyph_width * glyph_height; + size_t initialDataSize = GLYPH_COUNT * glyph_width * glyph_height; - fprintf(sourceFile, "/* Rasterized = %5d bytes (%d glyphs x %d pixels)\n", initialDataSize, CHARACTER_COUNT, glyph_width*glyph_height); + fprintf(sourceFile, "/* Rasterized = %5d bytes (%d glyphs x %d pixels)\n", initialDataSize, GLYPH_COUNT, glyph_width*glyph_height); fprintf(sourceFile, " * Downsampled = %5d bytes (1/%d of rasterized)\n", initialDataSize*greyscaleBitsPerPixel/8, 8/greyscaleBitsPerPixel); fprintf(sourceFile, " * Compressed = %5d bytes (%.2f%% of rasterized) */\n", finalDataSize, 100.0*finalDataSize/initialDataSize); @@ -266,67 +264,8 @@ int main(int argc, char * argv[]) { fprintf(sourceFile, "const KDFont KDFont::private%s(glyphWidth, glyphHeight, glyphDataOffset, glyphData);\n", font_name); -#else - - fprintf(sourceFile, "/* Auto-generated by rasterizer */\n\n"); - fprintf(sourceFile, "const unsigned char bitmap%s[%d][%d][%d] = {\n", font_name, NUMBER_OF_SYMBOLS+CHARACTER_RANGE_END-CHARACTER_RANGE_START+1, glyph_height, glyph_width); - for (unsigned char character = CHARACTER_RANGE_START; character <= CHARACTER_RANGE_END; character++) { - fprintf(sourceFile, " {\n"); - int characterX = ((character-CHARACTER_RANGE_START)%GRID_WIDTH * (glyph_width+grid_size)); - int characterY = ((character-CHARACTER_RANGE_START)/GRID_WIDTH * (glyph_height+grid_size)); - for (int y = 0; y < glyph_height; y++) { - fprintf(sourceFile, " {"); - for (int x = 0; x < glyph_width; x++) { - pixel_t * pixel = (bitmap_image.pixels + (y+characterY)*bitmap_image.width + (x+characterX)); - fprintf(sourceFile, "0x%02x", 0xFF - pixel->green); - if (x+1 < glyph_width) { - fprintf(sourceFile, ", "); - } - } - fprintf(sourceFile, "}"); - if (y+1 < glyph_height) { - fprintf(sourceFile, ","); - } - fprintf(sourceFile, "\n"); - } - fprintf(sourceFile, " }"); - fprintf(sourceFile, ","); - fprintf(sourceFile, "\n"); - } - for (int charIndex = 0; charIndex < NUMBER_OF_SYMBOLS; charIndex++) { - wchar_t wideChar = codePointForSymbol[charIndex]; - fprintf(sourceFile, " {\n"); - int characterX = ((charIndex+1+CHARACTER_RANGE_END-CHARACTER_RANGE_START)%GRID_WIDTH * (glyph_width+grid_size)); - int characterY = ((charIndex+1+CHARACTER_RANGE_END-CHARACTER_RANGE_START)/GRID_WIDTH * (glyph_height+grid_size)); - for (int y = 0; y < glyph_height; y++) { - fprintf(sourceFile, " {"); - for (int x = 0; x < glyph_width; x++) { - pixel_t * pixel = (bitmap_image.pixels + (y+characterY)*bitmap_image.width + (x+characterX)); - fprintf(sourceFile, "0x%02x", 0xFF - pixel->green); - if (x+1 < glyph_width) { - fprintf(sourceFile, ", "); - } - } - fprintf(sourceFile, "}"); - if (y+1 < glyph_height) { - fprintf(sourceFile, ","); - } - fprintf(sourceFile, "\n"); - } - fprintf(sourceFile, " }"); - if (charIndex < NUMBER_OF_SYMBOLS - 1) { - fprintf(sourceFile, ","); - } - fprintf(sourceFile, "\n"); - } - - fprintf(sourceFile, "};\n"); - -#endif - fclose(sourceFile); - free(bitmap_image.pixels); return 0;