Add ui::Graphics::drawTextBlob() function

This commit is contained in:
David Capello 2024-11-29 23:18:05 -03:00
parent 1e56e7da5a
commit c586ac5b14
2 changed files with 24 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "text/font.h"
#include "text/font_metrics.h"
#include "text/shaper_features.h"
#include "text/text_blob.h"
#include "ui/display.h"
#include "ui/scale.h"
#include "ui/theme.h"
@ -356,6 +357,25 @@ void Graphics::drawText(const std::string& str,
dirty(gfx::Rect(pt.x, pt.y, textBounds.w, textBounds.h));
}
void Graphics::drawTextBlob(const text::TextBlobRef& textBlob,
const gfx::PointF& pt0,
const Paint& paint)
{
ASSERT(m_font);
if (!textBlob)
return;
gfx::PointF pt(m_dx+pt0.x, m_dy+pt0.y);
os::SurfaceLock lock(m_surface.get());
gfx::RectF textBounds = textBlob->bounds();
text::draw_text(m_surface.get(), textBlob, pt, &paint);
textBounds.offset(pt);
dirty(textBounds);
}
namespace {
class DrawUITextDelegate : public text::DrawTextDelegate {

View File

@ -111,6 +111,10 @@ namespace ui {
text::DrawTextDelegate* delegate = nullptr,
text::ShaperFeatures features = {});
void drawTextBlob(const text::TextBlobRef& textBlob,
const gfx::PointF& pt,
const Paint& paint);
void drawUIText(const std::string& str, gfx::Color fg, gfx::Color bg, const gfx::Point& pt, const int mnemonic);
void drawAlignedUIText(const std::string& str, gfx::Color fg, gfx::Color bg, const gfx::Rect& rc, const int align);