Update testime program to accept font parameter. gsoc2009_IME
authorJiang Jiang <gzjjgod@gmail.com>
Thu, 06 Aug 2009 09:01:03 +0000
branchgsoc2009_IME
changeset 3137311c678f3b2e
parent 3136 962357f325e1
child 3138 7100a1a20143
Update testime program to accept font parameter.
test/testime.c
     1.1 --- a/test/testime.c	Thu Aug 06 08:59:53 2009 +0000
     1.2 +++ b/test/testime.c	Thu Aug 06 09:01:03 2009 +0000
     1.3 @@ -8,7 +8,7 @@
     1.4  #include <SDL/SDL_ttf.h>
     1.5   
     1.6  #define DEFAULT_PTSIZE  30
     1.7 -#define DEFAULT_FONT    "DroidSansFallback.ttf"
     1.8 +#define DEFAULT_FONT    "/System/Library/Fonts/华文细黑.ttf"
     1.9  #define MAX_TEXT_LENGTH 256
    1.10  
    1.11  SDL_Surface *screen;
    1.12 @@ -18,9 +18,38 @@
    1.13  SDL_Color textColor = { 0, 0, 0 };
    1.14  char text[MAX_TEXT_LENGTH], *markedText;
    1.15  
    1.16 +void usage()
    1.17 +{
    1.18 +    printf("usage: testime [--font fontfile] [--fullscreen]\n");
    1.19 +    exit(0);
    1.20 +}
    1.21 +
    1.22  void InitVideo(int argc, char *argv[])
    1.23  {
    1.24      int width = 500, height = 250;
    1.25 +    int flags = SDL_HWSURFACE;
    1.26 +    const char *fontname = DEFAULT_FONT;
    1.27 +    int fullscreen = 0;
    1.28 +
    1.29 +    for (argc--, argv++; argc > 0; argc--, argv++)
    1.30 +    {
    1.31 +        if (strcmp(argv[0], "--help") == 0)
    1.32 +            usage();
    1.33 +
    1.34 +        else if (strcmp(argv[0], "--fullscreen") == 0)
    1.35 +            fullscreen = 1;
    1.36 +
    1.37 +        else if (strcmp(argv[0], "--font") == 0)
    1.38 +        {
    1.39 +            argc--;
    1.40 +            argv++;
    1.41 +
    1.42 +            if (argc > 0)
    1.43 +                fontname = argv[0];
    1.44 +            else
    1.45 +                usage();
    1.46 +        }
    1.47 +    }
    1.48  
    1.49      SDL_putenv("SDL_VIDEO_WINDOW_POS=center");
    1.50      if (SDL_Init(SDL_INIT_VIDEO) < 0)
    1.51 @@ -32,17 +61,17 @@
    1.52      /* Initialize fonts */
    1.53      TTF_Init();
    1.54  
    1.55 -    font = TTF_OpenFont(DEFAULT_FONT, DEFAULT_PTSIZE);
    1.56 +    font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
    1.57      if (! font)
    1.58      {
    1.59          fprintf(stderr, "Failed to find font: %s\n", SDL_GetError());
    1.60          exit(-1);
    1.61      }
    1.62  
    1.63 +    printf("Using font: %s\n", fontname);
    1.64      atexit(SDL_Quit);
    1.65  
    1.66 -    int flags = SDL_HWSURFACE;
    1.67 -    if (argc > 1 && strcmp(argv[1], "--fullscreen") == 0)
    1.68 +    if (fullscreen)
    1.69      {
    1.70          SDL_DisplayMode mode;
    1.71          SDL_GetDesktopDisplayMode(&mode);
    1.72 @@ -123,8 +152,11 @@
    1.73          return;
    1.74      }
    1.75  
    1.76 +    cursorRect = markedRect;
    1.77 +    cursorRect.w = 2;
    1.78 +    cursorRect.h = h;
    1.79 +
    1.80      SDL_FillRect(screen, &markedRect, backColor);
    1.81 -
    1.82      if (markedText)
    1.83      {
    1.84          RenderText(screen, font, markedText, markedRect.x, markedRect.y, textColor);
    1.85 @@ -134,12 +166,12 @@
    1.86          underlineRect.y += (h - 2);
    1.87          underlineRect.h = 2;
    1.88          underlineRect.w = w;
    1.89 +
    1.90 +        cursorRect.x += w + 1;
    1.91 +
    1.92          SDL_FillRect(screen, &underlineRect, lineColor);
    1.93      }
    1.94  
    1.95 -    cursorRect = markedRect;
    1.96 -    cursorRect.w = 2;
    1.97 -    cursorRect.h = h;
    1.98      SDL_FillRect(screen, &cursorRect, lineColor);
    1.99  
   1.100      SDL_Flip(screen);