[Libreoffice-commits] core.git: sw/inc sw/source

Caolán McNamara caolanm at redhat.com
Thu May 15 04:40:45 PDT 2014


 sw/inc/EnhancedPDFExportHelper.hxx              |   11 ++
 sw/source/core/text/EnhancedPDFExportHelper.cxx |  108 ++++++++++++++++++++----
 sw/source/core/uibase/uno/unotxdoc.cxx          |    9 +-
 3 files changed, 106 insertions(+), 22 deletions(-)

New commits:
commit c1cad9bbc3d2721304e7ac592b5d7396ad1a7c98
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu May 15 12:38:10 2014 +0100

    Resolves: fdo#78204 adjust note icons on comments-in-margins case
    
    the page has been scaled by 75% and vertically centered so the page positions
    need to be also adjusted.
    
    Change-Id: I7ab6b4956933ba444441c857e78aee8e5c1cf97a

diff --git a/sw/inc/EnhancedPDFExportHelper.hxx b/sw/inc/EnhancedPDFExportHelper.hxx
index d8c4ef4..d236317 100644
--- a/sw/inc/EnhancedPDFExportHelper.hxx
+++ b/sw/inc/EnhancedPDFExportHelper.hxx
@@ -36,6 +36,8 @@ namespace vcl
 class OutputDevice;
 class SwFrm;
 class SwLinePortion;
+class SwPageFrm;
+class SwPrintData;
 class SwTxtPainter;
 class SwEditShell;
 class StringRangeEnumerator;
@@ -207,6 +209,8 @@ class SwEnhancedPDFExportHelper
     bool mbSkipEmptyPages;
     bool mbEditEngineOnly;
 
+    const SwPrintData& mrPrintData;
+
     static TableColumnsMap aTableColumnsMap;
     static LinkIdMap aLinkIdMap;
     static NumListIdMap aNumListIdMap;
@@ -229,7 +233,8 @@ class SwEnhancedPDFExportHelper
                                OutputDevice& rOut,
                                const OUString& rPageRange,
                                bool bSkipEmptyPages,
-                               bool bEditEngineOnly );
+                               bool bEditEngineOnly,
+                               const SwPrintData& rPrintData );
 
     ~SwEnhancedPDFExportHelper();
 
@@ -240,6 +245,10 @@ class SwEnhancedPDFExportHelper
     static FrmTagIdMap& GetFrmTagIdMap() { return aFrmTagIdMap; }
 
     static LanguageType GetDefaultLanguage() {return eLanguageDefault; }
+
+    //scale and position rRectangle if we're scaling due to notes in margins.
+    Rectangle SwRectToPDFRect(const SwPageFrm* pCurrPage,
+        const Rectangle& rRectangle) const;
 };
 
 #endif
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index f310c5f..6afa51d 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -69,6 +69,7 @@
 #include <itrpaint.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <IMark.hxx>
+#include <printdata.hxx>
 #include <SwNodeNum.hxx>
 #include <switerator.hxx>
 #include <stack>
@@ -677,7 +678,9 @@ void SwTaggedPDFHelper::SetAttributes( vcl::PDFWriter::StructElement eType )
                  ( pFrm->IsTabFrm() &&
                    !static_cast<const SwTabFrm*>(pFrm)->IsFollow() &&
                    !static_cast<const SwTabFrm*>(pFrm)->HasFollow() ) )
-                mpPDFExtOutDevData->SetStructureBoundingBox( pFrm->Frm().SVRect() );
+            {
+                mpPDFExtOutDevData->SetStructureBoundingBox(pFrm->Frm().SVRect());
+            }
         }
 
         if ( bRowSpan )
