can open/close fonts now
authorDana Jansens <danakj@orodu.net>
Wed, 28 May 2003 16:47:22 +0000 (16:47 +0000)
committerDana Jansens <danakj@orodu.net>
Wed, 28 May 2003 16:47:22 +0000 (16:47 +0000)
glft/.cvsignore
glft/Makefile.am
glft/debug.c [new file with mode: 0644]
glft/debug.h [new file with mode: 0644]
glft/font.c [new file with mode: 0644]
glft/font.h [new file with mode: 0644]
glft/glft.h
glft/init.c
glft/init.h [new file with mode: 0644]
glft/test.c

index 9b06cfc47f6ec935fe7143ce070f59311cef58a8..fc1eb28d4bb3232f32aa3cf7576b77c7572b16bb 100644 (file)
@@ -5,3 +5,5 @@ Makefile
 libglft.la
 init.lo
 glfttest
+debug.lo
+font.lo
index 16206dd330f5fcf86925b1740dbaa95576dc7f7b..e106496dc9476e97b91afaeb081760c10a5ec361 100644 (file)
@@ -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 (file)
index 0000000..d93603d
--- /dev/null
@@ -0,0 +1,11 @@
+#include <stdio.h>
+#include <stdarg.h>
+
+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 (file)
index 0000000..a1afe8e
--- /dev/null
@@ -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 (file)
index 0000000..53c8d7c
--- /dev/null
@@ -0,0 +1,46 @@
+#include "font.h"
+#include "glft.h"
+#include "init.h"
+#include "debug.h"
+#include <assert.h>
+#include <stdlib.h>
+
+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 (file)
index 0000000..2eab714
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __glft_font_h
+#define __glft_font_h
+
+#include <fontconfig/fontconfig.h>
+
+struct GlftFont {
+    FcFontSet *set;
+
+    /* extended font attributes */
+    FcBool shadow;
+    int shadow_offset;
+    float shadow_alpha;
+};
+
+#endif
index 2dd1377a782a71eaffd0d9132ba59f7768345467..b8e4bccf92c18523df974de1a9c175e25bd9b58f 100644 (file)
@@ -3,8 +3,18 @@
 
 #include <fontconfig/fontconfig.h>
 
-struct GlftFont;
+/* initialization */
 
 FcBool GlftInit();
 
+/* fonts */
+
+struct GlftFont;
+
+struct GlftFont *GlftFontOpen(const char *name);
+
+void GlftFontClose(struct GlftFont *font);
+
+/* rendering */
+
 #endif
index 1162172e4817aa09939cc9c46326b432fbe24181..bedd16c546d48e5058c6bb95a81f186ec34933e4 100644 (file)
@@ -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 (file)
index 0000000..43fcb22
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __glft_init_h
+#define __glft_init_h
+
+extern FcBool init_done;
+
+#endif
index 9cf0c8870bbb70b9a753e1c36a4ffb1863e876c7..8b350104453f72cc24c7b605007a3a3eed4e79ab 100644 (file)
@@ -1,6 +1,19 @@
 #include "glft.h"
+#include <stdio.h>
 
-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;
 }