sw/qa/core/text/text.cxx | 15 ++++++++++++++- sw/source/core/text/itrform2.cxx | 26 +++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-)
New commits: commit 122419be4f7bf576f7db5456b8b6b1f6f700487f Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Oct 24 08:45:26 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Oct 24 10:57:34 2022 +0200 sw content controls, alias: add PDF export Now that content controls have aliases, map that to PDF's description and then map the content to PDF's text when the content control is not in placeholder mode. This way the widget will have a description even if it's already filled in, which helps a11y. Change-Id: Ia66455eba26300c5dbb2d62b5858bac82546acf8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141716 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index a0f7726c42b1..8f3f18fd56d3 100644 --- a/sw/qa/core/text/text.cxx +++ b/sw/qa/core/text/text.cxx @@ -37,6 +37,9 @@ #include <IDocumentRedlineAccess.hxx> #include <formatcontentcontrol.hxx> #include <strings.hrc> +#include <ndtxt.hxx> +#include <txatbase.hxx> +#include <textcontentcontrol.hxx> constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/"; @@ -630,7 +633,17 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF) sal_Int32 nPlaceHolderLen = SwResId(STR_CONTENT_CONTROL_PLACEHOLDER).getLength(); pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, nPlaceHolderLen, /*bBasicCall=*/false); - pWrtShell->Insert("mydesc"); + pWrtShell->Insert("mycontent"); + const SwPosition* pStart = pWrtShell->GetCursor()->Start(); + SwTextNode* pTextNode = pStart->GetNode().GetTextNode(); + sal_Int32 nIndex = pStart->GetContentIndex(); + SwTextAttr* pAttr + = pTextNode->GetTextAttrAt(nIndex, RES_TXTATR_CONTENTCONTROL, sw::GetTextAttrMode::Parent); + auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr); + const SwFormatContentControl& rFormatContentControl = pTextContentControl->GetContentControl(); + std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl(); + // Alias/title, to be mapped to PDF's description. + pContentControl->SetAlias("mydesc"); // When exporting to PDF: StoreToTempFile("writer_pdf_Export"); diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index f925daaa8b97..aada2e757e1d 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -1042,15 +1042,23 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co } // Description for accessibility purposes. - SwPosition aPoint(*pTextNode, nStart); - SwPosition aMark(*pTextNode, nEnd); - SwPaM aPam(aMark, aPoint); - OUString aDescription = aPam.GetText(); - static sal_Unicode const aForbidden[] = { - CH_TXTATR_BREAKWORD, - 0 - }; - pDescriptor->Description = comphelper::string::removeAny(aDescription, aForbidden); + if (!pContentControl->GetAlias().isEmpty()) + { + pDescriptor->Description = pContentControl->GetAlias(); + } + + if (!pContentControl->GetShowingPlaceHolder()) + { + SwPosition aPoint(*pTextNode, nStart); + SwPosition aMark(*pTextNode, nEnd); + SwPaM aPam(aMark, aPoint); + OUString aText = aPam.GetText(); + static sal_Unicode const aForbidden[] = { + CH_TXTATR_BREAKWORD, + 0 + }; + pDescriptor->Text = comphelper::string::removeAny(aText, aForbidden); + } // Calculate the bounding rectangle of this content control, which can be one or more layout // portions in one or more lines.