Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/italic #3

Merged
merged 2 commits into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PKG_CHECK_MODULES([XKBCOMMON], [xkbcommon])
AC_SUBST(XKBCOMMON_CFLAGS)
AC_SUBST(XKBCOMMON_LIBS)

PKG_CHECK_MODULES([TSM], [libtsm])
PKG_CHECK_MODULES([TSM], [libtsm >= 4.0.0])
AC_SUBST(TSM_CFLAGS)
AC_SUBST(TSM_LIBS)

Expand Down
2 changes: 1 addition & 1 deletion src/font.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void kmscon_font_unref(struct kmscon_font *font)
*/
SHL_EXPORT
int kmscon_font_render(struct kmscon_font *font,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
const struct kmscon_glyph **out)
{
if (!font || !out || !ch || !len)
Expand Down
6 changes: 3 additions & 3 deletions src/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct kmscon_font_attr {
unsigned int points;
bool bold;
bool italic;
bool underline;
unsigned int height;
unsigned int width;
};
Expand All @@ -72,7 +73,6 @@ struct kmscon_font {
const struct kmscon_font_ops *ops;
struct kmscon_font_attr attr;
unsigned int baseline;
bool underline;
void *data;
};

Expand All @@ -83,7 +83,7 @@ struct kmscon_font_ops {
const struct kmscon_font_attr *attr);
void (*destroy) (struct kmscon_font *font);
int (*render) (struct kmscon_font *font,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
const struct kmscon_glyph **out);
int (*render_empty) (struct kmscon_font *font,
const struct kmscon_glyph **out);
Expand All @@ -101,7 +101,7 @@ void kmscon_font_ref(struct kmscon_font *font);
void kmscon_font_unref(struct kmscon_font *font);

int kmscon_font_render(struct kmscon_font *font,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
const struct kmscon_glyph **out);
int kmscon_font_render_empty(struct kmscon_font *font,
const struct kmscon_glyph **out);
Expand Down
2 changes: 1 addition & 1 deletion src/font_8x16.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void kmscon_font_8x16_destroy(struct kmscon_font *font)
}

static int kmscon_font_8x16_render(struct kmscon_font *font,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
const struct kmscon_glyph **out)
{
if (len > 1 || *ch >= 256)
Expand Down
46 changes: 27 additions & 19 deletions src/font_pango.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ 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, bool underline)
uint64_t id, const uint32_t *ch, size_t len, const struct kmscon_font_attr *attr)
{
struct kmscon_glyph *glyph;
PangoLayout *layout;
PangoAttrList *attrlist;
PangoRectangle rec;
PangoLayoutLine *line;
FT_Bitmap bitmap;
Expand All @@ -131,7 +132,7 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out,

pthread_mutex_lock(&face->glyph_lock);
res = shl_hashtable_find(face->glyphs, (void**)&glyph,
(void*)(long)id);
(void*)(uint64_t)id);
pthread_mutex_unlock(&face->glyph_lock);
if (res) {
*out = glyph;
Expand All @@ -150,28 +151,35 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out,
glyph->width = cwidth;

layout = pango_layout_new(face->ctx);
attrlist = pango_layout_get_attributes(layout);
if (attrlist == NULL) {
attrlist = pango_attr_list_new();
pango_layout_set_attributes(layout, attrlist);
pango_attr_list_unref(attrlist);
}

/* render one line only */
pango_layout_set_height(layout, 0);

/* 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));
/* underline if requested */
if (attr->underline) {
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));
}
pango_attr_list_change(attrlist,
pango_attr_underline_new(PANGO_UNDERLINE_NONE));
}

/* italic if requested */
if (attr->italic) {
pango_attr_list_change(attrlist,
pango_attr_style_new(PANGO_STYLE_ITALIC));
} else {
pango_attr_list_change(attrlist,
pango_attr_style_new(PANGO_STYLE_NORMAL));
}

