filter/CppunitTest_filter_pdf.mk          |    6 ++++
 filter/qa/pdf.cxx                         |   37 +++++++++++++++++++++++++++-
 sw/inc/PostItMgr.hxx                      |    3 ++
 sw/source/core/view/vprint.cxx            |    2 +
 sw/source/uibase/docvw/AnnotationWin2.cxx |   39 +++++++++++++++++++++---------
 sw/source/uibase/docvw/PostItMgr.cxx      |   26 +++++++++++++++-----
 6 files changed, 95 insertions(+), 18 deletions(-)

New commits:
commit cac49e213f19c1a6e660ac4063874a9b60ab005c
Author:     Jaume Pujantell <[email protected]>
AuthorDate: Wed Aug 13 14:31:31 2025 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Feb 2 10:56:20 2026 +0100

    lok: pdf export comments in margin
    
    Enable print comments in margin for PDF in LOK without tiled comments.
    Right now comments are only printed if they are being shown in the LO
    document which excludes LOK without tiled comments. Also the post-it
    manager and annotation window assume in some places that MapMode is used
    and correctly set, which is not the case in LOK.
    
    Adapted an existing test about printing comments in margin to test also
    for LOK.
    
    Change-Id: I362cb89ade6d4f53832fd9a722196d214360aae6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189511
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198492
    Tested-by: Miklos Vajna <[email protected]>

diff --git a/filter/CppunitTest_filter_pdf.mk b/filter/CppunitTest_filter_pdf.mk
index 912b84e0edb4..36437555c795 100644
--- a/filter/CppunitTest_filter_pdf.mk
+++ b/filter/CppunitTest_filter_pdf.mk
@@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,filter_pdf, \
     cppuhelper \
     sal \
     subsequenttest \
+    sw \
     test \
     tl \
     unotest \
@@ -35,6 +36,11 @@ $(eval $(call gb_CppunitTest_use_libraries,filter_pdf, \
 
 $(eval $(call gb_CppunitTest_use_sdk_api,filter_pdf))
 
+$(eval $(call gb_CppunitTest_set_include,filter_pdf,\
+    -I$(SRCDIR)/sw/inc \
+    $$(INCLUDE) \
+))
+
 $(eval $(call gb_CppunitTest_use_ure,filter_pdf))
 $(eval $(call gb_CppunitTest_use_vcl,filter_pdf))
 
diff --git a/filter/qa/pdf.cxx b/filter/qa/pdf.cxx
index 1fdd75baf886..c62b9aa17e8a 100644
--- a/filter/qa/pdf.cxx
+++ b/filter/qa/pdf.cxx
@@ -16,9 +16,11 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/graphic/XGraphic.hpp>
 
+#include <comphelper/lok.hxx>
 #include <comphelper/propertyvalue.hxx>
 #include <tools/stream.hxx>
 #include <unotools/streamwrap.hxx>
+#include <unotxdoc.hxx>
 #include <vcl/filter/PDFiumLibrary.hxx>
 #include <tools/helpers.hxx>
 
@@ -36,6 +38,7 @@ public:
     }
 
     void setUp() override;
+    void tearDown() override;
     void doTestCommentsInMargin(bool commentsInMarginEnabled);
 };
 
@@ -46,6 +49,14 @@ void Test::setUp()
     MacrosTest::setUpX509(m_directories, u"filter_pdf"_ustr);
 }
 
