Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


This patches replace MultiSelection with StringRangeEnumerator in
Draw, because StringRangeEnumerator allows duplicated and reversed
ranges, i.e. "1,1,3-1". Second patch contains only cleaning changes.
From 85168ff499322b97256af3f0cb07c5bf7af3bca8 Mon Sep 17 00:00:00 2001
From: Ivan Timofeev <timofeev.i.s@gmail.com>
Date: Sun, 2 Oct 2011 22:18:51 +0400
Subject: [PATCH 1/2] migrate to StringRangeEnumerator in Draw

---
 sd/source/ui/view/DocumentRenderer.cxx |  129 +++++++++++++++++++-------------
 1 files changed, 78 insertions(+), 51 deletions(-)

diff --git a/sd/source/ui/view/DocumentRenderer.cxx b/sd/source/ui/view/DocumentRenderer.cxx
index efb1cbc..94a9508 100644
--- a/sd/source/ui/view/DocumentRenderer.cxx
+++ b/sd/source/ui/view/DocumentRenderer.cxx
@@ -202,14 +202,25 @@ namespace {
             return GetBoolValue("PrintPaperFromSetup", false);
         }
 
-        OUString GetPrinterSelection (void) const
+        bool IsPrintMarkedOnly (void) const
+        {
+            return GetBoolValue("PrintContent", sal_Int32(2));
+        }
+
+        OUString GetPrinterSelection (sal_Int32 nPageCount, sal_Int32 nCurrentPageIndex) const
         {
             sal_Int32 nContent = static_cast<sal_Int32>(mrProperties.getIntValue( "PrintContent", 
0 ));
-            OUString sValue( A2S("all") );
+            OUString sValue = ::rtl::OUStringBuffer(4)
+                .append(static_cast<sal_Int32>(1))
+                .append(static_cast<sal_Unicode>('-'))
+                .append(nPageCount).makeStringAndClear();
+
             if( nContent == 1 )
-                sValue = mrProperties.getStringValue( "PageRange", A2S( "all" ) );
-            else if( nContent == 2 )
-                sValue = A2S( "selection" );
+                sValue = mrProperties.getStringValue( "PageRange", sValue );
+            else if ( nContent == 2 )
+                sValue = nCurrentPageIndex < 0
+                    ? OUString() : OUString::valueOf(nCurrentPageIndex);
+
             return sValue;
         }
 
@@ -313,8 +324,7 @@ namespace {
     public:
         PrintInfo (
             const Printer* pPrinter,
-            const OUString& rsPrinterSelection,
-            const ::boost::shared_ptr<ViewShell> pView)
+            const bool bPrintMarkedOnly)
             : mpPrinter(pPrinter),
               mnDrawMode(DRAWMODE_DEFAULT),
               msTimeDate(),
@@ -323,8 +333,7 @@ namespace {
               maPageSize(0,0),
               meOrientation(ORIENTATION_PORTRAIT),
               maMap(),
-              maSelection(rsPrinterSelection, pView ? pView->getCurrentPage() : NULL),
-              mbPrintMarkedOnly(maSelection.IsMarkedOnly())
+              mbPrintMarkedOnly(bPrintMarkedOnly)
         {}
 
         const Printer* mpPrinter;
@@ -335,8 +344,7 @@ namespace {
         Size maPageSize;
         Orientation meOrientation;
         MapMode maMap;
-        const Selection maSelection;
-        bool mbPrintMarkedOnly;
+        const bool mbPrintMarkedOnly;
     };
 
 
@@ -1440,7 +1448,12 @@ private:
         mbIsDisposed = true;
     }
 
-
+    sal_Int32 GetCurrentPageIndex()
+    {
+        ViewShell *pShell = mrBase.GetMainViewShell().get();
+        SdPage *pCurrentPage = pShell ? pShell->getCurrentPage() : NULL;
+        return pCurrentPage ? (pCurrentPage->GetPageNum()-1)/2 : -1;
+    }
 
     /** Determine and set the paper orientation.
     */
@@ -1494,7 +1507,7 @@ private:
 
         ViewShell* pShell = mrBase.GetMainViewShell().get();
 
