2 Copyright © 1995-2001, 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(ULONG n
)
24 UBYTE Index
= (n
& 0xff) +
32 /****************************************************************************************/
34 /* Functions for solving the TextFontExtension problem using hashes */
36 #define GFBI(x) ((struct GfxBase_intern *)x)
38 /****************************************************************************************/
40 static inline ULONG
tfe_calchashidx(APTR ptr
)
42 ULONG val
= (ULONG
)ptr
;
44 ULONG idx
= (val
& 0xff) +
46 ((val
>> 16) & 0xff) +
49 idx
&= (TFE_HASHTABSIZE
- 1);
54 /****************************************************************************************/
56 struct tfe_hashnode
*tfe_hashlookup(struct TextFont
*tf
, struct GfxBase
*GfxBase
)
59 ULONG idx
= tfe_calchashidx(tf
);
60 struct tfe_hashnode
*n
= NULL
;
63 ObtainSemaphoreShared( &GFBI(GfxBase
)->tfe_hashtab_sema
);
65 for ( n
= GFBI(GfxBase
)->tfe_hashtab
[idx
]; n
; n
= n
->next
)
73 ReleaseSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
78 /****************************************************************************************/
80 struct tfe_hashnode
*tfe_hashnode_create(struct GfxBase
*GfxBase
)
82 struct tfe_hashnode
*n
;
84 n
= AllocMem( sizeof (struct tfe_hashnode
), MEMF_ANY
|MEMF_CLEAR
);
89 /****************************************************************************************/
91 void tfe_hashadd(struct tfe_hashnode
*hn
93 , struct TextFontExtension
*etf
94 , struct GfxBase
*GfxBase
)
97 ULONG idx
= tfe_calchashidx(tf
);
102 ObtainSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
104 hn
->next
= GFBI(GfxBase
)->tfe_hashtab
[idx
];
105 GFBI(GfxBase
)->tfe_hashtab
[idx
] = hn
;
107 ReleaseSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
112 /****************************************************************************************/
114 void tfe_hashdelete(struct TextFont
*tf
, struct GfxBase
*GfxBase
)
116 ULONG idx
= tfe_calchashidx(tf
);
117 struct tfe_hashnode
*n
, *last
= NULL
;
119 ObtainSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
121 for (n
= GFBI(GfxBase
)->tfe_hashtab
[idx
]; n
; n
= n
->next
)
126 last
->next
= n
->next
;
128 GFBI(GfxBase
)->tfe_hashtab
[idx
] = n
->next
;
130 FreeMem(n
, sizeof (struct tfe_hashnode
));
136 ReleaseSemaphore( &GFBI(GfxBase
)->tfe_hashtab_sema
);
142 /****************************************************************************************/
144 OOP_Object
*fontbm_to_hiddbm(struct TextFont
*font
, struct GfxBase
*GfxBase
)
150 /* Caclulate sizes for the font bitmap */
151 struct TagItem bm_tags
[] =
153 { aHidd_BitMap_Width
, 0 },
154 { aHidd_BitMap_Height
, 0 },
155 { aHidd_BitMap_StdPixFmt
, vHidd_StdPixFmt_Plane
},
159 tmp_gc
= obtain_cache_object(SDD(GfxBase
)->gc_cache
, GfxBase
);
163 width
= font
->tf_Modulo
* 8;
164 height
= font
->tf_YSize
;
166 bm_tags
[0].ti_Data
= width
;
167 bm_tags
[1].ti_Data
= height
;
169 #warning Handle color textfonts
171 bm_obj
= HIDD_Gfx_NewBitMap(SDD(GfxBase
)->gfxhidd
, bm_tags
);
174 struct TagItem gc_tags
[] =
176 { aHidd_GC_DrawMode
, vHidd_GC_DrawMode_Copy
},
177 { aHidd_GC_Foreground
, 1 },
178 { aHidd_GC_Background
, 0 },
179 { aHidd_GC_ColorExpansionMode
, vHidd_GC_ColExp_Opaque
},
183 /* Copy the character data into the bitmap */
184 OOP_SetAttrs(tmp_gc
, gc_tags
);
186 HIDD_BM_PutTemplate(bm_obj
, tmp_gc
, font
->tf_CharData
, font
->tf_Modulo
,
187 0, 0, 0, width
, height
, FALSE
);
191 release_cache_object(SDD(GfxBase
)->gc_cache
, tmp_gc
, GfxBase
);
196 /****************************************************************************************/
198 UBYTE
*colorfontbm_to_chunkybuffer(struct TextFont
*font
, struct GfxBase
*GfxBase
)
203 width
= font
->tf_Modulo
* 8;
204 height
= font
->tf_YSize
;
206 chunky
= AllocVec(width
* height
, MEMF_CLEAR
);
211 UBYTE d
, shift
= 1, plane
= 0;
213 InitBitMap(&bm
, CTF(font
)->ctf_Depth
, width
, height
);
215 for(d
= 0; d
< CTF(font
)->ctf_Depth
; d
++, shift
<<= 1)
217 if (CTF(font
)->ctf_PlanePick
& shift
)
219 bm
.Planes
[d
] = (PLANEPTR
)(CTF(font
)->ctf_CharData
[plane
++]);
223 bm
.Planes
[d
] = (CTF(font
)->ctf_PlaneOnOff
& shift
) ? (PLANEPTR
)-1 : NULL
;
230 ReadPixelArray8(&rp
, 0, 0, width
- 1, height
- 1, chunky
, NULL
);
237 /****************************************************************************************/