ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/Client.xs
(Generate patch)

Comparing deliantra/Deliantra-Client/Client.xs (file contents):
Revision 1.5 by root, Sun Apr 9 00:06:09 2006 UTC vs.
Revision 1.10 by root, Sun Apr 9 17:34:15 2006 UTC

6 6
7#include <SDL.h> 7#include <SDL.h>
8#include <SDL_opengl.h> 8#include <SDL_opengl.h>
9 9
10#include <pango/pango.h> 10#include <pango/pango.h>
11#include <pango/pangofc-fontmap.h>
11#include <pango/pangoft2.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>
12 18
13static PangoContext *context; 19static PangoContext *context;
14static PangoFontMap *fontmap; 20static PangoFontMap *fontmap;
15 21
16MODULE = Crossfire::Client PACKAGE = Crossfire::Client 22MODULE = Crossfire::Client PACKAGE = Crossfire::Client
17 23
18BOOT: 24BOOT:
19{ 25{
20 fontmap = pango_ft2_font_map_new (); 26 fontmap = pango_ft2_font_map_new ();
21 context = pango_context_new (); 27 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
22 pango_context_set_font_map (context, fontmap);
23} 28}
29
30void
31lowdelay (int fd, int val = 1)
32 CODE:
33 setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val));
24 34
25char * 35char *
26gl_version () 36gl_version ()
27 CODE: 37 CODE:
28 RETVAL = (char *)glGetString (GL_VERSION); 38 RETVAL = (char *)glGetString (GL_VERSION);
35 RETVAL = (char *)glGetString (GL_EXTENSIONS); 45 RETVAL = (char *)glGetString (GL_EXTENSIONS);
36 OUTPUT: 46 OUTPUT:
37 RETVAL 47 RETVAL
38 48
39void 49void
50set_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
61void
40font_render (SV *text_, int height) 62font_render (SV *text_, int height = 10)
41 PPCODE: 63 PPCODE:
42{ 64{
43 STRLEN textlen; 65 STRLEN textlen;
44 char *text = SvPVutf8 (text_, textlen); 66 char *text = SvPVutf8 (text_, textlen);
45 SV *retval; 67 SV *retval;
46 int w, h; 68 int w, h;
47 FT_Bitmap bitmap; 69 FT_Bitmap bitmap;
48 PangoLayout *layout; 70 PangoLayout *layout;
49 PangoFontDescription *font = pango_context_get_font_description (context); 71 PangoFontDescription *font = pango_context_get_font_description (context);
50 pango_font_description_set_absolute_size (font, 40 * PANGO_SCALE); 72 pango_font_description_set_absolute_size (font, height * PANGO_SCALE);
51 73
52 layout = pango_layout_new (context); 74 layout = pango_layout_new (context);
53 pango_layout_set_markup (layout, text, textlen); 75 pango_layout_set_markup (layout, text, textlen);
54 pango_layout_get_pixel_size (layout, &w, &h); 76 pango_layout_get_pixel_size (layout, &w, &h);
55 77
56 w = (w + 3) & ~3; 78 w = (w + 3) & ~3;
79 if (!w) w = 1;
57 if (h == 0) h = 1; 80 if (!h) h = 1;
58 81
59 retval = newSV (w * h); 82 retval = newSV (w * h);
60 SvPOK_only (retval); 83 SvPOK_only (retval);
61 SvCUR_set (retval, w * h); 84 SvCUR_set (retval, w * h);
62 85

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines