1 |
#include "EXTERN.h" |
2 |
#include "perl.h" |
3 |
#include "XSUB.h" |
4 |
|
5 |
#include <string.h> |
6 |
|
7 |
#include <SDL.h> |
8 |
#include <SDL_opengl.h> |
9 |
|
10 |
#include <pango/pango.h> |
11 |
#include <pango/pangoft2.h> |
12 |
|
13 |
static PangoContext *context; |
14 |
static PangoFontMap *fontmap; |
15 |
|
16 |
MODULE = Crossfire::Client PACKAGE = Crossfire::Client |
17 |
|
18 |
BOOT: |
19 |
{ |
20 |
fontmap = pango_ft2_font_map_new (); |
21 |
context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); |
22 |
} |
23 |
|
24 |
char * |
25 |
gl_version () |
26 |
CODE: |
27 |
RETVAL = (char *)glGetString (GL_VERSION); |
28 |
OUTPUT: |
29 |
RETVAL |
30 |
|
31 |
char * |
32 |
gl_extensions () |
33 |
CODE: |
34 |
RETVAL = (char *)glGetString (GL_EXTENSIONS); |
35 |
OUTPUT: |
36 |
RETVAL |
37 |
|
38 |
void |
39 |
set_font (char *file) |
40 |
CODE: |
41 |
{ |
42 |
int count; |
43 |
FcPattern *pattern = FcFreeTypeQuery ((const FcChar8 *)file, 0, 0, &count); |
44 |
FcConfigAppFontAddFile (0, (const FcChar8 *)file); /* no idea wether this is required */ |
45 |
PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern); |
46 |
FcPatternDestroy (pattern); |
47 |
pango_context_set_font_description (context, font); |
48 |
} |
49 |
|
50 |
void |
51 |
font_render (SV *text_, int height = 10) |
52 |
PPCODE: |
53 |
{ |
54 |
STRLEN textlen; |
55 |
char *text = SvPVutf8 (text_, textlen); |
56 |
SV *retval; |
57 |
int w, h; |
58 |
FT_Bitmap bitmap; |
59 |
PangoLayout *layout; |
60 |
PangoFontDescription *font = pango_context_get_font_description (context); |
61 |
pango_font_description_set_absolute_size (font, height * PANGO_SCALE); |
62 |
|
63 |
layout = pango_layout_new (context); |
64 |
pango_layout_set_markup (layout, text, textlen); |
65 |
pango_layout_get_pixel_size (layout, &w, &h); |
66 |
|
67 |
w = (w + 3) & ~3; |
68 |
if (!w) w = 1; |
69 |
if (!h) h = 1; |
70 |
|
71 |
retval = newSV (w * h); |
72 |
SvPOK_only (retval); |
73 |
SvCUR_set (retval, w * h); |
74 |
|
75 |
bitmap.rows = h; |
76 |
bitmap.width = w; |
77 |
bitmap.pitch = w; |
78 |
bitmap.buffer = (unsigned char*)SvPVX (retval); |
79 |
bitmap.num_grays = 256; |
80 |
bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; |
81 |
|
82 |
memset (bitmap.buffer, 0, w * h); |
83 |
|
84 |
pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); |
85 |
g_object_unref (layout); |
86 |
|
87 |
EXTEND (SP, 3); |
88 |
PUSHs (sv_2mortal (newSViv (w))); |
89 |
PUSHs (sv_2mortal (newSViv (h))); |
90 |
PUSHs (sv_2mortal (retval)); |
91 |
} |