1 | /* |
---|
2 | * makefont.c: create a font bitmap from a .ttf file. |
---|
3 | * $Id: makefont.c 443 2005-01-10 00:37:53Z sam $ |
---|
4 | * |
---|
5 | * Copyright: (c) 2004 Sam Hocevar <sam@zoy.org> |
---|
6 | * This program is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the Do What The Fuck You Want To |
---|
8 | * Public License as published by Banlu Kemiyatorn. See |
---|
9 | * http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
10 | * |
---|
11 | * Build example: |
---|
12 | * gcc -Wall makefont.c -o makefont `sdl-config --cflags --libs` -lSDL_ttf |
---|
13 | * |
---|
14 | * Usage: |
---|
15 | * makefont <font.ttf> <size> <text> <output.bmp> |
---|
16 | */ |
---|
17 | |
---|
18 | #include <stdlib.h> |
---|
19 | #include <stdio.h> |
---|
20 | |
---|
21 | #include "SDL.h" |
---|
22 | #include "SDL_ttf.h" |
---|
23 | |
---|
24 | int main(int argc, char *argv[]) |
---|
25 | { |
---|
26 | SDL_Color bg = { 0xff, 0xff, 0xff, 0 }; |
---|
27 | SDL_Color fg = { 0x00, 0x00, 0x00, 0 }; |
---|
28 | SDL_Surface *text; |
---|
29 | TTF_Font *font; |
---|
30 | |
---|
31 | if(argc != 5) |
---|
32 | { |
---|
33 | fprintf(stderr, "usage: %s <font.ttf> <size> <text> <output.bmp>\n", |
---|
34 | argv[0]); |
---|
35 | return 1; |
---|
36 | } |
---|
37 | |
---|
38 | TTF_Init(); |
---|
39 | font = TTF_OpenFont(argv[1], atoi(argv[2])); |
---|
40 | if(!font) |
---|
41 | { |
---|
42 | fprintf(stderr, "could not load font %s: %s\n", |
---|
43 | argv[1], SDL_GetError()); |
---|
44 | TTF_Quit(); |
---|
45 | return 1; |
---|
46 | } |
---|
47 | |
---|
48 | TTF_SetFontStyle(font, TTF_STYLE_NORMAL); |
---|
49 | text = TTF_RenderUTF8_Shaded(font, argv[3], fg, bg); |
---|
50 | if(!text) |
---|
51 | { |
---|
52 | fprintf(stderr, "text rendering failed: %s\n", SDL_GetError()); |
---|
53 | TTF_CloseFont(font); |
---|
54 | TTF_Quit(); |
---|
55 | return 1; |
---|
56 | } |
---|
57 | |
---|
58 | SDL_SaveBMP(text, argv[4]); |
---|
59 | SDL_FreeSurface(text); |
---|
60 | TTF_CloseFont(font); |
---|
61 | TTF_Quit(); |
---|
62 | |
---|
63 | return 0; |
---|
64 | } |
---|
65 | |
---|