2013-07-28 07:22:24 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms of the GFX License. If a copy of
|
|
|
|
* the license was not distributed with this file, you can obtain one at:
|
|
|
|
*
|
2018-10-01 15:32:39 +00:00
|
|
|
* http://ugfx.io/license.html
|
2013-07-28 07:22:24 +00:00
|
|
|
*/
|
|
|
|
|
2013-07-28 07:08:45 +00:00
|
|
|
#include "mf_scaledfont.h"
|
|
|
|
|
2013-09-06 02:23:48 +00:00
|
|
|
#ifndef MF_NO_COMPILE
|
|
|
|
|
2013-07-28 07:08:45 +00:00
|
|
|
struct scaled_renderstate
|
|
|
|
{
|
|
|
|
mf_pixel_callback_t orig_callback;
|
|
|
|
void *orig_state;
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 x_scale;
|
|
|
|
gU8 y_scale;
|
|
|
|
gI16 x0;
|
|
|
|
gI16 y0;
|
2013-07-28 07:08:45 +00:00
|
|
|
};
|
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
static void scaled_pixel_callback(gI16 x, gI16 y, gU8 count,
|
|
|
|
gU8 alpha, void *state)
|
2013-07-28 07:08:45 +00:00
|
|
|
{
|
|
|
|
struct scaled_renderstate *rstate = state;
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 dy;
|
2013-07-28 07:08:45 +00:00
|
|
|
|
|
|
|
count *= rstate->x_scale;
|
|
|
|
x = rstate->x0 + x * rstate->x_scale;
|
|
|
|
y = rstate->y0 + y * rstate->y_scale;
|
|
|
|
|
|
|
|
for (dy = 0; dy < rstate->y_scale; dy++)
|
|
|
|
{
|
|
|
|
rstate->orig_callback(x, y + dy, count, alpha, rstate->orig_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 mf_scaled_character_width(const struct mf_font_s *font,
|
|
|
|
gU16 character)
|
2013-07-28 07:08:45 +00:00
|
|
|
{
|
|
|
|
struct mf_scaledfont_s *sfont = (struct mf_scaledfont_s*)font;
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 basewidth;
|
2013-07-28 07:08:45 +00:00
|
|
|
|
|
|
|
basewidth = sfont->basefont->character_width(sfont->basefont, character);
|
|
|
|
|
|
|
|
return sfont->x_scale * basewidth;
|
|
|
|
}
|
|
|
|
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 mf_scaled_render_character(const struct mf_font_s *font,
|
|
|
|
gI16 x0, gI16 y0,
|
|
|
|
gU16 character,
|
2013-07-28 07:08:45 +00:00
|
|
|
mf_pixel_callback_t callback,
|
|
|
|
void *state)
|
|
|
|
{
|
|
|
|
struct mf_scaledfont_s *sfont = (struct mf_scaledfont_s*)font;
|
|
|
|
struct scaled_renderstate rstate;
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 basewidth;
|
2013-07-28 07:08:45 +00:00
|
|
|
|
|
|
|
rstate.orig_callback = callback;
|
|
|
|
rstate.orig_state = state;
|
|
|
|
rstate.x_scale = sfont->x_scale;
|
|
|
|
rstate.y_scale = sfont->y_scale;
|
|
|
|
rstate.x0 = x0;
|
|
|
|
rstate.y0 = y0;
|
|
|
|
|
|
|
|
basewidth = sfont->basefont->render_character(sfont->basefont, 0, 0,
|
|
|
|
character, scaled_pixel_callback, &rstate);
|
|
|
|
|
|
|
|
return sfont->x_scale * basewidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mf_scale_font(struct mf_scaledfont_s *newfont,
|
|
|
|
const struct mf_font_s *basefont,
|
2018-11-03 00:51:23 +00:00
|
|
|
gU8 x_scale, gU8 y_scale)
|
2013-07-28 07:08:45 +00:00
|
|
|
{
|
|
|
|
newfont->font = *basefont;
|
|
|
|
newfont->basefont = basefont;
|
|
|
|
|
|
|
|
newfont->font.width *= x_scale;
|
|
|
|
newfont->font.height *= y_scale;
|
|
|
|
newfont->font.baseline_x *= x_scale;
|
|
|
|
newfont->font.baseline_y *= y_scale;
|
|
|
|
newfont->font.min_x_advance *= x_scale;
|
|
|
|
newfont->font.max_x_advance *= x_scale;
|
|
|
|
newfont->font.line_height *= y_scale;
|
2013-08-17 13:32:53 +00:00
|
|
|
newfont->font.character_width = &mf_scaled_character_width;
|
|
|
|
newfont->font.render_character = &mf_scaled_render_character;
|
2013-07-28 07:08:45 +00:00
|
|
|
|
|
|
|
newfont->x_scale = x_scale;
|
|
|
|
newfont->y_scale = y_scale;
|
|
|
|
}
|
|
|
|
|
2013-09-06 02:23:48 +00:00
|
|
|
#endif //MF_NO_COMPILE
|