text: font: implement underlines

This commit is contained in:
Aetf 2014-10-12 02:36:39 +08:00
parent 0b34527199
commit 7b049cee0c
6 changed files with 46 additions and 8 deletions

View File

@ -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;
};

View File

@ -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;

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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;