From c306802ec260c30a2a22262d57deffa41dd990c4 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 28 May 2003 16:47:22 +0000 Subject: [PATCH] can open/close fonts now --- glft/.cvsignore | 2 ++ glft/Makefile.am | 14 ++++++++++---- glft/debug.c | 11 +++++++++++ glft/debug.h | 6 ++++++ glft/font.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ glft/font.h | 15 +++++++++++++++ glft/glft.h | 12 +++++++++++- glft/init.c | 4 +++- glft/init.h | 6 ++++++ glft/test.c | 17 +++++++++++++++-- 10 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 glft/debug.c create mode 100644 glft/debug.h create mode 100644 glft/font.c create mode 100644 glft/font.h create mode 100644 glft/init.h diff --git a/glft/.cvsignore b/glft/.cvsignore index 9b06cfc4..fc1eb28d 100644 --- a/glft/.cvsignore +++ b/glft/.cvsignore @@ -5,3 +5,5 @@ Makefile libglft.la init.lo glfttest +debug.lo +font.lo diff --git a/glft/Makefile.am b/glft/Makefile.am index 16206dd3..e106496d 100644 --- a/glft/Makefile.am +++ b/glft/Makefile.am @@ -15,10 +15,16 @@ glfttest_LDFLAGS=-lglft -L. glfttest_SOURCES=test.c lib_LTLIBRARIES=libglft.la -libglft_la_SOURCES=init.c - - -noinst_HEADERS=glft.h +libglft_la_SOURCES=\ + init.c \ + font.c \ + debug.c + +noinst_HEADERS=\ + glft.h \ + font.h \ + init.h \ + debug.h MAINTAINERCLEANFILES=Makefile.in diff --git a/glft/debug.c b/glft/debug.c new file mode 100644 index 00000000..d93603de --- /dev/null +++ b/glft/debug.c @@ -0,0 +1,11 @@ +#include +#include + +void GlftDebug(char *a, ...) +{ +#ifdef DEBUG + va_list vl; + va_start(vl, a); + vprintf(a, vl); +#endif +} diff --git a/glft/debug.h b/glft/debug.h new file mode 100644 index 00000000..a1afe8e4 --- /dev/null +++ b/glft/debug.h @@ -0,0 +1,6 @@ +#ifndef __glft_debug_h +#define __glft_debug_h + +void GlftDebug(char *a, ...); + +#endif diff --git a/glft/font.c b/glft/font.c new file mode 100644 index 00000000..53c8d7cf --- /dev/null +++ b/glft/font.c @@ -0,0 +1,46 @@ +#include "font.h" +#include "glft.h" +#include "init.h" +#include "debug.h" +#include +#include + +struct GlftFont *GlftFontOpen(const char *name) +{ + struct GlftFont *font; + FcPattern *pat; + FcFontSet *set; + double alpha; + + assert(init_done); + + pat = FcNameParse((const unsigned char*)name); + assert(pat); + set = FcFontSetCreate(); + if (!FcFontSetAdd(set, pat)) { + FcPatternDestroy(pat); + FcFontSetDestroy(set); + GlftDebug("failed to load font\n"); + return NULL; + } + + font = malloc(sizeof(struct GlftFont)); + font->set = set; + if (FcResultMatch != FcPatternGetBool(pat, "shadow", 0, &font->shadow)) + font->shadow = FcFalse; + if (FcResultMatch != + FcPatternGetInteger(pat, "shadowoffset", 0, &font->shadow_offset)) + font->shadow_offset = 2; + if (FcResultMatch != FcPatternGetDouble(pat, "shadowalpha", 0, &alpha)) + alpha = 0.5; + font->shadow_alpha = (float)alpha; + return font; +} + +void GlftFontClose(struct GlftFont *font) +{ + if (font) { + FcFontSetDestroy(font->set); + free(font); + } +} diff --git a/glft/font.h b/glft/font.h new file mode 100644 index 00000000..2eab714f --- /dev/null +++ b/glft/font.h @@ -0,0 +1,15 @@ +#ifndef __glft_font_h +#define __glft_font_h + +#include + +struct GlftFont { + FcFontSet *set; + + /* extended font attributes */ + FcBool shadow; + int shadow_offset; + float shadow_alpha; +}; + +#endif diff --git a/glft/glft.h b/glft/glft.h index 2dd1377a..b8e4bccf 100644 --- a/glft/glft.h +++ b/glft/glft.h @@ -3,8 +3,18 @@ #include -struct GlftFont; +/* initialization */ FcBool GlftInit(); +/* fonts */ + +struct GlftFont; + +struct GlftFont *GlftFontOpen(const char *name); + +void GlftFontClose(struct GlftFont *font); + +/* rendering */ + #endif diff --git a/glft/init.c b/glft/init.c index 1162172e..bedd16c5 100644 --- a/glft/init.c +++ b/glft/init.c @@ -1,6 +1,8 @@ #include "glft.h" +FcBool init_done = 0; + FcBool GlftInit() { - return FcInit(); + return init_done = FcInit(); } diff --git a/glft/init.h b/glft/init.h new file mode 100644 index 00000000..43fcb226 --- /dev/null +++ b/glft/init.h @@ -0,0 +1,6 @@ +#ifndef __glft_init_h +#define __glft_init_h + +extern FcBool init_done; + +#endif diff --git a/glft/test.c b/glft/test.c index 9cf0c887..8b350104 100644 --- a/glft/test.c +++ b/glft/test.c @@ -1,6 +1,19 @@ #include "glft.h" +#include -int main() +int main(int argc, char **argv) { - GlftInit(); + struct GlftFont *font; + + if (argc < 2) { + printf("Usage: %s fontname\n", argv[0]); + return 1; + } + + if (!GlftInit()) return 1; + + font = GlftFontOpen(argv[1]); + GlftFontClose(font); + + return 0; } -- 2.34.1