--- deliantra/Deliantra-Client/Client.xs 2006/04/11 13:27:48 1.16 +++ deliantra/Deliantra-Client/Client.xs 2006/04/12 18:09:21 1.21 @@ -25,10 +25,26 @@ } *CFClient__Layout; static void -layout_get_pixel_size (CFClient__Layout self, int *w, int *h) +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); + 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); @@ -44,6 +60,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); } @@ -82,6 +99,12 @@ pango_context_set_font_description (context, font); } +void +wait_events (SV *rfd_, SV *wfd_) + PPCODE: +{ +} + MODULE = CFClient PACKAGE = CFClient::Layout CFClient::Layout @@ -126,6 +149,7 @@ { int w, h; + layout_update (self); layout_get_pixel_size (self, &w, &h); EXTEND (SP, 2); @@ -133,6 +157,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: @@ -141,6 +192,7 @@ int w, h; FT_Bitmap bitmap; + layout_update (self); layout_get_pixel_size (self, &w, &h); retval = newSV (w * h); @@ -178,8 +230,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);