diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-03-15 10:06:49 +0100 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-03-15 13:59:44 +0100 |
commit | 5a4c3575945876f90dc2f6d67211107ed3b1de4f (patch) | |
tree | fb773ee563e0daeb3d2a02926c01639d00ad5eed /vcl/unx/gtk4 | |
parent | ae00b39c43b7c767d7f0eea78eb104b983799265 (diff) |
gtk4 a11y: Extract helper function for text attr conversion
Extract conversion of LO's text attr representation to the
one that the GTK implementation in
`lo_accessible_text_get_attributes` needs to return to
a new helper function `convertUnoTextAttributesToGtk` that
will be reused in an upcoming commit to implement handling
of default text attributes for which API has recently been
added to GTK.
Change-Id: I01a703012c668149a29c3ce759437a1b716988dc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164859
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl/unx/gtk4')
-rw-r--r-- | vcl/unx/gtk4/gtkaccessibletext.cxx | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/vcl/unx/gtk4/gtkaccessibletext.cxx b/vcl/unx/gtk4/gtkaccessibletext.cxx index ffe4108a1e6f..4d7853c054d4 100644 --- a/vcl/unx/gtk4/gtkaccessibletext.cxx +++ b/vcl/unx/gtk4/gtkaccessibletext.cxx @@ -125,6 +125,38 @@ static gboolean lo_accessible_text_get_selection(GtkAccessibleText* self, gsize* return true; } +static int +convertUnoTextAttributesToGtk(const css::uno::Sequence<css::beans::PropertyValue>& rAttribs, + char*** attribute_names, char*** attribute_values) +{ + std::vector<std::pair<OString, OUString>> aNameValuePairs; + for (const css::beans::PropertyValue& rAttribute : rAttribs) + { + if (rAttribute.Name == "CharFontName") + { + const OUString sValue = *o3tl::doAccess<OUString>(rAttribute.Value); + aNameValuePairs.emplace_back(GTK_ACCESSIBLE_ATTRIBUTE_FAMILY, sValue); + } + } + + if (aNameValuePairs.empty()) + return 0; + + const int nCount = aNameValuePairs.size(); + *attribute_names = g_new(char*, nCount + 1); + *attribute_values = g_new(char*, nCount + 1); + for (int i = 0; i < nCount; i++) + { + (*attribute_names)[i] = g_strdup(aNameValuePairs[i].first.getStr()); + (*attribute_values)[i] = g_strdup( + OUStringToOString(aNameValuePairs[i].second, RTL_TEXTENCODING_UTF8).getStr()); + } + (*attribute_names)[nCount] = nullptr; + (*attribute_values)[nCount] = nullptr; + + return nCount; +} + static gboolean lo_accessible_text_get_attributes(GtkAccessibleText* self, unsigned int offset, gsize* n_ranges, GtkAccessibleTextRange** ranges, char*** attribute_names, char*** attribute_values) @@ -152,40 +184,20 @@ static gboolean lo_accessible_text_get_attributes(GtkAccessibleText* self, unsig else aAttribs = xText->getCharacterAttributes(offset, css::uno::Sequence<OUString>()); - std::vector<std::pair<OString, OUString>> aNameValuePairs; - for (const css::beans::PropertyValue& rAttribute : aAttribs) - { - if (rAttribute.Name == "CharFontName") - { - const OUString sValue = *o3tl::doAccess<OUString>(rAttribute.Value); - aNameValuePairs.emplace_back(GTK_ACCESSIBLE_ATTRIBUTE_FAMILY, sValue); - } - } - - if (aNameValuePairs.empty()) + const int nCount = convertUnoTextAttributesToGtk(aAttribs, attribute_names, attribute_values); + if (nCount == 0) return false; - const css::accessibility::TextSegment aAttributeRun - = xText->getTextAtIndex(offset, css::accessibility::AccessibleTextType::ATTRIBUTE_RUN); - - const int nCount = aNameValuePairs.size(); *n_ranges = nCount; *ranges = g_new(GtkAccessibleTextRange, nCount); - *attribute_names = g_new(char*, nCount + 1); - *attribute_values = g_new(char*, nCount + 1); - + // just use start and end of attribute run for each single attribute + const css::accessibility::TextSegment aAttributeRun + = xText->getTextAtIndex(offset, css::accessibility::AccessibleTextType::ATTRIBUTE_RUN); for (int i = 0; i < nCount; i++) { - // just use start and end of attribute run for each single attribute ((*ranges)[i]).start = aAttributeRun.SegmentStart; ((*ranges)[i]).length = aAttributeRun.SegmentEnd - aAttributeRun.SegmentStart; - - (*attribute_names)[i] = g_strdup(aNameValuePairs[i].first.getStr()); - (*attribute_values)[i] = g_strdup( - OUStringToOString(aNameValuePairs[i].second, RTL_TEXTENCODING_UTF8).getStr()); } - (*attribute_names)[nCount] = nullptr; - (*attribute_values)[nCount] = nullptr; return true; } |