@@ -1447,12 +1450,14 @@ SwEnhancedPDFExportHelper::SwEnhancedPDFExportHelper( SwEditShell& rSh,
                                                       OutputDevice& rOut,
                                                       const OUString& rPageRange,
                                                       bool bSkipEmptyPages,
-                                                      bool bEditEngineOnly )
+                                                      bool bEditEngineOnly,
+                                                      const SwPrintData& rPrintData )
     : mrSh( rSh ),
       mrOut( rOut ),
       mpRangeEnum( 0 ),
       mbSkipEmptyPages( bSkipEmptyPages ),
-      mbEditEngineOnly( bEditEngineOnly )
+      mbEditEngineOnly( bEditEngineOnly ),
+      mrPrintData( rPrintData )
 {
     if ( !rPageRange.isEmpty() )
         mpRangeEnum = new StringRangeEnumerator( rPageRange, 0, mrSh.GetPageCount()-1 );
@@ -1502,6 +1507,29 @@ SwEnhancedPDFExportHelper::~SwEnhancedPDFExportHelper()
     delete mpRangeEnum;
 }
 
+Rectangle SwEnhancedPDFExportHelper::SwRectToPDFRect(const SwPageFrm* pCurrPage,
+    const Rectangle& rRectangle) const
+{
+    sal_Int16 nPostItMode = mrPrintData.GetPrintPostIts();
+    if (nPostItMode != POSTITS_INMARGINS)
+        return rRectangle;
+    //the page has been scaled by 75% and vertically centered, so adjust these
+    //rectangles equivalently
+    Rectangle aRect(rRectangle);
+    Size aRectSize(aRect.GetSize());
+    double fScale = 0.75;
+    aRectSize.Width() = (aRectSize.Width() * fScale);
+    aRectSize.Height() = (aRectSize.Height() * fScale);
+    long nOrigHeight = pCurrPage->Frm().Height();
+    long nNewHeight = nOrigHeight*fScale;
+    long nShiftY = (nOrigHeight-nNewHeight)/2;
+    aRect.Left() = (aRect.Left() * fScale);
+    aRect.Top() = (aRect.Top() * fScale);
+    aRect.Move(0, nShiftY);
+    aRect.SetSize(aRectSize);
+    return aRect;
+}
+
 void SwEnhancedPDFExportHelper::EnhancedPDFExport()
 {
     vcl::PDFExtOutDevData* pPDFExtOutDevData =
@@ -1555,6 +1583,8 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                     {
                         // Link Rectangle
                         const SwRect& rNoteRect = mrSh.GetCharRect();
+                        const SwPageFrm* pCurrPage =
+                            static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
 
                         // Link PageNums
                         std::vector<sal_Int32> aNotePageNums = CalcOutputPageNums( rNoteRect );
@@ -1580,7 +1610,8 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                             aNote.Contents = pField->GetTxt();
 
                             // Link Export
-                            pPDFExtOutDevData->CreateNote( rNoteRect.SVRect(), aNote, aNotePageNums[nNumIdx] );
+                            Rectangle aRect(SwRectToPDFRect(pCurrPage, rNoteRect.SVRect()));
+                            pPDFExtOutDevData->CreateNote(aRect, aNote, aNotePageNums[nNumIdx]);
                         }
                     }
                 }
@@ -1632,6 +1663,9 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                     aTmp.insert( aTmp.begin(), mrSh.SwCrsrShell::_GetCrsr()->begin(), mrSh.SwCrsrShell::_GetCrsr()->end() );
                     OSL_ENSURE( !aTmp.empty(), "Enhanced pdf export - rectangles are missing" );
 
+                    const SwPageFrm* pSelectionPage =
+                        static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                     // Create the destination for internal links:
                     sal_Int32 nDestId = -1;
                     if ( bIntern )
@@ -1643,12 +1677,18 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                         // Destination Rectangle
                         const SwRect& rDestRect = mrSh.GetCharRect();
 
+                        const SwPageFrm* pCurrPage =
+                            static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                         // Destination PageNum
                         const sal_Int32 nDestPageNum = CalcOutputPageNum( rDestRect );
 
                         // Destination Export
                         if ( -1 != nDestPageNum )
