filter/qa/data/commentsInMargin.odt                        |binary
 filter/qa/pdf.cxx                                          |   39 +++++++++++++
 filter/source/pdf/impdialog.cxx                            |   12 ++++
 filter/source/pdf/impdialog.hxx                            |    2 
 filter/source/pdf/pdfexport.cxx                            |    7 ++
 filter/source/pdf/pdfexport.hxx                            |    1 
 filter/source/pdf/pdffilter.cxx                            |    1 
 filter/uiconfig/ui/pdfgeneralpage.ui                       |   36 +++++++++---
 include/vcl/pdfextoutdevdata.hxx                           |    4 +
 officecfg/registry/schema/org/openoffice/Office/Common.xcs |    6 ++
 sw/source/uibase/uno/unotxdoc.cxx                          |    7 +-
 vcl/source/gdi/pdfextoutdevdata.cxx                        |    4 +
 12 files changed, 108 insertions(+), 11 deletions(-)

New commits:
commit 19e3bab1a8def52d9a60f67bd87697e828e37773
Author:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
AuthorDate: Thu Nov 24 15:19:17 2022 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>
CommitDate: Mon Nov 28 11:24:57 2022 +0100

    tdf#77650 Add option to place comments in margin (PDF Export)
    
    This was somehow possible already when the document was printed with
    comments in margin before - but it was not possible to set this option
    when exporting a PDF via dialog or API.
    
    To use this setting via API, set the "ExportNotesInMargin" property.
    
    Change-Id: I97a80c5b3b3b2cde669496fd881a41ea0acc5c28
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143234
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de>

diff --git a/filter/qa/data/commentsInMargin.odt 
b/filter/qa/data/commentsInMargin.odt
new file mode 100644
index 000000000000..3286f9e01899
Binary files /dev/null and b/filter/qa/data/commentsInMargin.odt differ
diff --git a/filter/qa/pdf.cxx b/filter/qa/pdf.cxx
index b631a3f8a4a8..cc83f59e1652 100644
--- a/filter/qa/pdf.cxx
+++ b/filter/qa/pdf.cxx
@@ -37,6 +37,7 @@ public:
 
     void setUp() override;
     void tearDown() override;
+    void doTestCommentsInMargin(bool commentsInMarginEnabled);
 };
 
 void Test::setUp()
@@ -144,6 +145,44 @@ CPPUNIT_TEST_FIXTURE(Test, testPdfDecompositionSize)
 #endif
 }
 
