From 88beb484c59a5839638adc962de7c57118fba89b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 15 Feb 2004 22:19:43 +0000 Subject: [project @ 2004-02-15 22:19:43 by jmb] Font support in draw export. svn path=/import/netsurf/; revision=549 --- riscos/font.c | 31 +++++++++++++++++++++++++++++ riscos/save_draw.c | 58 +++++++++++++++++++++++++++++++++++++----------------- riscos/save_draw.h | 4 ++-- 3 files changed, 73 insertions(+), 20 deletions(-) (limited to 'riscos') diff --git a/riscos/font.c b/riscos/font.c index 46234031f..0fea4b542 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -118,6 +118,36 @@ struct font_set *font_new_set() return set; } +/** + * Font enumerator + * + * Call this multiple times to enumerate all available font names. + * *handle should be zero (0) on first call. + * + * Returns a NULL pointer and a handle of -1 if there are no more fonts. + */ +const char *enumerate_fonts(struct font_set* set, int *handle) +{ + int i; + + assert(set); + + if (*handle < 0 || handle == 0) { /* a bit of sanity checking */ + *handle = -1; + return NULL; + } + + for (i = *handle; i!=FONT_FAMILIES*FONT_FACES && set->font[i]==0; + i++) ; /* find next font in use */ + + if (i == FONT_FAMILIES*FONT_FACES) { /* no more fonts */ + *handle = -1; + return NULL; + } + + *handle = i+1; /* update handle for next call */ + return font_table[i]; +} /** * Open a font for use based on a css_style. @@ -217,6 +247,7 @@ struct font_data *font_open(struct font_set *set, struct css_style *style) } } + data->id = f; data->handle = handle; data->size = size; data->space_width = font_width(data, " ", 1); diff --git a/riscos/save_draw.c b/riscos/save_draw.c index c6df48093..836b87a75 100644 --- a/riscos/save_draw.c +++ b/riscos/save_draw.c @@ -23,8 +23,7 @@ #include "netsurf/utils/utils.h" /** - * \todo fix fonts (see below) - * fix jpegs + * \todo fix jpegs * GUI */ @@ -36,7 +35,7 @@ static unsigned long length; static drawfile_diagram *d; -static void add_font_table(void); +static void add_font_table(struct content *content); static void add_options(void); static void add_objects(struct content *content, struct box *box, unsigned long cbc, long x, long y); @@ -75,7 +74,7 @@ void save_as_draw(struct content *c) { d->bbox.x1 = A4PAGEWIDTH*512; d->bbox.y1 = A4PAGEHEIGHT*512; - add_font_table(); + add_font_table(c); add_options(); @@ -99,29 +98,52 @@ void save_as_draw(struct content *c) { * add font table * \todo add all fonts required. for now we just use Homerton Medium */ -void add_font_table() { +void add_font_table(struct content *content) { - drawfile_object *dro = xcalloc(8+28, sizeof(char)); - drawfile_font_table *ft = xcalloc(28, sizeof(char)); - drawfile_FONT_DEF(40) fd[] = { - { 1, "Homerton.Medium\\ELatin1" }, - /*{ 2, "Homerton.Medium.Oblique\\ELatin1" }, - { 3, "Homerton.Bold\\ELatin1" }, - { 4, "Homerton.Bold.Oblique\\ELatin1" },*/ - }; + drawfile_object *dro; + drawfile_font_table *ft = xcalloc(0, sizeof(char)); + drawfile_font_def *fd = xcalloc(0, sizeof(char)); + int handle = 0, ftlen=0; + const char *name; + + do { + name = enumerate_fonts(content->data.html.fonts, &handle); + + if (handle == -1 && name == 0) + break; + + /* at this point, handle is always (font_table entry + 1) */ + fd = xrealloc(fd, 1+strlen(name)+1); + memset(fd, 0, 1+strlen(name)+1); + fd->font_index = handle; + memcpy((char*)&fd->font_name, name, strlen(name)); + + ft = xrealloc(ft, ftlen+1+strlen(name)+1); + memcpy((char*)ft+ftlen, fd, 1+strlen(name)+1); + + ftlen += 1+strlen(name)+1; + + } while (handle != -1); + + /* word align end of list */ + if (((ftlen+3)/4*4) != 0) { + ft = xrealloc(ft, (unsigned)(ftlen+3)/4*4); + ftlen = (ftlen+3)/4*4; + } - memcpy(ft->font_def, (char*)&fd, 28); + dro = xcalloc((unsigned)8+ftlen, sizeof(char)); dro->type = drawfile_TYPE_FONT_TABLE; - dro->size = 8+28; - memcpy((char*)&dro->data.font_table, ft, 28); + dro->size = 8+ftlen; + memcpy((char*)&dro->data.font_table, ft, (unsigned)ftlen); d = xrealloc(d, (unsigned)length+dro->size); memcpy((char*)&d->objects, dro, (unsigned)dro->size); - length += 8+28; + length += 8+ftlen; + xfree(fd); xfree(ft); xfree(dro); } @@ -242,7 +264,7 @@ void add_objects(struct content *content, struct box *box, dt->bbox.y1 = y; dt->fill = box->style->color<<8; dt->bg_hint = cbc<<8; - dt->style.font_index = 1; + dt->style.font_index = box->font->id+1; dt->xsize = box->font->size*40; dt->ysize = box->font->size*40; dt->base.x = x; diff --git a/riscos/save_draw.h b/riscos/save_draw.h index ca58e924d..934537aa9 100644 --- a/riscos/save_draw.h +++ b/riscos/save_draw.h @@ -2,13 +2,13 @@ * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 John M Bell + * Copyright 2004 John M Bell */ #ifndef _NETSURF_RISCOS_SAVE_DRAW_H_ #define _NETSURF_RISCOS_SAVE_DRAW_H_ -#include "netsurf/content/content.h" +struct content; void save_as_draw(struct content *c); -- cgit v1.2.3