-                            nDestId = pPDFExtOutDevData->CreateDest( rDestRect.SVRect(), nDestPageNum );
+                        {
+                            Rectangle aRect(SwRectToPDFRect(pCurrPage, rDestRect.SVRect()));
+                            nDestId = pPDFExtOutDevData->CreateDest(aRect, nDestPageNum);
+                        }
                     }
 
                     if ( !bIntern || -1 != nDestId )
@@ -1670,8 +1710,9 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                             for ( size_t nNumIdx = 0; nNumIdx < aLinkPageNums.size(); ++nNumIdx )
                             {
                                 // Link Export
+                                Rectangle aRect(SwRectToPDFRect(pSelectionPage, rLinkRect.SVRect()));
                                 const sal_Int32 nLinkId =
-                                    pPDFExtOutDevData->CreateLink( rLinkRect.SVRect(), aLinkPageNums[nNumIdx] );
+                                    pPDFExtOutDevData->CreateLink(aRect, aLinkPageNums[nNumIdx]);
 
                                 // Store link info for tagged pdf output:
                                 const IdMapEntry aLinkEntry( rLinkRect, nLinkId );
@@ -1705,6 +1746,9 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
             if ( RES_DRAWFRMFMT != pFrmFmt->Which() &&
                  SFX_ITEM_SET == pFrmFmt->GetAttrSet().GetItemState( RES_URL, true, &pItem ) )
             {
+                const SwPageFrm* pCurrPage =
+                    static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                 OUString aURL( static_cast<const SwFmtURL*>(pItem)->GetURL() );
                 const bool bIntern = '#' == aURL[0];
 
@@ -1719,12 +1763,17 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                     // Destination Rectangle
                     const SwRect& rDestRect = mrSh.GetCharRect();
 
+                    pCurrPage = static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                     // Destination PageNum
                     const sal_Int32 nDestPageNum = CalcOutputPageNum( rDestRect );
 
                     // Destination Export
                     if ( -1 != nDestPageNum )
-                        nDestId = pPDFExtOutDevData->CreateDest( rDestRect.SVRect(), nDestPageNum );
+                    {
+                        Rectangle aRect(SwRectToPDFRect(pCurrPage, rDestRect.SVRect()));
+                        nDestId = pPDFExtOutDevData->CreateDest(aRect, nDestPageNum);
+                    }
                 }
 
                 if ( !bIntern || -1 != nDestId )
@@ -1738,8 +1787,9 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                     // Link Export
                     for ( size_t nNumIdx = 0; nNumIdx < aLinkPageNums.size(); ++nNumIdx )
                     {
+                        Rectangle aRect(SwRectToPDFRect(pCurrPage, aLinkRect.SVRect()));
                         const sal_Int32 nLinkId =
-                            pPDFExtOutDevData->CreateLink( aLinkRect.SVRect(), aLinkPageNums[nNumIdx] );
+                            pPDFExtOutDevData->CreateLink(aRect, aLinkPageNums[nNumIdx]);
 
                         // Connect Link and Destination:
                         if ( bIntern )
@@ -1801,13 +1851,16 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                     mrSh.GotoRefMark( rRefName, pField->GetSubType(), pField->GetSeqNo() );
                     const SwRect& rDestRect = mrSh.GetCharRect();
 
+                    const SwPageFrm* pCurrPage = static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                     // Destination PageNum
                     const sal_Int32 nDestPageNum = CalcOutputPageNum( rDestRect );
 
                     if ( -1 != nDestPageNum )
                     {
                         // Destination Export
-                        const sal_Int32 nDestId = pPDFExtOutDevData->CreateDest( rDestRect.SVRect(), nDestPageNum );
+                        Rectangle aRect(SwRectToPDFRect(pCurrPage, rDestRect.SVRect()));
+                        const sal_Int32 nDestId = pPDFExtOutDevData->CreateDest(aRect, nDestPageNum);
 
                         // #i44368# Links in Header/Footer
                         const SwPosition aPos( *pTNd );
@@ -1826,8 +1879,9 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                             for ( size_t nNumIdx = 0; nNumIdx < aLinkPageNums.size(); ++nNumIdx )
                             {
                                 // Link Export
+                                aRect = SwRectToPDFRect(pCurrPage, rLinkRect.SVRect());
                                 const sal_Int32 nLinkId =
-                                    pPDFExtOutDevData->CreateLink( rLinkRect.SVRect(), aLinkPageNums[nNumIdx] );
+                                    pPDFExtOutDevData->CreateLink(aRect, aLinkPageNums[nNumIdx]);
 
                                 // Store link info for tagged pdf output:
                                 const IdMapEntry aLinkEntry( rLinkRect, nLinkId );
@@ -1893,14 +1947,18 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                 // Destination Rectangle
                 const SwRect& rDestRect = mrSh.GetCharRect();
 
+                const SwPageFrm* pCurrPage =
+                    static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                 // Destination PageNum
                 const sal_Int32 nDestPageNum = CalcOutputPageNum( rDestRect );
 
                 for ( size_t nNumIdx = 0; nNumIdx < aLinkPageNums.size(); ++nNumIdx )
                 {
                     // Link Export
+                    Rectangle aRect(SwRectToPDFRect(pCurrPage, aLinkRect.SVRect()));
                     const sal_Int32 nLinkId =
-                        pPDFExtOutDevData->CreateLink( aLinkRect.SVRect(), aLinkPageNums[nNumIdx] );
+                        pPDFExtOutDevData->CreateLink(aRect, aLinkPageNums[nNumIdx]);
 
                     // Store link info for tagged pdf output:
                     const IdMapEntry aLinkEntry( aLinkRect, nLinkId );
@@ -1908,8 +1966,9 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
 
                     if ( -1 != nDestPageNum )
                     {
+                        aRect = SwRectToPDFRect(pCurrPage, rDestRect.SVRect());
                         // Destination Export
-                        const sal_Int32 nDestId = pPDFExtOutDevData->CreateDest( rDestRect.SVRect(), nDestPageNum );
+                        const sal_Int32 nDestId = pPDFExtOutDevData->CreateDest(rDestRect.SVRect(), nDestPageNum);
 
                         // Connect Link and Destination:
                         pPDFExtOutDevData->SetLinkDest( nLinkId, nDestId );
@@ -1954,14 +2013,18 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                 mrSh.GotoOutline(i);
                 const SwRect& rDestRect = mrSh.GetCharRect();
 
+                const SwPageFrm* pCurrPage =
+                    static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                 // Destination PageNum
                 const sal_Int32 nDestPageNum = CalcOutputPageNum( rDestRect );
 
                 if ( -1 != nDestPageNum )
                 {
                     // Destination Export
+                    Rectangle aRect(SwRectToPDFRect(pCurrPage, rDestRect.SVRect()));
                     const sal_Int32 nDestId =
-                        pPDFExtOutDevData->CreateDest( rDestRect.SVRect(), nDestPageNum );
+                        pPDFExtOutDevData->CreateDest(aRect, nDestPageNum);
 
                     // Outline entry text
                     const OUString& rEntry = mrSh.getIDocumentOutlineNodesAccess()->getOutlineText( i, true, false, false );
@@ -1999,12 +2062,18 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                 // Destination Rectangle
                 const SwRect& rDestRect = mrSh.GetCharRect();
 
+                const SwPageFrm* pCurrPage =
+                    static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                 // Destination PageNum
                 const sal_Int32 nDestPageNum = CalcOutputPageNum( rDestRect );
 
                 // Destination Export
                 if ( -1 != nDestPageNum )
-                    pPDFExtOutDevData->CreateNamedDest( sBkName, rDestRect.SVRect(), nDestPageNum );
+                {
+                    Rectangle aRect(SwRectToPDFRect(pCurrPage, rDestRect.SVRect()));
+                    pPDFExtOutDevData->CreateNamedDest(sBkName, aRect, nDestPageNum);
+                }
             }
             mrSh.SwCrsrShell::ClearMark();
             //<--- i56629
@@ -2030,22 +2099,26 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
                 // Destination Rectangle
                 const SwRect& rDestRect = mrSh.GetCharRect();
 
+                const SwPageFrm* pCurrPage =
+                    static_cast<const SwPageFrm*>( mrSh.GetLayout()->Lower() );
+
                 // Destination PageNum
                 const sal_Int32 nDestPageNum = CalcOutputPageNum( rDestRect );
 
                 if ( -1 != nDestPageNum )
                 {
+                    Rectangle aRect(SwRectToPDFRect(pCurrPage, rDestRect.SVRect()));
                     if ( aIBeg->nLinkId != -1 )
                     {
                         // Destination Export
-                        const sal_Int32 nDestId = pPDFExtOutDevData->CreateDest( rDestRect.SVRect(), nDestPageNum );
+                        const sal_Int32 nDestId = pPDFExtOutDevData->CreateDest(aRect, nDestPageNum);
 
                         // Connect Link and Destination:
                         pPDFExtOutDevData->SetLinkDest( aIBeg->nLinkId, nDestId );
                     }
                     else
                     {
-                        pPDFExtOutDevData->DescribeRegisteredDest( aIBeg->nDestId, rDestRect.SVRect(), nDestPageNum );
+                        pPDFExtOutDevData->DescribeRegisteredDest(aIBeg->nDestId, aRect, nDestPageNum);
                     }
                 }
             }
@@ -2161,8 +2234,9 @@ void SwEnhancedPDFExportHelper::MakeHeaderFooterLinks( vcl::PDFExtOutDevData& rP
                 for ( size_t nNumIdx = 0; nNumIdx < aHFLinkPageNums.size(); ++nNumIdx )
                 {
                     // Link Export
+                    Rectangle aRect(SwRectToPDFRect(pPageFrm, aHFLinkRect.SVRect()));
                     const sal_Int32 nHFLinkId =
-                        rPDFExtOutDevData.CreateLink( aHFLinkRect.SVRect(), aHFLinkPageNums[nNumIdx] );
+                        rPDFExtOutDevData.CreateLink(aRect, aHFLinkPageNums[nNumIdx]);
 
                     // Connect Link and Destination:
                     if ( bIntern )
diff --git a/sw/source/core/uibase/uno/unotxdoc.cxx b/sw/source/core/uibase/uno/unotxdoc.cxx
index e535fce..7b29743 100644
--- a/sw/source/core/uibase/uno/unotxdoc.cxx
+++ b/sw/source/core/uibase/uno/unotxdoc.cxx
@@ -3012,13 +3012,14 @@ void SAL_CALL SwXTextDocument::render(
                                             ((SwView*)pView)->GetWrtShellPtr() :
                                             0;
 
+                    SwPrintData const& rSwPrtOptions =
+                        *m_pRenderData->GetSwPrtOptions();
+
                     if (bIsPDFExport && bFirstPage && pWrtShell)
                     {
-                        SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, false );
+                        SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, false, rSwPrtOptions );
                     }
 
-                    SwPrintData const& rSwPrtOptions =
-                        *m_pRenderData->GetSwPrtOptions();
                     if (bPrintProspect)
                         pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
                     else    // normal printing and PDF export
@@ -3032,7 +3033,7 @@ void SAL_CALL SwXTextDocument::render(
 
                     if (bIsPDFExport && bLastPage && pWrtShell)
                     {
-                        SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages,  true );
+                        SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, true, rSwPrtOptions );
                     }
 
                     pVwSh->SetPDFExportOption( false );


More information about the Libreoffice-commits mailing list