Skip to content
Snippets Groups Projects
Commit 0e756f50 authored by Mirar (Pontus Hagland)'s avatar Mirar (Pontus Hagland)
Browse files

added default font

Rev: src/modules/Image/Makefile.in:1.24
Rev: src/modules/Image/font.c:1.49
Rev: src/modules/Image/module_testsuite.in:1.8
Rev: src/modules/Image/testsuite.in.in:1.16
parent bc19edfc
Branches
Tags
No related merge requests found
# $Id: Makefile.in,v 1.23 1999/05/23 17:46:37 mirar Exp $
# $Id: Makefile.in,v 1.24 1999/05/24 14:33:09 mirar Exp $
SRCDIR=@srcdir@
VPATH=@srcdir@:@srcdir@/../..:../..
OBJS = image_module.o \
image.o font.o togif.o matrix.o pnm_compat.o blit.o \
pattern.o dct.o operator.o x.o colortable.o polyfill.o \
orient.o colors.o search.o layers.o
orient.o colors.o search.o layers.o default_font.o
MODNAME=image
MODULE_SUBDIRS=encodings
MODULE_ARCHIVES=encodings/encodings.a
......
/* $Id: font.c,v 1.48 1999/05/23 17:46:40 mirar Exp $ */
/* $Id: font.c,v 1.49 1999/05/24 14:33:10 mirar Exp $ */
#include "global.h"
#include <config.h>
#define SPACE_CHAR 'i'
extern unsigned char * image_default_font;
#define IMAGE_DEFAULT_FONT_SIZE 30596
/*
**! module Image
**! note
**! $Id: font.c,v 1.48 1999/05/23 17:46:40 mirar Exp $
**! $Id: font.c,v 1.49 1999/05/24 14:33:10 mirar Exp $
**! class Font
**!
**! note
......@@ -219,7 +222,7 @@ static INLINE void free_font_struct(struct font *font)
{
if (font)
{
if (font->mem)
if (font->mem && font->mem!=image_default_font)
{
#ifdef HAVE_MMAP
munmap(font->mem,font->mmaped_size);
......@@ -334,27 +337,33 @@ static INLINE void write_char(struct _char *ci,
void font_load(INT32 args);
void font_create(INT32 args)
{
if (args)
{
font_load(args);
pop_stack();
}
}
void font_load(INT32 args)
{
int fd;
if (args<1
|| sp[-args].type!=T_STRING)
error("font->read: illegal or wrong number of arguments\n");
size_t size;
if (THIS)
{
free_font_struct(THIS);
THIS=NULL;
}
if (!args)
{
THIS=(struct font *)xalloc(sizeof(struct font));
THIS->mem=image_default_font;
size=IMAGE_DEFAULT_FONT_SIZE;
goto loading_default;
}
if (sp[-args].type!=T_STRING)
error("font->read: illegal or wrong number of arguments\n");
do
{
#ifdef FONT_DEBUG
......@@ -365,7 +374,6 @@ void font_load(INT32 args)
if (fd >= 0)
{
size_t size;
struct font *new_font;
size = (size_t) file_size(fd);
......@@ -391,6 +399,8 @@ void font_load(INT32 args)
#endif
THREADS_DISALLOW();
loading_default:
if (THIS->mem)
{
struct file_head
......@@ -473,6 +483,8 @@ void font_load(INT32 args)
}
if (!args) goto done;
fd_close(fd);
pop_n_elems(args);
ref_push_object(THISOBJ); /* success */
......@@ -488,6 +500,7 @@ void font_load(INT32 args)
#ifdef FONT_DEBUG
else fprintf(stderr,"FONT wrong cookie\n");
#endif
if (!args) goto done; /* just in case */
} /* mem failure */
#ifdef FONT_DEBUG
else fprintf(stderr,"FONT mem failure\n");
......@@ -504,6 +517,8 @@ void font_load(INT32 args)
else fprintf(stderr,"FONT fd failure\n");
#endif
done:
pop_n_elems(args);
push_int(0);
return;
......@@ -888,7 +903,7 @@ void init_image_font(void)
ADD_FUNCTION("create",font_create,tFunc(tOr(tVoid,tStr),tVoid),0);
/* function(string:object) */
ADD_FUNCTION("write",font_write,tFunc(tStr,tObj),0);
ADD_FUNCTION("write",font_write,tFuncV(,tStr,tObj),0);
/* function(:int) */
ADD_FUNCTION("height",font_height,tFunc(,tInt),0);
......
This diff is collapsed.
......@@ -246,10 +246,30 @@
if (!equal(img->max(),({255,254,253}))) fail("wrong maxcolor");
ok();
//-----------------------------------------------------
#chapter Image.Font
#test instansiating default font
if (!objectp(Image.Font())) fail("not object");
ok();
#test writing simple text with default font
object f=Image.Font();
object i=f->write("hej");
if (i!=Image.PNM.decode(MIME.decode_base64("UDQKMTkgMTEK///gv/7gv//grzjglt7gth7gtv7gtv7gtx7g//7g//Hg")))
fail("incorrect");
ok();
#test writing multiple lines with default font
object f=Image.Font();
object i=f->write("h","o");
if (i!=Image.PNM.decode(MIME.decode_base64("UDQKNyAyMwr+vr6ulra2trb+/v7+/s62tra2zv7+/g==")))
fail("incorrect");
ok();
//-----------------------------------------------------
#chapter colortable
#chapter Image.Colortable
#test colortable - black/white init & cast
object c=Image.Colortable(({Image.Color.white,Image.Color.black}));
......@@ -660,7 +680,7 @@ if (!(Stinares-expected_result<80))
fail("->match_phase(float f, object needle) differ too much");
/*
This is used to create more tests. Please don't remove!
This is used to create more tests. Please don't remMIME.encode_base64ove!
MIME.encode_base64(Image.JPEG.encode(Stinares));
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment