void Font_DrawFlat::draw_text(Canvas &canvas, const Pointf &position, const std::string &text, const Colorf &color, float line_spacing) { float offset_x = 0; float offset_y = 0; UTF8_Reader reader(text.data(), text.length()); RenderBatchTriangle *batcher = canvas.impl->batcher.get_triangle_batcher(); while (!reader.is_end()) { unsigned int glyph = reader.get_char(); reader.next(); if (glyph == '\n') { offset_x = 0; offset_y += line_spacing; continue; } Font_TextureGlyph *gptr = glyph_cache->get_glyph(canvas, font_engine, glyph); if (gptr) { if (!gptr->texture.is_null()) { float xp = offset_x + position.x + gptr->offset.x; float yp = offset_y + position.y + gptr->offset.y; Rectf dest_size(xp, yp, Sizef(gptr->geometry.get_size())); batcher->draw_image(canvas, gptr->geometry, dest_size, color, gptr->texture); } offset_x += gptr->metrics.advance.width; offset_y += gptr->metrics.advance.height; } } }
void Font_DrawScaled::draw_text(Canvas &canvas, const Pointf &position, const std::string &text, const Colorf &color, float line_spacing) { float offset_x = 0; float offset_y = 0; UTF8_Reader reader(text.data(), text.length()); RenderBatchTriangle *batcher = canvas.impl->batcher.get_triangle_batcher(); const Mat4f original_transform = canvas.get_transform(); clan::Mat4f scale_matrix = clan::Mat4f::scale(scaled_height, scaled_height, scaled_height); Sizef advance; while (!reader.is_end()) { unsigned int glyph = reader.get_char(); reader.next(); if (glyph == '\n') { offset_x = 0; offset_y += line_spacing * scaled_height; continue; } canvas.set_transform(original_transform * Mat4f::translate(position.x + offset_x, position.y + offset_y, 0) * scale_matrix); Font_TextureGlyph *gptr = glyph_cache->get_glyph(canvas, font_engine, glyph); if (gptr) { if (!gptr->texture.is_null()) { float xp = gptr->offset.x; float yp = gptr->offset.y; Rectf dest_size(xp, yp, gptr->size); batcher->draw_image(canvas, gptr->geometry, dest_size, color, gptr->texture); } offset_x += gptr->metrics.advance.width * scaled_height; offset_y += gptr->metrics.advance.height * scaled_height; } } canvas.set_transform(original_transform); }
void GlyphCache::draw_text(FontEngine *font_engine, Canvas &canvas, float xpos, float ypos, const std::string &text, const Colorf &color) { std::string::size_type string_length = text.length(); if (string_length==0) { return; } RenderBatchTriangle *batcher = canvas.impl->batcher.get_triangle_batcher(); GraphicContext &gc = canvas.get_gc(); // Scan the string UTF8_Reader reader(text.data(), text.length()); while(!reader.is_end()) { unsigned int glyph = reader.get_char(); reader.next(); Font_TextureGlyph *gptr = get_glyph(font_engine, gc, glyph); if (gptr == NULL) continue; if (!gptr->texture.is_null()) { float xp = xpos + gptr->offset.x; float yp = ypos + gptr->offset.y; Rectf dest_size(xp, yp, Sizef(gptr->geometry.get_size())); if (enable_subpixel) { batcher->draw_glyph_subpixel(canvas, gptr->geometry, dest_size, color, gptr->texture); }else { batcher->draw_image(canvas, gptr->geometry, dest_size, color, gptr->texture); } } xpos += gptr->increment.x; ypos += gptr->increment.y; } }