--- deliantra/Deliantra-Client/Client.xs 2006/04/11 13:14:36 1.15 +++ deliantra/Deliantra-Client/Client.xs 2006/04/12 20:06:36 1.22 @@ -11,6 +11,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -25,8 +29,27 @@ } *CFClient__Layout; static void +substitute_func (FcPattern *pattern, gpointer data) +{ + FcPatternAddBool (pattern, FC_HINTING , 1); + FcPatternAddBool (pattern, FC_AUTOHINT, 1); +} + +static void +layout_update (CFClient__Layout self) +{ + /* use a random scale factor to account for unknown descenders, 0.8 works + * reasonably well with bitstream vera + */ + PangoFontDescription *font = pango_context_get_font_description (context); + pango_font_description_set_absolute_size (font, self->base_height * (PANGO_SCALE * 8 / 10)); +} + +static void layout_get_pixel_size (CFClient__Layout self, int *w, int *h) { + layout_update (self); + pango_layout_get_pixel_size (self->pl, w, h); *w = (*w + 3) & ~3; @@ -41,6 +64,7 @@ BOOT: { fontmap = pango_ft2_font_map_new (); + pango_ft2_font_map_set_default_substitute ((PangoFT2FontMap *)fontmap, substitute_func, 0, 0); context = pango_ft2_font_map_create_context ((PangoFT2FontMap *)fontmap); } @@ -108,6 +132,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 +147,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 +155,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 +190,7 @@ int w, h; FT_Bitmap bitmap; + layout_update (self); layout_get_pixel_size (self, &w, &h); retval = newSV (w * h); @@ -173,8 +228,8 @@ if (items < 5) { - w = SvNV (*hv_fetch (hv, "width", 5, 1)); - h = SvNV (*hv_fetch (hv, "height", 6, 1)); + w = SvNV (*hv_fetch (hv, "w", 1, 1)); + h = SvNV (*hv_fetch (hv, "h", 1, 1)); } glBindTexture (GL_TEXTURE_2D, name);