--- deliantra/Deliantra-Client/Client.xs 2006/06/28 23:41:11 1.123 +++ deliantra/Deliantra-Client/Client.xs 2006/07/04 23:23:31 1.124 @@ -20,12 +20,12 @@ #include #include +#define PANGO_ENABLE_BACKEND +#define G_DISABLE_CAST_CHECKS + #include #include -#include -#include -#include #ifndef _WIN32 # include @@ -53,6 +53,12 @@ #define MIN_FONT_HEIGHT 10 +#if 1 +# define PARACHUTE SDL_INIT_NOPARACHUTE +#else +# define PARACHUTE 0 +#endif + static struct { #define GL_FUNC(ptr,name) ptr name; @@ -70,6 +76,12 @@ glBlendFunc (sa, da); } +#include "texcache.c" + +#include "pango-font.c" +#include "pango-fontmap.c" +#include "pango-render.c" + typedef Mix_Chunk *CFClient__MixChunk; typedef Mix_Music *CFClient__MixMusic; @@ -94,16 +106,15 @@ } typedef struct cf_layout { - PangoLayout *pl; // either derived from a cairo or ft2 context - int rgba; // wether we use rgba (cairo) or grayscale (ft2) + PangoLayout *pl; float r, g, b, a; // default color for rgba mode int base_height; CFClient__Font font; } *CFClient__Layout; static CFClient__Font default_font; -static PangoContext *ft2_context, *cairo_context; -static PangoFontMap *ft2_fontmap, *cairo_fontmap; +static PangoContext *opengl_context; +static PangoFontMap *opengl_fontmap; static void substitute_func (FcPattern *pattern, gpointer data) @@ -465,32 +476,14 @@ void pango_init () CODE: - // delayed, so it can pick up new fonts added by AddFontResourceEx { - { - ft2_fontmap = pango_ft2_font_map_new (); - pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)ft2_fontmap, substitute_func, 0, 0); - ft2_context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)ft2_fontmap); - } - { - cairo_font_options_t *fopt = cairo_font_options_create (); - cairo_fontmap = pango_cairo_font_map_get_default (); - cairo_context = pango_cairo_font_map_create_context ((PangoCairoFontMap *)cairo_fontmap); -#ifdef _WIN32 - // cairo looks like shit eaten twice on windows - cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_NONE); -#else - cairo_font_options_set_antialias (fopt, CAIRO_ANTIALIAS_GRAY); -#endif - cairo_font_options_set_hint_style (fopt, CAIRO_HINT_STYLE_FULL); - cairo_font_options_set_hint_metrics (fopt, CAIRO_HINT_METRICS_ON); - pango_cairo_context_set_font_options (cairo_context, fopt); - cairo_font_options_destroy (fopt); - } + opengl_fontmap = pango_opengl_font_map_new (); + pango_opengl_font_map_set_default_substitute ((PangoOpenGLFontMap *)opengl_fontmap, substitute_func, 0, 0); + opengl_context = pango_opengl_font_map_create_context ((PangoOpenGLFontMap *)opengl_fontmap); } int -SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO) +SDL_Init (U32 flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | PARACHUTE) void SDL_Quit () @@ -638,10 +631,6 @@ add_font (char *file) CODE: FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ -#ifdef _WIN32 - // cairo... sigh... requires win2000 - AddFontResourceEx (file, FR_PRIVATE, 0); -#endif void load_image_inline (SV *image_) @@ -780,13 +769,18 @@ MODULE = CFClient PACKAGE = CFClient::Layout +void +clear_font_cache () + CODE: + pango_fc_font_map_cache_clear ((PangoFcFontMap *)opengl_fontmap); + tc_clear (); + CFClient::Layout -new (SV *class, int rgba = 0) +new (SV *class, int type = 0) CODE: New (0, RETVAL, 1, struct cf_layout); - RETVAL->pl = pango_layout_new (rgba ? cairo_context : ft2_context); - RETVAL->rgba = rgba; + RETVAL->pl = pango_layout_new (opengl_context); RETVAL->r = 1.; RETVAL->g = 1.; RETVAL->b = 1.; @@ -805,13 +799,6 @@ g_object_unref (self->pl); Safefree (self); -int -is_rgba (CFClient::Layout self) - CODE: - RETVAL = self->rgba; - OUTPUT: - RETVAL - void set_text (CFClient::Layout self, SV *text_) CODE: @@ -1030,95 +1017,13 @@ } void -render (CFClient::Layout self) +render (CFClient::Layout self, float x, float y) PPCODE: -{ - SV *retval; - int w, h; - - layout_get_pixel_size (self, &w, &h); - - if (self->rgba) - { - cairo_surface_t *surface; - cairo_t *cairo; - - retval = newSV (w * h * 4); - SvPOK_only (retval); - SvCUR_set (retval, w * h * 4); - - memset (SvPVX (retval), 0, w * h * 4); - - surface = cairo_image_surface_create_for_data ( - (void*)SvPVX (retval), CAIRO_FORMAT_ARGB32, w, h, w * 4); - cairo = cairo_create (surface); - cairo_set_source_rgba (cairo, self->r, self->g, self->b, self->a); - - pango_cairo_show_layout (cairo, self->pl); - - cairo_destroy (cairo); - cairo_surface_destroy (surface); - - // what a mess, and its premultiplied, too :( - { - uint32_t *p = (uint32_t *)SvPVX (retval); - uint32_t *e = p + w * h; - - while (p < e) - { - uint32_t rgba = *p; - rgba = (rgba >> 24) | (rgba << 8); -#if 0 -#ifdef _WIN32 - {//D - uint8_t r = rgba >> 24; - uint8_t g = rgba >> 16; - uint8_t b = rgba >> 8; - uint8_t a = rgba >> 0; - - rgba = (rgba & 0xffffff00) | a; - } -#endif -#endif - rgba = SDL_SwapBE32 (rgba); - *p++ = rgba; - } - } - - EXTEND (SP, 5); - PUSHs (sv_2mortal (newSViv (w))); - PUSHs (sv_2mortal (newSViv (h))); - PUSHs (sv_2mortal (retval)); - PUSHs (sv_2mortal (newSViv (GL_RGBA))); - PUSHs (sv_2mortal (newSViv (GL_RGBA))); - } - else - { - FT_Bitmap bitmap; - - retval = newSV (w * h); - SvPOK_only (retval); - SvCUR_set (retval, w * h); - - bitmap.rows = h; - bitmap.width = w; - bitmap.pitch = w; - bitmap.buffer = (unsigned char*)SvPVX (retval); - bitmap.num_grays = 256; - bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; - - memset (bitmap.buffer, 0, w * h); - - pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE); - - EXTEND (SP, 5); - PUSHs (sv_2mortal (newSViv (w))); - PUSHs (sv_2mortal (newSViv (h))); - PUSHs (sv_2mortal (retval)); - PUSHs (sv_2mortal (newSViv (GL_ALPHA))); - PUSHs (sv_2mortal (newSViv (GL_ALPHA))); - } -} + pango_opengl_render_layout_subpixel ( + self->pl, + x * PANGO_SCALE, y * PANGO_SCALE, + self->r, self->g, self->b, self->a + ); MODULE = CFClient PACKAGE = CFClient::Texture