if (!g_file_exist(filename))
{
LOG(LOG_LEVEL_ERROR, "Can't find font file %s", filename);
} else
{ int file_size = g_file_get_size(filename); if (file_size < FV1_MIN_FILE_SIZE || file_size > FV1_MAX_FILE_SIZE)
{
LOG(LOG_LEVEL_ERROR, "Font file %s has bad size %d",
filename, file_size);
} else
{ struct stream *s; int fd;
make_stream(s);
init_stream(s, file_size + 1024);
fd = g_file_open_ro(filename);
if (fd < 0)
{
LOG(LOG_LEVEL_ERROR, "Can't open font file %s", filename);
} else
{ int b = g_file_read(fd, s->data, file_size + 1024);
g_file_close(fd);
/*****************************************************************************/ int
write_stream(int fd, struct stream *s)
{ constchar *p = s->data; int rv = 1;
while (p < s->end)
{ int len = g_file_write(fd, p, s->end - p); if (len <= 0)
{
rv = 0; break;
}
p += len;
}
return rv;
}
/*****************************************************************************/ int
fv1_file_save(conststruct fv1_file *fv1, constchar *filename)
{ int fd; struct fv1_glyph *blank_glyph; /* Needed for bad characters */
fd = g_file_open_ex(filename, 0, 1, 1, 1); int rv = 1; if (fd < 0)
{
LOG(LOG_LEVEL_ERROR, "Unable to open %s for writing [%s]", filename,
g_get_strerror());
} else
{ struct stream *s;
make_stream(s);
init_stream(s, 1024);
/* Write the header */
out_uint8a(s, FV1_SIGNATURE, sizeof(FV1_SIGNATURE)); int len = g_strlen(fv1->font_name); if (len > FV1_MAX_FONT_NAME_SIZE)
{
len = FV1_MAX_FONT_NAME_SIZE;
}
out_uint8a(s, fv1->font_name, len); while (len++ < FV1_MAX_FONT_NAME_SIZE)
{
out_uint8(s, '\0');
}
out_uint16_le(s, fv1->point_size);
out_uint16_le(s, fv1->style);
out_uint16_le(s, fv1->body_height);
out_uint16_le(s, fv1->min_descender);
out_uint8a(s, "\0\0\0\0", 4);
s_mark_end(s); if (!write_stream(fd, s))
{
LOG(LOG_LEVEL_ERROR, "Unable to write file header [%s]",
g_get_strerror());
} elseif ((blank_glyph = fv1_alloc_glyph(-1, 0, 0)) == NULL)
{
LOG(LOG_LEVEL_ERROR, "Unable to allocate blank glyph");
} else
{ int u;
for (u = FV1_MIN_CHAR; u < FV1_GLYPH_END(fv1); ++u)
{ conststruct fv1_glyph *g = FV1_GET_GLYPH(fv1, u); int datasize; if (g == NULL)
{
LOG(LOG_LEVEL_WARNING, "Glyph %d is not set", u);
g = blank_glyph;
} else
{
datasize = FONT_DATASIZE(g); if (datasize > FV1_MAX_GLYPH_DATASIZE)
{
LOG(LOG_LEVEL_WARNING, "glyph %d datasize %d exceeds max of %d" " - glyph will be blank",
u, datasize, FV1_MAX_GLYPH_DATASIZE);
g = blank_glyph;
}
}
init_stream(s, 16 + FONT_DATASIZE(g));
out_uint16_le(s, g->width);
out_uint16_le(s, g->height);
out_uint16_le(s, g->baseline);
out_uint16_le(s, g->offset);
out_uint16_le(s, g->inc_by);
out_uint8a(s, "\0\0\0\0\0\0", 6);
out_uint8a(s, g->data, FONT_DATASIZE(g));
s_mark_end(s);
if (!write_stream(fd, s))
{
LOG(LOG_LEVEL_ERROR, "Unable to write glyph %d [%s]",
u, g_get_strerror()); break;
}
}
g_free(blank_glyph);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.