In Un*x, SDL_Pango is hard to use as system-independent module, because it depends on fontconfig and Pango which are designed as system-singleton modules. If you use SDL_Pango, your software will require those modules installed to target system. If your software is shipped as shrink-wrap package, it may cause much problem on your support desk. You should carefully design your installation process.
In Windows, SDL_Pango is distributed as "merge module" which contains fontconfig and Pango. Those binaries are modified as side-by-side components. You should use Windows Installer and merge the module on your MSI package. The merge module not only contains files, but also includes custom action which must be run at installation.
<span font_family="Courier New"><i>This is Courier New and italic.</i></span>
Color, size, subscript/superscript, obliquing, weight, and other many features are also available in same way.
In MinGW, I recommend you to use VS2003. Otherwise you may run into the maze of distribution. If you insist MinGW, you should use MinGW binary archive.
In Un*x, installation consists of:
./configure make make install
#include "SDL_Pango.h"
In Windows, SDL_Pango.h is installed on %ProgramFiles%\SDL_Pango
Development\include
(usually C:\Program
Files\SDL_Pango
Development\include
). You should add this directory to include path.
Note: Some systems may not have the SDL_Pango library and include file in the same place as the SDL library and includes are located, in that case you will need to add more -I and -L paths to these command lines.
Simple Example for compiling an object file:
cc -c `sdl-config --cflags` mysource.c
Simple Example for linking an object file:
cc -o myprogram mysource.o `sdl-config --libs` -lSDL_Pango
Now myprogram is ready to run.
You can see a sample of autoconfiscation in 'test' directory.
In Windows, MSI package installs many dlls to %ProgramFiles%\SDL_Pango
Development\import_lib
. To link with SDL_Pango you should use SDL_Pango.lib.
SDL_Pango.dll depends on many dlls and other many files. Those dlls are installed on %ProgramFiles%\SDL_Pango
Development\bin
. MSI package adds the directory to PATH environment variable.
In Windows, local.conf of fontconfig is placed on %ProgramFiles%\SDL_Pango
Development\etc\fonts
. You should know about fontconfig's font cache mechanism.
SDLPango_Context *context = SDLPango_CreateContext();
Specify default colors and minimum surface size.
SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_WHITE_LETTER); SDLPango_SetMinimumSize(context, 640, 0);
Set markup text.
SDLPango_SetMarkup(context, "This is <i>markup</i> text.", -1);
Now you can get the size of surface.
int w = SDLPango_GetLayoutWidth(context); int h = SDLPango_GetLayoutHeight(context);
Create surface to draw.
int margin_x = 10; int margin_y = 10; SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w + margin_x * 2, h + margin_y * 2, 32, (Uint32)(255 << (8 * 3)), (Uint32)(255 << (8 * 2)), (Uint32)(255 << (8 * 1)), 255);
And draw on it.
SDLPango_Draw(context, surface, margin_x, margin_y);
You must free the surface by yourself.
SDL_FreeSurface(surface);
Free context.
SDLPango_FreeContext(context);
You can see actual code in test/testbench
.cpp.
In Windows, font files must be installed on apprication folder (usually C:\Program
Files\
[Manufacturer]\[ProductName]). The property of apprication folder must be TARGETDIR
(this is default setting of VS2003). SDL.dll also must be installed on apprication folder. Add SDL_Pango.msm to your MSI package.