val = tsm_ucs4_to_utf8_alloc(ch, len, &ulen);
Expand Down Expand Up @@ -219,7 +227,7 @@ static int get_glyph(struct face *face, struct kmscon_glyph **out,
pango_ft2_render_layout_line(&bitmap, line, -rec.x, face->baseline);

pthread_mutex_lock(&face->glyph_lock);
ret = shl_hashtable_insert(face->glyphs, (void*)(long)id, glyph);
ret = shl_hashtable_insert(face->glyphs, (void*)(uint64_t)id, glyph);
pthread_mutex_unlock(&face->glyph_lock);
if (ret) {
log_error("cannot add glyph to hashtable");
Expand Down Expand Up @@ -415,14 +423,14 @@ static void kmscon_font_pango_destroy(struct kmscon_font *font)
manager_put_face(face);
}

static int kmscon_font_pango_render(struct kmscon_font *font, uint32_t id,
static int kmscon_font_pango_render(struct kmscon_font *font, uint64_t id,
const uint32_t *ch, size_t len,
const struct kmscon_glyph **out)
{
struct kmscon_glyph *glyph;
int ret;

ret = get_glyph(font->data, &glyph, id, ch, len, font->underline);
ret = get_glyph(font->data, &glyph, id, ch, len, &font->attr);
if (ret)
return ret;

Expand Down
15 changes: 8 additions & 7 deletions src/font_unifont.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <libtsm.h>
#include "font.h"
#include "shl_hashtable.h"
#include "shl_log.h"
Expand Down Expand Up @@ -105,7 +106,7 @@ static void unfold(uint8_t *dst, uint8_t val)
*dst = 0xff * !!val;
}

static int find_glyph(uint32_t id, const struct kmscon_glyph **out)
static int find_glyph(uint32_t ch, const struct kmscon_glyph **out)
{
struct kmscon_glyph *g;
int ret;
Expand All @@ -124,21 +125,21 @@ static int find_glyph(uint32_t id, const struct kmscon_glyph **out)
}
} else {
res = shl_hashtable_find(cache, (void**)out,
(void*)(long)id);
(void*)(uint64_t)ch);
if (res) {
ret = 0;
goto out_unlock;
}
}

