# HG changeset patch # User Matti Hamalainen # Date 1365997453 -10800 # Node ID 151747a24f5747f624c0bc36d11993fe98ef8403 # Parent 78cef1000a1885b106d08e3acca5bf56214f6987 Add color setting option to fontconv. diff -r 78cef1000a18 -r 151747a24f57 fontconv.c --- a/fontconv.c Mon Apr 15 04:16:46 2013 +0300 +++ b/fontconv.c Mon Apr 15 06:44:13 2013 +0300 @@ -19,6 +19,8 @@ int optSplitWidth = 8, optSplitHeight = 8; +SDL_Color optColor = { 255, 255, 255, 100 }; + DMOptArg optList[] = { @@ -26,6 +28,7 @@ { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, { 2, 'o', "output", "Output file (default stdout)", OPT_ARGREQ }, { 3, 's', "size", "Set glyph dimensions (-s WxH) for image->font conversion", OPT_ARGREQ }, + { 4, 'c', "color", "TTF font rendering color (def: 0xFFFFFF)", OPT_ARGREQ }, }; const int optListN = sizeof(optList) / sizeof(optList[0]); @@ -73,6 +76,28 @@ } break; + case 4: + { + int colR, colG, colB, colA = 100; + if (optArg[0] == '#' || optArg[0] == '$') optArg++; + else + if (optArg[0] == '0' && optArg[1] == 'x') optArg += 2; + + if (sscanf(optArg, "%02x%02x%02x", &colR, &colG, &colB) != 3 && + sscanf(optArg, "%02x%02x%02x%02x", &colR, &colG, &colB, &colA) != 4) + { + dmError("Invalid RGB hex representation '%s'.\n", + optArg); + return FALSE; + } + + optColor.r = colR; + optColor.g = colG; + optColor.b = colB; + optColor.unused = colA; + } + break; + default: dmError("Unknown argument '%s'.\n", currArg); return FALSE; @@ -286,7 +311,6 @@ if ((ttf = TTF_OpenFont(optInFilename, optSplitWidth)) != NULL) { int i; - SDL_Color col = { 255, 255, 255, 100 }; dmMsg(1, "Input is a TTF TrueType font, rendering at %d x %d.\n", optSplitWidth, optSplitHeight); @@ -302,7 +326,7 @@ char str[2]; str[0] = i; str[1] = 0; - font->glyphs[i] = TTF_RenderText_Blended(ttf, str, col); + font->glyphs[i] = TTF_RenderText_Blended(ttf, str, optColor); } } #endif