From 14db5a2ab0ac0e4734766ecf62be14fdcb46db15 Mon Sep 17 00:00:00 2001 From: ZHK Date: Wed, 7 Feb 2024 17:10:48 +0800 Subject: [PATCH] - Restored .clang-format - Removed system-specific lines in .vcxproj files - Should fixed compilation on other platforms --- .clang-format | 2 +- VisualC/SDL_ttf.vcxproj | 10 +- VisualC/SDL_ttf.vcxproj.filters | 85 +++++----- VisualC/glfont/glfont.vcxproj | 7 +- VisualC/showfont/showfont.vcxproj | 12 +- examples/showfont.c | 267 +++++++++++------------------- 6 files changed, 145 insertions(+), 238 deletions(-) diff --git a/.clang-format b/.clang-format index 7083da1d..d28aae9a 100644 --- a/.clang-format +++ b/.clang-format @@ -26,7 +26,7 @@ BreakBeforeBraces: Custom BraceWrapping: AfterCaseLabel: true AfterClass: true - AfterControlStatement: true + AfterControlStatement: Never AfterEnum: true AfterFunction: true AfterNamespace: true diff --git a/VisualC/SDL_ttf.vcxproj b/VisualC/SDL_ttf.vcxproj index d6b9392b..bca85e73 100644 --- a/VisualC/SDL_ttf.vcxproj +++ b/VisualC/SDL_ttf.vcxproj @@ -117,7 +117,6 @@ Level3 OldStyle StreamingSIMDExtensions - K:\ProjectsMine\SDL_ttf\external\SDL\include _DEBUG;%(PreprocessorDefinitions) @@ -145,14 +144,13 @@ MultiThreadedDLL Level3 OldStyle - K:\ProjectsMine\SDL_ttf\external\SDL\include _DEBUG;%(PreprocessorDefinitions) SDL3.lib;ucrtd.lib;%(AdditionalDependencies) - external\lib\x64;K:\ProjectsMine\SDL_ttf\external\SDL\VisualC\x64\Debug;%(AdditionalLibraryDirectories) + external\lib\x64;%(AdditionalLibraryDirectories) true Windows @@ -172,7 +170,6 @@ MultiThreadedDLL Level3 StreamingSIMDExtensions - K:\ProjectsMine\SDL_ttf\external\SDL\include NDEBUG;%(PreprocessorDefinitions) @@ -197,14 +194,13 @@ DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;TTF_USE_HARFBUZZ=1;FT_PUBLIC_FUNCTION_ATTRIBUTE=;FT_CONFIG_OPTION_USE_HARFBUZZ;FT2_BUILD_LIBRARY;HAVE_FREETYPE;%(PreprocessorDefinitions) MultiThreadedDLL Level3 - K:\ProjectsMine\SDL_ttf\external\SDL\include NDEBUG;%(PreprocessorDefinitions) SDL3.lib;%(AdditionalDependencies) - external\lib\x64;K:\ProjectsMine\SDL_ttf\external\SDL\VisualC\x64\Release;%(AdditionalLibraryDirectories) + external\lib\x64;%(AdditionalLibraryDirectories) Windows @@ -400,4 +396,4 @@ - \ No newline at end of file + diff --git a/VisualC/SDL_ttf.vcxproj.filters b/VisualC/SDL_ttf.vcxproj.filters index 289c189a..ea6ea142 100644 --- a/VisualC/SDL_ttf.vcxproj.filters +++ b/VisualC/SDL_ttf.vcxproj.filters @@ -177,6 +177,9 @@ Sources\HarfBuzz + + Sources\HarfBuzz + Sources\HarfBuzz @@ -204,6 +207,42 @@ Sources\HarfBuzz + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + + + Sources\HarfBuzz + Sources\HarfBuzz @@ -240,50 +279,6 @@ Sources\FreeType - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -315,4 +310,4 @@ x64 - \ No newline at end of file + diff --git a/VisualC/glfont/glfont.vcxproj b/VisualC/glfont/glfont.vcxproj index 4a299ff0..d07993d4 100644 --- a/VisualC/glfont/glfont.vcxproj +++ b/VisualC/glfont/glfont.vcxproj @@ -113,7 +113,6 @@ WIN32;NDEBUG;_WINDOWS;HAVE_OPENGL;%(PreprocessorDefinitions) MultiThreadedDLL Level3 - K:\ProjectsMine\SDL_ttf\external\SDL\include NDEBUG;%(PreprocessorDefinitions) @@ -144,7 +143,6 @@ WIN32;NDEBUG;_WINDOWS;HAVE_OPENGL;%(PreprocessorDefinitions) MultiThreadedDLL Level3 - K:\ProjectsMine\SDL_ttf\external\SDL\include NDEBUG;%(PreprocessorDefinitions) @@ -177,7 +175,6 @@ MultiThreadedDLL Level3 OldStyle - K:\ProjectsMine\SDL_ttf\external\SDL\include _DEBUG;%(PreprocessorDefinitions) @@ -211,7 +208,6 @@ MultiThreadedDLL Level3 OldStyle - K:\ProjectsMine\SDL_ttf\external\SDL\include;K:\ProjectsMine\SDL_ttf\include _DEBUG;%(PreprocessorDefinitions) @@ -221,7 +217,6 @@ opengl32.lib;SDL3.lib;%(AdditionalDependencies) true Windows - K:\ProjectsMine\SDL_ttf\external\SDL\VisualC\x64\Debug;%(AdditionalLibraryDirectories) @@ -249,4 +244,4 @@ - \ No newline at end of file + diff --git a/VisualC/showfont/showfont.vcxproj b/VisualC/showfont/showfont.vcxproj index e1dd4f18..60e7e2b6 100644 --- a/VisualC/showfont/showfont.vcxproj +++ b/VisualC/showfont/showfont.vcxproj @@ -113,7 +113,6 @@ WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 - K:\ProjectsMine\SDL_ttf\external\SDL\include NDEBUG;%(PreprocessorDefinitions) @@ -144,7 +143,6 @@ WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) MultiThreadedDLL Level3 - K:\ProjectsMine\SDL_ttf\external\SDL\include;K:\ProjectsMine\SDL_ttf\include NDEBUG;%(PreprocessorDefinitions) @@ -152,8 +150,7 @@ SDL3.lib;%(AdditionalDependencies) - Console - K:\ProjectsMine\SDL_ttf\external\SDL\VisualC\x64\Release + Windows @@ -178,7 +175,6 @@ MultiThreadedDLL Level3 OldStyle - K:\ProjectsMine\SDL_ttf\external\SDL\include _DEBUG;%(PreprocessorDefinitions) @@ -212,7 +208,6 @@ MultiThreadedDLL Level3 OldStyle - K:\ProjectsMine\SDL_ttf\external\SDL\include;K:\ProjectsMine\SDL_ttf\include _DEBUG;%(PreprocessorDefinitions) @@ -221,8 +216,7 @@ SDL3.lib;%(AdditionalDependencies) true - Console - K:\ProjectsMine\SDL_ttf\external\SDL\VisualC\x64\Debug;%(AdditionalLibraryDirectories) + Windows @@ -250,4 +244,4 @@ - \ No newline at end of file + diff --git a/examples/showfont.c b/examples/showfont.c index af22131d..00292121 100644 --- a/examples/showfont.c +++ b/examples/showfont.c @@ -31,18 +31,16 @@ #include #define DEFAULT_PTSIZE 18 -#define DEFAULT_TEXT "The quick brown fox jumped over the lazy dog" +#define DEFAULT_TEXT "The quick brown fox jumped over the lazy dog." #define WIDTH 1280 #define HEIGHT 800 -#define TTF_SHOWFONT_USAGE \ - "Usage:\n" \ - " %s [-windowsize w,h] [-solid] [-shaded] [-blended] [-wrapped] [-b] [-i] [-u] [-s] [-outline size] [-hintlight | -hintmono | -hintnone] [-nokerning] [-wrap] [-fgcol r,g,b,a] [-bgcol r,g,b,a] [-utf8txtfile pathName] .ttf [ptsize] [text] \n" - -#define TTF_SHOWFONT_USAGE_WITH_EXAMPLE \ - TTF_SHOWFONT_USAGE##"Example:\n" \ - " %s -b -wrap -fgcol 255,0,255,255 -bgcol 64,64,64,255 NotoSansSC.ttf 32 \"This is a test.\"\n" \ - " %s -windowsize 1920,1200 -utf8txtfile content.txt NotoSansSC.ttf" +#define TTF_SHOWFONT_USAGE \ + "Usage:\n" \ + " %s [-windowsize w,h] [-solid] [-shaded] [-blended] [-wrapped] [-b] [-i] [-u] [-s] [-outline size] [-hintlight | -hintmono | -hintnone] [-nokerning] [-wrap] [-fgcol r,g,b,a] [-bgcol r,g,b,a] [-utf8txtfile pathName] .ttf [ptsize] [text] \n" \ + "Example:\n" \ + " %s -b -wrap -fgcol 255,0,255,255 -bgcol 64,64,64,255 NotoSansSC.ttf 32 \"This is a test.\"\n" \ + " %s -windowsize 1920,1200 -utf8txtfile content.txt NotoSansSC.ttf" typedef enum { @@ -77,11 +75,15 @@ static void cleanup(int exitcode) exit(exitcode); } +void show_usage(const char *appName) +{ + SDL_Log(TTF_SHOWFONT_USAGE, appName, appName, appName); +} + int load_file(char **bufferAddr, const char *pathName) { FILE *file = fopen(pathName, "rb"); - if (file == NULL) - { + if (file == NULL) { perror("Error opening file"); return 1; } @@ -89,8 +91,7 @@ int load_file(char **bufferAddr, const char *pathName) fseek(file, 0, SEEK_END); long file_size = ftell(file); - if (file_size == 0) - { + if (file_size == 0) { fclose(file); return 0; } @@ -102,22 +103,18 @@ int load_file(char **bufferAddr, const char *pathName) memset(buffer, 0, file_size + 1); size_t bytesRead = fread(buffer, 1, file_size, file); - if (bytesRead == 0) - { + if (bytesRead == 0) { perror("Error reading file"); fclose(file); return 1; } - if (fread(buffer, file_size, 1, file) != 0) - { + if (fread(buffer, file_size, 1, file) != 0) { return 1; } - for (int i = 0; i < file_size; ++i) - { - if (iscntrl(buffer[i])) - { + for (int i = 0; i < file_size; ++i) { + if (iscntrl(buffer[i])) { buffer[i] = 32; } } @@ -174,100 +171,75 @@ int main(int argc, char *argv[]) forecol = &black; backcol = &white; - if (argc == 1) - { - printf(TTF_SHOWFONT_USAGE_WITH_EXAMPLE, argv0, argv0, argv0); + if (argc == 1) { + show_usage(argv0); return (1); } - for (i = 1; argv[i] && argv[i][0] == '-'; ++i) - { - if (SDL_strcmp(argv[i], "-solid") == 0) - { + for (i = 1; argv[i] && argv[i][0] == '-'; ++i) { + if (SDL_strcmp(argv[i], "-solid") == 0) { rendermethod = TextRenderSolid; - } else if (SDL_strcmp(argv[i], "-shaded") == 0) - { + } else if (SDL_strcmp(argv[i], "-shaded") == 0) { rendermethod = TextRenderShaded; - } else if (SDL_strcmp(argv[i], "-blended") == 0) - { + } else if (SDL_strcmp(argv[i], "-blended") == 0) { rendermethod = TextRenderBlended; - } else if (SDL_strcmp(argv[i], "-b") == 0) - { + } else if (SDL_strcmp(argv[i], "-b") == 0) { renderstyle |= TTF_STYLE_BOLD; - } else if (SDL_strcmp(argv[i], "-i") == 0) - { + } else if (SDL_strcmp(argv[i], "-i") == 0) { renderstyle |= TTF_STYLE_ITALIC; - } else if (SDL_strcmp(argv[i], "-u") == 0) - { + } else if (SDL_strcmp(argv[i], "-u") == 0) { renderstyle |= TTF_STYLE_UNDERLINE; - } else if (SDL_strcmp(argv[i], "-s") == 0) - { + } else if (SDL_strcmp(argv[i], "-s") == 0) { renderstyle |= TTF_STYLE_STRIKETHROUGH; - } else if (SDL_strcmp(argv[i], "-outline") == 0) - { - if (SDL_sscanf(argv[++i], "%d", &outline) != 1) - { - SDL_Log(TTF_SHOWFONT_USAGE, argv0); + } else if (SDL_strcmp(argv[i], "-outline") == 0) { + if (SDL_sscanf(argv[++i], "%d", &outline) != 1) { + show_usage(argv0); return (1); } - } else if (SDL_strcmp(argv[i], "-hintlight") == 0) - { + } else if (SDL_strcmp(argv[i], "-hintlight") == 0) { hinting = TTF_HINTING_LIGHT; - } else if (SDL_strcmp(argv[i], "-hintmono") == 0) - { + } else if (SDL_strcmp(argv[i], "-hintmono") == 0) { hinting = TTF_HINTING_MONO; - } else if (SDL_strcmp(argv[i], "-hintnone") == 0) - { + } else if (SDL_strcmp(argv[i], "-hintnone") == 0) { hinting = TTF_HINTING_NONE; - } else if (SDL_strcmp(argv[i], "-nokerning") == 0) - { + } else if (SDL_strcmp(argv[i], "-nokerning") == 0) { kerning = 0; - } else if (SDL_strcmp(argv[i], "-wrap") == 0) - { + } else if (SDL_strcmp(argv[i], "-wrap") == 0) { wrap = 1; - } else if (SDL_strcmp(argv[i], "-dump") == 0) - { + } else if (SDL_strcmp(argv[i], "-dump") == 0) { dump = 1; - } else if (SDL_strcmp(argv[i], "-fgcol") == 0) - { + } else if (SDL_strcmp(argv[i], "-fgcol") == 0) { int r, g, b, a = 0xFF; - if (SDL_sscanf(argv[++i], "%d,%d,%d,%d", &r, &g, &b, &a) < 3) - { - SDL_Log(TTF_SHOWFONT_USAGE, argv0); + if (SDL_sscanf(argv[++i], "%d,%d,%d,%d", &r, &g, &b, &a) < 3) { + show_usage(argv0); return (1); } forecol->r = (Uint8)r; forecol->g = (Uint8)g; forecol->b = (Uint8)b; forecol->a = (Uint8)a; - } else if (SDL_strcmp(argv[i], "-bgcol") == 0) - { + } else if (SDL_strcmp(argv[i], "-bgcol") == 0) { int r, g, b, a = 0xFF; - if (SDL_sscanf(argv[++i], "%d,%d,%d,%d", &r, &g, &b, &a) < 3) - { - SDL_Log(TTF_SHOWFONT_USAGE, argv0); + if (SDL_sscanf(argv[++i], "%d,%d,%d,%d", &r, &g, &b, &a) < 3) { + show_usage(argv0); return (1); } backcol->r = (Uint8)r; backcol->g = (Uint8)g; backcol->b = (Uint8)b; backcol->a = (Uint8)a; - } else if (SDL_strcmp(argv[i], "-utf8txtfile") == 0) - { + } else if (SDL_strcmp(argv[i], "-utf8txtfile") == 0) { load_file(&fileMessage, argv[++i]); rendertype = RENDER_UTF8; wrap = 1; - } else if (SDL_strcmp(argv[i], "-windowsize") == 0) - { - if (SDL_sscanf(argv[++i], "%d,%d", &winWidth, &winHeight) < 2) - { - SDL_Log(TTF_SHOWFONT_USAGE, argv0); + } else if (SDL_strcmp(argv[i], "-windowsize") == 0) { + if (SDL_sscanf(argv[++i], "%d,%d", &winWidth, &winHeight) < 2) { + show_usage(argv0); return (1); } - wrapWidth = winWidth - 10; - } else - { - SDL_Log(TTF_SHOWFONT_USAGE, argv0); + wrapWidth = winWidth; + } else { + show_usage(argv0); return (1); } } @@ -275,15 +247,13 @@ int main(int argc, char *argv[]) argc -= i; /* Check usage */ - if (!argv[0]) - { + if (!argv[0]) { SDL_Log(TTF_SHOWFONT_USAGE, argv0); return (1); } /* Initialize the TTF library */ - if (TTF_Init() < 0) - { + if (TTF_Init() < 0) { SDL_Log("Couldn't initialize TTF: %s\n", SDL_GetError()); SDL_Quit(); return (2); @@ -291,21 +261,17 @@ int main(int argc, char *argv[]) /* Open the font file with the requested point size */ ptsize = 0; - if (argc > 1) - { + if (argc > 1) { ptsize = SDL_atoi(argv[1]); } - if (ptsize == 0) - { + if (ptsize == 0) { i = 2; ptsize = DEFAULT_PTSIZE; - } else - { + } else { i = 3; } font = TTF_OpenFont(argv[0], ptsize); - if (font == NULL) - { + if (font == NULL) { SDL_Log("Couldn't load %d pt font from %s: %s\n", ptsize, argv[0], SDL_GetError()); cleanup(2); @@ -315,16 +281,13 @@ int main(int argc, char *argv[]) TTF_SetFontKerning(font, kerning); TTF_SetFontHinting(font, hinting); - if (dump) - { - for (i = 48; i < 123; i++) - { + if (dump) { + for (i = 48; i < 123; i++) { SDL_Surface *glyph = NULL; glyph = TTF_RenderGlyph_Shaded(font, i, *forecol, *backcol); - if (glyph) - { + if (glyph) { char outname[64]; SDL_snprintf(outname, sizeof(outname), "glyph-%d.bmp", i); SDL_SaveBMP(glyph, outname); @@ -334,21 +297,18 @@ int main(int argc, char *argv[]) } /* Create a window */ - if (SDL_CreateWindowAndRenderer(winWidth, winHeight, 0, &window, &renderer) < 0) - { + if (SDL_CreateWindowAndRenderer(winWidth, winHeight, 0, &window, &renderer) < 0) { SDL_Log("SDL_CreateWindowAndRenderer() failed: %s\n", SDL_GetError()); cleanup(2); } - if (window) - { + if (window) { SDL_SetWindowTitle(window, argv0); } /* Show which font file we're looking at */ SDL_snprintf(string, sizeof(string), "Font file: %s", argv[0]); /* possible overflow */ - switch (rendermethod) - { + switch (rendermethod) { case TextRenderSolid: text = TTF_RenderText_Solid(font, string, *forecol); break; @@ -359,8 +319,7 @@ int main(int argc, char *argv[]) text = TTF_RenderText_Blended(font, string, *forecol); break; } - if (text != NULL) - { + if (text != NULL) { scene.captionRect.x = 4.0f; scene.captionRect.y = 4.0f; scene.captionRect.w = (float)text->w; @@ -370,49 +329,37 @@ int main(int argc, char *argv[]) } /* Render and center the message */ - if (fileMessage != NULL) - { + if (fileMessage != NULL) { message = fileMessage; - } else - { - if (argc > 2) - { + } else { + if (argc > 2) { message = argv[2]; - } else - { + } else { message = DEFAULT_TEXT; } } - switch (rendertype) - { + switch (rendertype) { case RENDER_LATIN1: - switch (rendermethod) - { + switch (rendermethod) { case TextRenderSolid: - if (wrap) - { + if (wrap) { text = TTF_RenderText_Solid_Wrapped(font, message, *forecol, wrapWidth); - } else - { + } else { text = TTF_RenderText_Solid(font, message, *forecol); } break; case TextRenderShaded: - if (wrap) - { + if (wrap) { text = TTF_RenderText_Shaded_Wrapped(font, message, *forecol, *backcol, wrapWidth); - } else - { + } else { text = TTF_RenderText_Shaded(font, message, *forecol, *backcol); } break; case TextRenderBlended: - if (wrap) - { + if (wrap) { text = TTF_RenderText_Blended_Wrapped(font, message, *forecol, wrapWidth); - } else - { + } else { text = TTF_RenderText_Blended(font, message, *forecol); } break; @@ -420,32 +367,25 @@ int main(int argc, char *argv[]) break; case RENDER_UTF8: - switch (rendermethod) - { + switch (rendermethod) { case TextRenderSolid: - if (wrap) - { + if (wrap) { text = TTF_RenderUTF8_Solid_Wrapped(font, message, *forecol, wrapWidth); - } else - { + } else { text = TTF_RenderUTF8_Solid(font, message, *forecol); } break; case TextRenderShaded: - if (wrap) - { + if (wrap) { text = TTF_RenderUTF8_Shaded_Wrapped(font, message, *forecol, *backcol, wrapWidth); - } else - { + } else { text = TTF_RenderUTF8_Shaded(font, message, *forecol, *backcol); } break; case TextRenderBlended: - if (wrap) - { + if (wrap) { text = TTF_RenderUTF8_Blended_Wrapped(font, message, *forecol, wrapWidth); - } else - { + } else { text = TTF_RenderUTF8_Blended(font, message, *forecol); } break; @@ -455,42 +395,33 @@ int main(int argc, char *argv[]) case RENDER_UNICODE: { Uint16 *unicode_text = SDL_iconv_utf8_ucs2(message); - switch (rendermethod) - { + switch (rendermethod) { case TextRenderSolid: - if (wrap) - { + if (wrap) { text = TTF_RenderUNICODE_Solid_Wrapped(font, unicode_text, *forecol, wrapWidth); - } else - { + } else { text = TTF_RenderUNICODE_Solid(font, unicode_text, *forecol); } break; case TextRenderShaded: - if (wrap) - { + if (wrap) { text = TTF_RenderUNICODE_Shaded_Wrapped(font, unicode_text, *forecol, *backcol, wrapWidth); - } else - { + } else { text = TTF_RenderUNICODE_Shaded(font, unicode_text, *forecol, *backcol); } break; case TextRenderBlended: - if (wrap) - { + if (wrap) { text = TTF_RenderUNICODE_Blended_Wrapped(font, unicode_text, *forecol, wrapWidth); - } else - { + } else { text = TTF_RenderUNICODE_Blended(font, unicode_text, *forecol); } break; } SDL_free(unicode_text); + } break; } - break; - } - if (text == NULL) - { + if (text == NULL) { SDL_Log("Couldn't render text: %s\n", SDL_GetError()); TTF_CloseFont(font); cleanup(2); @@ -507,16 +438,13 @@ int main(int argc, char *argv[]) /* Wait for a keystroke, and blit text on mouse press */ done = 0; - while (!done) - { - if (!SDL_WaitEvent(&event)) - { - // SDL_Log("SDL_PullEvent() error: %s\n", SDL_GetError()); - // done = 1; + while (!done) { + if (!SDL_WaitEvent(&event)) { + SDL_Log("SDL_PullEvent() error: %s\n", SDL_GetError()); + done = 1; continue; } - switch (event.type) - { + switch (event.type) { case SDL_EVENT_MOUSE_BUTTON_DOWN: scene.messageRect.x = (float)(event.button.x - text->w / 2); scene.messageRect.y = (float)(event.button.y - text->h / 2); @@ -539,8 +467,7 @@ int main(int argc, char *argv[]) SDL_DestroyTexture(scene.message); cleanup(0); - if (fileMessage != NULL) - { + if (fileMessage != NULL) { free(fileMessage); }