+void Test::tearDown()
+{
+    UnoApiTest::tearDown();
+
+    if (comphelper::LibreOfficeKit::isActive())
+        comphelper::LibreOfficeKit::setActive(false);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testSignCertificateSubjectName)
 {
     std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
@@ -144,6 +155,11 @@ void Test::doTestCommentsInMargin(bool 
commentsInMarginEnabled)
         return;
 
     loadFromFile(u"commentsInMargin.odt");
+    if (comphelper::LibreOfficeKit::isActive())
+    {
+        SwXTextDocument* pTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+        
pTextDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+    }
     uno::Reference<css::lang::XMultiServiceFactory> xFactory = 
getMultiServiceFactory();
     uno::Reference<document::XFilter> xFilter(
         xFactory->createInstance(u"com.sun.star.document.PDFFilter"_ustr), 
uno::UNO_QUERY);
@@ -168,7 +184,19 @@ void Test::doTestCommentsInMargin(bool 
commentsInMarginEnabled)
     {
         // Unfortunately, the comment box is DPI dependent, and the lines 
there may split
         // at higher DPIs, creating additional objects on import, hence the 
"_GREATER"
-        CPPUNIT_ASSERT_GREATER(8, pPdfDocument->openPage(0)->getObjectCount());
+        auto pPage = pPdfDocument->openPage(0);
+        int nObjs = pPage->getObjectCount();
+        CPPUNIT_ASSERT_GREATER(8, nObjs);
+        bool bFound = false;
+        int i = 0;
+        for (; i < nObjs && !bFound; ++i)
+        {
+            auto pObj = pPage->getObject(i);
+            if (pObj->getText(pPage->getTextPage()) == "Nice comment over 
here.")
+                bFound = true;
+        }
+        CPPUNIT_ASSERT_MESSAGE("The comment text was not found.", bFound);
+        CPPUNIT_ASSERT_GREATER(400., pPage->getObject(i - 
1)->getBounds().getMinX());
     }
     else
         CPPUNIT_ASSERT_EQUAL(1, pPdfDocument->openPage(0)->getObjectCount());
@@ -179,6 +207,13 @@ CPPUNIT_TEST_FIXTURE(Test, testCommentsInMargin)
     // Test that setting/unsetting the "ExportNotesInMargin" property works 
correctly
     doTestCommentsInMargin(true);
     doTestCommentsInMargin(false);
+    comphelper::LibreOfficeKit::setActive(true);
+    comphelper::LibreOfficeKit::setTiledAnnotations(true);
+    doTestCommentsInMargin(true);
+    doTestCommentsInMargin(false);
+    comphelper::LibreOfficeKit::setTiledAnnotations(false);
+    doTestCommentsInMargin(true);
+    doTestCommentsInMargin(false);
 }
 
 CPPUNIT_TEST_FIXTURE(Test, testWatermarkColor)
diff --git a/sw/inc/PostItMgr.hxx b/sw/inc/PostItMgr.hxx
index 8c25f381641b..ef9155e2960f 100644
--- a/sw/inc/PostItMgr.hxx
+++ b/sw/inc/PostItMgr.hxx
@@ -100,6 +100,7 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public 
SfxListener,
         FieldShadowState                mShadowState;
         std::optional<OutlinerParaObject> mpAnswer;
         OUString                        maAnswerText;
+        bool mbForceShow = false;
 
         // data structure to collect the <SwAnnotationWin> instances for 
certain <SwFrame> instances.
         std::unique_ptr<sw::sidebarwindows::SwFrameSidebarWinContainer> 
mpFrameSidebarWinContainer;
@@ -252,6 +253,8 @@ class SAL_DLLPUBLIC_RTTI SwPostItMgr final : public 
SfxListener,
         void PaintTile(OutputDevice& rRenderContext);
 
         sw::sidebarwindows::SidebarPosition GetSidebarPos(const Point& 
rPointLogic);
+
+        void SetForceShow(bool bForce) { mbForceShow = bForce; }
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
index a1c14fb3c65d..fc1f20a85555 100644
--- a/sw/source/core/view/vprint.cxx
+++ b/sw/source/core/view/vprint.cxx
@@ -520,10 +520,12 @@ bool SwViewShell::PrintOrPDFExport(
 
         if (pPostItManager)
         {
+            pPostItManager->SetForceShow(true);
             pPostItManager->CalcRects();
             pPostItManager->LayoutPostIts();
             pPostItManager->DrawNotesForPage(pOutDev, nPage-1);
             oOrigHeight.emplace(pStPage->getFrameArea().Height());
+            pPostItManager->SetForceShow(false);
         }
     }
 
diff --git a/sw/source/uibase/docvw/AnnotationWin2.cxx 
b/sw/source/uibase/docvw/AnnotationWin2.cxx
index 83344e82d2e2..667266a2cfff 100644
--- a/sw/source/uibase/docvw/AnnotationWin2.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin2.cxx
@@ -172,6 +172,26 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, 
const Point& rPt)
         