if (id > 0xffff) {
if (ch > 0xffff) {
ret = -ERANGE;
goto out_unlock;
}

start = _binary_src_font_unifont_data_bin_start;
end = _binary_src_font_unifont_data_bin_end;
d = &start[id];
d = &start[ch];

if (d >= end) {
ret = -ERANGE;
Expand Down Expand Up @@ -186,7 +187,7 @@ static int find_glyph(uint32_t id, const struct kmscon_glyph **out)
unfold(&g->buf.data[i * 8 + 7], d->data[i] & 0x01);
}

ret = shl_hashtable_insert(cache, (void*)(long)id, g);
ret = shl_hashtable_insert(cache, (void*)(uint64_t)ch, g);
if (ret) {
log_error("cannot insert glyph into glyph-cache: %d", ret);
goto err_data;
Expand Down Expand Up @@ -240,14 +241,14 @@ static void kmscon_font_unifont_destroy(struct kmscon_font *font)
cache_unref();
}

static int kmscon_font_unifont_render(struct kmscon_font *font, uint32_t id,
static int kmscon_font_unifont_render(struct kmscon_font *font, uint64_t id,
const uint32_t *ch, size_t len,
const struct kmscon_glyph **out)
{
if (len > 1)
return -ERANGE;

return find_glyph(id, out);
return find_glyph(id & TSM_UCS4_MAX, out);
}

static int kmscon_font_unifont_render_inval(struct kmscon_font *font,
Expand Down
4 changes: 2 additions & 2 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ int kmscon_text_prepare(struct kmscon_text *txt)
* Returns: 0 on success or negative error code if this glyph couldn't be drawn.
*/
int kmscon_text_draw(struct kmscon_text *txt,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr)
Expand Down Expand Up @@ -438,7 +438,7 @@ void kmscon_text_abort(struct kmscon_text *txt)
}

int kmscon_text_draw_cb(struct tsm_screen *con,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr,
Expand Down
6 changes: 3 additions & 3 deletions src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct kmscon_text_ops {
void (*unset) (struct kmscon_text *txt);
int (*prepare) (struct kmscon_text *txt);
int (*draw) (struct kmscon_text *txt,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr);
Expand All @@ -93,15 +93,15 @@ unsigned int kmscon_text_get_rows(struct kmscon_text *txt);

int kmscon_text_prepare(struct kmscon_text *txt);
int kmscon_text_draw(struct kmscon_text *txt,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr);
int kmscon_text_render(struct kmscon_text *txt);
void kmscon_text_abort(struct kmscon_text *txt);

int kmscon_text_draw_cb(struct tsm_screen *con,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr,
Expand Down
11 changes: 8 additions & 3 deletions src/text_bblit.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int bblit_set(struct kmscon_text *txt)
}

static int bblit_draw(struct kmscon_text *txt,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr)
Expand All @@ -80,9 +80,14 @@ static int bblit_draw(struct kmscon_text *txt,
font = txt->font;

if (attr->underline)
font->underline = true;
font->attr.underline = true;
else
font->underline = false;
font->attr.underline = false;

if (attr->italic)
font->attr.italic = true;
else
font->attr.italic = false;

if (!len) {
ret = kmscon_font_render_empty(font, &glyph);
Expand Down
11 changes: 8 additions & 3 deletions src/text_bbulk.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void bbulk_unset(struct kmscon_text *txt)
}

static int bbulk_draw(struct kmscon_text *txt,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr)
Expand All @@ -133,9 +133,14 @@ static int bbulk_draw(struct kmscon_text *txt,
font = txt->font;

if (attr->underline)
font->underline = true;
font->attr.underline = true;
else
font->underline = false;
font->attr.underline = false;

if (attr->italic)
font->attr.italic = true;
else
font->attr.italic = false;

if (!len) {
ret = kmscon_font_render_empty(font, &glyph);
Expand Down
17 changes: 11 additions & 6 deletions src/text_gltex.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ static struct atlas *get_atlas(struct kmscon_text *txt, unsigned int num)
}

static int find_glyph(struct kmscon_text *txt, struct glyph **out,
uint32_t id, const uint32_t *ch, size_t len, const struct tsm_screen_attr *attr)
uint64_t id, const uint32_t *ch, size_t len, const struct tsm_screen_attr *attr)
{
struct gltex *gt = txt->data;
struct atlas *atlas;
Expand All @@ -402,12 +402,17 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out,
}

if (attr->underline)
font->underline = true;
font->attr.underline = true;
else
font->underline = false;
font->attr.underline = false;

if (attr->italic)
font->attr.italic = true;
else
font->attr.italic = false;

res = shl_hashtable_find(gtable, (void**)&glyph,
(void*)(unsigned long)id);
(void*)(uint64_t)id);
if (res) {
*out = glyph;
return 0;
Expand Down Expand Up @@ -510,7 +515,7 @@ static int find_glyph(struct kmscon_text *txt, struct glyph **out,
glyph->atlas = atlas;
glyph->texoff = atlas->fill;

ret = shl_hashtable_insert(gtable, (void*)(long)id, glyph);
ret = shl_hashtable_insert(gtable, (void*)(uint64_t)id, glyph);
if (ret)
goto err_free;

Expand Down Expand Up @@ -548,7 +553,7 @@ static int gltex_prepare(struct kmscon_text *txt)
}

static int gltex_draw(struct kmscon_text *txt,
uint32_t id, const uint32_t *ch, size_t len,
uint64_t id, const uint32_t *ch, size_t len,
unsigned int width,
unsigned int posx, unsigned int posy,
const struct tsm_screen_attr *attr)
Expand Down
Loading