11// LAF Text Library
2- // Copyright (c) 2024 Igara Studio S.A.
2+ // Copyright (c) 2024-2025 Igara Studio S.A.
33//
44// This file is released under the terms of the MIT license.
55// Read LICENSE.txt for more information.
@@ -49,11 +49,31 @@ class AdapterBuilder : public TextBlob::RunHandler {
4949 void commitRunBuffer (TextBlob::RunInfo& info) override
5050 {
5151 if (info.clusters && info.glyphCount > 0 ) {
52- float advanceX = 0 .0f ;
52+ gfx::RectF selectionBounds;
53+ gfx::RectF textBounds;
54+ std::vector<gfx::RectF> glyphsBounds;
55+ for (int i = 0 ; i < info.glyphCount ; ++i) {
56+ auto bounds = info.getGlyphBounds (i);
57+ glyphsBounds.push_back (bounds);
58+ textBounds |= bounds;
59+
60+ if (m_delegate && m_delegate->isSelectedChar (i))
61+ selectionBounds |= bounds;
62+ }
5363
5464 os::Paint paint;
5565 paint.style (os::Paint::Fill);
5666
67+ if (m_surface && m_bg != gfx::ColorNone) {
68+ paint.color (m_bg);
69+ m_surface->drawRect (textBounds.offset (m_origin), paint);
70+ }
71+
72+ if (m_delegate && !selectionBounds.isEmpty ())
73+ m_delegate->drawSelectionBg (selectionBounds.offset (m_origin));
74+
75+ float advanceX = 0 .0f ;
76+
5777 for (int i = 0 ; i < info.glyphCount ; ++i) {
5878 int utf8Begin, utf8End;
5979
@@ -71,7 +91,7 @@ class AdapterBuilder : public TextBlob::RunHandler {
7191
7292 const std::string utf8text = m_text.substr (utf8Begin, utf8End - utf8Begin);
7393
74- gfx::RectF bounds = info. getGlyphBounds (i) ;
94+ gfx::RectF bounds = glyphsBounds[i] ;
7595 bounds.offset (m_origin);
7696
7797 advanceX += bounds.w ;
@@ -100,11 +120,6 @@ class AdapterBuilder : public TextBlob::RunHandler {
100120 if (m_delegate)
101121 m_delegate->preDrawChar (bounds);
102122
103- if (m_bg != gfx::ColorNone) {
104- paint.color (m_bg);
105- m_surface->drawRect (bounds, paint);
106- }
107-
108123 if (m_surface && info.font ) {
109124 if (info.font ->type () == FontType::SpriteSheet) {
110125 const auto * spriteFont = static_cast <const SpriteSheetFont*>(info.font .get ());
0 commit comments