Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions text/draw_text.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF Text Library
// Copyright (c) 2022-2025 Igara Studio S.A.
// Copyright (c) 2022-2024 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This file is released under the terms of the MIT license.
Expand Down Expand Up @@ -32,20 +32,6 @@ class DrawTextDelegate {
public:
virtual ~DrawTextDelegate() {}

// This is called before processing and drawing character by character.
// Returns true if the character index is in the range of selected characters.
virtual bool isSelectedChar(const int index)
{
// Do nothing
return false;
}

// This is called before processing and drawing character by character.
virtual void drawSelectionBg(const gfx::RectF& bounds)
{
// Do nothing
}

// This is called before drawing the character.
virtual void preProcessChar(const int index,
const codepoint_t codepoint,
Expand Down
26 changes: 3 additions & 23 deletions text/draw_text_shaper.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// LAF Text Library
// Copyright (c) 2024-2025 Igara Studio S.A.
// Copyright (c) 2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -49,31 +49,11 @@ class AdapterBuilder : public TextBlob::RunHandler {
void commitRunBuffer(TextBlob::RunInfo& info) override
{
if (info.clusters && info.glyphCount > 0) {
gfx::RectF selectionBounds;
gfx::RectF textBounds;
std::vector<gfx::RectF> glyphsBounds(info.glyphCount);
for (int i = 0; i < info.glyphCount; ++i) {
auto bounds = info.getGlyphBounds(i);
glyphsBounds[i] = bounds;
textBounds |= bounds;

if (m_delegate && m_delegate->isSelectedChar(i))
selectionBounds |= bounds;
}
float advanceX = 0.0f;

os::Paint paint;
paint.style(os::Paint::Fill);

if (m_surface && m_bg != gfx::ColorNone) {
paint.color(m_bg);
m_surface->drawRect(textBounds.offset(m_origin), paint);
}

if (m_delegate && !selectionBounds.isEmpty())
m_delegate->drawSelectionBg(selectionBounds.offset(m_origin));

float advanceX = 0.0f;

for (int i = 0; i < info.glyphCount; ++i) {
int utf8Begin, utf8End;

Expand All @@ -91,7 +71,7 @@ class AdapterBuilder : public TextBlob::RunHandler {

const std::string utf8text = m_text.substr(utf8Begin, utf8End - utf8Begin);

gfx::RectF bounds = glyphsBounds[i];
gfx::RectF bounds = info.getGlyphBounds(i);
bounds.offset(m_origin);

advanceX += bounds.w;
Expand Down