Files
cthulhu/internal/app/braille_text_attributes.go

65 lines
1.5 KiB
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
package app
import (
"strings"
"unicode/utf8"
"git.stormux.org/storm/cthulhu/internal/atspi"
"git.stormux.org/storm/cthulhu/internal/braille"
"git.stormux.org/storm/cthulhu/internal/config"
)
func markTextAttributeRun(frame *braille.Frame, run atspi.TextAttributeRun, sourceStart, frameStart, textLength int, settings config.TextAttributeSettings) {
if settings.Indicator == 0 || run.End <= run.Start || textLength <= 0 {
return
}
marked := false
for _, choice := range settings.Choices {
if !choice.Braille {
continue
}
if choice.Key == "text-spelling" {
if atspi.TextAttributesMisspelled(run.Values) {
marked = true
break
}
continue
}
value := strings.TrimSpace(run.Values[choice.Key])
if value == "" {
continue
}
for _, known := range characterAttributeOrder {
if known.key != choice.Key {
continue
}
if value != known.ignore {
marked = true
}
break
}
if marked {
break
}
}
if !marked {
return
}
begin := max(run.Start, sourceStart)
end := min(run.End, sourceStart+textLength)
if begin >= end {
return
}
count := utf8.RuneCountInString(frame.Text)
if len(frame.Dots) < count {
frame.Dots = append(frame.Dots, make([]byte, count-len(frame.Dots))...)
}
for offset := begin; offset < end; offset++ {
frame.Dots[frameStart+offset-sourceStart] |= byte(settings.Indicator)
}
}