diff options
-rw-r--r-- | text.c | 47 |
1 files changed, 32 insertions, 15 deletions
@@ -49,11 +49,11 @@ static xcb_window_t w; #define _BLOCK(_txt) {.block = {.type = COMMAND_BLOCK, .length = sizeof(_txt) - 1, .data = _txt}} union Command body[] = { + {.span = {.type = COMMAND_SPAN, .position = 28, .length = 11}}, _BLOCK( "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam auctor porta eros at tempus. Aliquam " "elementum lectus id mi fermentum, non consectetur urna lobortis." ), - {.span = {.type = COMMAND_SPAN, .position = 27, .length = 11}}, _BLOCK("Phasellus dignissim rhoncus magna at imperdiet."), {.type = COMMAND_DONE}, }; @@ -154,22 +154,39 @@ void draw_body(cairo_t * ctx) PangoFontDescription * desc = pango_font_description_from_string(FONT); cairo_set_source_rgb(ctx, 0., 0., 0.); int y = MARGIN; + PangoAttrList * attrs = pango_attr_list_new(); // TODO-maybe: Don't recreate attributes lists each redraw? for (union Command * command = body; COMMAND_DONE != command->type; ++command) { - if (COMMAND_SPAN == command->type) - continue; - cairo_move_to(ctx, MARGIN, y); - PangoLayout * layout = pango_cairo_create_layout(ctx); - pango_layout_set_font_description(layout, desc); - pango_layout_set_wrap(layout, PANGO_WRAP_WORD); - pango_layout_set_width(layout, (width - 2 * MARGIN) * PANGO_SCALE); - pango_layout_set_text(layout, command->block.data, command->block.length); - pango_cairo_update_layout(ctx, layout); - pango_cairo_show_layout(ctx, layout); - int height; - pango_layout_get_pixel_size(layout, NULL, &height); - y += height + MARGIN; - g_object_unref(layout); + switch (command->type) + { + case COMMAND_SPAN: + ; + PangoAttribute * attr = pango_attr_foreground_new(0x0000, 0x0000, 0xffff); + attr->start_index = command->span.position; + attr->end_index = command->span.position + command->span.length; + pango_attr_list_change(attrs, attr); + break; + case COMMAND_BLOCK: + cairo_move_to(ctx, MARGIN, y); + PangoLayout * layout = pango_cairo_create_layout(ctx); + pango_layout_set_attributes(layout, attrs); + pango_attr_list_unref(attrs); + attrs = pango_attr_list_new(); + pango_layout_set_font_description(layout, desc); + pango_layout_set_wrap(layout, PANGO_WRAP_WORD); + pango_layout_set_width(layout, (width - 2 * MARGIN) * PANGO_SCALE); + pango_layout_set_text(layout, command->block.data, command->block.length); + pango_cairo_update_layout(ctx, layout); + pango_cairo_show_layout(ctx, layout); + int height; + pango_layout_get_pixel_size(layout, NULL, &height); + y += height + MARGIN; + break; + case COMMAND_NOTHING: + default: + break; + } } + pango_attr_list_unref(attrs); pango_font_description_free(desc); } |