-        PrintInfo aInfo (mpPrinter, mpOptions->GetPrinterSelection(), mrBase.GetMainViewShell());
+        PrintInfo aInfo (mpPrinter, mpOptions->IsPrintMarkedOnly());
 
         if (aInfo.mpPrinter!=NULL && pShell!=NULL)
         {
@@ -1691,12 +1704,10 @@ private:
     SdPage* GetFilteredPage (
         const sal_Int32 nPageIndex,
         const PageKind ePageKind,
-        const PrintInfo& rInfo) const
+        const PrintInfo& /*rInfo*/) const
     {
         OSL_ASSERT(mrBase.GetDocument() != NULL);
         OSL_ASSERT(nPageIndex>=0);
-        if ( ! rInfo.maSelection.IsSelected(nPageIndex))
-            return NULL;
         SdPage* pPage = mrBase.GetDocument()->GetSdPage(
             sal::static_int_cast<sal_uInt16>(nPageIndex),
             ePageKind);
@@ -1748,20 +1759,22 @@ private:
 
         long nPageH = aOutRect.GetHeight();
 
-        for (sal_uInt16
-                 nIndex=0,
-                 nCount=mrBase.GetDocument()->GetSdPageCount(PK_STANDARD);
-             nIndex < nCount;
-             )
+        ::std::vector< sal_Int32 > aPages;
+        sal_Int32 nPageCount = mrBase.GetDocument()->GetSdPageCount(PK_STANDARD);
+        StringRangeEnumerator::getRangesFromString(
+            mpOptions->GetPrinterSelection(nPageCount, GetCurrentPageIndex()),
+            aPages, 0, nPageCount-1);
+
+        for (size_t nIndex = 0, nCount = aPages.size(); nIndex < nCount;)
         {
             pOutliner->Clear();
-            pOutliner->SetFirstPageNumber(nIndex+1);
+            pOutliner->SetFirstPageNumber(aPages[nIndex]+1);
 
             Paragraph* pPara = NULL;
             sal_Int32 nH (0);
             while (nH < nPageH && nIndex<nCount)
             {
-                SdPage* pPage = GetFilteredPage(nIndex, PK_STANDARD, rInfo);
+                SdPage* pPage = GetFilteredPage(aPages[nIndex], PK_STANDARD, rInfo);
                 ++nIndex;
                 if (pPage == NULL)
                     continue;
@@ -1949,31 +1962,37 @@ private:
         mrBase.GetDocument()->setHandoutPageCount( nHandoutPageCount );
 
         // Distribute pages to handout pages.
+        StringRangeEnumerator aRangeEnum(
+            mpOptions->GetPrinterSelection(nPageCount, GetCurrentPageIndex()),
+            0, nPageCount-1);
         ::std::vector<sal_uInt16> aPageIndices;
-        std::vector<SdPage*> aPagesVector;
-        for (sal_uInt16
-                 nIndex=0,
-                 nCount= nPageCount,
-                 nHandoutPageIndex=0;
-             nIndex <= nCount;
-             ++nIndex)
+        sal_uInt16 nPrinterPageIndex = 0;
+        StringRangeEnumerator::Iterator it = aRangeEnum.begin(), itEnd = aRangeEnum.end();
+        bool bLastLoop = false;
+        while (!bLastLoop)
         {
-            if (nIndex < nCount)
+            if (it != itEnd)
             {
-                if (GetFilteredPage(nIndex, PK_STANDARD, rInfo) == NULL)
+                sal_Int32 nPageIndex = *it;
+                ++it;
+                if (GetFilteredPage(nPageIndex, PK_STANDARD, rInfo) == NULL)
                     continue;
-                aPageIndices.push_back(nIndex);
+                aPageIndices.push_back(nPageIndex);
+            }
+            else
+            {
+                bLastLoop = true;
             }
 
             // Create a printer page when we have found one page for each
             // placeholder or when this is the last (and special) loop.
             if (aPageIndices.size() == nShapeCount
-                || nIndex==nCount)
+                || bLastLoop)
             {
                 maPrinterPages.push_back(
                     ::boost::shared_ptr<PrinterPage>(
                         new HandoutPrinterPage(
-                            nHandoutPageIndex++,
+                            nPrinterPageIndex++,
                             aPageIndices,
                             aMap,
                             rInfo.msTimeDate,
@@ -2031,13 +2050,17 @@ private:
         pViewShell->WriteFrameViewData();
         Point aPtZero;
 
-        for (sal_uInt16
-                 nIndex=0,
-                 nCount=mrBase.GetDocument()->GetSdPageCount(PK_STANDARD);
-             nIndex < nCount;
-             ++nIndex)
-        {
-            SdPage* pPage = GetFilteredPage(nIndex, ePageKind, rInfo);
+        sal_Int32 nPageCount = mrBase.GetDocument()->GetSdPageCount(PK_STANDARD);
+        StringRangeEnumerator aRangeEnum(
+            mpOptions->GetPrinterSelection(nPageCount, GetCurrentPageIndex()),
+            0, nPageCount-1);
+        for (StringRangeEnumerator::Iterator
+                 it = aRangeEnum.begin(),
+                 itEnd = aRangeEnum.end();
+             it != itEnd;
+             ++it)
+        {
+            SdPage* pPage = GetFilteredPage(*it, ePageKind, rInfo);
             if (pPage == NULL)
                 continue;
 
@@ -2090,12 +2113,12 @@ private:
                 && aPageHeight < rInfo.maPrintSize.Height())
             {
                 // Put multiple slides on one printer page.
-                PrepareTiledPage(nIndex, *pPage, ePageKind, rInfo);
+                PrepareTiledPage(*it, *pPage, ePageKind, rInfo);
             }
             else
             {
                 rInfo.maMap = aMap;
-                PrepareScaledPage(nIndex, *pPage, ePageKind, rInfo);
+                PrepareScaledPage(*it, *pPage, ePageKind, rInfo);
             }
         }
     }
@@ -2155,16 +2178,20 @@ private:
         }
 
         // create vector of pages to print
+        sal_Int32 nPageCount = mrBase.GetDocument()->GetSdPageCount(ePageKind);
+        StringRangeEnumerator aRangeEnum(
+            mpOptions->GetPrinterSelection(nPageCount, GetCurrentPageIndex()),
+            0, nPageCount-1);
         ::std::vector< sal_uInt16 > aPageVector;
-        for (sal_uInt16
-                 nIndex=0,
-                 nCount=mrBase.GetDocument()->GetSdPageCount(ePageKind);
-             nIndex < nCount;
-             ++nIndex)
+        for (StringRangeEnumerator::Iterator
+                 it = aRangeEnum.begin(),
+                 itEnd = aRangeEnum.end();
+             it != itEnd;
+             ++it)
         {
-            SdPage* pPage = GetFilteredPage(nIndex, ePageKind, rInfo);
+            SdPage* pPage = GetFilteredPage(*it, ePageKind, rInfo);
             if (pPage != NULL)
-                aPageVector.push_back(nIndex);
+                aPageVector.push_back(*it);
         }
 
         // create pairs of pages to print on each page
-- 
1.7.6.3

From feb15e21506f2c36fbf8c0a70f23be9a4fa16fc8 Mon Sep 17 00:00:00 2001
From: Ivan Timofeev <timofeev.i.s@gmail.com>
Date: Sun, 2 Oct 2011 23:04:55 +0400
Subject: [PATCH 2/2] remove unused and dead code in DocumentRenderer.cxx

---
 sd/source/ui/view/DocumentRenderer.cxx |   96 ++------------------------------
 1 files changed, 5 insertions(+), 91 deletions(-)

diff --git a/sd/source/ui/view/DocumentRenderer.cxx b/sd/source/ui/view/DocumentRenderer.cxx
index 94a9508..6c7a234 100644
--- a/sd/source/ui/view/DocumentRenderer.cxx
+++ b/sd/source/ui/view/DocumentRenderer.cxx
@@ -272,49 +272,6 @@ namespace {
 
 
 
-    /** This class is like MultiSelection but understands two special values.
-        "all" indicates that all pages are selected.  "selection" indicates that no
-        pages but a set of shapes is selected.
-    */
-    class Selection
-    {
-    public:
-        Selection (const OUString& rsSelection, const SdPage* pCurrentPage)
-            : mbAreAllPagesSelected(rsSelection.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("all"))),
-              
mbIsShapeSelection(rsSelection.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("selection"))),
-              mnCurrentPageIndex(pCurrentPage!=NULL ? (pCurrentPage->GetPageNum()-1)/2 : -1),
-              mpSelectedPages()
-        {
-            if ( ! (mbAreAllPagesSelected || mbIsShapeSelection))
-                mpSelectedPages.reset(new MultiSelection(rsSelection));
-        }
-
-        bool IsMarkedOnly (void) const
-        {
-            return mbIsShapeSelection;
-        }
-
-        /** Call with a 0 based page index.
-        */
-        bool IsSelected (const sal_Int32 nIndex) const
-        {
-            if (mbAreAllPagesSelected)
-                return true;
-            else if (mpSelectedPages)
-                return mpSelectedPages->IsSelected(nIndex+1);
-            else if (mbIsShapeSelection && nIndex==mnCurrentPageIndex)
-                return true;
-            else
-                return false;
-        }
-
-    private:
-        const bool mbAreAllPagesSelected;
-        const bool mbIsShapeSelection;
-        const sal_Int32 mnCurrentPageIndex;
-        ::boost::scoped_ptr<MultiSelection> mpSelectedPages;
-    };
-
     /** A collection of values that helps to reduce the number of arguments
         given to some functions.  Note that not all values are set at the
         same time.
@@ -1480,7 +1437,6 @@ private:
           )
         {
             maPrintSize = awt::Size(aPaperSize.Height(), aPaperSize.Width());
-            //            rInfo.maPrintSize = Size(rInfo.maPrintSize.Height(), 
rInfo.maPrintSize.Width());
         }
         else
         {
@@ -1560,13 +1516,6 @@ private:
                     aInfo.mnDrawMode = DRAWMODE_DEFAULT;
             }
 
-            // check if selected range of pages contains transparent objects
-            /*
-            const bool bPrintPages (bPrintNotes || bPrintDraw || bPrintHandout);
-            const bool bContainsTransparency (bPrintPages && ContainsTransparency());
-            if (pPrinter->InitJob (mrBase.GetWindow(), !bIsAPI && bContainsTransparency))
-            */
-
             if (mpOptions->IsDraw())
                 PrepareStdOrNotes(PK_STANDARD, aInfo);
             if (mpOptions->IsNotes())
@@ -1667,35 +1616,6 @@ private:
 
 
 
-    /** Detect whether any of the slides that are to be printed contains
-        partially transparent or translucent shapes.
-    */
-    bool ContainsTransparency (const PrintInfo& rInfo) const
-    {
-        // const bool bPrintExcluded (mpOptions->IsPrintExcluded());
-        bool bContainsTransparency = false;
-
-        for (sal_uInt16
-                 nIndex=0,
-                 nCount=mrBase.GetDocument()->GetSdPageCount(PK_STANDARD);
-             nIndex < nCount && !bContainsTransparency;
-             ++nIndex)
-        {
-            SdPage* pPage = GetFilteredPage(nIndex, PK_STANDARD, rInfo);
-            if (pPage == NULL)
-                continue;
-
-            bContainsTransparency = pPage->HasTransparentObjects();
-            if ( ! bContainsTransparency && pPage->TRG_HasMasterPage())
-                bContainsTransparency = pPage->TRG_GetMasterPage().HasTransparentObjects();
-        }
-
-        return bContainsTransparency;
-    }
-
-
-
-
     /** Detect whether the specified slide is to be printed.
         @return
             When the slide is not to be printed then <NULL/> is returned.
@@ -1703,8 +1623,7 @@ private:
     */
     SdPage* GetFilteredPage (
         const sal_Int32 nPageIndex,
-        const PageKind ePageKind,
-        const PrintInfo& /*rInfo*/) const
+        const PageKind ePageKind) const
     {
         OSL_ASSERT(mrBase.GetDocument() != NULL);
         OSL_ASSERT(nPageIndex>=0);
@@ -1732,7 +1651,6 @@ private:
     {
         MapMode aMap (rInfo.maMap);
         Point aPageOfs (rInfo.mpPrinter->GetPageOffset() );
-        // aMap.SetOrigin(Point() - aPageOfs);
         aMap.SetScaleX(Fraction(1,2));
         aMap.SetScaleY(Fraction(1,2));
         mpPrinter->SetMapMode(aMap);
@@ -1774,7 +1692,7 @@ private:
             sal_Int32 nH (0);
             while (nH < nPageH && nIndex<nCount)
             {
-                SdPage* pPage = GetFilteredPage(aPages[nIndex], PK_STANDARD, rInfo);
+                SdPage* pPage = GetFilteredPage(aPages[nIndex], PK_STANDARD);
                 ++nIndex;
                 if (pPage == NULL)
                     continue;
@@ -1920,9 +1838,6 @@ private:
 
         MapMode aMap (rInfo.maMap);
         const Point aPageOfs (rInfo.mpPrinter->GetPageOffset());
-        //DrawView* pPrintView;
-
-        // aMap.SetOrigin(Point() - aPageOfs);
 
         if ( bScalePage )
         {
@@ -1975,7 +1890,7 @@ private:
             {
                 sal_Int32 nPageIndex = *it;
                 ++it;
-                if (GetFilteredPage(nPageIndex, PK_STANDARD, rInfo) == NULL)
+                if (GetFilteredPage(nPageIndex, PK_STANDARD) == NULL)
                     continue;
                 aPageIndices.push_back(nPageIndex);
             }
@@ -2027,7 +1942,6 @@ private:
             return;
 
         MapMode aMap (rInfo.maMap);
-        // aMap.SetOrigin(Point() - rInfo.mpPrinter->GetPageOffset());
         rInfo.maMap = aMap;
 
         if (mpOptions->IsBooklet())
@@ -2060,7 +1974,7 @@ private:
              it != itEnd;
              ++it)
         {
-            SdPage* pPage = GetFilteredPage(*it, ePageKind, rInfo);
+            SdPage* pPage = GetFilteredPage(*it, ePageKind);
             if (pPage == NULL)
                 continue;
 
@@ -2189,7 +2103,7 @@ private:
              it != itEnd;
              ++it)
         {
-            SdPage* pPage = GetFilteredPage(*it, ePageKind, rInfo);
+            SdPage* pPage = GetFilteredPage(*it, ePageKind);
             if (pPage != NULL)
                 aPageVector.push_back(*it);
         }
-- 
1.7.6.3


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.