61 Load_Font_Image( filename);
62 Name = strdup( filename);
98 float current_width = sd.
Width;
99 float current_height = sd.
Height;
104 if (current_width < 256) {
110 int new_height = new_width;
117 new_surface->
Clear();
124 for (
int char_index = 0; char_index < 256; char_index++) {
128 int src_x = (int)(UOffsetTable[ char_index ] * current_width + 0.5);
129 int src_y = (int)(VOffsetTable[ char_index ] * current_height + 0.5);
130 int width = (int)(UWidthTable[ char_index ] * current_width + 0.5);
131 int height = (int)(VHeight * current_height + 0.5);
137 if (new_x + width > new_width) {
143 if (new_y + height > new_height) {
145 WWDEBUG_SAY((
"Font doesn't fit texture 2 on char %c\n", char_index ));
151 new_surface->
Copy(new_x, new_y,src_x,src_y,width,height,surface);
156 UOffsetTable[ char_index ] = (float)(new_x) / (float)new_width;
157 VOffsetTable[ char_index ] = (float)(new_y) / (float)new_width;
160 UWidthTable[ char_index ] *= (float)current_width / (
float)new_width;
166 VHeight *= (float)current_height / (
float)new_height;
174 _surface = new_surface;
193 SurfaceClass::SurfaceDescription sd;
195 float width = sd.
Width;
199 for (
int char_index = 0; char_index < 256; char_index++) {
203 int x0 = (int)(UOffsetTable[ char_index ] * width + 0.5);
204 int y0 = (int)(VOffsetTable[ char_index ] * height + 0.5);
205 int x1 = x0 + (int)(UWidthTable[ char_index ] * width + 0.5);
206 int y1 = y0 + (int)(VHeight * height + 0.5);
209 Vector2i minb(x0,y0);
210 Vector2i maxb(x1,y1);
212 surface->
FindBB(&minb,&maxb);
224 if (char_index > 0x80) {
229 UOffsetTable[ char_index ] = (float)x0 / width;
230 UWidthTable[ char_index ] = (float)( x1 - x0 ) / width;
231 CharWidthTable[ char_index ] = x1 - x0;
236 Minimize_Font_Image( _surface );
249bool Font3DDataClass::Load_Font_Image(
const char *filename )
252 SurfaceClass *surface =
NEW_REF(SurfaceClass,(filename));
255 SurfaceClass::SurfaceDescription sd;
266 int width = sd.
Width;
271 for (
int char_index = 0; char_index < 256; char_index++) {
273 if ( char_index >= 0x7F ) {
275 UOffsetTable[ char_index ] = 0;
276 VOffsetTable[ char_index ] = 0;
277 UWidthTable[ char_index ] = 0;
278 CharWidthTable[ char_index ] = 0;
290 if ( end <= start ) {
291 WWDEBUG_SAY((
"Error Char %d start %d end %d width %d\n", char_index, start, end, width ));
296 UOffsetTable[ char_index ] = (float)start / width;
297 VOffsetTable[ char_index ] = 0;
298 UWidthTable[ char_index ] = (float)(end - start) / width;
299 CharWidthTable[ char_index ] = end - start;
308 Minimize_Font_Image( _surface );
314 float font_width = sd.
Width;
315 float font_height = sd.
Height;
316 float mono_pixel_width = (font_width / 16);
317 float mono_pixel_height = (font_height / 16);
321 for (
int char_index = 0; char_index < 256; char_index++) {
322 UOffsetTable[ char_index ] = (float)((char_index % 16) * mono_pixel_width) / font_width;
323 VOffsetTable[ char_index ] = (float)((char_index / 16) * mono_pixel_height) / font_height;
324 UWidthTable[ char_index ] = mono_pixel_width / font_width;
325 CharWidthTable[ char_index ] = mono_pixel_width;
327 VHeight = mono_pixel_height / font_height;
328 CharHeight = mono_pixel_height;
334 Make_Proportional( _surface );
360 SpaceSpacing = (int)(FontData->Char_Width(
'H') / 2.0f);
361 InterCharSpacing = 1;
362 Build_Cached_Tables();
380 MonoSpacing = FontData->Char_Width(
'W') + 1;
381 Build_Cached_Tables();
384void Font3DInstanceClass::Build_Cached_Tables()
387 for (
int a=0;a<256;++a) {
390 width = SpaceSpacing;
393 ScaledWidthTable[a] = Scale * width;
394 if (MonoSpacing != 0.0f) {
395 ScaledSpacingTable[a] = Scale * MonoSpacing;
397 ScaledSpacingTable[a] = Scale * (width + InterCharSpacing);
400 ScaledHeight = floorf(Scale * (
float)FontData->Char_Height(
'A'));
413 for (; *test_str; test_str++) {
423 for (; *test_str; test_str++) {
unsigned char Char_Width(WCHAR ch=(WCHAR) 'H')
Font3DDataClass(const char *filename)
float Char_Spacing(WCHAR ch) const
Font3DInstanceClass(const char *filename)
void Set_Mono_Spaced(void)
float String_Width(const WCHAR *test_str)
void Get_Description(SurfaceDescription &surface_desc)
void Copy(unsigned int dstx, unsigned int dsty, unsigned int srcx, unsigned int srcy, unsigned int width, unsigned int height, const SurfaceClass *other)
bool Is_Transparent_Column(unsigned int column)
void FindBB(Vector2i *min, Vector2i *max)
virtual Font3DDataClass * Get_Font3DData(const char *name)
static WW3DAssetManager * Get_Instance(void)
#define REF_PTR_RELEASE(x)