aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2020-01-17 22:51:42 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2020-01-17 22:51:42 +0100
commitac87d21dd360a1801bc3948e91143d614cf62ee6 (patch)
tree6cef83b611f8beba2db046e95197e284b3bd2542
parent9e868be82dece154324edd19720bff18186604f7 (diff)
downloadd2tk-ac87d21dd360a1801bc3948e91143d614cf62ee6.tar.xz
core: prototype fontconfig support.
-rw-r--r--VERSION2
-rw-r--r--d2tk/base.h2
-rw-r--r--d2tk/core.h1
-rw-r--r--meson.build10
-rw-r--r--src/backend_cairo.c7
-rw-r--r--src/backend_nanovg.c7
-rw-r--r--src/base.c2
-rw-r--r--src/base_pty.c8
-rw-r--r--src/core.c47
-rw-r--r--src/core_internal.h4
-rw-r--r--ttf/FiraCode: bold.ttf (renamed from ttf/FiraCode-Bold.ttf)bin315784 -> 315784 bytes
-rw-r--r--ttf/FiraCode: light.ttf (renamed from ttf/FiraCode-Light.ttf)bin276684 -> 276684 bytes
-rw-r--r--ttf/FiraCode: medium.ttf (renamed from ttf/FiraCode-Medium.ttf)bin286232 -> 286232 bytes
-rw-r--r--ttf/FiraCode: regular.ttf (renamed from ttf/FiraCode-Regular.ttf)bin290360 -> 290360 bytes
-rw-r--r--ttf/FiraSans: bold.ttf (renamed from ttf/FiraSans-Bold.ttf)bin521312 -> 521312 bytes
15 files changed, 69 insertions, 21 deletions
diff --git a/VERSION b/VERSION
index b7bdabc..2626b71 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.971
+0.1.973
diff --git a/d2tk/base.h b/d2tk/base.h
index 38108e7..6b92457 100644
--- a/d2tk/base.h
+++ b/d2tk/base.h
@@ -26,8 +26,6 @@
#include <utf8.h/utf8.h>
-#include "config.h"
-
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/d2tk/core.h b/d2tk/core.h
index bbe0d3c..8de5cc5 100644
--- a/d2tk/core.h
+++ b/d2tk/core.h
@@ -21,6 +21,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include "config.h"
#include <d2tk/d2tk.h>
#ifdef __cplusplus
diff --git a/meson.build b/meson.build
index f3fa461..d6f79a5 100644
--- a/meson.build
+++ b/meson.build
@@ -294,31 +294,31 @@ config_h = configure_file(
if not use_fontconfig.enabled()
fira_sans_bold_ttf = configure_file(
- input : join_paths('ttf', 'FiraSans-Bold.ttf'),
+ input : join_paths('ttf', 'FiraSans: bold.ttf'),
output : 'FiraSans-Bold.ttf',
copy : true,
install : false)
fira_code_bold_ttf = configure_file(
- input : join_paths('ttf', 'FiraCode-Bold.ttf'),
+ input : join_paths('ttf', 'FiraCode: bold.ttf'),
output : 'FiraCode-Bold.ttf',
copy : true,
install : false)
fira_code_light_ttf = configure_file(
- input : join_paths('ttf', 'FiraCode-Light.ttf'),
+ input : join_paths('ttf', 'FiraCode: light.ttf'),
output : 'FiraCode-Light.ttf',
copy : true,
install : false)
fira_code_medium_ttf = configure_file(
- input : join_paths('ttf', 'FiraCode-Medium.ttf'),
+ input : join_paths('ttf', 'FiraCode: medium.ttf'),
output : 'FiraCode-Medium.ttf',
copy : true,
install : false)
fira_code_regular_ttf = configure_file(
- input : join_paths('ttf', 'FiraCode-Regular.ttf'),
+ input : join_paths('ttf', 'FiraCode: regular.ttf'),
output : 'FiraCode-Regular.ttf',
copy : true,
install : false)
diff --git a/src/backend_cairo.c b/src/backend_cairo.c
index 14d3d81..332017b 100644
--- a/src/backend_cairo.c
+++ b/src/backend_cairo.c
@@ -576,13 +576,12 @@ d2tk_cairo_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
if(!*sprite)
{
- char *ft_path = NULL;
- assert(asprintf(&ft_path, "%s%s", backend->bundle_path, body->face) != -1);
- assert(ft_path);
+ char ft_path [1024];
+ d2tk_core_get_font_path(core, backend->bundle_path, body->face,
+ sizeof(ft_path), ft_path);
FT_Face ft_face = NULL;
FT_New_Face(backend->library, ft_path, 0, &ft_face);
- free(ft_path);
assert(ft_face);
cairo_font_face_t *face = cairo_ft_font_face_create_for_ft_face(ft_face, 0);
diff --git a/src/backend_nanovg.c b/src/backend_nanovg.c
index 247e4eb..4e4dbb6 100644
--- a/src/backend_nanovg.c
+++ b/src/backend_nanovg.c
@@ -657,12 +657,11 @@ d2tk_nanovg_process(void *data, d2tk_core_t *core, const d2tk_com_t *com,
if(!*sprite)
{
- char *ft_path = NULL;
- assert(asprintf(&ft_path, "%s%s", backend->bundle_path, body->face) != -1);
- assert(ft_path);
+ char ft_path [1024];
+ d2tk_core_get_font_path(core, backend->bundle_path, body->face,
+ sizeof(ft_path), ft_path);
const int face = nvgCreateFont(ctx, body->face, ft_path);
- free(ft_path);
assert(face != -1);
*sprite = (uintptr_t)face;
diff --git a/src/base.c b/src/base.c
index 411e5be..77a29f3 100644
--- a/src/base.c
+++ b/src/base.c
@@ -644,7 +644,7 @@ d2tk_base_is_active_hot(d2tk_base_t *base, d2tk_id_t id,
#define light_orange 0xffcf00ff
#define dark_orange 0xcf9f00ff
-#define FONT_SANS_BOLD "FiraSans-Bold.ttf"
+#define FONT_SANS_BOLD "FiraSans: bold"
D2TK_API const d2tk_style_t *
d2tk_base_get_default_style()
diff --git a/src/base_pty.c b/src/base_pty.c
index 687bb0a..8795532 100644
--- a/src/base_pty.c
+++ b/src/base_pty.c
@@ -38,10 +38,10 @@
#define MAX(x, y) (x > y ? y : x)
-#define FONT_CODE_LIGHT "FiraCode-Light.ttf"
-#define FONT_CODE_REGULAR "FiraCode-Regular.ttf"
-#define FONT_CODE_MEDIUM "FiraCode-Medium.ttf"
-#define FONT_CODE_BOLD "FiraCode-Bold.ttf"
+#define FONT_CODE_LIGHT "FiraCode: light"
+#define FONT_CODE_REGULAR "FiraCode: regular"
+#define FONT_CODE_MEDIUM "FiraCode: medium"
+#define FONT_CODE_BOLD "FiraCode: bold"
typedef struct _cell_t cell_t;
typedef struct _d2tk_atom_body_pty_t d2tk_atom_body_pty_t;
diff --git a/src/core.c b/src/core.c
index fbf9864..c4672c9 100644
--- a/src/core.c
+++ b/src/core.c
@@ -33,6 +33,10 @@
#include "core_internal.h"
#include <d2tk/hash.h>
+#if D2TK_FONTCONFIG
+# include <fontconfig/fontconfig.h>
+#endif
+
#define _D2TK_SPRITES_MAX 0x10000 //FIXME how big?
#define _D2TK_SPRITES_MASK (_D2TK_SPRITES_MAX - 1)
#define _D2TK_SPRITES_TTL 0x100
@@ -1633,3 +1637,46 @@ d2tk_core_set_full_refresh(d2tk_core_t *core)
{
core->full_refresh = true;
}
+
+int
+d2tk_core_get_font_path(d2tk_core_t *core, const char *bundle_path,
+ const char *rel_path, size_t abs_len, char *abs_path)
+{
+ int ret = 1;
+
+#if D2TK_FONTCONFIG
+ (void)core;
+ (void)bundle_path;
+
+ FcConfig *config = FcInitLoadConfigAndFonts();
+ FcPattern *pat = FcNameParse((FcChar8 *)rel_path);
+ FcConfigSubstitute(config, pat, FcMatchPattern);
+ FcDefaultSubstitute(pat);
+
+ //FcPatternPrint(pat);
+
+ FcResult result;
+ FcPattern *font = FcFontMatch(config, pat, &result);
+ if(font)
+ {
+ FcChar8 *file = NULL;
+ if(FcPatternGetString(font, FC_FILE, 0, &file) == FcResultMatch)
+ {
+ fprintf(stderr, "[%s] '%s' '%s'\n", __func__, rel_path, file);
+ snprintf(abs_path, abs_len, "%s", file);
+ ret = 0;
+ }
+
+ FcPatternDestroy(font);
+ }
+
+ FcPatternDestroy(pat);
+
+ FcConfigDestroy(config);
+#else
+ snprintf(abs_path, abs_len, "%s%s.ttf", bundle_path, rel_path);
+ ret = 0;
+#endif
+
+ return ret;
+}
diff --git a/src/core_internal.h b/src/core_internal.h
index d281832..d46af9e 100644
--- a/src/core_internal.h
+++ b/src/core_internal.h
@@ -292,6 +292,10 @@ d2tk_core_set_bg_color(d2tk_core_t *core, uint32_t rgba);
uint32_t
d2tk_core_get_bg_color(d2tk_core_t *core);
+int
+d2tk_core_get_font_path(d2tk_core_t *core, const char *bundle_path,
+ const char *rel_path, size_t abs_len, char *abs_path);
+
#ifdef __cplusplus
}
#endif
diff --git a/ttf/FiraCode-Bold.ttf b/ttf/FiraCode: bold.ttf
index 5030383..5030383 100644
--- a/ttf/FiraCode-Bold.ttf
+++ b/ttf/FiraCode: bold.ttf
Binary files differ
diff --git a/ttf/FiraCode-Light.ttf b/ttf/FiraCode: light.ttf
index 95913af..95913af 100644
--- a/ttf/FiraCode-Light.ttf
+++ b/ttf/FiraCode: light.ttf
Binary files differ
diff --git a/ttf/FiraCode-Medium.ttf b/ttf/FiraCode: medium.ttf
index eca9e18..eca9e18 100644
--- a/ttf/FiraCode-Medium.ttf
+++ b/ttf/FiraCode: medium.ttf
Binary files differ
diff --git a/ttf/FiraCode-Regular.ttf b/ttf/FiraCode: regular.ttf
index 97c1159..97c1159 100644
--- a/ttf/FiraCode-Regular.ttf
+++ b/ttf/FiraCode: regular.ttf
Binary files differ
diff --git a/ttf/FiraSans-Bold.ttf b/ttf/FiraSans: bold.ttf
index f03425a..f03425a 100644
--- a/ttf/FiraSans-Bold.ttf
+++ b/ttf/FiraSans: bold.ttf
Binary files differ