--- deliantra/Deliantra-Client/Client.xs 2006/04/11 13:14:36 1.15 +++ deliantra/Deliantra-Client/Client.xs 2006/04/11 17:02:35 1.17 @@ -25,8 +25,18 @@ } *CFClient__Layout; static void +layout_update (CFClient__Layout self) +{ + PangoFontDescription *font = pango_context_get_font_description (context); + pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); +} + +static void layout_get_pixel_size (CFClient__Layout self, int *w, int *h) { + PangoFontDescription *font = pango_context_get_font_description (context); + pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); + pango_layout_get_pixel_size (self->pl, w, h); *w = (*w + 3) & ~3; @@ -108,6 +118,11 @@ } void +set_height (CFClient::Layout self, int base_height) + CODE: + self->base_height = base_height; + +void set_width (CFClient::Layout self, int max_width = -1) CODE: pango_layout_set_width (self->pl, max_width < 0 ? max_width : max_width * PANGO_SCALE); @@ -118,9 +133,7 @@ { int w, h; - PangoFontDescription *font = pango_context_get_font_description (context); - pango_font_description_set_absolute_size (font, self->base_height * PANGO_SCALE); - + layout_update (self); layout_get_pixel_size (self, &w, &h); EXTEND (SP, 2); @@ -128,6 +141,33 @@ PUSHs (sv_2mortal (newSViv (h))); } +int +xy_to_index (CFClient::Layout self, int x, int y) + CODE: +{ + int index, trailing; + + layout_update (self); + pango_layout_xy_to_index (self->pl, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); + + RETVAL = index; +} + OUTPUT: + RETVAL + +void +cursor_pos (CFClient::Layout self, int index) + PPCODE: +{ + PangoRectangle strong_pos; + layout_update (self); + pango_layout_get_cursor_pos (self->pl, index, &strong_pos, 0); + EXTEND (SP, 3); + PUSHs (sv_2mortal (newSViv (strong_pos.x / PANGO_SCALE))); + PUSHs (sv_2mortal (newSViv (strong_pos.y / PANGO_SCALE))); + PUSHs (sv_2mortal (newSViv (strong_pos.height / PANGO_SCALE))); +} + void render (CFClient::Layout self) PPCODE: @@ -136,6 +176,7 @@ int w, h; FT_Bitmap bitmap; + layout_update (self); layout_get_pixel_size (self, &w, &h); retval = newSV (w * h);