Calculate font size properly
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sat, 26 Nov 2011 16:12:17 +0000 (17:12 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sat, 26 Nov 2011 16:12:17 +0000 (17:12 +0100)
We set the font size to the absolute size we have per cell instead of using a
fixed font-size.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/console.c
src/console.h
src/console_char.c

index 61d4214..c55afd2 100644 (file)
@@ -306,7 +306,7 @@ int kmscon_console_resize(struct kmscon_console *con, uint32_t x, uint32_t y)
        if (!con || !size || size < x || size < y)
                return -EINVAL;
 
-       ret = kmscon_font_new(&font);
+       ret = kmscon_font_new(&font, con->res_y / y);
        if (ret)
                return ret;
 
index aa653ba..08f260b 100644 (file)
@@ -35,7 +35,7 @@ int kmscon_char_append_u8(struct kmscon_char *ch, const char *str, size_t len);
 
 /* font objects with cached glyphs */
 
-int kmscon_font_new(struct kmscon_font **out);
+int kmscon_font_new(struct kmscon_font **out, uint32_t height);
 void kmscon_font_ref(struct kmscon_font *font);
 void kmscon_font_unref(struct kmscon_font *font);
 
index a70cc62..b9a3c9a 100644 (file)
@@ -329,9 +329,10 @@ static int kmscon_glyph_set(struct kmscon_glyph *glyph,
 
 /*
  * Creates a new font
+ * \height is the height in pixel that we have for each character.
  * Returns 0 on success and stores the new font in \out.
  */
-int kmscon_font_new(struct kmscon_font **out)
+int kmscon_font_new(struct kmscon_font **out, uint32_t height)
 {
        struct kmscon_font *font;
        int ret;
@@ -340,7 +341,7 @@ int kmscon_font_new(struct kmscon_font **out)
        PangoLanguage *lang;
        cairo_font_options_t *opt;
 
-       if (!out)
+       if (!out || !height)
                return -EINVAL;
 
        font = malloc(sizeof(*font));
@@ -361,14 +362,14 @@ int kmscon_font_new(struct kmscon_font **out)
        }
 
        pango_context_set_base_dir(font->ctx, PANGO_DIRECTION_LTR);
-       pango_cairo_context_set_resolution(font->ctx, 72);
 
-       desc = pango_font_description_from_string("monospace 18");
+       desc = pango_font_description_from_string("monospace");
        if (!desc) {
                ret = -EFAULT;
                goto err_ctx;
        }
 
+       pango_font_description_set_absolute_size(desc, PANGO_SCALE * height);
        pango_context_set_font_description(font->ctx, desc);
        pango_font_description_free(desc);