2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 Desc: Misc font help funcs
9 #include <proto/exec.h>
10 #include <proto/oop.h>
11 #include <proto/graphics.h>
13 #include <exec/memory.h>
14 #include <graphics/text.h>
16 #include "graphics_intern.h"
17 #include "gfxfuncsupport.h"
18 #include "fontsupport.h"
20 /****************************************************************************************/
22 ULONG
CalcHashIndex(IPTR n
, UWORD hashsize
)
24 UBYTE Index
= (n
& 0xff)
36 Index
&= (hashsize
- 1);
40 /****************************************************************************************/
42 /* Functions for solving the TextFontExtension problem using hashes */
44 #define GFBI(x) ((struct GfxBase_intern *)x)
46 /****************************************************************************************/
48 struct tfe_hashnode
*tfe_hashlookup(struct TextFont
*tf
, struct GfxBase
*GfxBase
)
51 ULONG idx
= CalcHashIndex((IPTR
)tf
, TFE_HASHTABSIZE
);
52 struct tfe_hashnode
*n
= NULL
;
55 ObtainSemaphoreShared( &GFBI(GfxBase
)->tfe_hashtab_sema
);
57 for ( n
= GFBI(GfxBase
)->tfe_hashtab
[idx
]; n
; n
= n
->next
)
65 ReleaseSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
70 /****************************************************************************************/
72 struct tfe_hashnode
*tfe_hashnode_create(struct GfxBase
*GfxBase
)
74 struct tfe_hashnode
*n
;
76 n
= AllocMem( sizeof (struct tfe_hashnode
), MEMF_ANY
|MEMF_CLEAR
);
81 /****************************************************************************************/
83 void tfe_hashadd(struct tfe_hashnode
*hn
85 , struct TextFontExtension
*etf
86 , struct GfxBase
*GfxBase
)
89 ULONG idx
= CalcHashIndex((IPTR
)tf
, TFE_HASHTABSIZE
);
94 ObtainSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
96 hn
->next
= GFBI(GfxBase
)->tfe_hashtab
[idx
];
97 GFBI(GfxBase
)->tfe_hashtab
[idx
] = hn
;
99 ReleaseSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
104 /****************************************************************************************/
106 void tfe_hashdelete(struct TextFont
*tf
, struct GfxBase
*GfxBase
)
108 ULONG idx
= CalcHashIndex((IPTR
)tf
, TFE_HASHTABSIZE
);
109 struct tfe_hashnode
*n
, *last
= NULL
;
111 ObtainSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
113 for (n
= GFBI(GfxBase
)->tfe_hashtab
[idx
]; n
; n
= n
->next
)
118 last
->next
= n
->next
;
120 GFBI(GfxBase
)->tfe_hashtab
[idx
] = n
->next
;
122 FreeMem(n
, sizeof (struct tfe_hashnode
));
128 ReleaseSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
134 /****************************************************************************************/
136 UBYTE
*colorfontbm_to_chunkybuffer(struct TextFont
*font
, struct GfxBase
*GfxBase
)
141 width
= font
->tf_Modulo
* 8;
142 height
= font
->tf_YSize
;
144 chunky
= AllocVec(width
* height
, MEMF_CLEAR
);
149 UBYTE d
, shift
= 1, plane
= 0;
151 InitBitMap(&bm
, CTF(font
)->ctf_Depth
, width
, height
);
153 for(d
= 0; d
< CTF(font
)->ctf_Depth
; d
++, shift
<<= 1)
155 if (CTF(font
)->ctf_PlanePick
& shift
)
157 bm
.Planes
[d
] = (PLANEPTR
)(CTF(font
)->ctf_CharData
[plane
++]);
161 bm
.Planes
[d
] = (CTF(font
)->ctf_PlaneOnOff
& shift
) ? (PLANEPTR
)-1 : NULL
;
168 ReadPixelArray8(&rp
, 0, 0, width
- 1, height
- 1, chunky
, NULL
);
174 /****************************************************************************************/