text: move font layer into top-level font_* namespace
authorDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 3 Jan 2013 15:55:56 +0000 (16:55 +0100)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Thu, 3 Jan 2013 15:55:56 +0000 (16:55 +0100)
The font layer does not longer depend on the text layer so move it into
its own namespace.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Makefile.am
src/font.c [moved from src/text_font.c with 98% similarity]
src/font.h [new file with mode: 0644]
src/font_8x16.c [moved from src/text_font_8x16.c with 99% similarity]
src/font_freetype2.c [moved from src/text_font_freetype2.c with 98% similarity]
src/font_pango.c [moved from src/text_font_pango.c with 97% similarity]
src/font_unifont.c [moved from src/text_font_unifont.c with 75% similarity]
src/font_unifont_data.hex [moved from src/text_font_unifont_data.hex with 100% similarity]
src/genunifont.c

index e05da1f..d0efef1 100644 (file)
@@ -327,79 +327,36 @@ src/static_shaders.c: $(SHADERS) genshader$(EXEEXT)
 # This generates the unifont sources from raw hex-encoded font data.
 #
 
-UNIFONT = src/text_font_unifont_data.hex
+UNIFONT = src/font_unifont_data.hex
 
 EXTRA_DIST += $(UNIFONT)
-CLEANFILES += src/text_font_unifont_data.c
+CLEANFILES += src/font_unifont_data.c
 genunifont_SOURCES = src/genunifont.c
 
-src/text_font_unifont_data.c: $(UNIFONT) genunifont$(EXEEXT)
-       $(AM_V_GEN)./genunifont$(EXEEXT) src/text_font_unifont_data.c $(UNIFONT)
+src/font_unifont_data.c: $(UNIFONT) genunifont$(EXEEXT)
+       $(AM_V_GEN)./genunifont$(EXEEXT) src/font_unifont_data.c $(UNIFONT)
 
 #
-# Text-font library
-# The text-font library is used by kmscon _and_ wlterm but is currently linked
+# Font library
+# The font library is used by kmscon _and_ wlterm but is currently linked
 # statically as it hasn't been cleaned up entirely.
 # It has a build-time dependency to UTERM and runtime dependencies to TSM.
 #
 
-TEXT_FONT_LIBS = libtext-font.la
-if BUILD_ENABLE_FONT_UNIFONT
-TEXT_FONT_LIBS += libtext-font-unifont.la
-endif
-if BUILD_ENABLE_FONT_FREETYPE2
-TEXT_FONT_LIBS += libtext-font-freetype2.la
-endif
-if BUILD_ENABLE_FONT_PANGO
-TEXT_FONT_LIBS += libtext-font-pango.la
-endif
-
 if BUILD_ENABLE_KMSCON
-noinst_LTLIBRARIES += $(TEXT_FONT_LIBS)
-else
-if BUILD_ENABLE_WLTERM
-noinst_LTLIBRARIES += $(TEXT_FONT_LIBS)
-endif
+noinst_LTLIBRARIES += libfont.la
 endif
 
-libtext_font_la_SOURCES = \
+libfont_la_SOURCES = \
        $(SHL_REGISTER) \
-       src/text.h \
-       src/text_font.c \
-       src/text_font_8x16.c
-libtext_font_la_LIBADD = \
+       src/font.h \
+       src/font.c \
+       src/font_8x16.c
+libfont_la_LIBADD = \
        -lpthread
-libtext_font_la_LDFLAGS = \
+libfont_la_LDFLAGS = \
        -rdynamic
 
-libtext_font_unifont_la_SOURCES = src/text_font_unifont.c
-nodist_libtext_font_unifont_la_SOURCES = src/text_font_unifont_data.c
-
-libtext_font_freetype2_la_SOURCES = \
-       $(SHL_DLIST) \
-       $(SHL_HASHTABLE) \
-       src/text_font_freetype2.c
-libtext_font_freetype2_la_CPPFLAGS = \
-       $(AM_CPPFLAGS) \
-       $(FREETYPE2_CFLAGS)
-libtext_font_freetype2_la_LIBADD = \
-       $(FREETYPE2_LIBS) \
-       -lpthread \
-       libtsm.la
-
-libtext_font_pango_la_SOURCES = \
-       $(SHL_DLIST) \
-       $(SHL_HASHTABLE) \
-       src/githead.h \
-       src/text_font_pango.c
-libtext_font_pango_la_CPPFLAGS = \
-       $(AM_CPPFLAGS) \
-       $(PANGO_CFLAGS)
-libtext_font_pango_la_LIBADD = \
-       $(PANGO_LIBS) \
-       -lpthread \
-       libtsm.la
-
 #
 # Kmscon Modules
 #
