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.15 by root, Tue Apr 11 13:14:36 2006 UTC vs.
Revision 1.20 by root, Wed Apr 12 02:00:06 2006 UTC

23 PangoLayout *pl; 23 PangoLayout *pl;
24 int base_height; 24 int base_height;
25} *CFClient__Layout; 25} *CFClient__Layout;
26 26
27static void 27static void
28substitute_func (FcPattern *pattern, gpointer data)
29{
30 FcPatternAddBool (pattern, FC_HINTING , 1);
31 FcPatternAddBool (pattern, FC_AUTOHINT, 1);
32}
33
34static void
35layout_update (CFClient__Layout self)
36{
37 /* use a random scale factor to account for unknown descenders, 0.8 works
38 * reasonably well with bitstream vera
39 */
40 PangoFontDescription *font = pango_context_get_font_description (context);
41 pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10));
42}
43
44static void
28layout_get_pixel_size (CFClient__Layout self, int *w, int *h) 45layout_get_pixel_size (CFClient__Layout self, int *w, int *h)
29{ 46{
47 layout_update (self);
48
30 pango_layout_get_pixel_size (self->pl, w, h); 49 pango_layout_get_pixel_size (self->pl, w, h);
31 50
32 *w = (*w + 3) & ~3; 51 *w = (*w + 3) & ~3;
33 if (!*w) *w = 1; 52 if (!*w) *w = 1;
34 if (!*h) *h = 1; 53 if (!*h) *h = 1;
39PROTOTYPES: ENABLE 58PROTOTYPES: ENABLE
40 59
41BOOT: 60BOOT:
42{ 61{
43 fontmap = pango_ft2_font_map_new (); 62 fontmap = pango_ft2_font_map_new ();
63 pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0);
44 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); 64 context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap);
45} 65}
46 66
47void 67void
48lowdelay (int fd, int val = 1) 68lowdelay (int fd, int val = 1)
106 126
107 pango_layout_set_markup (self->pl, text, textlen); 127 pango_layout_set_markup (self->pl, text, textlen);
108} 128}
109 129
110void 130void
131set_height (CFClient::Layout self, int base_height)
132 CODE:
133 self->base_height = base_height;
134
135void
111set_width (CFClient::Layout self, int max_width = -1) 136set_width (CFClient::Layout self, int max_width = -1)
112 CODE: 137 CODE:
113 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); 138 pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE);
114 139
115void 140void
116size (CFClient::Layout self) 141size (CFClient::Layout self)
117 PPCODE: 142 PPCODE:
118{ 143{
119 int w, h; 144 int w, h;
120 145
121 PangoFontDescription *font = pango_context_get_font_description (context); 146 layout_update (self);
122 pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE);
123
124 layout_get_pixel_size (self, &w, &h); 147 layout_get_pixel_size (self, &w, &h);
125 148
126 EXTEND (SP, 2); 149 EXTEND (SP, 2);
127 PUSHs (sv_2mortal (newSViv (w))); 150 PUSHs (sv_2mortal (newSViv (w)));
128 PUSHs (sv_2mortal (newSViv (h))); 151 PUSHs (sv_2mortal (newSViv (h)));
129} 152}
130 153
154int
155xy_to_index (CFClient::Layout self, int x, int y)
156 CODE:
157{
158 int index, trailing;
159
160 layout_update (self);
161 pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing);
162
163 RETVAL = index;
164}
165 OUTPUT:
166 RETVAL
167
168void
169cursor_pos (CFClient::Layout self, int index)
170 PPCODE:
171{
172 PangoRectangle strong_pos;
173 layout_update (self);
174 pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0);
175 EXTEND (SP, 3);
176 PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE)));
177 PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE)));
178 PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE)));
179}
180
131void 181void
132render (CFClient::Layout self) 182render (CFClient::Layout self)
133 PPCODE: 183 PPCODE:
134{ 184{
135 SV *retval; 185 SV *retval;
136 int w, h; 186 int w, h;
137 FT_Bitmap bitmap; 187 FT_Bitmap bitmap;
138 188
189 layout_update (self);
139 layout_get_pixel_size (self, &w, &h); 190 layout_get_pixel_size (self, &w, &h);
140 191
141 retval = newSV (w * h); 192 retval = newSV (w * h);
142 SvPOK_only (retval); 193 SvPOK_only (retval);
143 SvCUR_set (retval, w * h); 194 SvCUR_set (retval, w * h);
171 double t = SvNV (*hv_fetch (hv, "t", 1, 1)); 222 double t = SvNV (*hv_fetch (hv, "t", 1, 1));
172 int name = SvIV (*hv_fetch (hv, "name", 4, 1)); 223 int name = SvIV (*hv_fetch (hv, "name", 4, 1));
173 224
174 if (items < 5) 225 if (items < 5)
175 { 226 {
176 w = SvNV (*hv_fetch (hv, "width", 5, 1)); 227 w = SvNV (*hv_fetch (hv, "w", 1, 1));
177 h = SvNV (*hv_fetch (hv, "height", 6, 1)); 228 h = SvNV (*hv_fetch (hv, "h", 1, 1));
178 } 229 }
179 230
180 glBindTexture (GL_TEXTURE_2D, name); 231 glBindTexture (GL_TEXTURE_2D, name);
181 glBegin (GL_QUADS); 232 glBegin (GL_QUADS);
182 glTexCoord2d (0, 0); glVertex2d (x , y ); 233 glTexCoord2d (0, 0); glVertex2d (x , y );

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines