--- deliantra/Deliantra-Client/Client.xs 2006/06/17 15:07:52 1.119 +++ deliantra/Deliantra-Client/Client.xs 2006/06/28 23:41:11 1.123 @@ -44,6 +44,8 @@ #include "glext.h" +#define OBJ_STR "\xef\xbf\xbc" /* U+FFFC, objetc replacement character */ + #define FOW_DARKNESS 32 #define MAP_EXTEND_X 32 @@ -73,6 +75,24 @@ typedef PangoFontDescription *CFClient__Font; +static int +shape_attr_p (PangoLayoutRun *run) +{ + GSList *attrs = run->item->analysis.extra_attrs; + + while (attrs) + { + PangoAttribute *attr = attrs->data; + + if (attr->klass->type == PANGO_ATTR_SHAPE) + return 1; + + attrs = attrs->next; + } + + return 0; +} + typedef struct cf_layout { PangoLayout *pl; // either derived from a cairo or ft2 context int rgba; // wether we use rgba (cairo) or grayscale (ft2) @@ -812,6 +832,90 @@ pango_layout_set_markup (self->pl, text, textlen); } +void +set_shapes (CFClient::Layout self, ...) + CODE: +{ + PangoAttrList *attrs = 0; + const char *text = pango_layout_get_text (self->pl); + const char *pos = text; + int arg = 4; + + while (arg < items && (pos = strstr (pos, OBJ_STR))) + { + PangoRectangle inkrect, rect; + PangoAttribute *attr; + + int x = SvIV (ST (arg - 3)); + int y = SvIV (ST (arg - 2)); + int w = SvIV (ST (arg - 1)); + int h = SvIV (ST (arg )); + + inkrect.x = 0; + inkrect.y = 0; + inkrect.width = 0; + inkrect.height = 0; + + rect.x = x * PANGO_SCALE; + rect.y = y * PANGO_SCALE; + rect.width = w * PANGO_SCALE; + rect.height = h * PANGO_SCALE; + + if (!attrs) + attrs = pango_layout_get_attributes (self->pl); + + attr = pango_attr_shape_new (&inkrect, &rect); + attr->start_index = pos - text; + attr->end_index = attr->start_index + sizeof (OBJ_STR) - 1; + pango_attr_list_insert (attrs, attr); + + arg += 4; + pos += sizeof (OBJ_STR) - 1; + } + + if (attrs) + pango_layout_set_attributes (self->pl, attrs); +} + +void +get_shapes (CFClient::Layout self) + PPCODE: +{ + PangoLayoutIter *iter = pango_layout_get_iter (self->pl); + + do + { + PangoLayoutRun *run = pango_layout_iter_get_run (iter); + + if (run && shape_attr_p (run)) + { + PangoRectangle extents; + pango_layout_iter_get_run_extents (iter, 0, &extents); + + PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.x)))); + PUSHs (sv_2mortal (newSViv (PANGO_PIXELS (extents.y)))); + } + } + while (pango_layout_iter_next_run (iter)); + + pango_layout_iter_free (iter); +} + +int +has_wrapped (CFClient::Layout self) + CODE: +{ + int lines = 1; + const char *text = pango_layout_get_text (self->pl); + + while (*text) + lines += *text++ == '\n'; + + RETVAL = lines < pango_layout_get_line_count (self->pl); +} + OUTPUT: + RETVAL + SV * get_text (CFClient::Layout self) CODE: @@ -890,6 +994,18 @@ } int +descent (CFClient::Layout self) + CODE: +{ + PangoRectangle rect; + PangoLayoutLine *line = pango_layout_get_line (self->pl, 0); + pango_layout_line_get_pixel_extents (line, 0, &rect); + RETVAL = PANGO_DESCENT (rect); +} + OUTPUT: + RETVAL + +int xy_to_index (CFClient::Layout self, int x, int y) CODE: { @@ -1235,8 +1351,8 @@ { flags = (data [0] << 8) + data [1]; data += 2; - x = ((flags >> 10) & 63) + self->x; - y = ((flags >> 4) & 63) + self->y; + x = self->x + ((flags >> 10) & 63); + y = self->y + ((flags >> 4) & 63); cell = map_get_cell (self, x, y); @@ -1343,8 +1459,8 @@ int last_name; mapface face; - vx = self->x + (self->w - sw + 1) / 2 - shift_x; - vy = self->y + (self->h - sh + 1) / 2 - shift_y; + vx = self->x + self->w / 2 - sw / 2 - shift_x; + vy = self->y + self->h / 2 - sh / 2 - shift_y; /* int vx = self->vx = self->w >= sw @@ -1414,26 +1530,26 @@ CODE: { static float color[16][3] = { - { 0.00, 0.00, 0.00 }, - { 1.00, 1.00, 1.00 }, - { 0.00, 0.00, 0.55 }, - { 1.00, 0.00, 0.00 }, - - { 1.00, 0.54, 0.00 }, - { 0.11, 0.56, 1.00 }, - { 0.93, 0.46, 0.00 }, - { 0.18, 0.54, 0.34 }, - - { 0.56, 0.73, 0.56 }, - { 0.80, 0.80, 0.80 }, - { 0.55, 0.41, 0.13 }, - { 0.99, 0.77, 0.26 }, - - { 0.74, 0.65, 0.41 }, - - { 0.00, 1.00, 1.00 }, - { 1.00, 0.00, 1.00 }, - { 1.00, 1.00, 0.00 }, + { 0.00F, 0.00F, 0.00F }, + { 1.00F, 1.00F, 1.00F }, + { 0.00F, 0.00F, 0.55F }, + { 1.00F, 0.00F, 0.00F }, + + { 1.00F, 0.54F, 0.00F }, + { 0.11F, 0.56F, 1.00F }, + { 0.93F, 0.46F, 0.00F }, + { 0.18F, 0.54F, 0.34F }, + + { 0.56F, 0.73F, 0.56F }, + { 0.80F, 0.80F, 0.80F }, + { 0.55F, 0.41F, 0.13F }, + { 0.99F, 0.77F, 0.26F }, + + { 0.74F, 0.65F, 0.41F }, + + { 0.00F, 1.00F, 1.00F }, + { 1.00F, 0.00F, 1.00F }, + { 1.00F, 1.00F, 0.00F }, }; int x, y;