@@ -413,7 +370,7 @@ mod_pango_la_SOURCES = \
        $(SHL_HASHTABLE) \
        src/kmscon_module_interface.h \
        src/githead.h \
-       src/text_font_pango.c \
+       src/font_pango.c \
        src/kmscon_mod_pango.c
 mod_pango_la_CPPFLAGS = \
        $(AM_CPPFLAGS) \
@@ -481,7 +438,7 @@ kmscon_LDADD = \
        $(XKBCOMMON_LIBS) \
        libeloop.la \
        libuterm.la \
-       $(TEXT_FONT_LIBS) \
+       libfont.la \
        -lpthread
 kmscon_LDFLAGS = \
        -rdynamic
@@ -556,7 +513,6 @@ wlterm_LDADD = \
        $(XKBCOMMON_LIBS) \
        libeloop.la \
        libtsm.la \
-       $(TEXT_FONT_LIBS) \
        -lpthread
 
 #
similarity index 98%
rename from src/text_font.c
rename to src/font.c
index 000f201..30a16ae 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * kmscon - Font handling of Text Renderer
+ * kmscon - Font handling
  *
- * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -24,9 +24,9 @@
  */
 
 /**
- * SECTION:text_font
- * @short_description: Font handling of text renderer
- * @include: text.h
+ * SECTION:font
+ * @short_description: Font handling
+ * @include: font.h
  *
  * The text renderer needs a backend that draws glyphs which then can be shown
  * on the screen. This font handling subsystem provides a very simple API to
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
+#include "font.h"
 #include "kmscon_module.h"
 #include "log.h"
 #include "shl_dlist.h"
 #include "shl_register.h"
-#include "text.h"
-#include "uterm.h"
 
-#define LOG_SUBSYSTEM "text_font"
+#define LOG_SUBSYSTEM "font"
 
 static struct shl_register font_reg = SHL_REGISTER_INIT(font_reg);
 
diff --git a/src/font.h b/src/font.h
new file mode 100644 (file)
index 0000000..b3f056f
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * kmscon - Font Renderer
+ *
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
+ *
+ * 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 Renderer
+ */
+
+#ifndef KMSCON_FONT_H
+#define KMSCON_FONT_H
+
+#include <errno.h>
+#include <stdlib.h>
+#include "kmscon_module.h"
+#include "uterm.h"
+
+/* fonts */
+
+struct kmscon_font_attr;
+struct kmscon_glyph;
+struct kmscon_font;
+struct kmscon_font_ops;
+
+#define KMSCON_FONT_MAX_NAME 128
+#define KMSCON_FONT_DEFAULT_NAME "monospace"
+#define KMSCON_FONT_DEFAULT_PPI 72
+
+struct kmscon_font_attr {
+       char name[KMSCON_FONT_MAX_NAME];
+       unsigned int ppi;
+       unsigned int points;
+       bool bold;
+       bool italic;
+       unsigned int height;
+       unsigned int width;
+};
+
+void kmscon_font_attr_normalize(struct kmscon_font_attr *attr);
+bool kmscon_font_attr_match(const struct kmscon_font_attr *a1,
+                           const struct kmscon_font_attr *a2);
+
+struct kmscon_glyph {
+       struct uterm_video_buffer buf;
+       unsigned int width;
+       void *data;
+};
+
+struct kmscon_font {
+       unsigned long ref;
+       struct shl_register_record *record;
+       const struct kmscon_font_ops *ops;
+       struct kmscon_font_attr attr;
+       unsigned int baseline;
+       void *data;
+};
+
+struct kmscon_font_ops {
+       const char *name;
+       struct kmscon_module *owner;
+       int (*init) (struct kmscon_font *out,
+                    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,
+                      const struct kmscon_glyph **out);
+       int (*render_empty) (struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
+       int (*render_inval) (struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
+};
+
+int kmscon_font_register(const struct kmscon_font_ops *ops);
+void kmscon_font_unregister(const char *name);
+
+int kmscon_font_find(struct kmscon_font **out,
+                    const struct kmscon_font_attr *attr,
+                    const char *backend);
+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,
+                      const struct kmscon_glyph **out);
+int kmscon_font_render_empty(struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
+int kmscon_font_render_inval(struct kmscon_font *font,
+                            const struct kmscon_glyph **out);
+
+/* modularized backends */
+
+extern struct kmscon_font_ops kmscon_font_8x16_ops;
+extern struct kmscon_font_ops kmscon_font_unifont_ops;
+extern struct kmscon_font_ops kmscon_font_freetype2_ops;
+extern struct kmscon_font_ops kmscon_font_pango_ops;
+
+#endif /* KMSCON_FONT_H */
similarity index 99%
rename from src/text_font_8x16.c
rename to src/font_8x16.c
index 5622c68..ae2cae0 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * kmscon - Fixed 8x16 font for font handling of text renderer
+ * kmscon - Fixed 8x16 font
  *
- * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -24,9 +24,9 @@
  */
 
 /**
- * SECTION:text_font_8x16.c
- * @short_description: Fixed 8x16 font for font handling of text renderer
- * @include: text.h
+ * SECTION:font_8x16.c
+ * @short_description: Fixed 8x16 font
+ * @include: font.h
  *
  * This is a fixed font renderer backend that supports just one font which is
  * statically compiled into the file. This font is a very simple 8x16 font with
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include "font.h"
 #include "log.h"
-#include "text.h"
 #include "uterm.h"
 
-#define LOG_SUBSYSTEM "text_font_8x16"
+#define LOG_SUBSYSTEM "font_8x16"
 
 /* forward declaration; see end of file for real array */
 static const struct kmscon_glyph kmscon_font_8x16_glyphs[256];
similarity index 98%
rename from src/text_font_freetype2.c
rename to src/font_freetype2.c
index 277afd6..a035bee 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * kmscon - Freetype2 backend for font handling of text renderer
+ * kmscon - Freetype2 font backend
  *
- * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com>
  * Copyright (c) 2011 University of Tuebingen
  *
  * Permission is hereby granted, free of charge, to any person obtaining
@@ -25,9 +25,9 @@
  */
 
 /**
- * SECTION:text_font_freetype2.c
- * @short_description: Freetype2 backend for font handling of text renderer
- * @include: text.h
+ * SECTION:font_freetype2.c
+ * @short_description: Freetype2 font backend
+ * @include: font.h
  *
  * The freetype2 backend uses freetype2 to render glyphs into memory
  * buffers. It uses a hashmap to cache all rendered glyphs of a single
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
+#include "font.h"
 #include "log.h"
 #include "shl_dlist.h"
 #include "shl_hashtable.h"
-#include "text.h"
 #include "uterm.h"
 
-#define LOG_SUBSYSTEM "text_font_freetype2"
+#define LOG_SUBSYSTEM "font_freetype2"
 
 struct glyph {
        bool shrinked;
similarity index 97%
rename from src/text_font_pango.c
rename to src/font_pango.c
index 155dd0e..22b9128 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * kmscon - Pango backend for font handling of text renderer
+ * kmscon - Pango font backend
  *
- * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@googlemail.com>
  * Copyright (c) 2011 University of Tuebingen
  *
  * Permission is hereby granted, free of charge, to any person obtaining
@@ -25,9 +25,9 @@
  */
 
 /**
- * SECTION:text_font_pango.c
- * @short_description: Pango backend for font handling of text renderer
- * @include: text.h
+ * SECTION:font_pango.c
+ * @short_description: Pango font backend
+ * @include: font.h
  *
  * The pango backend uses pango and freetype2 to render glyphs into memory
  * buffers. It uses a hashmap to cache all rendered glyphs of a single
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
+#include "font.h"
 #include "log.h"
 #include "shl_dlist.h"
 #include "shl_hashtable.h"
-#include "text.h"
 #include "tsm_unicode.h"
 #include "uterm.h"
 
-#define LOG_SUBSYSTEM "text_font_pango"
+#define LOG_SUBSYSTEM "font_pango"
 
 struct face {
        unsigned long ref;
similarity index 75%
rename from src/text_font_unifont.c
rename to src/font_unifont.c
index 6970c2a..3431d09 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * kmscon - Fixed unifont font for font handling of text renderer
+ * kmscon - Fixed unifont font
  *
  * Copyright (c) 2012 Ted Kotz <ted@kotz.us>
- * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
+ * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@googlemail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -25,9 +25,9 @@
  */
 
 /**
- * SECTION:text_font_unifont.c
- * @short_description: Fixed unifont font for font handling of text renderer
- * @include: text.h
+ * SECTION:font_unifont.c
+ * @short_description: Fixed unifont font
+ * @include: font.h
  * 
  * This is a fixed font renderer backend that supports just one font which is
  * statically compiled into the file. This bitmap font has 8x16 and 16x16 
  * hex format. This font is from the GNU unifont project available at: 
  * http://unifoundry.com/unifont.html
  *
- * This file is heavily based on text_font_8x16.c
+ * This file is heavily based on font_8x16.c
  * 
  */
 
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include "font.h"
 #include "log.h"
-#include "text.h"
 #include "uterm.h"
 
-#define LOG_SUBSYSTEM "text_font_unifont"
+#define LOG_SUBSYSTEM "font_unifont"
 
 /* array is generated and compiled externally */
-extern const struct kmscon_glyph kmscon_text_font_unifont_data_hex_glyphs[];
-extern size_t kmscon_text_font_unifont_data_hex_len;
+extern const struct kmscon_glyph kmscon_font_unifont_data_hex_glyphs[];
+extern size_t kmscon_font_unifont_data_hex_len;
 
 static int kmscon_font_unifont_init(struct kmscon_font *out,
                                    const struct kmscon_font_attr *attr)
@@ -80,22 +80,22 @@ static int kmscon_font_unifont_render(struct kmscon_font *font, uint32_t id,
                                      const uint32_t *ch, size_t len,
                                      const struct kmscon_glyph **out)
 {
-       if (len > 1 || *ch >= kmscon_text_font_unifont_data_hex_len)
+       if (len > 1 || *ch >= kmscon_font_unifont_data_hex_len)
                return -ERANGE;
 
-       *out = &kmscon_text_font_unifont_data_hex_glyphs[*ch];
+       *out = &kmscon_font_unifont_data_hex_glyphs[*ch];
        return 0;
 }
 
 static int kmscon_font_unifont_render_inval(struct kmscon_font *font,
                                            const struct kmscon_glyph **out)
 {
-       if (0xfffd < kmscon_text_font_unifont_data_hex_len)
-               *out = &kmscon_text_font_unifont_data_hex_glyphs[0xfffd];
-       else if ('?' < kmscon_text_font_unifont_data_hex_len)
-               *out = &kmscon_text_font_unifont_data_hex_glyphs['?'];
+       if (0xfffd < kmscon_font_unifont_data_hex_len)
+               *out = &kmscon_font_unifont_data_hex_glyphs[0xfffd];
+       else if ('?' < kmscon_font_unifont_data_hex_len)
+               *out = &kmscon_font_unifont_data_hex_glyphs['?'];
        else
-               *out = &kmscon_text_font_unifont_data_hex_glyphs[0];
+               *out = &kmscon_font_unifont_data_hex_glyphs[0];
 
        return 0;
 }
@@ -103,8 +103,8 @@ static int kmscon_font_unifont_render_inval(struct kmscon_font *font,
 static int kmscon_font_unifont_render_empty(struct kmscon_font *font,
                                            const struct kmscon_glyph **out)
 {
-       if (' ' < kmscon_text_font_unifont_data_hex_len) {
-               *out = &kmscon_text_font_unifont_data_hex_glyphs[' '];
+       if (' ' < kmscon_font_unifont_data_hex_len) {
+               *out = &kmscon_font_unifont_data_hex_glyphs[' '];
                return 0;
        } else {
                return kmscon_font_unifont_render_inval(font, out);
index 973630c..b3c5121 100644 (file)
@@ -319,7 +319,7 @@ int main(int argc, char **argv)
                                 "by genunifont.c */\n\n"
                                 "#include <stdint.h>\n"
                                 "#include <stdlib.h>\n"
-                                "#include \"text.h\"\n\n";
+                                "#include \"font.h\"\n\n";
        int ret = EXIT_FAILURE;
 
        if (argc < 2) {