text: add bold font as separate font object

We now allow the user to specify the font that is used for bold
characters. If NULL is given, the normal font is used.

The bold font is not used by any renderer backend, yet, but will be hooked
up later.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-11-08 13:40:37 +01:00
parent d4a1f69fe3
commit 4368500596
3 changed files with 16 additions and 1 deletions

View File

@ -240,7 +240,7 @@ static int add_display(struct kmscon_terminal *term, struct uterm_display *disp)
goto err_font;
}
ret = kmscon_text_set(scr->txt, scr->font, scr->screen);
ret = kmscon_text_set(scr->txt, scr->font, NULL, scr->screen);
if (ret) {
log_error("cannot set text-renderer parameters");
goto err_text;

View File

@ -295,6 +295,7 @@ void kmscon_text_unref(struct kmscon_text *text)
* kmscon_text_set:
* @txt: Valid text-renderer object
* @font: font object
* @bold_font: bold font object or NULL
* @screen: screen object
*
* This makes the text-renderer @txt use the font @font and screen @screen. You
@ -303,11 +304,15 @@ void kmscon_text_unref(struct kmscon_text *text)
* None of the arguments can be NULL!
* If this function fails then you must assume that no font/screen will be set
* and the object is invalid.
* If @bold_font is NULL, @font is also used for bold characters. The caller
* must make sure that @font and @bold_font have the same metrics. The renderers
* will always use the metrics of @font.
*
* Returns: 0 on success, negative error code on failure.
*/
int kmscon_text_set(struct kmscon_text *txt,
struct kmscon_font *font,
struct kmscon_font *bold_font,
struct uterm_screen *screen)
{
int ret;
@ -315,21 +320,27 @@ int kmscon_text_set(struct kmscon_text *txt,
if (!txt || !font || !screen)
return -EINVAL;
if (!bold_font)
bold_font = font;
kmscon_text_unset(txt);
txt->font = font;
txt->bold_font = bold_font;
txt->screen = screen;
if (txt->ops->set) {
ret = txt->ops->set(txt);
if (ret) {
txt->font = NULL;
txt->bold_font = NULL;
txt->screen = NULL;
return ret;
}
}
kmscon_font_ref(txt->font);
kmscon_font_ref(txt->bold_font);
uterm_screen_ref(txt->screen);
return 0;
@ -353,8 +364,10 @@ void kmscon_text_unset(struct kmscon_text *txt)
txt->ops->unset(txt);
kmscon_font_unref(txt->font);
kmscon_font_unref(txt->bold_font);
uterm_screen_unref(txt->screen);
txt->font = NULL;
txt->bold_font = NULL;
txt->screen = NULL;
txt->cols = 0;
txt->rows = 0;

View File

@ -123,6 +123,7 @@ struct kmscon_text {
void *data;
struct kmscon_font *font;
struct kmscon_font *bold_font;
struct uterm_screen *screen;
unsigned int cols;
unsigned int rows;
@ -153,6 +154,7 @@ void kmscon_text_unref(struct kmscon_text *txt);
int kmscon_text_set(struct kmscon_text *txt,
struct kmscon_font *font,
struct kmscon_font *bold_font,
struct uterm_screen *screen);
void kmscon_text_unset(struct kmscon_text *txt);
unsigned int kmscon_text_get_cols(struct kmscon_text *txt);