pPDFExtOutDevData->WrapBeginStructureElement(vcl::PDFWriter::NonStructElement, 
OUString());
     }
 
+    auto lclSizePixelToLogic = [this](Size szs) {
+        // In LOK without tiled annotations, SwAnnotationWin desn't have the
+        // right conversion when printing to PDF but mxSidebarTextControl does
+        if (comphelper::LibreOfficeKit::isActive()
+            && !comphelper::LibreOfficeKit::isTiledAnnotations())
+            return 
mxSidebarTextControl->GetDrawingArea()->get_ref_device().PixelToLogic(szs);
+        else
+            return PixelToLogic(szs);
+    };
+
+    auto lclPointPixelToLogic = [this](Point pnt) {
+        // In LOK without tiled annotations, SwAnnotationWin desn't have the
+        // right conversion when printing to PDF but mxSidebarTextControl does
+        if (comphelper::LibreOfficeKit::isActive()
+            && !comphelper::LibreOfficeKit::isTiledAnnotations())
+            return 
mxSidebarTextControl->GetDrawingArea()->get_ref_device().PixelToLogic(pnt);
+        else
+            return PixelToLogic(pnt);
+    };
+
     pDev->Push();
 
     pDev->SetFillColor(mColorDark);
@@ -182,7 +202,7 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, const 
Point& rPt)
     aFont.SetFontHeight(aFont.GetFontHeight() * 20);
     pDev->SetFont(aFont);
 
-    Size aSz = PixelToLogic(GetSizePixel());
+    Size aSz = lclSizePixelToLogic(GetSizePixel());
 
     pDev->DrawRect(tools::Rectangle(rPt, aSz));
 
@@ -190,8 +210,8 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, const 
Point& rPt)
     {
         int x, y, width, height;
         mxMetadataAuthor->get_extents_relative_to(*m_xContainer, x, y, width, 
height);
-        Point aPos(rPt + PixelToLogic(Point(x, y)));
-        Size aSize(PixelToLogic(Size(width, height)));
+        Point aPos(rPt + lclPointPixelToLogic(Point(x, y)));
+        Size aSize(lclSizePixelToLogic(Size(width, height)));
 
         pDev->Push(vcl::PushFlags::CLIPREGION);
         pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
@@ -203,8 +223,8 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, const 
Point& rPt)
     {
         int x, y, width, height;
         mxMetadataDate->get_extents_relative_to(*m_xContainer, x, y, width, 
height);
-        Point aPos(rPt + PixelToLogic(Point(x, y)));
-        Size aSize(PixelToLogic(Size(width, height)));
+        Point aPos(rPt + lclPointPixelToLogic(Point(x, y)));
+        Size aSize(lclSizePixelToLogic(Size(width, height)));
 
         pDev->Push(vcl::PushFlags::CLIPREGION);
         pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
@@ -216,8 +236,8 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, const 
Point& rPt)
     {
         int x, y, width, height;
         mxMetadataResolved->get_extents_relative_to(*m_xContainer, x, y, 
width, height);
-        Point aPos(rPt + PixelToLogic(Point(x, y)));
-        Size aSize(PixelToLogic(Size(width, height)));
+        Point aPos(rPt + lclPointPixelToLogic(Point(x, y)));
+        Size aSize(lclSizePixelToLogic(Size(width, height)));
 
         pDev->Push(vcl::PushFlags::CLIPREGION);
         pDev->IntersectClipRegion(tools::Rectangle(aPos, aSize));
@@ -244,7 +264,7 @@ void SwAnnotationWin::DrawForPage(OutputDevice* pDev, const 
Point& rPt)
         // completely shown
         int x, y, width, height;
         mxMenuButton->get_extents_relative_to(*m_xContainer, x, y, width, 
height);
-        Point aPos(rPt + PixelToLogic(Point(x, y)));
+        Point aPos(rPt + lclPointPixelToLogic(Point(x, y)));
         pDev->DrawText(aPos, u"..."_ustr);
     }
 
