Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / graphics / extendfont.c
blobf97ba42a98a8c551fa2fe156e5462f57e07e11df
1 /*
2 Copyright © 1995-2007, 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 build the TextFontExtension from if it doesn't exist.
40 If a NULL pointer is given, ExtendFont will allocate 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 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
64 struct TagItem def_tags = { TAG_DONE, 0};
65 struct tfe_hashnode *hn;
66 struct TextFontExtension *tfe;
67 BOOL new_hashnode = FALSE;
69 if (font == NULL)
70 return FALSE;
72 ObtainSemaphore(&PrivGBase(GfxBase)->fontsem);
74 /* Does the font allready have an extension ? */
75 hn = tfe_hashlookup(font, GfxBase);
76 if (NULL == hn)
78 hn = tfe_hashnode_create(GfxBase);
79 if (NULL == hn)
81 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
83 return FALSE;
85 new_hashnode = TRUE;
88 tfe = hn->ext;
89 if (NULL != tfe)
91 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
93 return TRUE;
97 /* Try to build an extension */
98 if (!fontTags)
99 fontTags = &def_tags;
101 if ((tfe = AllocMem(sizeof (struct TextFontExtension_intern), MEMF_ANY|MEMF_CLEAR)) != NULL)
103 /* Back pointer from tfe to hash */
105 ((struct TextFontExtension_intern *)tfe)->hash = hn;
107 /* We make a copy of the tagitems */
108 if ((tfe->tfe_Tags = CloneTagItems(fontTags)) != NULL)
111 tfe->tfe_MatchWord = TFE_MATCHWORD;
112 tfe->tfe_BackPtr = font;
113 tfe->tfe_OrigReplyPort = font->tf_Message.mn_ReplyPort;
115 if (!hn->font_bitmap)
117 hn->font_bitmap = fontbm_to_hiddbm(font, GfxBase);
120 if (hn->font_bitmap)
122 BOOL ok = TRUE;
124 if ((font->tf_Style & FSF_COLORFONT) &&
125 ((CTF(font)->ctf_Flags & CT_COLORMASK) != CT_ANTIALIAS))
127 /* Real colorfont */
129 if (!(hn->chunky_colorfont = colorfontbm_to_chunkybuffer(font, GfxBase)))
131 ok = FALSE;
135 if (ok)
137 if (new_hashnode)
139 tfe_hashadd(hn, font, tfe, GfxBase);
141 else
143 hn->ext = tfe;
146 font->tf_Extension = (void *)tfe;
147 font->tf_Style |= FSF_TAGGED;
149 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
151 return TRUE;
153 } /* if (ok) */
155 OOP_DisposeObject(hn->font_bitmap);
157 } /* if (hn->font_bitmap) */
160 FreeTagItems(tfe->tfe_Tags);
163 FreeMem(tfe, sizeof (struct TextFontExtension_intern));
165 } /* if (memory for extension allocated) */
167 ReleaseSemaphore(&PrivGBase(GfxBase)->fontsem);
169 return FALSE;
171 AROS_LIBFUNC_EXIT
172 } /* ExtendFont */