Add function to render a single unicode codepoint

This commit is contained in:
Francesco Abbate 2020-06-01 11:25:22 +02:00
parent 4ec521dd37
commit edb103716a
1 changed files with 60 additions and 0 deletions

View File

@ -137,6 +137,47 @@ public:
x += x_delta / scale_x;
}
template<class Rasterizer, class Scanline, class RenSolid>
void draw_codepoint(Rasterizer& ras, Scanline& sl,
RenSolid& ren_solid, const color_type color,
int codepoint, double& x, double& y, double height)
{
const double scale_x = 100;
m_feng.height(height);
m_feng.width(height * scale_x);
m_feng.hinting(m_hinting);
// Represent the delta in x scaled by scale_x.
double x_delta = 0;
double start_x = x;
const agg::glyph_cache* glyph = m_fman.glyph(codepoint);
if(glyph)
{
if(m_kerning)
{
m_fman.add_kerning(&x_delta, &y);
}
m_fman.init_embedded_adaptors(glyph, 0, 0);
if(glyph->data_type == agg::glyph_data_outline)
{
double ty = m_hinting ? floor(y + 0.5) : y;
ras.reset();
m_mtx.reset();
m_mtx *= agg::trans_affine_scaling(1.0 / scale_x, 1);
m_mtx *= agg::trans_affine_translation(start_x + x_delta / scale_x, ty);
ras.add_path(m_trans);
ren_solid.color(color);
agg::render_scanlines(ras, sl, ren_solid);
}
y += glyph->advance_y;
x += (x_delta + glyph->advance_x) / scale_x;
}
}
void clear(agg::rendering_buffer& ren_buf, const color_type color) {
pixfmt_type pf(ren_buf);
base_ren_type ren_base(pf);
@ -161,4 +202,23 @@ public:
renderer_solid ren_solid(ren_base);
draw_text(ras, sl, ren_solid, text_color, text, x, y, text_size);
}
void render_codepoint(agg::rendering_buffer& ren_buf,
const double text_size,
const color_type text_color,
double& x, double& y,
int codepoint)
{
if (!m_font_loaded) {
return;
}
agg::scanline_u8 sl;
agg::rasterizer_scanline_aa<> ras;
ras.clip_box(0, 0, ren_buf.width(), ren_buf.height());
agg::pixfmt_alpha8 pf(ren_buf);
base_ren_type ren_base(pf);
renderer_solid ren_solid(ren_base);
draw_codepoint(ras, sl, ren_solid, text_color, codepoint, x, y, text_size);
}
};