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