static bool font_renderer_create_atlas(ft_font_renderer_t *handle, float font_size) { unsigned i, x, y; freetype_atlas_slot_t* slot = NULL; unsigned max_width = round((handle->face->bbox.xMax - handle->face->bbox.xMin) * font_size / handle->face->units_per_EM); unsigned max_height = round((handle->face->bbox.yMax - handle->face->bbox.yMin) * font_size / handle->face->units_per_EM); unsigned atlas_width = max_width * FT_ATLAS_COLS; unsigned atlas_height = max_height * FT_ATLAS_ROWS; uint8_t *atlas_buffer = (uint8_t*) calloc(atlas_width * atlas_height, 1); if (!atlas_buffer) return false; handle->atlas.buffer = atlas_buffer; handle->atlas.width = atlas_width; handle->atlas.height = atlas_height; slot = handle->atlas_slots; for (y = 0; y < FT_ATLAS_ROWS; y++) { for (x = 0; x < FT_ATLAS_COLS; x++) { slot->glyph.atlas_offset_x = x * max_width; slot->glyph.atlas_offset_y = y * max_height; slot++; } } for (i = 0; i < 256; i++) font_renderer_ft_get_glyph(handle, i); for (i = 0; i < 256; i++) if(isalnum(i)) font_renderer_ft_get_glyph(handle, i); return true; }
static bool font_renderer_create_atlas(ft_font_renderer_t *handle, float font_size) { unsigned i, x, y; freetype_atlas_slot_t* slot = NULL; /* TODO: find a better way to determine max_width/max_height */ unsigned max_width = font_size; unsigned max_height = font_size; handle->atlas.width = max_width * FT_ATLAS_COLS; handle->atlas.height = max_height * FT_ATLAS_ROWS; handle->atlas.buffer = (uint8_t*) calloc(handle->atlas.width * handle->atlas.height, 1); if (!handle->atlas.buffer) return false; slot = handle->atlas_slots; for (y = 0; y < FT_ATLAS_ROWS; y++) { for (x = 0; x < FT_ATLAS_COLS; x++) { slot->glyph.atlas_offset_x = x * max_width; slot->glyph.atlas_offset_y = y * max_height; slot++; } } for (i = 0; i < 256; i++) font_renderer_ft_get_glyph(handle, i); for (i = 0; i < 256; i++) if(isalnum(i)) font_renderer_ft_get_glyph(handle, i); return true; }