Began adding support for using SDL_Pango, a wrapper to Pango,
a library for layout and rendering of text, with an emphasis on internationalization. (The hope is to improve support for languages that SDL_ttf doesn't support well; e.g., Arabic and Telegu.) TTF_Font structs and some functions were replaced by a new TuxPaint_Font struct and function, which wraps around either TTF_Font or SDLPango_Context, depending on whether SDL_Pango is being used. Note: STILL NEEDS WORK!
This commit is contained in:
parent
516d913692
commit
095ba8efb3
6 changed files with 338 additions and 55 deletions
5
Makefile
5
Makefile
|
|
@ -7,7 +7,7 @@
|
|||
# bill@newbreedsoftware.com
|
||||
# http://www.tuxpaint.org/
|
||||
|
||||
# June 14, 2002 - July 8, 2007
|
||||
# June 14, 2002 - July 12, 2007
|
||||
|
||||
|
||||
# The version number, for release:
|
||||
|
|
@ -108,8 +108,9 @@ CURSOR_SHAPES=LARGE
|
|||
|
||||
# Libraries, paths, and flags:
|
||||
|
||||
SDL_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_ttf $(SDL_MIXER_LIB)
|
||||
SDL_LIBS=$(shell sdl-config --libs) -lSDL_image -lSDL_ttf $(SDL_MIXER_LIB) $(SDL_PANGO_LIB)
|
||||
SDL_MIXER_LIB=-lSDL_mixer
|
||||
SDL_PANGO_LIB=-lSDL_Pango
|
||||
SDL_CFLAGS=$(shell sdl-config --cflags) $(SVG_CFLAGS)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,17 @@ $Id$
|
|||
(Blur, Fill, Lighten, Darken, Mirror, Flip, Rainbow, Blocks, Chalk,
|
||||
Grass, Negative, Tint, Smudge, Drip, Cartoon, Brick (large & small))
|
||||
|
||||
* Began adding support for using SDL_Pango, a wrapper to Pango,
|
||||
a library for layout and rendering of text, with an emphasis on
|
||||
internationalization. (The hope is to improve support for languages
|
||||
that SDL_ttf doesn't support well; e.g., Arabic and Telegu.)
|
||||
|
||||
TTF_Font structs and some functions were replaced by a new
|
||||
TuxPaint_Font struct and function, which wraps around either TTF_Font
|
||||
or SDLPango_Context, depending on whether SDL_Pango is being used.
|
||||
|
||||
Note: STILL NEEDS WORK!
|
||||
|
||||
* New Brushes
|
||||
-----------
|
||||
* Sparkles (based on old Magic Tool)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@
|
|||
void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
|
||||
unsigned dirlen, tp_ftw_str * files, unsigned i)
|
||||
{
|
||||
/* FIXME */
|
||||
|
||||
#ifdef NO_SDLPANGO
|
||||
|
||||
dirlen = dirlen;
|
||||
|
||||
while (i--)
|
||||
|
|
@ -65,14 +69,14 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
|
|||
if (loadable)
|
||||
{
|
||||
char fname[512];
|
||||
TTF_Font *font;
|
||||
TuxPaint_Font *font;
|
||||
snprintf(fname, sizeof fname, "%s/%s", dir, files[i].str);
|
||||
//printf("Loading font: %s\n", fname);
|
||||
font = TTF_OpenFont(fname, text_sizes[text_size]);
|
||||
font = TuxPaint_Font_OpenFont("", fname, text_sizes[text_size]);
|
||||
if (font)
|
||||
{
|
||||
const char *restrict const family = TTF_FontFaceFamilyName(font);
|
||||
const char *restrict const style = TTF_FontFaceStyleName(font);
|
||||
const char *restrict const family = TuxPaint_Font_FontFaceFamilyName(font);
|
||||
const char *restrict const style = TuxPaint_Font_FontFaceStyleName(font);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
@ -149,6 +153,9 @@ void loadfont_callback(SDL_Surface * screen, const char *restrict const dir,
|
|||
free(files[i].str);
|
||||
}
|
||||
free(files);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
186
src/fonts.c
186
src/fonts.c
|
|
@ -59,13 +59,28 @@ extern WrapperData macosx;
|
|||
#ifndef FORKED_FONTS
|
||||
SDL_Thread *font_thread;
|
||||
#endif
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
|
||||
#include "SDL_Pango.h"
|
||||
#if !defined(SDL_PANGO_H)
|
||||
#error "---------------------------------------------------"
|
||||
#error "If you installed SDL_Pango from a package, be sure"
|
||||
#error "to get the development package, as well!"
|
||||
#error "(e.g., 'libsdl-pango1-dev.rpm')"
|
||||
#error "---------------------------------------------------"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int no_system_fonts;
|
||||
volatile long font_thread_done = 0, font_thread_aborted = 0;
|
||||
volatile long waiting_for_fonts = 0;
|
||||
int font_scanner_pid;
|
||||
int font_socket_fd;
|
||||
|
||||
TTF_Font *medium_font, *small_font, *large_font, *locale_font;
|
||||
TuxPaint_Font *medium_font, *small_font, *large_font, *locale_font;
|
||||
|
||||
family_info **user_font_families;
|
||||
int num_font_families = 0;
|
||||
|
|
@ -78,6 +93,7 @@ int num_font_styles_max = 0;
|
|||
int text_state;
|
||||
unsigned text_size = 4; // initial text size
|
||||
|
||||
|
||||
/* Unfortunately, there is a bug in SDL_ttf-2.0.6, the current version
|
||||
that causes a segmentation fault if an attempt is made to call
|
||||
TTF_OpenFont() with the filename of a font that doesn't exist. This
|
||||
|
|
@ -108,8 +124,16 @@ TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize)
|
|||
|
||||
/* #define TTF_OpenFont BUGFIX_TTF_OpenFont206 */
|
||||
|
||||
TTF_Font *try_alternate_font(int size)
|
||||
TuxPaint_Font *try_alternate_font(int size)
|
||||
{
|
||||
#ifndef NO_SDLPANGO
|
||||
|
||||
/* Do we need to do anything when we use SDL_Pango?
|
||||
-bjk 2007.07.12 */
|
||||
|
||||
(void)size; // silence 'unused parameter' warning
|
||||
|
||||
#else
|
||||
char str[128];
|
||||
char prefix[64];
|
||||
char *p;
|
||||
|
|
@ -122,37 +146,48 @@ TTF_Font *try_alternate_font(int size)
|
|||
|
||||
return TTF_OpenFont(str, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TTF_Font *load_locale_font(TTF_Font * fallback, int size)
|
||||
TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
|
||||
{
|
||||
TTF_Font *ret = NULL;
|
||||
TuxPaint_Font *ret = NULL;
|
||||
if (need_own_font)
|
||||
{
|
||||
#ifndef NO_SDLPANGO
|
||||
|
||||
/* FIXME: Do we even need to do anything when using SDL_Pango? -bjk 2007.07.12 */
|
||||
|
||||
(void)size; // silence 'unused parameter' warning
|
||||
|
||||
return(fallback);
|
||||
|
||||
#else
|
||||
char str[128];
|
||||
snprintf(str, sizeof(str), "%sfonts/locale/%s.ttf",
|
||||
DATA_PREFIX, lang_prefix);
|
||||
|
||||
ret = TTF_OpenFont(str, size);
|
||||
ret = TuxPaint_OpenFont(str, size);
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (ret == NULL)
|
||||
{
|
||||
snprintf(str, sizeof(str), "%sfonts/%s.ttf", DATA_PREFIX, lang_prefix);
|
||||
ret = TTF_OpenFont(str, size);
|
||||
ret = TuxPaint_Font_OpenFont(str, size);
|
||||
}
|
||||
|
||||
if (ret == NULL)
|
||||
{
|
||||
snprintf(str, sizeof(str), "/Library/Fonts/%s.ttf", lang_prefix);
|
||||
ret = TTF_OpenFont(str, size);
|
||||
ret = TuxPaint_Font_OpenFont(str, size);
|
||||
}
|
||||
|
||||
if (ret == NULL)
|
||||
{
|
||||
snprintf(str, sizeof(str), "%s/%s.ttf", macosx.fontsPath, lang_prefix);
|
||||
ret = TTF_OpenFont(str, size);
|
||||
ret = TuxPaint_Font_OpenFont(str, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -180,10 +215,50 @@ TTF_Font *load_locale_font(TTF_Font * fallback, int size)
|
|||
set_current_language();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
return ret ? ret : fallback;
|
||||
}
|
||||
|
||||
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
|
||||
{
|
||||
#ifndef NO_SDLPANGO
|
||||
SDLPango_FreeContext(tpf->pango_context);
|
||||
tpf->pango_context = NULL;
|
||||
free(tpf);
|
||||
#else
|
||||
TTF_CloseFont(tpf->ttf_font);
|
||||
tpf->ttf_font = NULL;
|
||||
free(tpf);
|
||||
#endif
|
||||
}
|
||||
|
||||
TuxPaint_Font * TuxPaint_Font_OpenFont(const char * pangodesc, const char * ttffilename, int size)
|
||||
{
|
||||
TuxPaint_Font * tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font));
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
|
||||
char desc[1024];
|
||||
|
||||
snprintf(desc, sizeof(desc), "%s %d", pangodesc, size - 2);
|
||||
|
||||
tpf->pango_context = SDLPango_CreateContext_GivenFontDesc(desc);
|
||||
tpf->height = size - 2; /* FIXME: Is this accurate!? -bjk 2007.07.12 */
|
||||
|
||||
(void)(ttffilename);
|
||||
#else
|
||||
|
||||
tpf->ttf_font = TTF_OpenFont(ttffilename, size);
|
||||
tpf->height = TTF_FontHeight(getfonthandle(tpf->font)));
|
||||
|
||||
(void)(pangodesc);
|
||||
#endif
|
||||
|
||||
return(tpf);
|
||||
}
|
||||
|
||||
|
||||
#ifdef FORKED_FONTS
|
||||
|
||||
|
|
@ -1045,16 +1120,27 @@ void groupfonts(void)
|
|||
}
|
||||
|
||||
|
||||
TTF_Font *getfonthandle(int desire)
|
||||
TuxPaint_Font *getfonthandle(int desire)
|
||||
{
|
||||
int missing = 0;
|
||||
family_info *fi = user_font_families[desire];
|
||||
char *name = fi->filename[text_state];
|
||||
char *pathname;
|
||||
char description[1024];
|
||||
|
||||
if (fi->handle)
|
||||
return fi->handle;
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
snprintf(description, sizeof(description), "%s%s%s", fi->family,
|
||||
(text_state ^ TTF_STYLE_ITALIC ? " italic" : ""),
|
||||
(text_state ^ TTF_STYLE_BOLD ? " bold" : ""));
|
||||
|
||||
pathname = (char *) "";
|
||||
|
||||
printf("getfonthandle(%d) asking SDL_Pango for %s\n", desire, description);
|
||||
#else
|
||||
|
||||
if (!name)
|
||||
{
|
||||
name = fi->filename[text_state ^ TTF_STYLE_ITALIC];
|
||||
|
|
@ -1073,9 +1159,16 @@ TTF_Font *getfonthandle(int desire)
|
|||
pathname = alloca(strlen(fi->directory) + 1 + strlen(name) + 1);
|
||||
sprintf(pathname, "%s/%s", fi->directory, name);
|
||||
|
||||
fi->handle = TTF_OpenFont(pathname, text_sizes[text_size]);
|
||||
strcpy(description, "");
|
||||
#endif
|
||||
|
||||
fi->handle = TuxPaint_Font_OpenFont(description, pathname, text_sizes[text_size]);
|
||||
// if the font doesn't load, we die -- it did load OK before though
|
||||
|
||||
#ifdef NO_SDLPANGO
|
||||
TTF_SetFontStyle(fi->handle, missing);
|
||||
#endif
|
||||
|
||||
return fi->handle;
|
||||
}
|
||||
|
||||
|
|
@ -1156,9 +1249,12 @@ int surfcmp(const void *s1, const void *s2)
|
|||
}
|
||||
|
||||
// check if the characters will render distinctly
|
||||
int charset_works(TTF_Font * font, const char *s)
|
||||
int charset_works(TuxPaint_Font * font, const char *s)
|
||||
{
|
||||
SDL_Color black = { 0, 0, 0, 0 };
|
||||
#ifndef SDL_NOPANGO
|
||||
SDLPango_Matrix pango_color;
|
||||
#endif
|
||||
SDL_Surface **surfs = malloc(strlen(s) * sizeof surfs[0]);
|
||||
unsigned count = 0;
|
||||
int ret = 0;
|
||||
|
|
@ -1171,7 +1267,16 @@ int charset_works(TTF_Font * font, const char *s)
|
|||
c[offset++] = *s++;
|
||||
while ((*s & 0xc0u) == 0x80u); // assume safe input
|
||||
c[offset++] = '\0';
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
sdl_color_to_pango_color(black, &pango_color);
|
||||
SDLPango_SetDefaultColor(font->pango_context, &pango_color);
|
||||
SDLPango_SetText(font->pango_context, c, -1);
|
||||
tmp_surf = SDLPango_CreateSurfaceDraw(font->pango_context);
|
||||
#else
|
||||
tmp_surf = TTF_RenderUTF8_Blended(font, c, black);
|
||||
#endif
|
||||
|
||||
if (!tmp_surf)
|
||||
{
|
||||
#if 0
|
||||
|
|
@ -1199,3 +1304,62 @@ out:
|
|||
free(surfs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf)
|
||||
{
|
||||
return(tpf->height);
|
||||
}
|
||||
|
||||
const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf)
|
||||
{
|
||||
#ifndef NO_SDLPANGO
|
||||
/* FIXME */
|
||||
return("");
|
||||
#else
|
||||
return (TTF_FontFaceFamilyName(tpf->ttf_font));
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf)
|
||||
{
|
||||
#ifndef NO_SDLPANGO
|
||||
/* FIXME */
|
||||
return("");
|
||||
#else
|
||||
return (TTF_FontFaceStyleName(tpf->ttf_font));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
|
||||
void sdl_color_to_pango_color(SDL_Color sdl_color,
|
||||
SDLPango_Matrix * pango_color)
|
||||
{
|
||||
Uint8 pc[4][4];
|
||||
|
||||
pc[0][0] = 0;
|
||||
pc[1][0] = 0;
|
||||
pc[2][0] = 0;
|
||||
pc[3][0] = 0;
|
||||
|
||||
pc[0][1] = sdl_color.r;
|
||||
pc[1][1] = sdl_color.g;
|
||||
pc[2][1] = sdl_color.b;
|
||||
pc[3][1] = 255;
|
||||
|
||||
pc[0][2] = 0;
|
||||
pc[1][2] = 0;
|
||||
pc[2][2] = 0;
|
||||
pc[3][2] = 0;
|
||||
|
||||
pc[0][3] = 0;
|
||||
pc[1][3] = 0;
|
||||
pc[2][3] = 0;
|
||||
pc[3][3] = 0;
|
||||
|
||||
memcpy(pango_color, pc, 16);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
44
src/fonts.h
44
src/fonts.h
|
|
@ -17,6 +17,12 @@
|
|||
#include "SDL.h"
|
||||
#include "SDL_ttf.h"
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
#include "SDL_Pango.h"
|
||||
#endif
|
||||
|
||||
#define PANGO_DEFAULT_FONT "BitStream Vera"
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/* Disable threaded font loading on Windows */
|
||||
|
|
@ -55,8 +61,24 @@ TTF_Font *BUGFIX_TTF_OpenFont206(const char *const file, int ptsize);
|
|||
#define TTF_OpenFont BUGFIX_TTF_OpenFont206
|
||||
*/
|
||||
|
||||
TTF_Font *try_alternate_font(int size);
|
||||
TTF_Font *load_locale_font(TTF_Font * fallback, int size);
|
||||
|
||||
/* Stuff that wraps either SDL_Pango or SDL_TTF for font rendering: */
|
||||
|
||||
|
||||
typedef struct TuxPaint_Font_s {
|
||||
#ifndef NO_SDLPANGO
|
||||
SDLPango_Context * pango_context;
|
||||
#else
|
||||
TTF_Font * ttf_font;
|
||||
#endif
|
||||
int height;
|
||||
} TuxPaint_Font;
|
||||
|
||||
int TuxPaint_Font_FontHeight(TuxPaint_Font * tpf);
|
||||
|
||||
|
||||
TuxPaint_Font *try_alternate_font(int size);
|
||||
TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size);
|
||||
int load_user_fonts(SDL_Surface * screen, void *vp);
|
||||
|
||||
#ifdef FORKED_FONTS
|
||||
|
|
@ -112,11 +134,11 @@ typedef struct family_info
|
|||
char *directory;
|
||||
char *family;
|
||||
char *filename[4];
|
||||
TTF_Font *handle;
|
||||
TuxPaint_Font *handle;
|
||||
int score;
|
||||
} family_info;
|
||||
|
||||
extern TTF_Font *medium_font, *small_font, *large_font, *locale_font;
|
||||
extern TuxPaint_Font *medium_font, *small_font, *large_font, *locale_font;
|
||||
|
||||
extern family_info **user_font_families;
|
||||
extern int num_font_families;
|
||||
|
|
@ -134,12 +156,22 @@ void parse_font_style(style_info * si);
|
|||
void groupfonts_range(style_info ** base, int count);
|
||||
void dupe_markdown_range(family_info ** base, int count);
|
||||
void groupfonts(void);
|
||||
TTF_Font *getfonthandle(int desire);
|
||||
TuxPaint_Font *getfonthandle(int desire);
|
||||
void loadfonts(SDL_Surface * screen, const char *const dir);
|
||||
|
||||
int do_surfcmp(const SDL_Surface * const *const v1,
|
||||
const SDL_Surface * const *const v2);
|
||||
int surfcmp(const void *s1, const void *s2);
|
||||
int charset_works(TTF_Font * font, const char *s);
|
||||
int charset_works(TuxPaint_Font * font, const char *s);
|
||||
|
||||
TuxPaint_Font * TuxPaint_Font_OpenFont(const char * pangodesc, const char * ttffilename, int size);
|
||||
void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf);
|
||||
const char * TuxPaint_Font_FontFaceFamilyName(TuxPaint_Font * tpf);
|
||||
const char * TuxPaint_Font_FontFaceStyleName(TuxPaint_Font * tpf);
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
void sdl_color_to_pango_color(SDL_Color sdl_color,
|
||||
SDLPango_Matrix * pango_color);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
132
src/tuxpaint.c
132
src/tuxpaint.c
|
|
@ -22,7 +22,7 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
(See COPYING.txt)
|
||||
|
||||
June 14, 2002 - July 8, 2007
|
||||
June 14, 2002 - July 12, 2007
|
||||
$Id$
|
||||
*/
|
||||
|
||||
|
|
@ -334,6 +334,21 @@ extern WrapperData macosx;
|
|||
#error "---------------------------------------------------"
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef NO_SDLPANGO
|
||||
|
||||
#include "SDL_Pango.h"
|
||||
#if !defined(SDL_PANGO_H)
|
||||
#error "---------------------------------------------------"
|
||||
#error "If you installed SDL_Pango from a package, be sure"
|
||||
#error "to get the development package, as well!"
|
||||
#error "(e.g., 'libsdl-pango1-dev.rpm')"
|
||||
#error "---------------------------------------------------"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef NOSOUND
|
||||
#include "SDL_mixer.h"
|
||||
#if !defined(_SDL_MIXER_H) && !defined(_MIXER_H_)
|
||||
|
|
@ -507,7 +522,6 @@ static const char *getfilename(const char *path)
|
|||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// sizing
|
||||
|
||||
|
|
@ -842,6 +856,10 @@ static int recording, playing;
|
|||
static char *playfile;
|
||||
static FILE *demofi;
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
SDLPango_Context * pango_context;
|
||||
#endif
|
||||
|
||||
|
||||
/* Magic tools API and tool handles: */
|
||||
|
||||
|
|
@ -935,22 +953,37 @@ static SDL_Surface *zoom(SDL_Surface * src, int new_x, int new_y);
|
|||
|
||||
|
||||
|
||||
|
||||
static SDL_Surface *render_text(TTF_Font * restrict font,
|
||||
static SDL_Surface *render_text(TuxPaint_Font * restrict font,
|
||||
const char *restrict str, SDL_Color color)
|
||||
{
|
||||
SDL_Surface *ret;
|
||||
int height;
|
||||
|
||||
ret = TTF_RenderUTF8_Blended(font, str, color);
|
||||
#ifdef NO_SDLPANGO
|
||||
ret = TTF_RenderUTF8_Blended(font->ttf_font, str, color);
|
||||
#else
|
||||
SDLPango_Matrix pango_color;
|
||||
|
||||
sdl_color_to_pango_color(color, &pango_color);
|
||||
|
||||
SDLPango_SetDefaultColor(font->pango_context, &pango_color);
|
||||
SDLPango_SetText(font->pango_context, str, -1);
|
||||
ret = SDLPango_CreateSurfaceDraw(font->pango_context);
|
||||
#endif
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
// Sometimes a font will be missing a character we need. Sometimes the library
|
||||
// will substitute a rectangle without telling us. Sometimes it returns NULL.
|
||||
// Probably we should use FreeType directly. For now though...
|
||||
height = TTF_FontHeight(font);
|
||||
|
||||
/*
|
||||
height = TuxPaint_Font_FontHeight(font);
|
||||
if (height < 2)
|
||||
height = 2;
|
||||
*/
|
||||
height = 2;
|
||||
|
||||
return thumbnail(img_title_large_off, height * strlen(str) / 2, height, 0);
|
||||
}
|
||||
|
||||
|
|
@ -975,24 +1008,40 @@ static Uint16 *wcstou16(const wchar_t * str)
|
|||
return res;
|
||||
}
|
||||
|
||||
static SDL_Surface *render_text_w(TTF_Font * restrict font,
|
||||
|
||||
/* FIXME: This should also use SDL_Pango -bjk 2007.07.12 */
|
||||
|
||||
static SDL_Surface *render_text_w(TuxPaint_Font * restrict font,
|
||||
const wchar_t * restrict str,
|
||||
SDL_Color color)
|
||||
{
|
||||
SDL_Surface *ret;
|
||||
int height;
|
||||
Uint16 *ustr;
|
||||
#ifndef NO_SDLPANGO
|
||||
SDLPango_Matrix pango_color;
|
||||
#endif
|
||||
|
||||
ustr = wcstou16(str);
|
||||
ustr = wcstou16(str); // FIXME: For SDL_Pango, too? -bjk 2007.07.12
|
||||
|
||||
#ifdef NO_SDLPANGO
|
||||
ret = TTF_RenderUNICODE_Blended(font, ustr, color);
|
||||
free(ustr);
|
||||
#else
|
||||
sdl_color_to_pango_color(color, &pango_color);
|
||||
|
||||
SDLPango_SetDefaultColor(font->pango_context, &pango_color);
|
||||
SDLPango_SetText(font->pango_context, (char *) ustr, -1); // char * cast ok for SDL_Pango? -bjk 2007.07.12
|
||||
ret = SDLPango_CreateSurfaceDraw(font->pango_context);
|
||||
#endif
|
||||
|
||||
free(ustr); // FIXME: For SDL_Pango, too? -bjk 2007.07.12
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
// Sometimes a font will be missing a character we need. Sometimes the library
|
||||
// will substitute a rectangle without telling us. Sometimes it returns NULL.
|
||||
// Probably we should use FreeType directly. For now though...
|
||||
height = TTF_FontHeight(font);
|
||||
height = TuxPaint_Font_FontHeight(font);
|
||||
if (height < 2)
|
||||
height = 2;
|
||||
return thumbnail(img_title_large_off, height * wcslen(str) / 2, height, 0);
|
||||
|
|
@ -1993,7 +2042,7 @@ static void mainloop(void)
|
|||
texttool_len = 0;
|
||||
cursor_textwidth = 0;
|
||||
}
|
||||
font_height = TTF_FontHeight(getfonthandle(cur_font));
|
||||
font_height = TuxPaint_Font_FontHeight(getfonthandle(cur_font));
|
||||
|
||||
cursor_x = cursor_left;
|
||||
cursor_y = min(cursor_y + font_height, canvas->h - font_height);
|
||||
|
|
@ -2672,7 +2721,7 @@ static void mainloop(void)
|
|||
if (user_font_families[i]
|
||||
&& user_font_families[i]->handle)
|
||||
{
|
||||
TTF_CloseFont(user_font_families[i]->handle);
|
||||
TuxPaint_Font_CloseFont(user_font_families[i]->handle);
|
||||
user_font_families[i]->handle = NULL;
|
||||
}
|
||||
}
|
||||
|
|
@ -2758,15 +2807,17 @@ static void mainloop(void)
|
|||
}
|
||||
else if (cur_tool == TOOL_TEXT)
|
||||
{
|
||||
char font_tux_text[512];
|
||||
/* FIXME */ /* char font_tux_text[512]; */
|
||||
|
||||
cur_font = cur_thing;
|
||||
|
||||
/* FIXME */
|
||||
/*
|
||||
snprintf(font_tux_text, sizeof font_tux_text, "%s (%s).",
|
||||
TTF_FontFaceFamilyName(getfonthandle(cur_font)),
|
||||
TTF_FontFaceStyleName(getfonthandle(cur_font)));
|
||||
// printf("font change:%s\n", font_tux_text);
|
||||
draw_tux_text(TUX_GREAT, font_tux_text, 1);
|
||||
*/
|
||||
|
||||
if (do_draw)
|
||||
draw_fonts();
|
||||
|
|
@ -3751,16 +3802,15 @@ static void draw_blinking_cursor(void)
|
|||
|
||||
line_xor(cursor_x + cursor_textwidth, cursor_y,
|
||||
cursor_x + cursor_textwidth,
|
||||
cursor_y + TTF_FontHeight(getfonthandle(cur_font)));
|
||||
cursor_y + TuxPaint_Font_FontHeight(getfonthandle(cur_font)));
|
||||
|
||||
update_screen(cursor_x + r_canvas.x + cursor_textwidth,
|
||||
cursor_y + r_canvas.y,
|
||||
cursor_x + r_canvas.x + cursor_textwidth,
|
||||
cursor_y + r_canvas.y +
|
||||
TTF_FontHeight(getfonthandle(cur_font)));
|
||||
TuxPaint_Font_FontHeight(getfonthandle(cur_font)));
|
||||
}
|
||||
|
||||
|
||||
/* Draw using the current brush: */
|
||||
|
||||
static void brush_draw(int x1, int y1, int x2, int y2, int update)
|
||||
|
|
@ -5996,6 +6046,16 @@ static void setup(int argc, char *argv[])
|
|||
setup_language(getfilename(argv[0]));
|
||||
im_init(&im_data, get_current_language());
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
SDLPango_Init();
|
||||
|
||||
/* SDLPango accepts font description strings; cannot send it a
|
||||
TTF_Font. So right now, "pango_context" is set up once,
|
||||
with a default font, when the app starts... */
|
||||
|
||||
pango_context = SDLPango_CreateContext_GivenFontDesc("FreeSans");
|
||||
#endif
|
||||
|
||||
|
||||
/* NOTE: Moved run_font_scanner() call from main(), to here,
|
||||
so that the gettext() calls used while testing fonts
|
||||
|
|
@ -6448,8 +6508,9 @@ static void setup(int argc, char *argv[])
|
|||
|
||||
SDL_Flip(screen);
|
||||
|
||||
medium_font = TTF_OpenFont(DATA_PREFIX "fonts/default_font.ttf",
|
||||
18 - (only_uppercase * 3));
|
||||
medium_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT,
|
||||
DATA_PREFIX "fonts/default_font.ttf",
|
||||
18 - (only_uppercase * 3));
|
||||
|
||||
if (medium_font == NULL)
|
||||
{
|
||||
|
|
@ -6748,8 +6809,9 @@ static void setup(int argc, char *argv[])
|
|||
|
||||
/* Load system fonts: */
|
||||
|
||||
large_font = TTF_OpenFont(DATA_PREFIX "fonts/default_font.ttf",
|
||||
30 - (only_uppercase * 3));
|
||||
large_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT,
|
||||
DATA_PREFIX "fonts/default_font.ttf",
|
||||
30 - (only_uppercase * 3));
|
||||
|
||||
if (large_font == NULL)
|
||||
{
|
||||
|
|
@ -6764,7 +6826,8 @@ static void setup(int argc, char *argv[])
|
|||
}
|
||||
|
||||
|
||||
small_font = TTF_OpenFont(DATA_PREFIX "fonts/default_font.ttf",
|
||||
small_font = TuxPaint_Font_OpenFont(PANGO_DEFAULT_FONT,
|
||||
DATA_PREFIX "fonts/default_font.ttf",
|
||||
#ifdef __APPLE__
|
||||
12 - (only_uppercase * 2));
|
||||
#else
|
||||
|
|
@ -6825,7 +6888,7 @@ static void setup(int argc, char *argv[])
|
|||
{
|
||||
if (strlen(title_names[i]) > 0)
|
||||
{
|
||||
TTF_Font *myfont = large_font;
|
||||
TuxPaint_Font *myfont = large_font;
|
||||
char *td_str = textdir(gettext(title_names[i]));
|
||||
|
||||
if (need_own_font && strcmp(gettext(title_names[i]), title_names[i]))
|
||||
|
|
@ -7017,7 +7080,7 @@ static SDL_Surface *do_render_button_label(const char *const label)
|
|||
{
|
||||
SDL_Surface *tmp_surf, *surf;
|
||||
SDL_Color black = { 0, 0, 0, 0 };
|
||||
TTF_Font *myfont = small_font;
|
||||
TuxPaint_Font *myfont = small_font;
|
||||
char *td_str = textdir(gettext(label));
|
||||
char *upstr = uppercase(td_str);
|
||||
|
||||
|
|
@ -9215,7 +9278,7 @@ static void wordwrap_text_ex(const char *const str, SDL_Color color,
|
|||
int len;
|
||||
SDL_Surface *text;
|
||||
SDL_Rect dest, src;
|
||||
TTF_Font *myfont = medium_font;
|
||||
TuxPaint_Font *myfont = medium_font;
|
||||
|
||||
int utf8_str_len, last_text_height;
|
||||
unsigned char utf8_str[512];
|
||||
|
|
@ -10844,19 +10907,19 @@ static void cleanup(void)
|
|||
|
||||
if (medium_font != NULL)
|
||||
{
|
||||
TTF_CloseFont(medium_font);
|
||||
TuxPaint_Font_CloseFont(medium_font);
|
||||
medium_font = NULL;
|
||||
}
|
||||
|
||||
if (small_font != NULL)
|
||||
{
|
||||
TTF_CloseFont(small_font);
|
||||
TuxPaint_Font_CloseFont(small_font);
|
||||
small_font = NULL;
|
||||
}
|
||||
|
||||
if (large_font != NULL)
|
||||
{
|
||||
TTF_CloseFont(large_font);
|
||||
TuxPaint_Font_CloseFont(large_font);
|
||||
large_font = NULL;
|
||||
}
|
||||
|
||||
|
|
@ -10877,7 +10940,7 @@ static void cleanup(void)
|
|||
if (*++cpp)
|
||||
free(*cpp);
|
||||
if (user_font_families[i]->handle)
|
||||
TTF_CloseFont(user_font_families[i]->handle);
|
||||
TuxPaint_Font_CloseFont(user_font_families[i]->handle);
|
||||
free(user_font_families[i]->directory);
|
||||
free(user_font_families[i]->family);
|
||||
free(user_font_families[i]);
|
||||
|
|
@ -10983,6 +11046,11 @@ static void cleanup(void)
|
|||
|
||||
/* Close up! */
|
||||
|
||||
#ifndef NO_SDLPANGO
|
||||
if (pango_context != NULL)
|
||||
SDLPango_FreeContext(pango_context);
|
||||
#endif
|
||||
|
||||
TTF_Quit();
|
||||
SDL_Quit();
|
||||
|
||||
|
|
@ -14266,10 +14334,10 @@ static void do_render_cur_text(int do_blit)
|
|||
/* Keep cursor on the screen! */
|
||||
|
||||
if (cursor_y > ((48 * 7 + 40 + HEIGHTOFFSET) -
|
||||
TTF_FontHeight(getfonthandle(cur_font))))
|
||||
TuxPaint_Font_FontHeight(getfonthandle(cur_font))))
|
||||
{
|
||||
cursor_y = ((48 * 7 + 40 + HEIGHTOFFSET) -
|
||||
TTF_FontHeight(getfonthandle(cur_font)));
|
||||
TuxPaint_Font_FontHeight(getfonthandle(cur_font)));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue