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.13 by root, Tue Apr 11 12:27:51 2006 UTC vs.
Revision 1.14 by root, Tue Apr 11 13:05:11 2006 UTC

16#include <netinet/in.h> 16#include <netinet/in.h>
17#include <netinet/tcp.h> 17#include <netinet/tcp.h>
18 18
19static PangoContext *context; 19static PangoContext *context;
20static PangoFontMap *fontmap; 20static PangoFontMap *fontmap;
21
22typedef struct cf_layout {
23 PangoLayout *pl;
24 int base_height;
25} *Crossfire__Client__Layout;
26
27static void
28layout_get_pixel_size (Crossfire__Client__Layout self, int *w, int *h)
29{
30 pango_layout_get_pixel_size (self->pl, w, h);
31
32 *w = (*w + 3) & ~3;
33 if (!*w) *w = 1;
34 if (!*h) *h = 1;
35}
21 36
22MODULE = Crossfire::Client PACKAGE = Crossfire::Client 37MODULE = Crossfire::Client PACKAGE = Crossfire::Client
23 38
24PROTOTYPES: ENABLE 39PROTOTYPES: ENABLE
25 40
62 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0); 77 PangoFontDescription *font = pango_fc_font_description_from_pattern (pattern, 0);
63 FcPatternDestroy (pattern); 78 FcPatternDestroy (pattern);
64 pango_context_set_font_description (context, font); 79 pango_context_set_font_description (context, font);
65} 80}
66 81
67MODULE = Crossfire::Client PACKAGE = Crossfire::Client 82MODULE = Crossfire::Client PACKAGE = Crossfire::Client::Layout
83
84Crossfire::Client::Layout
85new (SV *class, int base_height = 10)
86 CODE:
87 New (0, RETVAL, 1, struct cf_layout);
88 RETVAL->base_height = base_height;
89 RETVAL->pl = pango_layout_new (context);
90 pango_layout_set_wrap (RETVAL->pl, PANGO_WRAP_WORD_CHAR);
91 OUTPUT:
92 RETVAL
68 93
69void 94void
70font_render (SV *text_, int height = 10) 95DESTROY (Crossfire::Client::Layout self)
71 PPCODE: 96 CODE:
97 g_object_unref (self->pl);
98 Safefree (self);
99
100void
101set_markup (Crossfire::Client::Layout self, SV *text_)
102 CODE:
72{ 103{
73 STRLEN textlen; 104 STRLEN textlen;
74 char *text = SvPVutf8 (text_, textlen); 105 char *text = SvPVutf8 (text_, textlen);
106
107 pango_layout_set_markup (self->pl, text, textlen);
108}
109
110void
111set_width (Crossfire::Client::Layout self, int max_width = -1)
112 CODE:
113 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
114
115void
116size (Crossfire::Client::Layout self)
117 PPCODE:
118{
119 int w, h;
120
121 PangoFontDescription *font = pango_context_get_font_description (context);
122 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE);
123
124 layout_get_pixel_size (self, &w, &h);
125
126 EXTEND (SP, 2);
127 PUSHs (sv_2mortal (newSViv (w)));
128 PUSHs (sv_2mortal (newSViv (h)));
129}
130
131void
132render (Crossfire::Client::Layout self)
133 PPCODE:
134{
75 SV *retval; 135 SV *retval;
76 int w, h; 136 int w, h;
77 FT_Bitmap bitmap; 137 FT_Bitmap bitmap;
78 PangoLayout *layout;
79 PangoFontDescription *font = pango_context_get_font_description (context);
80 pango_font_description_set_absolute_size (font, height * PANGO_SCALE);
81 138
82 layout = pango_layout_new (context);
83 pango_layout_set_markup (layout, text, textlen);
84 pango_layout_get_pixel_size (layout, &w, &h); 139 layout_get_pixel_size (self, &w, &h);
85
86 w = (w + 3) & ~3;
87 if (!w) w = 1;
88 if (!h) h = 1;
89 140
90 retval = newSV (w * h); 141 retval = newSV (w * h);
91 SvPOK_only (retval); 142 SvPOK_only (retval);
92 SvCUR_set (retval, w * h); 143 SvCUR_set (retval, w * h);
93 144
98 bitmap.num_grays = 256; 149 bitmap.num_grays = 256;
99 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY; 150 bitmap.pixel_mode = FT_PIXEL_MODE_GRAY;
100 151
101 memset (bitmap.buffer, 0, w * h); 152 memset (bitmap.buffer, 0, w * h);
102 153
103 pango_ft2_render_layout (&bitmap, layout, 0 * PANGO_SCALE, 0 * PANGO_SCALE); 154 pango_ft2_render_layout (&bitmap, self->pl, 0 * PANGO_SCALE, 0 * PANGO_SCALE);
104 g_object_unref (layout);
105 155
106 EXTEND (SP, 3); 156 EXTEND (SP, 3);
107 PUSHs (sv_2mortal (newSViv (w))); 157 PUSHs (sv_2mortal (newSViv (w)));
108 PUSHs (sv_2mortal (newSViv (h))); 158 PUSHs (sv_2mortal (newSViv (h)));
109 PUSHs (sv_2mortal (retval)); 159 PUSHs (sv_2mortal (retval));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines