From 67a3ecc79823e9cc880323f02b002b77bec16d09 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 29 Jun 2012 22:52:25 -0300 Subject: [PATCH] tools/libtxt/: add rendering of (compiled) edits (untested, WIP) --- tools/libtxt/Makefile | 2 +- tools/libtxt/font.c | 13 +++++++++++++ tools/libtxt/libtxt.h | 10 +++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/libtxt/Makefile b/tools/libtxt/Makefile index 5ba6346..750a09a 100644 --- a/tools/libtxt/Makefile +++ b/tools/libtxt/Makefile @@ -15,7 +15,7 @@ MAIN = libtxt.a CFLAGS = -g -Wall -OBJS = font.o +OBJS = edit.o font.o .PHONY: all clean spotless diff --git a/tools/libtxt/font.c b/tools/libtxt/font.c index 6b43e41..bb8b114 100644 --- a/tools/libtxt/font.c +++ b/tools/libtxt/font.c @@ -277,6 +277,19 @@ int draw_char(void *canvas, int width, int height, } +int char_height(const struct font *font, char c) +{ + const char *cp; + const struct sym *sym; + + cp = strchr(charset, c); + if (!cp) + return 0; + sym = font->sym+(cp-charset); + return sym->h; +} + + /* ----- Testing ----------------------------------------------------------- */ diff --git a/tools/libtxt/libtxt.h b/tools/libtxt/libtxt.h index 0dc54c5..00ce1ed 100644 --- a/tools/libtxt/libtxt.h +++ b/tools/libtxt/libtxt.h @@ -13,15 +13,20 @@ #ifndef LIBTXT_H #define LIBTXT_H +struct image; + +struct font; struct edit { enum edit_type { edit_string, edit_font, + edit_spc, edit_xoff, edit_xpos, edit_yoff, edit_ypos, + edit_nl, } type; union { const char *s; @@ -35,6 +40,7 @@ struct edit { * * * + * * * ... * @@ -52,10 +58,12 @@ void free_font(struct font *font); int draw_char(void *canvas, int width, int height, const struct font *font, char c, int x, int y); +int char_height(const struct font *font, char c); struct edit *text2edit(const char *s); char *edit2text(const struct edit *e); -void *apply_edits(int width, int height, const struct edit *e); +void *apply_edits(int width, int height, const struct edit *e, + const char **error); #endif /* !LIBTXT_H */