ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
Revision: 1.10
Committed: Sun Apr 9 17:34:15 2006 UTC (18 years, 1 month ago) by root
Branch: MAIN
Changes since 1.9: +12 -1 lines
Log Message:
*** empty log message ***

File Contents

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