summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-09-20 08:30:53 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-09-20 09:22:28 +0200
commitaddfb3cce0f7ce8fbd0b169d467b6956ed95dbb5 (patch)
tree44ad218bf4ee32be4b77003c0deea853ad60e41e /sw
parent6754b647c145cded1f54b49d53d37ad35ace211c (diff)
sw content controls: add a11y description for PDF export
Acrobat Reader shows these descriptions on mouse hovering on a form widget. Change-Id: I8614222e46c992baca8a57b13a948f88973e8911 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140215 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/text/text.cxx13
-rw-r--r--sw/source/core/text/itrform2.cxx14
2 files changed, 27 insertions, 0 deletions
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index 12dc50884f23..245f8c230ca6 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -35,6 +35,7 @@
#include <fmtfsize.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <formatcontentcontrol.hxx>
+#include <strings.hrc>
constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/text/data/";
@@ -623,6 +624,12 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF)
SwDoc* pDoc = createSwDoc();
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
pWrtShell->InsertContentControl(SwContentControlType::RICH_TEXT);
+ pWrtShell->SttEndDoc(/*bStt=*/true);
+ pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 1, /*bBasicCall=*/false);
+ sal_Int32 nPlaceHolderLen = SwResId(STR_CONTENT_CONTROL_PLACEHOLDER).getLength();
+ pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, nPlaceHolderLen,
+ /*bBasicCall=*/false);
+ pWrtShell->Insert("mydesc");
// When exporting to PDF:
StoreToTempFile("writer_pdf_Export");
@@ -635,6 +642,12 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testContentControlPDF)
// - Actual : 0
// i.e. the content control was just exported as normal text.
CPPUNIT_ASSERT_EQUAL(1, pPage->getAnnotationCount());
+ std::unique_ptr<vcl::pdf::PDFiumAnnotation> pAnnotation = pPage->getAnnotation(0);
+ CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFAnnotationSubType::Widget, pAnnotation->getSubType());
+
+ // Also verify that the widget description is correct, it was empty:
+ CPPUNIT_ASSERT_EQUAL(OUString("mydesc"),
+ pAnnotation->getFormFieldAlternateName(pPdfDocument.get()));
}
CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testCheckboxContentControlPDF)
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 320133b0ffce..f07ea0bc1de7 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -56,6 +56,7 @@
#include <IDocumentMarkAccess.hxx>
#include <comphelper/processfactory.hxx>
#include <vcl/pdfextoutdevdata.hxx>
+#include <comphelper/string.hxx>
#include <docsh.hxx>
#include <unocrsrhelper.hxx>
#include <textcontentcontrol.hxx>
@@ -984,6 +985,19 @@ bool SwContentControlPortion::DescribePDFControl(const SwTextPaintInfo& rInf) co
pDescriptor->TextFont = pFont->GetActualFont();
}
+ // Description for accessibility purposes.
+ SwTextContentControl* pTextAttr = pContentControl->GetTextAttr();
+ SwTextNode* pTextNode = pContentControl->GetTextNode();
+ SwPosition aPoint(*pTextNode, pTextAttr->GetStart());
+ SwPosition aMark(*pTextNode, *pTextAttr->GetEnd());
+ SwPaM aPam(aMark, aPoint);
+ OUString aDescription = aPam.GetText();
+ static sal_Unicode const aForbidden[] = {
+ CH_TXTATR_BREAKWORD,
+ 0
+ };
+ pDescriptor->Description = comphelper::string::removeAny(aDescription, aForbidden);
+
SwRect aLocation;
rInf.CalcRect(*this, &aLocation);
pDescriptor->Location = aLocation.SVRect();