sw/qa/core/text/text.cxx | 15 ++++++++++++++- sw/source/core/text/itrform2.cxx | 26 +++++++++++++++++--------- 2 files changed, 31 insertions(+), 10 deletions(-)
New commits: commit 05bdae6e949d91277978af88212a646d1bd715c3 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Oct 24 08:45:26 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Oct 25 08:20:49 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. (cherry picked from commit 122419be4f7bf576f7db5456b8b6b1f6f700487f) Change-Id: Ia66455eba26300c5dbb2d62b5858bac82546acf8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141726 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx index 7c3077c8cdae..95b1113979b1 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/"; @@ -541,7 +544,17 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF) sal_Int32 nPlaceHolderLen = SwResId(STR_CONTENT_CONTROL_PLACEHOLDER).getLength(); pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, nPlaceHolderLen, /*bBasicCall=*/false); - pWrtShell->Insert("mydesc"); + pWrtShell->Insert("mycontent"); + const SwPosition* pStart = pWrtShell->GetCursor()->Start(); + SwTextNode* pTextNode = pStart->nNode.GetNode().GetTextNode(); + sal_Int32 nIndex = pStart->nContent.GetIndex(); + SwTextAttr* pAttr + = pTextNode->GetTextAttrAt(nIndex, RES_TXTATR_CONTENTCONTROL, SwTextNode::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 3d9ed4edebfe..fad85e12337e 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -1003,15 +1003,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.