We use a new font factory which is used to create a new font. It will later also
be used to cache fonts and select proper system fonts.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
libkmscon_core_la_SOURCES = \
src/console.c src/console.h \
src/output.c src/output.h \
- src/console_char.c \
src/console_cell.c \
src/unicode.c src/unicode.h \
+ src/font_pango.c src/font.h \
src/log.c src/log.h \
src/eloop.c src/eloop.h \
src/vt.c src/vt.h \
#include <GL/glext.h>
#include "console.h"
+#include "font.h"
#include "log.h"
#include "unicode.h"
struct kmscon_console {
size_t ref;
- struct kmscon_symbol_table *st;
+ struct kmscon_font_factory *ff;
/* GL texture and font */
GLuint tex;
}
int kmscon_console_new(struct kmscon_console **out,
- struct kmscon_symbol_table *st)
+ struct kmscon_font_factory *ff)
{
struct kmscon_console *con;
int ret;
memset(con, 0, sizeof(*con));
con->ref = 1;
- con->st = st;
+ con->ff = ff;
log_debug("console: new console\n");
ret = kmscon_buffer_new(&con->cells, 0, 0);
con->cells_x = kmscon_buffer_get_width(con->cells);
con->cells_y = kmscon_buffer_get_height(con->cells);
- kmscon_symbol_table_ref(con->st);
+ kmscon_font_factory_ref(con->ff);
*out = con;
return 0;
kmscon_console_free_res(con);
kmscon_font_unref(con->font);
kmscon_buffer_unref(con->cells);
- kmscon_symbol_table_unref(con->st);
+ kmscon_font_factory_unref(con->ff);
free(con);
log_debug("console: destroing console\n");
}
if (con->cursor_y > con->cells_y)
con->cursor_y = con->cells_y;
- ret = kmscon_font_new(&font, height / con->cells_y, con->st);
+ ret = kmscon_font_factory_load(con->ff, &font, 0,
+ height / con->cells_y);
if (ret) {
log_err("console: cannot create new font: %d\n", ret);
return ret;
#include <inttypes.h>
#include <stdlib.h>
+#include "font.h"
#include "unicode.h"
-struct kmscon_font;
struct kmscon_buffer;
struct kmscon_console;
-/* font objects with cached glyphs */
-
-int kmscon_font_new(struct kmscon_font **out, unsigned int height,
- struct kmscon_symbol_table *st);
-void kmscon_font_ref(struct kmscon_font *font);
-void kmscon_font_unref(struct kmscon_font *font);
-
-unsigned int kmscon_font_get_height(struct kmscon_font *font);
-unsigned int kmscon_font_get_width(struct kmscon_font *font);
-int kmscon_font_draw(struct kmscon_font *font, kmscon_symbol_t ch,
- void *dcr, uint32_t x, uint32_t y);
-
/* console buffer with cell objects */
int kmscon_buffer_new(struct kmscon_buffer **out, unsigned int x,
/* console objects */
int kmscon_console_new(struct kmscon_console **out,
- struct kmscon_symbol_table *st);
+ struct kmscon_font_factory *ff);
void kmscon_console_ref(struct kmscon_console *con);
void kmscon_console_unref(struct kmscon_console *con);
--- /dev/null
+/*
+ * kmscon - Font Management
+ *
+ * Copyright (c) 2011 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2011 University of Tuebingen
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * Font Management
+ * A font factory helps loading and initializing fonts. The font object is used
+ * to draw glyphs onto the screen.
+ * Efficient caching is used to allow fast drawing operations.
+ */
+
+#ifndef KMSCON_FONT_H
+#define KMSCON_FONT_H
+
+#include <stdlib.h>
+#include "unicode.h"
+
+struct kmscon_font_factory;
+struct kmscon_font;
+
+int kmscon_font_factory_new(struct kmscon_font_factory **out,
+ struct kmscon_symbol_table *st);
+void kmscon_font_factory_ref(struct kmscon_font_factory *ff);
+void kmscon_font_factory_unref(struct kmscon_font_factory *ff);
+
+int kmscon_font_factory_load(struct kmscon_font_factory *ff,
+ struct kmscon_font **out, unsigned int width, unsigned int height);
+
+void kmscon_font_ref(struct kmscon_font *font);
+void kmscon_font_unref(struct kmscon_font *font);
+
+unsigned int kmscon_font_get_height(struct kmscon_font *font);
+unsigned int kmscon_font_get_width(struct kmscon_font *font);
+int kmscon_font_draw(struct kmscon_font *font, kmscon_symbol_t ch,
+ void *dcr, uint32_t x, uint32_t y);
+
+#endif /* KMSCON_FONT_H */
/*
- * kmscon - Console Characters
+ * kmscon - Font Management - Pango backend
*
* Copyright (c) 2011 David Herrmann <dh.herrmann@googlemail.com>
* Copyright (c) 2011 University of Tuebingen
*/
/*
- * Console Characters
- * A console always has a fixed width and height measured in number of
- * characters. This interfaces describes a single character.
- *
- * To be Unicode compatible, the most straightforward way would be using a UCS
- * number for each character and printing them. However, Unicode allows
- * combining marks, that is, a single printable character is constructed of
- * multiple characters. We support this by allowing to append characters to an
- * existing character. This should only be used with combining chars, though.
- * Otherwise you end up with multiple printable characters in a cell and the
- * output may get corrupted.
- *
- * We store each character (sequence) as UTF8 string because the pango library
- * accepts only UTF8. Hence, we avoid conversion to UCS or wide-characters.
+ * Pango Font Management
+ * This is the font backend using the pango library in conjunction with cairo as
+ * output. See glyph type for detailed information on the caching algorithms
+ * used.
*/
#include <errno.h>
#include <glib.h>
#include <pango/pango.h>
#include <pango/pangocairo.h>
-#include "console.h"
+#include "font.h"
#include "log.h"
#include "unicode.h"
} src;
};
+struct kmscon_font_factory {
+ unsigned long ref;
+ struct kmscon_symbol_table *st;
+};
+
struct kmscon_font {
size_t ref;
struct kmscon_symbol_table *st;
PangoContext *ctx;
};
-static int kmscon_font_lookup(struct kmscon_font *font, kmscon_symbol_t key,
- struct kmscon_glyph **out);
+static int kmscon_font_lookup(struct kmscon_font *font,
+ kmscon_symbol_t key, struct kmscon_glyph **out);
/*
* Glyphs
return 0;
}
+int kmscon_font_factory_new(struct kmscon_font_factory **out,
+ struct kmscon_symbol_table *st)
+{
+ struct kmscon_font_factory *ff;
+
+ if (!out)
+ return -EINVAL;
+
+ ff = malloc(sizeof(*ff));
+ if (!ff)
+ return -ENOMEM;
+
+ memset(ff, 0, sizeof(*ff));
+ ff->ref = 1;
+ ff->st = st;
+
+ kmscon_symbol_table_ref(ff->st);
+ *out = ff;
+
+ return 0;
+}
+
+void kmscon_font_factory_ref(struct kmscon_font_factory *ff)
+{
+ if (!ff)
+ return;
+
+ ++ff->ref;
+}
+
+void kmscon_font_factory_unref(struct kmscon_font_factory *ff)
+{
+ if (!ff || !ff->ref)
+ return;
+
+ if (--ff->ref)
+ return;
+
+ kmscon_symbol_table_unref(ff->st);
+ free(ff);
+}
+
/*
* Measure font width
* We simply draw all ASCII characters and use the average width as default
* \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, unsigned int height,
- struct kmscon_symbol_table *st)
+
+int kmscon_font_factory_load(struct kmscon_font_factory *ff,
+ struct kmscon_font **out, unsigned int width, unsigned int height)
{
struct kmscon_font *font;
int ret;
PangoLanguage *lang;
cairo_font_options_t *opt;
- if (!out || !height)
+ if (!ff || !out || !height)
return -EINVAL;
log_debug("font: new font (height %u)\n", height);
return -ENOMEM;
font->ref = 1;
font->height = height;
- font->st = st;
+ font->st = ff->st;
map = pango_cairo_font_map_get_default();
if (!map) {
#include "console.h"
#include "eloop.h"
+#include "font.h"
#include "log.h"
#include "terminal.h"
#include "unicode.h"
}
int kmscon_terminal_new(struct kmscon_terminal **out,
- struct kmscon_symbol_table *st)
+ struct kmscon_font_factory *ff)
{
struct kmscon_terminal *term;
int ret;
if (ret)
goto err_free;
- ret = kmscon_console_new(&term->console, st);
+ ret = kmscon_console_new(&term->console, ff);
if (ret)
goto err_idle;
#include <stdlib.h>
#include "console.h"
+#include "font.h"
#include "output.h"
#include "unicode.h"
struct kmscon_terminal;
int kmscon_terminal_new(struct kmscon_terminal **out,
- struct kmscon_symbol_table *st);
+ struct kmscon_font_factory *ff);
void kmscon_terminal_ref(struct kmscon_terminal *term);
void kmscon_terminal_unref(struct kmscon_terminal *term);
#include <GL/glext.h>
#include "console.h"
#include "eloop.h"
+#include "font.h"
#include "log.h"
#include "output.h"
#include "unicode.h"
struct kmscon_signal *sig_int;
struct kmscon_fd *stdin_fd;
struct kmscon_symbol_table *st;
+ struct kmscon_font_factory *ff;
struct kmscon_compositor *comp;
struct kmscon_vt *vt;
struct kmscon_console *con;
kmscon_console_unref(con->con);
kmscon_compositor_unref(con->comp);
kmscon_vt_unref(con->vt);
+ kmscon_font_factory_unref(con->ff);
kmscon_symbol_table_unref(con->st);
kmscon_eloop_rm_fd(con->stdin_fd);
kmscon_eloop_rm_signal(con->sig_int);
if (ret)
goto err_loop;
+ ret = kmscon_font_factory_new(&con->ff, con->st);
+ if (ret)
+ goto err_loop;
+
ret = kmscon_compositor_new(&con->comp);
if (ret)
goto err_loop;
if (ret)
goto err_loop;
- ret = kmscon_console_new(&con->con, con->st);
+ ret = kmscon_console_new(&con->con, con->ff);
if (ret)
goto err_loop;
struct kmscon_signal *sig_term;
struct kmscon_signal *sig_int;
struct kmscon_symbol_table *st;
+ struct kmscon_font_factory *ff;
struct kmscon_compositor *comp;
struct kmscon_input *input;
struct kmscon_vt *vt;
kmscon_vt_unref(app->vt);
kmscon_input_unref(app->input);
kmscon_compositor_unref(app->comp);
+ kmscon_font_factory_unref(app->ff);
kmscon_symbol_table_unref(app->st);
kmscon_eloop_rm_signal(app->sig_int);
kmscon_eloop_rm_signal(app->sig_term);
if (ret)
goto err_loop;
+ ret = kmscon_font_factory_new(&app->ff, app->st);
+ if (ret)
+ goto err_loop;
+
ret = kmscon_compositor_new(&app->comp);
if (ret)
goto err_loop;
if (ret)
goto err_loop;
- ret = kmscon_terminal_new(&app->term, app->st);
+ ret = kmscon_terminal_new(&app->term, app->ff);
if (ret)
goto err_loop;