@@ -833,9 +853,6 @@ void SwAnnotationWin::DoResize()
 
 void SwAnnotationWin::SetSizePixel( const Size& rNewSize )
 {
-    if (comphelper::LibreOfficeKit::isActive())
-        return;
-
     InterimItemWindow::SetSizePixel(rNewSize);
 
     if (mpShadow)
diff --git a/sw/source/uibase/docvw/PostItMgr.cxx 
b/sw/source/uibase/docvw/PostItMgr.cxx
index 5bcbdee0c061..a92ba71130e1 100644
--- a/sw/source/uibase/docvw/PostItMgr.cxx
+++ b/sw/source/uibase/docvw/PostItMgr.cxx
@@ -974,10 +974,18 @@ void SwPostItMgr::LayoutPostIts()
 
                             tools::Long Y = mpEditWin->LogicToPixel( 
Point(0,pItem->maLayoutInfo.mPosition.Bottom())).Y();
 
-                            aPostItHeight = ( pPostIt->GetPostItTextHeight() < 
pPostIt->GetMinimumSizeWithoutMeta()
-                                              ? 
pPostIt->GetMinimumSizeWithoutMeta()
-                                              : pPostIt->GetPostItTextHeight() 
)
-                                            + pPostIt->GetMetaHeight();
+                            tools::Long postItPixelTextHeight
+                                = (comphelper::LibreOfficeKit::isActive()
+                                       ? mpEditWin
+                                             ->LogicToPixel(
+                                                 Point(0, 
pPostIt->GetPostItTextHeight()))
+                                             .Y()
+                                       : pPostIt->GetPostItTextHeight());
+                            aPostItHeight
+                                = (postItPixelTextHeight < 
pPostIt->GetMinimumSizeWithoutMeta()
+                                       ? pPostIt->GetMinimumSizeWithoutMeta()
+                                       : postItPixelTextHeight)
+                                  + pPostIt->GetMetaHeight();
                             pPostIt->SetPosSizePixelRect( mlPageBorder ,
                                                           Y - 
GetInitialAnchorDistance(),
                                                           
GetSidebarWidth(true),
@@ -1011,7 +1019,7 @@ void SwPostItMgr::LayoutPostIts()
                     this->Broadcast(SwFormatFieldHint(pFormatField, nWhich, 
mpView));
                 }
 
-                if (!aVisiblePostItList.empty() && ShowNotes())
+                if (!aVisiblePostItList.empty() && bShowNotes)
                 {
                     bool bOldScrollbar = pPage->bScrollbar;
                     pPage->bScrollbar = LayoutByPage(aVisiblePostItList, 
pPage->mPageRect.SVRect(), lNeededHeight);
@@ -1182,6 +1190,10 @@ void SwPostItMgr::DrawNotesForPage(OutputDevice 
*pOutDev, sal_uInt32 nPage)
     assert(nPage < mPages.size());
     if (nPage >= mPages.size())
         return;
+    const bool bEnableMapMode
+        = comphelper::LibreOfficeKit::isActive() && 
!mpEditWin->IsMapModeEnabled();
+    if (bEnableMapMode)
+        mpEditWin->EnableMapMode();
     for (auto const& pItem : mPages[nPage]->mvSidebarItems)
     {
         SwAnnotationWin* pPostIt = pItem->mpPostIt;
@@ -1190,6 +1202,8 @@ void SwPostItMgr::DrawNotesForPage(OutputDevice *pOutDev, 
sal_uInt32 nPage)
         Point aPoint(mpEditWin->PixelToLogic(pPostIt->GetPosPixel()));
         pPostIt->DrawForPage(pOutDev, aPoint);
     }
+    if (bEnableMapMode)
+        mpEditWin->EnableMapMode(false);
 }
 
 void SwPostItMgr::PaintTile(OutputDevice& rRenderContext)
@@ -2275,7 +2289,7 @@ void SwPostItMgr::CorrectPositions()
 bool SwPostItMgr::ShowNotes() const
 {
     // we only want to see notes if Options - Writer - View - Notes is ticked
-    return mpWrtShell->GetViewOptions()->IsPostIts();
+    return mbForceShow || mpWrtShell->GetViewOptions()->IsPostIts();
 }
 
 bool SwPostItMgr::HasNotes() const

Reply via email to