text: font: add unifont backend
This adds a new Unifont font-backend based on the recently added Unifont data. The backend is disabled by default for 2 reasons: - It takes about 5min to compile and needs >1GB of memory on an Intel Atom N450 - License situation is unclear as it is GPL Written-by: Ted Kotz <ted@kotz.us> Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
e9b523c3f1
commit
4788267a9c
8
COPYING
8
COPYING
@ -3,6 +3,7 @@
|
||||
This software was written by:
|
||||
David Herrmann <dh.herrmann@googlemail.com>
|
||||
Ran Benita <ran234@gmail.com>
|
||||
Ted Kotz <ted@kotz.us>
|
||||
|
||||
= Copyright Notice =
|
||||
|
||||
@ -145,3 +146,10 @@ The "solarized" color palettes in vte.c are from:
|
||||
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.
|
||||
|
||||
The Unifont-Font is from http://unifoundry.com/unifont.html and licensed under
|
||||
the terms of the GNU GPL. So if you enable this font backend, then kmscon will
|
||||
also be released under the terms of the GNU GPL. Copyrights are:
|
||||
|
||||
Copyright 1998-2008 Roman Czyborra
|
||||
Copyright 1998-2008 Paul Hardy
|
||||
|
@ -146,6 +146,13 @@ libkmscon_core_la_SOURCES = \
|
||||
src/text.c \
|
||||
src/text_font.c
|
||||
|
||||
if KMSCON_HAVE_UNIFONT
|
||||
libkmscon_core_la_SOURCES += \
|
||||
src/text_font_unifont.h \
|
||||
src/text_font_unifont.c \
|
||||
src/text_font_unifont_data.c
|
||||
endif
|
||||
|
||||
if KMSCON_HAVE_8X16
|
||||
libkmscon_core_la_SOURCES += \
|
||||
src/text_font_8x16.c
|
||||
|
28
configure.ac
28
configure.ac
@ -130,6 +130,12 @@ AC_ARG_ENABLE([xkbcommon],
|
||||
[disable xkbcommon keyboard backend])])
|
||||
AC_MSG_RESULT([ok])
|
||||
|
||||
AC_MSG_CHECKING([whether to use static unifont backend])
|
||||
AC_ARG_ENABLE([unifont],
|
||||
[AS_HELP_STRING([--enable-unifont],
|
||||
[enable static unifont font backend (GPL)])])
|
||||
AC_MSG_RESULT([ok])
|
||||
|
||||
AC_MSG_CHECKING([whether to use static 8x16 font backend])
|
||||
AC_ARG_ENABLE([f8x16],
|
||||
[AS_HELP_STRING([--disable-f8x16],
|
||||
@ -403,9 +409,26 @@ AM_CONDITIONAL([UTERM_HAVE_XKBCOMMON], [test x$xkbcommon_enabled = xyes])
|
||||
|
||||
#
|
||||
# Font backends
|
||||
# This checks for the 8x16, freetype2 and pango font backends and enables them
|
||||
# if requested and available.
|
||||
# This checks for the unifont, 8x16, freetype2 and pango font backends and
|
||||
# enables them if requested and available.
|
||||
#
|
||||
# Please note that the Unifont-data is GPL'ed and we compile this statically
|
||||
# into our application. I do not consider this a "derivative" but a lawyer may
|
||||
# disagree. So please make sure you enable this only if you use the GPL as
|
||||
# license for kmscon.
|
||||
#
|
||||
|
||||
unifont_enabled=no
|
||||
if test x$enable_unifont = xyes ; then
|
||||
unifont_enabled=yes
|
||||
fi
|
||||
|
||||
if test x$unifont_enabled = xyes ; then
|
||||
AC_DEFINE([KMSCON_HAVE_UNIFONT], [1],
|
||||
[Use static unifont backend])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL([KMSCON_HAVE_UNIFONT], [test x$unifont_enabled = xyes])
|
||||
|
||||
f8x16_enabled=no
|
||||
if test ! x$enable_f8x16 = xno ; then
|
||||
@ -537,6 +560,7 @@ AC_MSG_NOTICE([Build configuration:
|
||||
OpenGLES2: $gles2_enabled
|
||||
|
||||
font backends:
|
||||
unifont: $unifont_enabled
|
||||
8x16: $f8x16_enabled
|
||||
freetype2: $freetype2_enabled
|
||||
pango: $pango_enabled
|
||||
|
@ -567,6 +567,7 @@ int main(int argc, char **argv)
|
||||
if (ret)
|
||||
goto err_out;
|
||||
|
||||
kmscon_font_unifont_load();
|
||||
kmscon_font_8x16_load();
|
||||
kmscon_font_pango_load();
|
||||
kmscon_font_freetype2_load();
|
||||
@ -606,6 +607,7 @@ int main(int argc, char **argv)
|
||||
kmscon_font_freetype2_unload();
|
||||
kmscon_font_pango_unload();
|
||||
kmscon_font_8x16_unload();
|
||||
kmscon_font_unifont_unload();
|
||||
conf_free(options, onum);
|
||||
log_info("exiting");
|
||||
|
||||
@ -617,6 +619,7 @@ err_unload:
|
||||
kmscon_font_freetype2_unload();
|
||||
kmscon_font_pango_unload();
|
||||
kmscon_font_8x16_unload();
|
||||
kmscon_font_unifont_unload();
|
||||
err_out:
|
||||
conf_free(options, onum);
|
||||
log_err("cannot initialize kmscon, errno %d: %s", ret, strerror(-ret));
|
||||
|
19
src/text.h
19
src/text.h
@ -180,6 +180,25 @@ void kmscon_text_abort(struct kmscon_text *txt);
|
||||
|
||||
/* modularized backends */
|
||||
|
||||
#ifdef KMSCON_HAVE_UNIFONT
|
||||
|
||||
int kmscon_font_unifont_load(void);
|
||||
void kmscon_font_unifont_unload(void);
|
||||
|
||||
#else
|
||||
|
||||
static inline int kmscon_font_unifont_load(void)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline void kmscon_font_unifont_unload(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef KMSCON_HAVE_8X16
|
||||
|
||||
int kmscon_font_8x16_load(void);
|
||||
|
145
src/text_font_unifont.c
Normal file
145
src/text_font_unifont.c
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* kmscon - Fixed unifont font for font handling of text renderer
|
||||
*
|
||||
* Copyright (c) 2012 Ted Kotz <ted@kotz.us>
|
||||
* Copyright (c) 2012 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:text_font_unifont.c
|
||||
* @short_description: Fixed unifont font for font handling of text renderer
|
||||
* @include: text.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
|
||||
* glyphs. This can statically compile in any font defined as a unifont style
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "log.h"
|
||||
#include "text.h"
|
||||
#include "unicode.h"
|
||||
#include "uterm.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "text_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;
|
||||
|
||||
static int kmscon_font_unifont_init(struct kmscon_font *out,
|
||||
const struct kmscon_font_attr *attr)
|
||||
{
|
||||
static const char name[] = "static-unifont";
|
||||
|
||||
log_debug("loading static unifont font");
|
||||
|
||||
memset(&out->attr, 0, sizeof(out->attr));
|
||||
memcpy(out->attr.name, name, sizeof(name));
|
||||
out->attr.bold = false;
|
||||
out->attr.italic = false;
|
||||
out->attr.width = 8;
|
||||
out->attr.height = 16;
|
||||
kmscon_font_attr_normalize(&out->attr);
|
||||
out->baseline = 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void kmscon_font_unifont_destroy(struct kmscon_font *font)
|
||||
{
|
||||
log_debug("unloading static unifont font");
|
||||
}
|
||||
|
||||
static int kmscon_font_unifont_render(struct kmscon_font *font,
|
||||
kmscon_symbol_t sym,
|
||||
const struct kmscon_glyph **out)
|
||||
{
|
||||
const uint32_t *val;
|
||||
size_t len;
|
||||
|
||||
val = kmscon_symbol_get(&sym, &len);
|
||||
if (len > 1 || *val >= kmscon_text_font_unifont_data_hex_len)
|
||||
return -ERANGE;
|
||||
|
||||
*out = &kmscon_text_font_unifont_data_hex_glyphs[*val];
|
||||
|
||||
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['?'];
|
||||
else
|
||||
*out = &kmscon_text_font_unifont_data_hex_glyphs[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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[' '];
|
||||
return 0;
|
||||
} else {
|
||||
return kmscon_font_unifont_render_inval(font, out);
|
||||
}
|
||||
}
|
||||
|
||||
static const struct kmscon_font_ops kmscon_font_unifont_ops = {
|
||||
.name = "unifont",
|
||||
.init = kmscon_font_unifont_init,
|
||||
.destroy = kmscon_font_unifont_destroy,
|
||||
.render = kmscon_font_unifont_render,
|
||||
.render_empty = kmscon_font_unifont_render_empty,
|
||||
.render_inval = kmscon_font_unifont_render_inval,
|
||||
};
|
||||
|
||||
int kmscon_font_unifont_load(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = kmscon_font_register(&kmscon_font_unifont_ops);
|
||||
if (ret) {
|
||||
log_error("cannot register unifont font");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void kmscon_font_unifont_unload(void)
|
||||
{
|
||||
kmscon_font_unregister(kmscon_font_unifont_ops.name);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user