From 7b049cee0cab9235d1954c1c84ceb0554ab5370e Mon Sep 17 00:00:00 2001 From: Aetf <7437103@gmail.com> Date: Sun, 12 Oct 2014 02:36:39 +0800 Subject: [PATCH] text: font: implement underlines --- src/font.h | 1 + src/font_pango.c | 21 +++++++++++++++++++-- src/text_bblit.c | 5 +++++ src/text_bbulk.c | 5 +++++ src/text_gltex.c | 11 ++++++++--- src/text_pixman.c | 11 ++++++++--- 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/font.h b/src/font.h index f7e4b01..d7c4cd6 100644 --- a/src/font.h +++ b/src/font.h @@ -72,6 +72,7 @@ struct kmscon_font { const struct kmscon_font_ops *ops; struct kmscon_font_attr attr; unsigned int baseline; + bool underline; void *data; }; diff --git a/src/font_pango.c b/src/font_pango.c index 171f3bd..4fca9c0 100644 --- a/src/font_pango.c +++ b/src/font_pango.c @@ -110,7 +110,7 @@ static void manager__unref() } static int get_glyph(struct face *face, struct kmscon_glyph **out, - uint32_t id, const uint32_t *ch, size_t len) + uint32_t id, const uint32_t *ch, size_t len, bool underline) { struct kmscon_glyph *glyph; PangoLayout *layout; @@ -157,6 +157,23 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out, /* no line spacing */ pango_layout_set_spacing(layout, 0); + /* underline if requested */ + PangoAttrList* attrlist = pango_layout_get_attributes(layout); + if (underline) { + if (attrlist == NULL) { + attrlist = pango_attr_list_new(); + pango_layout_set_attributes(layout, attrlist); + pango_attr_list_unref(attrlist); + } + pango_attr_list_change(attrlist, + pango_attr_underline_new(PANGO_UNDERLINE_SINGLE)); + } else { + if (attrlist != NULL) { + pango_attr_list_change(attrlist, + pango_attr_underline_new(PANGO_UNDERLINE_NONE)); + } + } + val = tsm_ucs4_to_utf8_alloc(ch, len, &ulen); if (!val) { ret = -ERANGE; @@ -405,7 +422,7 @@ static int kmscon_font_pango_render(struct kmscon_font *font, uint32_t id, struct kmscon_glyph *glyph; int ret; - ret = get_glyph(font->data, &glyph, id, ch, len); + ret = get_glyph(font->data, &glyph, id, ch, len, font->underline); if (ret) return ret; diff --git a/src/text_bblit.c b/src/text_bblit.c index 8cf9bfd..e051f69 100644 --- a/src/text_bblit.c +++ b/src/text_bblit.c @@ -79,6 +79,11 @@ static int bblit_draw(struct kmscon_text *txt, else font = txt->font; + if (attr->underline) + font->underline = true; + else + font->underline = false; + if (!len) { ret = kmscon_font_render_empty(font, &glyph); } else { diff --git a/src/text_bbulk.c b/src/text_bbulk.c index 3f238c1..6a2076a 100644 --- a/src/text_bbulk.c +++ b/src/text_bbulk.c @@ -132,6 +132,11 @@ static int bbulk_draw(struct kmscon_text *txt, else font = txt->font; + if (attr->underline) + font->underline = true; + else + font->underline = false; + if (!len) { ret = kmscon_font_render_empty(font, &glyph); } else { diff --git a/src/text_gltex.c b/src/text_gltex.c index 20f7eb3..27eec3f 100644 --- a/src/text_gltex.c +++ b/src/text_gltex.c @@ -381,7 +381,7 @@ err_free: } static int find_glyph(struct kmscon_text *txt, struct glyph **out, - uint32_t id, const uint32_t *ch, size_t len, bool bold) + uint32_t id, const uint32_t *ch, size_t len, const struct tsm_screen_attr *attr) { struct gltex *gt = txt->data; struct atlas *atlas; @@ -393,7 +393,7 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out, struct shl_hashtable *gtable; struct kmscon_font *font; - if (bold) { + if (attr->bold) { gtable = gt->bold_glyphs; font = txt->bold_font; } else { @@ -401,6 +401,11 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out, font = txt->font; } + if (attr->underline) + font->underline = true; + else + font->underline = false; + res = shl_hashtable_find(gtable, (void**)&glyph, (void*)(unsigned long)id); if (res) { @@ -556,7 +561,7 @@ static int gltex_draw(struct kmscon_text *txt, if (!width) return 0; - ret = find_glyph(txt, &glyph, id, ch, len, attr->bold); + ret = find_glyph(txt, &glyph, id, ch, len, attr); if (ret) return ret; atlas = glyph->atlas; diff --git a/src/text_pixman.c b/src/text_pixman.c index fc10f71..c48ccef 100644 --- a/src/text_pixman.c +++ b/src/text_pixman.c @@ -262,7 +262,7 @@ static void tp_unset(struct kmscon_text *txt) } static int find_glyph(struct kmscon_text *txt, struct tp_glyph **out, - uint32_t id, const uint32_t *ch, size_t len, bool bold) + uint32_t id, const uint32_t *ch, size_t len, const struct tsm_screen_attr *attr) { struct tp_pixman *tp = txt->data; struct tp_glyph *glyph; @@ -274,7 +274,7 @@ static int find_glyph(struct kmscon_text *txt, struct tp_glyph **out, int ret, stride; bool res; - if (bold) { + if (attr->bold) { gtable = tp->bold_glyphs; font = txt->bold_font; } else { @@ -282,6 +282,11 @@ static int find_glyph(struct kmscon_text *txt, struct tp_glyph **out, font = txt->font; } + if (attr->underline) + font->underline = true; + else + font->underline = false; + res = shl_hashtable_find(gtable, (void**)&glyph, (void*)(unsigned long)id); if (res) { @@ -402,7 +407,7 @@ static int tp_draw(struct kmscon_text *txt, if (!width) return 0; - ret = find_glyph(txt, &glyph, id, ch, len, attr->bold); + ret = find_glyph(txt, &glyph, id, ch, len, attr); if (ret) return ret;