changeset 633:151747a24f57

Add color setting option to fontconv.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 15 Apr 2013 06:44:13 +0300
parents 78cef1000a18
children 656332eec724
files fontconv.c
diffstat 1 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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