tdf#143612: map SecondaryRefValue in form pdf export
Change-Id: I590784eb94fb6f4f3a20c4f6d8e3fb618f60d0fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134227
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/include/vcl/pdfwriter.hxx b/include/vcl/pdfwriter.hxx
index a894a6a..44b6ec4 100644
--- a/include/vcl/pdfwriter.hxx
+++ b/include/vcl/pdfwriter.hxx
@@ -333,6 +333,7 @@ public:
{
bool Checked;
OUString OnValue; // the value of the checkbox if it is selected
OUString OffValue; // the value of the checkbox if it is not selected
CheckBoxWidget()
: AnyWidget( vcl::PDFWriter::CheckBox ),
@@ -350,6 +351,7 @@ public:
bool Selected;
sal_Int32 RadioGroup;
OUString OnValue; // the value of the radio button if it is selected
OUString OffValue; // the value of the radio button if it is not selected
RadioButtonWidget()
: AnyWidget( vcl::PDFWriter::RadioButton ),
diff --git a/toolkit/source/helper/formpdfexport.cxx b/toolkit/source/helper/formpdfexport.cxx
index bd9bd53..80008f0 100644
--- a/toolkit/source/helper/formpdfexport.cxx
+++ b/toolkit/source/helper/formpdfexport.cxx
@@ -571,6 +571,14 @@ namespace toolkitform
catch(...)
{
}
try
{
xModelProps->getPropertyValue( "SecondaryRefValue" ) >>= pCheckBoxWidget->OffValue;
}
catch(...)
{
}
}
@@ -590,6 +598,14 @@ namespace toolkitform
catch(...)
{
}
try
{
xModelProps->getPropertyValue( "SecondaryRefValue" ) >>= pRadioWidget->OffValue;
}
catch(...)
{
}
}
diff --git a/vcl/inc/pdf/pdfwriter_impl.hxx b/vcl/inc/pdf/pdfwriter_impl.hxx
index 6326f837..4826b79 100644
--- a/vcl/inc/pdf/pdfwriter_impl.hxx
+++ b/vcl/inc/pdf/pdfwriter_impl.hxx
@@ -463,7 +463,8 @@ struct PDFWidget : public PDFAnnotation
sal_Int32 m_nParent; // if not 0, parent's object number
std::vector<sal_Int32> m_aKids; // widget children, contains object numbers
std::vector<sal_Int32> m_aKidsIndex; // widget children, contains index to m_aWidgets
OUString m_aOnValue;
OUString m_aOnValue;
OUString m_aOffValue;
sal_Int32 m_nTabOrder; // lowest number gets first in tab order
sal_Int32 m_nRadioGroup;
sal_Int32 m_nMaxLen;
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf148442.odt b/vcl/qa/cppunit/pdfexport/data/tdf148442.odt
index 31fea48e62..819595d 100644
--- a/vcl/qa/cppunit/pdfexport/data/tdf148442.odt
+++ b/vcl/qa/cppunit/pdfexport/data/tdf148442.odt
Binary files differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 329e294..7aaa6c1 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -860,6 +860,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf148442)
CPPUNIT_ASSERT_EQUAL(OString("Yes"), pAS->GetValue());
CPPUNIT_ASSERT(!pN->GetItems().count("ref"));
CPPUNIT_ASSERT(pN->GetItems().count("Yes"));
CPPUNIT_ASSERT(pN->GetItems().count("Off"));
}
else if (nBtnCount == 2)
{
@@ -869,6 +870,7 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf148442)
// Without the fix in place, this test would have failed here
CPPUNIT_ASSERT(pN->GetItems().count("ref"));
CPPUNIT_ASSERT(!pN->GetItems().count("Yes"));
CPPUNIT_ASSERT(pN->GetItems().count("Off"));
}
else
{
@@ -876,6 +878,10 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf148442)
CPPUNIT_ASSERT_EQUAL(OString("Off"), pAS->GetValue());
CPPUNIT_ASSERT(pN->GetItems().count("ref"));
CPPUNIT_ASSERT(!pN->GetItems().count("Yes"));
// tdf#143612: Without the fix in place, this test would have failed here
CPPUNIT_ASSERT(!pN->GetItems().count("Off"));
CPPUNIT_ASSERT(pN->GetItems().count("refOff"));
}
}
}
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index f017a93..aabf9d5 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -4188,6 +4188,25 @@ bool PDFWriterImpl::emitWidgetAnnotations()
SAL_INFO("vcl.pdfwriter", "error: CheckBox without \"Yes\" stream" );
}
}
if ( !rWidget.m_aOffValue.isEmpty() )
{
auto app_it = rWidget.m_aAppearances.find( "N" );
if( app_it != rWidget.m_aAppearances.end() )
{
auto stream_it = app_it->second.find( "Off" );
if( stream_it != app_it->second.end() )
{
SvMemoryStream* pStream = stream_it->second;
app_it->second.erase( stream_it );
OStringBuffer aBuf( rWidget.m_aOffValue.getLength()*2 );
appendName( rWidget.m_aOffValue, aBuf );
(app_it->second)[ aBuf.makeStringAndClear() ] = pStream;
}
else
SAL_INFO("vcl.pdfwriter", "error: CheckBox without \"Off\" stream" );
}
}
}
OStringBuffer aLine( 1024 );
@@ -10736,6 +10755,26 @@ void PDFWriterImpl::ensureUniqueRadioOnValues()
SAL_INFO("vcl.pdfwriter", "error: RadioButton without \"Yes\" stream" );
}
}
if ( !rKid.m_aOffValue.isEmpty() )
{
auto app_it = rKid.m_aAppearances.find( "N" );
if( app_it != rKid.m_aAppearances.end() )
{
auto stream_it = app_it->second.find( "Off" );
if( stream_it != app_it->second.end() )
{
SvMemoryStream* pStream = stream_it->second;
app_it->second.erase( stream_it );
OStringBuffer aBuf( rKid.m_aOffValue.getLength()*2 );
appendName( rKid.m_aOffValue, aBuf );
(app_it->second)[ aBuf.makeStringAndClear() ] = pStream;
}
else
SAL_INFO("vcl.pdfwriter", "error: RadioButton without \"Off\" stream" );
}
}
// update selected radio button
if( rKid.m_aValue != "Off" )
{
@@ -10853,6 +10892,7 @@ sal_Int32 PDFWriterImpl::createControl( const PDFWriter::AnyWidget& rControl, sa
rNewWidget.m_aValue = "Off";
rNewWidget.m_aOnValue = rBtn.OnValue;
rNewWidget.m_aOffValue = rBtn.OffValue;
if( rRadioButton.m_aValue.isEmpty() && rBtn.Selected )
{
rNewWidget.m_aValue = rNewWidget.m_aOnValue;
@@ -10875,6 +10915,7 @@ sal_Int32 PDFWriterImpl::createControl( const PDFWriter::AnyWidget& rControl, sa
rNewWidget.m_aValue
= rBox.Checked ? std::u16string_view(u"Yes") : std::u16string_view(u"Off" );
rNewWidget.m_aOnValue = rBox.OnValue;
rNewWidget.m_aOffValue = rBox.OffValue;
// create default appearance before m_aRect gets transformed
createDefaultCheckBoxAppearance( rNewWidget, rBox );
}