[project @ 2004-02-15 22:19:43 by jmb]

Font support in draw export.

svn path=/import/netsurf/; revision=549
This commit is contained in:
John Mark Bell 2004-02-15 22:19:43 +00:00
parent 2f0c135aed
commit 88beb484c5
4 changed files with 75 additions and 20 deletions

View File

@ -12,6 +12,7 @@
#include "netsurf/css/css.h"
struct font_data {
int id;
int handle;
unsigned int size;
unsigned int space_width;
@ -26,5 +27,6 @@ void font_position_in_string(const char* text, struct font_data *font,
unsigned int length, unsigned long x, int* char_offset, int* pixel_offset);
char * font_split(struct font_data *data, const char * text, unsigned int length,
unsigned int width, unsigned int *used_width);
const char *enumerate_fonts(struct font_set *set, int *handle);
#endif

View File

@ -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);

View File

@ -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;
memcpy(ft->font_def, (char*)&fd, 28);
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;
}
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;

View File

@ -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 <jmb202@ecs.soton.ac.uk>
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
*/
#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);