New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / graphics / extendfont.c
blob517b2b1dc2883330be168e61cefdf9a3f3cadd9c
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function ExtendFont()
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include <proto/utility.h>
10 #include <proto/oop.h>
11 #include <exec/memory.h>
12 #include "graphics_intern.h"
13 #include "fontsupport.h"
15 #include <sys/types.h>
18 /*****************************************************************************
20 NAME */
21 #include <clib/graphics_protos.h>
23 AROS_LH2(ULONG, ExtendFont,
25 /* SYNOPSIS */
26 AROS_LHA(struct TextFont *, font, A0),
27 AROS_LHA(struct TagItem *, fontTags, A1),
29 /* LOCATION */
30 struct GfxBase *, GfxBase, 136, Graphics)
32 /* FUNCTION
33 Checks whether or not a TextFont has a TextFontExtension.
34 If no extension exists, and tags are supplied,
35 then it will try to build one.
37 INPUTS
38 font - font to check for an extension.
39 fontTags - tags to buil the TextFontExtesion from if it doesn't exist.
40 If a NULL pointer is given, ExtendFont will alocate default tags.
41 RESULT
42 success - FALSE if the font has no TextFontExtension and an extension
43 can't be built. TRUE otherwise.
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 ExtendFontTags(), StripFont()
54 INTERNALS
56 HISTORY
57 27-11-96 digulla automatically created from
58 graphics_lib.fd and clib/graphics_protos.h
60 *****************************************************************************/
62 AROS_LIBFUNC_INIT
63 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
65 struct TagItem def_tags = { TAG_DONE, 0};
66 struct tfe_hashnode *hn;
67 struct TextFontExtension *tfe;
68 BOOL new_hashnode = FALSE;
70 if (font == NULL)
71 return FALSE;
73 ObtainSemaphore(&PrivGBase(GfxBase)->fontsem);
75 /* Does the font allready have an extension ? */
76 hn = tfe_hashlookup(font, GfxBase);
77 if (NULL == hn)
79 hn = tfe_hashnode_create(GfxBase);
80 if (NULL == hn)
82 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
84 return FALSE;
86 new_hashnode = TRUE;
89 tfe = hn->ext;
90 if (NULL != tfe)
92 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
94 return TRUE;
98 /* Try to build an extension */
99 if (!fontTags)
100 fontTags = &def_tags;
102 if ((tfe = AllocMem(sizeof (struct TextFontExtension_intern), MEMF_ANY|MEMF_CLEAR)) != NULL)
104 /* Back pointer from tfe to hash */
106 TFE_INTERN(tfe)->hash = hn;
108 /* We make a copy of the tagitems */
109 if ((tfe->tfe_Tags = CloneTagItems(fontTags)) != NULL)
112 tfe->tfe_MatchWord = TFE_MATCHWORD;
113 tfe->tfe_BackPtr = font;
114 tfe->tfe_OrigReplyPort = font->tf_Message.mn_ReplyPort;
116 if (!hn->font_bitmap)
118 hn->font_bitmap = fontbm_to_hiddbm(font, GfxBase);
121 if (hn->font_bitmap)
123 BOOL ok = TRUE;
125 if ((font->tf_Style & FSF_COLORFONT) &&
126 ((CTF(font)->ctf_Flags & CT_COLORMASK) != CT_ANTIALIAS))
128 /* Real colorfont */
130 if (!(hn->chunky_colorfont = colorfontbm_to_chunkybuffer(font, GfxBase)))
132 ok = FALSE;
136 if (ok)
138 if (new_hashnode)
140 tfe_hashadd(hn, font, tfe, GfxBase);
142 else
144 hn->ext = tfe;
147 TFE(font->tf_Extension) = tfe;
148 font->tf_Style |= FSF_TAGGED;
150 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
152 return TRUE;
154 } /* if (ok) */
156 OOP_DisposeObject(hn->font_bitmap);
158 } /* if (hn->font_bitmap) */
161 FreeTagItems(tfe->tfe_Tags);
164 FreeMem(tfe, sizeof (struct TextFontExtension_intern));
166 } /* if (memory for extension allocated) */
168 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
170 return FALSE;
172 AROS_LIBFUNC_EXIT
173 } /* ExtendFont */