+void Test::doTestCommentsInMargin(bool commentsInMarginEnabled)
+{
+    std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
+    if (!pPDFium)
+        return;
+
+    loadFromURL(u"commentsInMargin.odt");
+    uno::Reference<css::lang::XMultiServiceFactory> xFactory = 
getMultiServiceFactory();
+    uno::Reference<document::XFilter> xFilter(
+        xFactory->createInstance("com.sun.star.document.PDFFilter"), 
uno::UNO_QUERY);
+    uno::Reference<document::XExporter> xExporter(xFilter, uno::UNO_QUERY);
+    xExporter->setSourceDocument(mxComponent);
+    SvMemoryStream aStream;
+    uno::Reference<io::XOutputStream> xOutputStream(new 
utl::OStreamWrapper(aStream));
+    uno::Sequence<beans::PropertyValue> aFilterData{ 
comphelper::makePropertyValue(
+        "ExportNotesInMargin", commentsInMarginEnabled) };
+    uno::Sequence<beans::PropertyValue> aDescriptor{
+        comphelper::makePropertyValue("FilterName", 
OUString("writer_pdf_Export")),
+        comphelper::makePropertyValue("FilterData", aFilterData),
+        comphelper::makePropertyValue("OutputStream", xOutputStream),
+    };
+    xFilter->filter(aDescriptor);
+
+    // Make sure the number of objects is correct
+    std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
+        = pPDFium->openDocument(aStream.GetData(), aStream.GetSize(), 
OString());
+    CPPUNIT_ASSERT(pPdfDocument);
+    CPPUNIT_ASSERT_EQUAL(commentsInMarginEnabled ? 9 : 1,
+                         pPdfDocument->openPage(0)->getObjectCount());
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testCommentsInMargin)
+{
+    // Test that setting/unsetting the "ExportNotesInMargin" property works 
correctly
+    doTestCommentsInMargin(true);
+    doTestCommentsInMargin(false);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testWatermarkColor)
 {
     // Given an empty Writer document:
diff --git a/filter/source/pdf/impdialog.cxx b/filter/source/pdf/impdialog.cxx
index 16b4b8a00616..fd68322f1a23 100644
--- a/filter/source/pdf/impdialog.cxx
+++ b/filter/source/pdf/impdialog.cxx
@@ -67,6 +67,7 @@ ImpPDFTabDialog::ImpPDFTabDialog(weld::Window* pParent, const 
Sequence< Property
     mbUseTaggedPDF( false ),
     mbUseTaggedPDFUserSelection( false ),
     mbExportNotes( true ),
+    mbExportNotesInMargin( false ),
     mbViewPDF( false ),
     mbUseReferenceXObject( false ),
     mbExportNotesPages( false ),
@@ -191,6 +192,8 @@ ImpPDFTabDialog::ImpPDFTabDialog(weld::Window* pParent, 
const Sequence< Property
         mbExportOnlyNotesPages = maConfigItem.ReadBool( 
"ExportOnlyNotesPages", false );
     }
     mbExportNotes = maConfigItem.ReadBool( "ExportNotes", false );
+    if (mbIsWriter)
+        mbExportNotesInMargin = maConfigItem.ReadBool( "ExportNotesInMargin", 
false );
     mbViewPDF = maConfigItem.ReadBool( "ViewPDFAfterExport", false );
 
     mbExportBookmarks = maConfigItem.ReadBool( "ExportBookmarks", true );
@@ -417,6 +420,8 @@ Sequence< PropertyValue > ImpPDFTabDialog::GetFilterData()
         maConfigItem.WriteBool( "ExportOnlyNotesPages", mbExportOnlyNotesPages 
);
     }
     maConfigItem.WriteBool( "ExportNotes", mbExportNotes );
+    if (mbIsWriter)
+        maConfigItem.WriteBool( "ExportNotesInMargin", mbExportNotesInMargin );
     maConfigItem.WriteBool( "ViewPDFAfterExport", mbViewPDF );
 
     maConfigItem.WriteBool( "ExportBookmarks", mbExportBookmarks );
@@ -518,6 +523,7 @@ ImpPDFTabGeneralPage::ImpPDFTabGeneralPage(weld::Container* 
pPage, weld::DialogC
     , mxCbExportHiddenSlides(m_xBuilder->weld_check_button("hiddenpages"))
     , mxCbSinglePageSheets(m_xBuilder->weld_check_button("singlepagesheets"))
     , mxCbExportNotes(m_xBuilder->weld_check_button("comments"))
+    , 
mxCbExportNotesInMargin(m_xBuilder->weld_check_button("commentsinmargin"))
     , mxCbViewPDF(m_xBuilder->weld_check_button("viewpdf"))
     , 
mxCbUseReferenceXObject(m_xBuilder->weld_check_button("usereferencexobject"))
     , mxCbExportNotesPages(m_xBuilder->weld_check_button("notes"))
@@ -556,6 +562,7 @@ void 
ImpPDFTabGeneralPage::SetFilterConfigItem(ImpPDFTabDialog* pParent)
     mbIsWriter = pParent->mbIsWriter;
     mbIsSpreadsheet = pParent->mbIsSpreadsheet;
 
+    mxCbExportNotesInMargin->set_sensitive( mbIsWriter );
     mxCbExportEmptyPages->set_sensitive( mbIsWriter );
     mxCbExportPlaceholders->set_sensitive( mbIsWriter );
 
@@ -618,6 +625,7 @@ void 
ImpPDFTabGeneralPage::SetFilterConfigItem(ImpPDFTabDialog* pParent)
     mxCbExportBookmarks->set_active( pParent->mbExportBookmarks );
 
     mxCbExportNotes->set_active( pParent->mbExportNotes );
+    mxCbExportNotesInMargin->set_active( pParent->mbExportNotesInMargin );
     mxCbViewPDF->set_active( pParent->mbViewPDF);
 
     if ( mbIsPresentation )
@@ -663,10 +671,12 @@ void 
ImpPDFTabGeneralPage::SetFilterConfigItem(ImpPDFTabDialog* pParent)
     {
         // tdf#54908 Make selection active if there is a selection in Writer's 
version
         mxRbSelection->set_active( bSelectionPresent );
+        mxCbExportNotesInMargin->set_active(pParent->mbExportNotesInMargin);
     }
     else
     {
         mxCbExportPlaceholders->set_active(false);
+        mxCbExportNotesInMargin->set_active(false);
     }
     mxCbExportEmptyPages->set_active(!pParent->mbIsSkipEmptyPages);
     mxCbExportPlaceholders->set_active(pParent->mbIsExportPlaceholders);
@@ -686,6 +696,8 @@ void ImpPDFTabGeneralPage::GetFilterConfigItem( 
ImpPDFTabDialog* pParent )
     pParent->mbReduceImageResolution = mxCbReduceImageResolution->get_active();
     pParent->mnMaxImageResolution = 
mxCoReduceImageResolution->get_active_text().toInt32();
     pParent->mbExportNotes = mxCbExportNotes->get_active();
+    if (mbIsWriter)
+        pParent->mbExportNotesInMargin = mxCbExportNotesInMargin->get_active();
     pParent->mbViewPDF = mxCbViewPDF->get_active();
     pParent->mbUseReferenceXObject = mxCbUseReferenceXObject->get_active();
     if ( mbIsPresentation )
diff --git a/filter/source/pdf/impdialog.hxx b/filter/source/pdf/impdialog.hxx
index 9dc97d653e37..828422bdc63e 100644
--- a/filter/source/pdf/impdialog.hxx
+++ b/filter/source/pdf/impdialog.hxx
@@ -83,6 +83,7 @@ class ImpPDFTabDialog final : public SfxTabDialogController
     sal_Int32                   mnPDFTypeSelection;
     bool                        mbPDFUACompliance;
     bool                        mbExportNotes;
+    bool                        mbExportNotesInMargin;
     bool                        mbViewPDF;
     bool                        mbUseReferenceXObject;
     bool                        mbExportNotesPages;
@@ -202,6 +203,7 @@ class ImpPDFTabGeneralPage : public SfxTabPage
     std::unique_ptr<weld::CheckButton> mxCbExportHiddenSlides;
     std::unique_ptr<weld::CheckButton> mxCbSinglePageSheets;
     std::unique_ptr<weld::CheckButton> mxCbExportNotes;
+    std::unique_ptr<weld::CheckButton> mxCbExportNotesInMargin;
     std::unique_ptr<weld::CheckButton> mxCbViewPDF;
     std::unique_ptr<weld::CheckButton> mxCbUseReferenceXObject;
     std::unique_ptr<weld::CheckButton> mxCbExportNotesPages;
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 8204d6da86b3..338463f184f8 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -86,6 +86,7 @@ PDFExport::PDFExport( const Reference< XComponent >& rxSrcDoc,
     mnPDFTypeSelection          ( 0 ),
     mbPDFUACompliance           ( false),
     mbExportNotes               ( true ),
+    mbExportNotesInMargin       ( false ),
     mbExportPlaceholders        ( false ),
     mbUseReferenceXObject       ( false ),
     mbExportNotesPages          ( false ),
@@ -518,6 +519,8 @@ bool PDFExport::Export( const OUString& rFile, const 
Sequence< PropertyValue >&
                     rProp.Value >>= mbPDFUACompliance;
                 else if ( rProp.Name == "ExportNotes" )
                     rProp.Value >>= mbExportNotes;
+                else if ( rProp.Name == "ExportNotesInMargin" )
+                    rProp.Value >>= mbExportNotesInMargin;
                 else if ( rProp.Name == "ExportNotesPages" )
                     rProp.Value >>= mbExportNotesPages;
                 else if ( rProp.Name == "ExportOnlyNotesPages" )
@@ -935,6 +938,7 @@ bool PDFExport::Export( const OUString& rFile, const 
Sequence< PropertyValue >&
                 vcl::PDFExtOutDevData aPDFExtOutDevData( *pOut );
                 pOut->SetExtOutDevData( &aPDFExtOutDevData );
                 aPDFExtOutDevData.SetIsExportNotes( mbExportNotes );
+                aPDFExtOutDevData.SetIsExportNotesInMargin( 
mbExportNotesInMargin );
                 aPDFExtOutDevData.SetIsExportTaggedPDF( mbUseTaggedPDF );
                 aPDFExtOutDevData.SetIsExportTransitionEffects( 
mbUseTransitionEffects );
                 aPDFExtOutDevData.SetIsExportFormFields( mbExportFormFields );
@@ -954,7 +958,8 @@ bool PDFExport::Export( const OUString& rFile, const 
Sequence< PropertyValue >&
                     comphelper::makePropertyValue("IsSkipEmptyPages", 
mbSkipEmptyPages),
                     comphelper::makePropertyValue("PageRange", aPageRange),
                     comphelper::makePropertyValue("ExportPlaceholders", 
mbExportPlaceholders),
-                    comphelper::makePropertyValue("SinglePageSheets", 
mbSinglePageSheets)
+                    comphelper::makePropertyValue("SinglePageSheets", 
mbSinglePageSheets),
+                    comphelper::makePropertyValue("ExportNotesInMargin", 
mbExportNotesInMargin)
                 };
                 Any& rExportNotesValue = aRenderOptions.getArray()[ 1 ].Value;
 
diff --git a/filter/source/pdf/pdfexport.hxx b/filter/source/pdf/pdfexport.hxx
index dfd371c3177b..5dbe15e36846 100644
--- a/filter/source/pdf/pdfexport.hxx
+++ b/filter/source/pdf/pdfexport.hxx
@@ -48,6 +48,7 @@ private:
     sal_Int32           mnPDFTypeSelection;
     bool                mbPDFUACompliance;
     bool                mbExportNotes;
+    bool                mbExportNotesInMargin;
     bool                mbExportPlaceholders;
     bool                mbUseReferenceXObject;
     bool                mbExportNotesPages;
diff --git a/filter/source/pdf/pdffilter.cxx b/filter/source/pdf/pdffilter.cxx
index f6596a3479e3..d28803aa01c9 100644
--- a/filter/source/pdf/pdffilter.cxx
+++ b/filter/source/pdf/pdffilter.cxx
@@ -110,6 +110,7 @@ bool PDFFilter::implExport( const Sequence< PropertyValue 
>& rDescriptor )
         aCfgItem.ReadInt32( "SelectPdfVersion", 0 );
         aCfgItem.ReadBool("PDFUACompliance", false);
         aCfgItem.ReadBool(  "ExportNotes", false );
+        aCfgItem.ReadBool(  "ExportNotesInMargin", false );
         aCfgItem.ReadBool( "ExportPlaceholders", false );
         aCfgItem.ReadBool(  "ExportNotesPages", false );
         aCfgItem.ReadBool(  "ExportOnlyNotesPages", false );
diff --git a/filter/uiconfig/ui/pdfgeneralpage.ui 
b/filter/uiconfig/ui/pdfgeneralpage.ui
index 844e3c341a7c..f39034a9b184 100644
--- a/filter/uiconfig/ui/pdfgeneralpage.ui
+++ b/filter/uiconfig/ui/pdfgeneralpage.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.40.0 -->
 <interface domain="flt">
   <requires lib="gtk+" version="3.20"/>
   <object class="GtkSizeGroup"/>
@@ -790,7 +790,7 @@
             <property name="label-xalign">0</property>
             <property name="shadow-type">none</property>
             <child>
-              <!-- n-columns=1 n-rows=9 -->
+              <!-- n-columns=1 n-rows=10 -->
               <object class="GtkGrid" id="grid2">
                 <property name="visible">True</property>
                 <property name="can-focus">False</property>
@@ -874,7 +874,7 @@
                   </object>
                   <packing>
                     <property name="left-attach">0</property>
-                    <property name="top-attach">7</property>
+                    <property name="top-attach">8</property>
                   </packing>
                 </child>
                 <child>
@@ -894,7 +894,7 @@
                   </object>
                   <packing>
                     <property name="left-attach">0</property>
-                    <property name="top-attach">8</property>
+                    <property name="top-attach">9</property>
                   </packing>
                 </child>
                 <child>
@@ -914,7 +914,7 @@
                   </object>
                   <packing>
                     <property name="left-attach">0</property>
-                    <property name="top-attach">5</property>
+                    <property name="top-attach">6</property>
                   </packing>
                 </child>
                 <child>
@@ -934,7 +934,7 @@
                   </object>
                   <packing>
                     <property name="left-attach">0</property>
-                    <property name="top-attach">3</property>
+                    <property name="top-attach">4</property>
                   </packing>
                 </child>
                 <child>
@@ -955,7 +955,7 @@
                   </object>
                   <packing>
                     <property name="left-attach">0</property>
-                    <property name="top-attach">4</property>
+                    <property name="top-attach">5</property>
                   </packing>
                 </child>
                 <child>
@@ -975,7 +975,27 @@
                   </object>
                   <packing>
                     <property name="left-attach">0</property>
-                    <property name="top-attach">6</property>
+                    <property name="top-attach">7</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkCheckButton" id="commentsinmargin">
+                    <property name="label" translatable="yes" 
context="pdfgeneralpage|commentsinmargin">_Comments in margin</property>
+                    <property name="visible">True</property>
+                    <property name="can-focus">True</property>
+                    <property name="receives-default">False</property>
+                    <property name="halign">start</property>
+                    <property name="use-underline">True</property>
+                    <property name="draw-indicator">True</property>
+                    <child internal-child="accessible">
+                      <object class="AtkObject" 
id="commentsinmargin-atkobject">
+                        <property name="AtkObject::accessible-description" 
translatable="yes" 
context="pdfgeneralpage|extended_tip|commentsinmargin">Select to export 
comments of Writer documents in the page margin.</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left-attach">0</property>
+                    <property name="top-attach">3</property>
                   </packing>
                 </child>
               </object>
diff --git a/include/vcl/pdfextoutdevdata.hxx b/include/vcl/pdfextoutdevdata.hxx
index 45cb71682f12..89696ef757b6 100644
--- a/include/vcl/pdfextoutdevdata.hxx
+++ b/include/vcl/pdfextoutdevdata.hxx
@@ -72,6 +72,7 @@ class VCL_DLLPUBLIC PDFExtOutDevData final : public 
ExtOutDevData
 
     bool                        mbTaggedPDF;
     bool                        mbExportNotes;
+    bool                        mbExportNotesInMargin;
     bool                        mbExportNotesPages;
     bool                        mbTransitionEffects;
     bool                        mbUseLosslessCompression;
@@ -104,6 +105,9 @@ public:
     bool    GetIsExportNotes() const { return mbExportNotes;}
     void        SetIsExportNotes( const bool bExportNotes );
 
+    bool    GetIsExportNotesInMargin() const { return mbExportNotesInMargin;}
+    void        SetIsExportNotesInMargin( const bool bExportNotesInMargin );
+
     bool    GetIsExportNotesPages() const { return mbExportNotesPages;}
     void        SetIsExportNotesPages( const bool bExportNotesPages );
 
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 2505345a8a39..4214307173da 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -4939,6 +4939,12 @@
             </info>
             <value>false</value>
           </prop>
+          <prop oor:name="ExportNotesInMargin" oor:type="xs:boolean" 
oor:nillable="false">
+            <info>
+              <desc>Specifies if notes are exported in the document 
margin.</desc>
+            </info>
+            <value>false</value>
+          </prop>
           <prop oor:name="ViewPDFAfterExport" oor:type="xs:boolean" 
oor:nillable="false">
             <info>
               <desc>Specifies if PDF automatically opens after export.</desc>
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 62ec394fe47c..3405a1631727 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -2974,11 +2974,14 @@ void SAL_CALL SwXTextDocument::render(
 
                     SwWrtShell* pWrtShell = pSwView ? 
pSwView->GetWrtShellPtr() : nullptr;
 
-                    SwPrintData const& rSwPrtOptions =
-                        *m_pRenderData->GetSwPrtOptions();
+                    SwPrintData rSwPrtOptions = 
*m_pRenderData->GetSwPrtOptions();
 
                     if (bIsPDFExport && (bFirstPage || bHasPDFExtOutDevData) 
&& pWrtShell)
                     {
+                        rSwPrtOptions.SetPrintPostIts(
+                            lcl_GetBoolProperty(rxOptions, 
"ExportNotesInMargin")
+                                ? SwPostItMode::InMargins
+                                : SwPostItMode::NONE);
                         SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, 
aPageRange, bIsSkipEmptyPages, false, rSwPrtOptions );
                     }
 
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx 
b/vcl/source/gdi/pdfextoutdevdata.cxx
index 00e4f4a9c1bd..3dfdd237f4d5 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -572,6 +572,10 @@ void PDFExtOutDevData::SetIsExportNotes( const bool 
bExportNotes )
 {
     mbExportNotes = bExportNotes;
 }
+void PDFExtOutDevData::SetIsExportNotesInMargin( const bool 
bExportNotesInMargin )
+{
+    mbExportNotesInMargin = bExportNotesInMargin;
+}
 void PDFExtOutDevData::SetIsExportNotesPages( const bool bExportNotesPages )
 {
     mbExportNotesPages = bExportNotesPages;

Reply via email to