src/fontcache.cpp
branchcustombridgeheads
changeset 5650 aefc131bf5ce
parent 5649 55c8267c933f
child 5860 7fdc9b423ba1
equal deleted inserted replaced
5649:55c8267c933f 5650:aefc131bf5ce
     9 #include "table/control_codes.h"
     9 #include "table/control_codes.h"
    10 #include "spritecache.h"
    10 #include "spritecache.h"
    11 #include "gfx.h"
    11 #include "gfx.h"
    12 #include "string.h"
    12 #include "string.h"
    13 #include "fontcache.h"
    13 #include "fontcache.h"
       
    14 #include "helpers.hpp"
    14 
    15 
    15 #ifdef WITH_FREETYPE
    16 #ifdef WITH_FREETYPE
    16 
    17 
    17 #include <ft2build.h>
    18 #include <ft2build.h>
    18 #include FT_FREETYPE_H
    19 #include FT_FREETYPE_H
    75 
    76 
    76 	/* For Unicode we need some conversion between widechar and
    77 	/* For Unicode we need some conversion between widechar and
    77 	 * normal char to match the data returned by RegEnumValue,
    78 	 * normal char to match the data returned by RegEnumValue,
    78 	 * otherwise just use parameter */
    79 	 * otherwise just use parameter */
    79 #if defined(UNICODE)
    80 #if defined(UNICODE)
    80 	font_namep = malloc(MAX_PATH * sizeof(TCHAR));
    81 	MallocT(&font_namep, MAX_PATH);
    81 	MB_TO_WIDE_BUFFER(font_name, font_namep, MAX_PATH * sizeof(TCHAR));
    82 	MB_TO_WIDE_BUFFER(font_name, font_namep, MAX_PATH * sizeof(TCHAR));
    82 #else
    83 #else
    83 	font_namep = (char*)font_name; // only cast because in unicode pointer is not const
    84 	font_namep = (char*)font_name; // only cast because in unicode pointer is not const
    84 #endif
    85 #endif
    85 
    86 
   343 
   344 
   344 static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph)
   345 static void SetGlyphPtr(FontSize size, WChar key, const GlyphEntry *glyph)
   345 {
   346 {
   346 	if (_glyph_ptr[size] == NULL) {
   347 	if (_glyph_ptr[size] == NULL) {
   347 		DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size);
   348 		DEBUG(freetype, 3, "Allocating root glyph cache for size %u", size);
   348 		_glyph_ptr[size] = calloc(256, sizeof(**_glyph_ptr));
   349 		CallocT(&_glyph_ptr[size], 256);
   349 	}
   350 	}
   350 
   351 
   351 	if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) {
   352 	if (_glyph_ptr[size][GB(key, 8, 8)] == NULL) {
   352 		DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size);
   353 		DEBUG(freetype, 3, "Allocating glyph cache for range 0x%02X00, size %u", GB(key, 8, 8), size);
   353 		_glyph_ptr[size][GB(key, 8, 8)] = calloc(256, sizeof(***_glyph_ptr));
   354 		CallocT(&_glyph_ptr[size][GB(key, 8, 8)], 256);
   354 	}
   355 	}
   355 
   356 
   356 	DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size);
   357 	DEBUG(freetype, 4, "Set glyph for unicode character 0x%04X, size %u", key, size);
   357 	_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
   358 	_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].sprite = glyph->sprite;
   358 	_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width  = glyph->width;
   359 	_glyph_ptr[size][GB(key, 8, 8)][GB(key, 0, 8)].width  = glyph->width;
   393 	/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */
   394 	/* Add 1 pixel for the shadow on the medium font. Our sprite must be at least 1x1 pixel */
   394 	width  = max(1, slot->bitmap.width + (size == FS_NORMAL));
   395 	width  = max(1, slot->bitmap.width + (size == FS_NORMAL));
   395 	height = max(1, slot->bitmap.rows  + (size == FS_NORMAL));
   396 	height = max(1, slot->bitmap.rows  + (size == FS_NORMAL));
   396 
   397 
   397 	/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
   398 	/* FreeType has rendered the glyph, now we allocate a sprite and copy the image into it */
   398 	sprite = calloc(width * height + 8, 1);
   399 	sprite = (Sprite*)calloc(width * height + 8, 1);
   399 	sprite->info   = 1;
   400 	sprite->info   = 1;
   400 	sprite->width  = width;
   401 	sprite->width  = width;
   401 	sprite->height = height;
   402 	sprite->height = height;
   402 	sprite->x_offs = slot->bitmap_left;
   403 	sprite->x_offs = slot->bitmap_left;
   403 	// XXX 2 should be determined somehow... it's right for the normal face
   404 	// XXX 2 should be determined somehow... it's right for the normal face
   481 }
   482 }
   482 
   483 
   483 
   484 
   484 void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite)
   485 void SetUnicodeGlyph(FontSize size, uint32 key, SpriteID sprite)
   485 {
   486 {
   486 	if (_unicode_glyph_map[size] == NULL) _unicode_glyph_map[size] = calloc(256, sizeof(*_unicode_glyph_map[size]));
   487 	if (_unicode_glyph_map[size] == NULL) CallocT(&_unicode_glyph_map[size], 256);
   487 	if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) _unicode_glyph_map[size][GB(key, 8, 8)] = calloc(256, sizeof(**_unicode_glyph_map[size]));
   488 	if (_unicode_glyph_map[size][GB(key, 8, 8)] == NULL) CallocT(&_unicode_glyph_map[size][GB(key, 8, 8)], 256);
   488 	_unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite;
   489 	_unicode_glyph_map[size][GB(key, 8, 8)][GB(key, 0, 8)] = sprite;
   489 }
   490 }
   490 
   491 
   491 
   492 
   492 void InitializeUnicodeGlyphMap(void)
   493 void InitializeUnicodeGlyphMap(void)