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

# User Rev Content
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 root 1.10 #include <pango/pangofc-fontmap.h>
12 root 1.5 #include <pango/pangoft2.h>
13    
14 root 1.10 #include <sys/types.h>
15     #include <sys/socket.h>
16     #include <netinet/in.h>
17     #include <netinet/tcp.h>
18    
19 root 1.5 static PangoContext *context;
20     static PangoFontMap *fontmap;
21 root 1.2
22 root 1.1 MODULE = Crossfire::Client PACKAGE = Crossfire::Client
23    
24 root 1.5 BOOT:
25     {
26     fontmap = pango_ft2_font_map_new ();
27 root 1.8 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
28 root 1.5 }
29    
30 root 1.10 void
31     lowdelay (int fd, int val = 1)
32     CODE:
33     setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
34    
35 root 1.3 char *
36 root 1.4 gl_version ()
37     CODE:
38 root 1.5 RETVAL = (char *)glGetString (GL_VERSION);
39 root 1.4 OUTPUT:
40     RETVAL
41    
42     char *
43 root 1.3 gl_extensions ()
44     CODE:
45 root 1.5 RETVAL = (char *)glGetString (GL_EXTENSIONS);
46 root 1.3 OUTPUT:
47     RETVAL
48    
49 root 1.5 void
50 root 1.9 set_font (char *file)
51 root 1.8 CODE:
52     {
53 root 1.9 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 root 1.10 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
57 root 1.9 FcPatternDestroy (pattern);
58 root 1.8 pango_context_set_font_description (context, font);
59     }
60    
61     void
62 root 1.7 font_render (SV *text_, int height = 10)
63 root 1.5 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 root 1.7 pango_font_description_set_absolute_size (font, height * PANGO_SCALE);
73 root 1.5
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 root 1.6 if (!w) w = 1;
80     if (!h) h = 1;
81 root 1.5
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 root 1.1
98 root 1.5 EXTEND (SP, 3);
99     PUSHs (sv_2mortal (newSViv (w)));
100     PUSHs (sv_2mortal (newSViv (h)));
101     PUSHs (sv_2mortal (retval));
102     }