From 80400973e06e08f0c1ab0b9a86418c1bcc4bbd5c Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Thu, 1 Nov 2018 15:38:58 +0300 Subject: tdf#118244 pdfexport: radio buttons use groupname now The previous implementation grouped radio buttons if their object name was the same. Likely this is a very old implementation, because the current radio buttons have a groupname property which links them together (although that too needed fixing in doc/docx), and their object names are unique. The old implementation still works - so that still needs to be supported, but I think I'll do that in a separate patch, so that it can be easily reverted if the old implementation is deprecated. Edge cases tested: -groupID of 0 works fine - doesn't have to be 1-based. -empty group name works fine (but breaks the old impl). -writer, calc, Change-Id: I84aebdac18b9edfa5ffcbfb23c15d0f37fcd47d1 Reviewed-on: https://gerrit.libreoffice.org/62742 Tested-by: Jenkins Reviewed-by: Justin Luth --- .../pdfexport/data/tdf118244_radioButtonGroup.odt | Bin 0 -> 12847 bytes vcl/qa/cppunit/pdfexport/pdfexport.cxx | 39 +++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 vcl/qa/cppunit/pdfexport/data/tdf118244_radioButtonGroup.odt (limited to 'vcl') diff --git a/vcl/qa/cppunit/pdfexport/data/tdf118244_radioButtonGroup.odt b/vcl/qa/cppunit/pdfexport/data/tdf118244_radioButtonGroup.odt new file mode 100644 index 000000000000..caabc4987c30 Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf118244_radioButtonGroup.odt differ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 1ee110972865..71fd198a0e35 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -94,6 +94,7 @@ public: void testTdf99680(); void testTdf99680_2(); void testTdf108963(); + void testTdf118244_radioButtonGroup(); #if HAVE_MORE_FONTS /// Test writing ToUnicode CMAP for LTR ligatures. void testTdf115117_1(); @@ -132,6 +133,7 @@ public: CPPUNIT_TEST(testTdf99680); CPPUNIT_TEST(testTdf99680_2); CPPUNIT_TEST(testTdf108963); + CPPUNIT_TEST(testTdf118244_radioButtonGroup); #if HAVE_MORE_FONTS CPPUNIT_TEST(testTdf115117_1); CPPUNIT_TEST(testTdf115117_1a); @@ -872,6 +874,43 @@ void PdfExportTest::testTdf108963() CPPUNIT_ASSERT_EQUAL(1, nYellowPathCount); } +void PdfExportTest::testTdf118244_radioButtonGroup() +{ + vcl::filter::PDFDocument aDocument; + load("tdf118244_radioButtonGroup.odt", aDocument); + + // The document has one page. + std::vector aPages = aDocument.GetPages(); + CPPUNIT_ASSERT_EQUAL(static_cast(1), aPages.size()); + + // There are eight radio buttons. + auto pAnnots = dynamic_cast(aPages[0]->Lookup("Annots")); + CPPUNIT_ASSERT(pAnnots); + CPPUNIT_ASSERT_EQUAL_MESSAGE("# of radio buttons",static_cast(8), pAnnots->GetElements().size()); + + sal_uInt32 nRadioGroups = 0; + for ( const auto& aElement : aDocument.GetElements() ) + { + auto pObject = dynamic_cast(aElement.get()); + if ( !pObject ) + continue; + auto pType = dynamic_cast(pObject->Lookup("FT")); + if ( pType && pType->GetValue() == "Btn" ) + { + auto pKids = dynamic_cast(pObject->Lookup("Kids")); + if ( pKids ) + { + size_t expectedSize = 2; + ++nRadioGroups; + if ( nRadioGroups == 2 ) + expectedSize = 5; + CPPUNIT_ASSERT_EQUAL(expectedSize, pKids->GetElements().size()); + } + } + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("# of radio groups", sal_uInt32(2), nRadioGroups); +} + #if HAVE_MORE_FONTS // This requires Carlito font, if it is missing the test will most likely // fail. -- cgit