LCOV - code coverage report
Current view: top level - sd/source/ui/tools - PreviewRenderer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 128 218 58.7 %
Date: 2012-08-25 Functions: 15 19 78.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 133 436 30.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "PreviewRenderer.hxx"
      31                 :            : 
      32                 :            : #include "DrawDocShell.hxx"
      33                 :            : #include "drawdoc.hxx"
      34                 :            : #include "drawview.hxx"
      35                 :            : #include "sdpage.hxx"
      36                 :            : #include "ViewShell.hxx"
      37                 :            : #include <vcl/virdev.hxx>
      38                 :            : #include <svx/svdpagv.hxx>
      39                 :            : #include <svx/svdoutl.hxx>
      40                 :            : #include <editeng/eeitem.hxx>
      41                 :            : #include <editeng/editstat.hxx>
      42                 :            : #include <vcl/svapp.hxx>
      43                 :            : #include <tools/diagnose_ex.h>
      44                 :            : #include <svx/sdr/contact/viewobjectcontact.hxx>
      45                 :            : #include <svx/sdr/contact/viewcontact.hxx>
      46                 :            : 
      47                 :            : using namespace ::com::sun::star;
      48                 :            : using namespace ::com::sun::star::uno;
      49                 :            : 
      50                 :            : 
      51                 :            : namespace sd {
      52                 :            : 
      53                 :            : const int PreviewRenderer::snSubstitutionTextSize = 11;
      54                 :            : const int PreviewRenderer::snFrameWidth = 1;
      55                 :            : 
      56                 :            : namespace {
      57                 :            :     /** This incarnation of the ViewObjectContactRedirector filters away all
      58                 :            :         PageObj objects, unconditionally.
      59                 :            :     */
      60                 :            :     class ViewRedirector : public ::sdr::contact::ViewObjectContactRedirector
      61                 :            :     {
      62                 :            :     public:
      63                 :            :         ViewRedirector (void);
      64                 :            :         virtual ~ViewRedirector (void);
      65                 :            :         virtual drawinglayer::primitive2d::Primitive2DSequence createRedirectedPrimitive2DSequence(
      66                 :            :             const sdr::contact::ViewObjectContact& rOriginal,
      67                 :            :                 const sdr::contact::DisplayInfo& rDisplayInfo);
      68                 :            :     };
      69                 :            : }
      70                 :            : 
      71                 :            : 
      72                 :            : 
      73                 :            : 
      74                 :            : //===== PreviewRenderer =======================================================
      75                 :            : 
      76                 :        126 : PreviewRenderer::PreviewRenderer (
      77                 :            :     OutputDevice* pTemplate,
      78                 :            :     const bool bHasFrame)
      79                 :          0 :     : mpPreviewDevice (new VirtualDevice()),
      80                 :            :       mpView(NULL),
      81                 :            :       mpDocShellOfView(NULL),
      82                 :            :       mnWidthOfView(0),
      83   [ +  -  +  - ]:        252 :       maFrameColor (svtools::ColorConfig().GetColorValue(svtools::DOCBOUNDARIES).nColor),
      84 [ +  - ][ +  - ]:        252 :       mbHasFrame(bHasFrame)
                 [ +  - ]
      85                 :            : {
      86         [ -  + ]:        126 :     if (pTemplate != NULL)
      87                 :            :     {
      88         [ #  # ]:          0 :         mpPreviewDevice->SetDigitLanguage (pTemplate->GetDigitLanguage());
      89         [ #  # ]:          0 :         mpPreviewDevice->SetBackground(pTemplate->GetBackground());
      90                 :            :     }
      91                 :            :     else
      92                 :            :     {
      93                 :        126 :         mpPreviewDevice->SetBackground(Wallpaper(
      94         [ +  - ]:        252 :             Application::GetSettings().GetStyleSettings().GetWindowColor()));
           [ +  -  +  - ]
                 [ +  - ]
      95                 :            :     }
      96                 :        126 : }
      97                 :            : 
      98                 :            : 
      99                 :            : 
     100                 :            : 
     101 [ +  - ][ +  - ]:        126 : PreviewRenderer::~PreviewRenderer (void)
     102                 :            : {
     103         [ +  + ]:        126 :     if (mpDocShellOfView != NULL)
     104         [ +  - ]:        122 :         EndListening (*mpDocShellOfView);
     105         [ -  + ]:        126 : }
     106                 :            : 
     107                 :            : 
     108                 :            : 
     109                 :            : 
     110                 :          0 : Image PreviewRenderer::RenderPage (
     111                 :            :     const SdPage* pPage,
     112                 :            :     const sal_Int32 nWidth,
     113                 :            :     const String& rSubstitutionText,
     114                 :            :     const bool bObeyHighContrastMode,
     115                 :            :     const bool bDisplayPresentationObjects)
     116                 :            : {
     117         [ #  # ]:          0 :     if (pPage != NULL)
     118                 :            :     {
     119         [ #  # ]:          0 :         const Size aPageModelSize (pPage->GetSize());
     120                 :            :         const double nAspectRatio (
     121                 :          0 :             double(aPageModelSize.Width()) / double(aPageModelSize.Height()));
     122         [ #  # ]:          0 :         const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
     123                 :            :         const sal_Int32 nHeight (sal::static_int_cast<sal_Int32>(
     124                 :          0 :             (nWidth - 2*nFrameWidth) / nAspectRatio + 2*nFrameWidth + 0.5));
     125                 :            :         return RenderPage (
     126                 :            :             pPage,
     127                 :            :             Size(nWidth,nHeight),
     128                 :            :             rSubstitutionText,
     129                 :            :             bObeyHighContrastMode,
     130         [ #  # ]:          0 :             bDisplayPresentationObjects);
     131                 :            :     }
     132                 :            :     else
     133                 :          0 :         return Image();
     134                 :            : }
     135                 :            : 
     136                 :            : 
     137                 :            : 
     138                 :            : 
     139                 :        270 : Image PreviewRenderer::RenderPage (
     140                 :            :     const SdPage* pPage,
     141                 :            :     Size aPixelSize,
     142                 :            :     const String& rSubstitutionText,
     143                 :            :     const bool bObeyHighContrastMode,
     144                 :            :     const bool bDisplayPresentationObjects)
     145                 :            : {
     146                 :        270 :     Image aPreview;
     147                 :            : 
     148         [ +  - ]:        270 :     if (pPage != NULL)
     149                 :            :     {
     150                 :            :         try
     151                 :            :         {
     152 [ +  - ][ +  - ]:        270 :             if (Initialize(pPage, aPixelSize, bObeyHighContrastMode))
     153                 :            :             {
     154         [ +  - ]:        270 :                 PaintPage(pPage, bDisplayPresentationObjects);
     155         [ +  - ]:        270 :                 PaintSubstitutionText(rSubstitutionText);
     156         [ +  - ]:        270 :                 PaintFrame();
     157                 :            : 
     158                 :        270 :                 Size aSize (mpPreviewDevice->GetOutputSizePixel());
     159                 :        270 :                 aPreview = mpPreviewDevice->GetBitmap (
     160                 :        270 :                     mpPreviewDevice->PixelToLogic(Point(0,0)),
     161 [ +  - ][ +  - ]:        810 :                     mpPreviewDevice->PixelToLogic(aSize));
                 [ +  - ]
           [ +  -  #  # ]
           [ +  -  +  -  
                   +  - ]
     162                 :            : 
     163         [ +  - ]:        270 :                 Cleanup();
     164                 :            :             }
     165                 :            :         }
     166         [ #  # ]:          0 :         catch (const com::sun::star::uno::Exception&)
     167                 :            :         {
     168                 :            :             DBG_UNHANDLED_EXCEPTION();
     169                 :            :         }
     170                 :            :     }
     171                 :            : 
     172                 :        270 :     return aPreview;
     173                 :            : }
     174                 :            : 
     175                 :            : 
     176                 :            : 
     177                 :            : 
     178                 :          0 : Image PreviewRenderer::RenderSubstitution (
     179                 :            :     const Size& rPreviewPixelSize,
     180                 :            :     const String& rSubstitutionText)
     181                 :            : {
     182                 :          0 :     Image aPreview;
     183                 :            : 
     184                 :            :     try
     185                 :            :     {
     186                 :            :         // Set size.
     187         [ #  # ]:          0 :         mpPreviewDevice->SetOutputSizePixel(rPreviewPixelSize);
     188                 :            : 
     189                 :            :         // Adjust contrast mode.
     190                 :            :         const bool bUseContrast (
     191         [ #  # ]:          0 :             Application::GetSettings().GetStyleSettings().GetHighContrastMode());
     192                 :          0 :         mpPreviewDevice->SetDrawMode (bUseContrast
     193                 :            :             ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
     194 [ #  # ][ #  # ]:          0 :             : ViewShell::OUTPUT_DRAWMODE_COLOR);
     195                 :            : 
     196                 :            :         // Set a map mode that makes a typical substitution text completely
     197                 :            :         // visible.
     198         [ #  # ]:          0 :         MapMode aMapMode (mpPreviewDevice->GetMapMode());
     199         [ #  # ]:          0 :         aMapMode.SetMapUnit(MAP_100TH_MM);
     200                 :          0 :         const double nFinalScale (25.0 * rPreviewPixelSize.Width() / 28000.0);
     201 [ #  # ][ #  # ]:          0 :         aMapMode.SetScaleX(nFinalScale);
     202 [ #  # ][ #  # ]:          0 :         aMapMode.SetScaleY(nFinalScale);
     203         [ #  # ]:          0 :         const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
     204                 :          0 :         aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(
     205 [ #  # ][ #  # ]:          0 :             Point(nFrameWidth,nFrameWidth),aMapMode));
     206         [ #  # ]:          0 :         mpPreviewDevice->SetMapMode (aMapMode);
     207                 :            : 
     208                 :            :         // Clear the background.
     209                 :            :         const Rectangle aPaintRectangle (
     210                 :            :             Point(0,0),
     211         [ #  # ]:          0 :             mpPreviewDevice->GetOutputSizePixel());
     212         [ #  # ]:          0 :         mpPreviewDevice->EnableMapMode(sal_False);
     213         [ #  # ]:          0 :         mpPreviewDevice->SetLineColor();
     214         [ #  # ]:          0 :         svtools::ColorConfig aColorConfig;
     215 [ #  # ][ #  # ]:          0 :         mpPreviewDevice->SetFillColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
     216         [ #  # ]:          0 :         mpPreviewDevice->DrawRect (aPaintRectangle);
     217         [ #  # ]:          0 :         mpPreviewDevice->EnableMapMode(sal_True);
     218                 :            : 
     219                 :            :         // Paint substitution text and a frame around it.
     220         [ #  # ]:          0 :         PaintSubstitutionText (rSubstitutionText);
     221         [ #  # ]:          0 :         PaintFrame();
     222                 :            : 
     223                 :          0 :         const Size aSize (mpPreviewDevice->GetOutputSizePixel());
     224                 :          0 :         aPreview = mpPreviewDevice->GetBitmap (
     225                 :          0 :             mpPreviewDevice->PixelToLogic(Point(0,0)),
     226 [ #  # ][ #  # ]:          0 :             mpPreviewDevice->PixelToLogic(aSize));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
     227                 :            :     }
     228         [ #  # ]:          0 :     catch (const com::sun::star::uno::Exception&)
     229                 :            :     {
     230                 :            :         DBG_UNHANDLED_EXCEPTION();
     231                 :            :     }
     232                 :            : 
     233                 :          0 :     return aPreview;
     234                 :            : }
     235                 :            : 
     236                 :            : 
     237                 :            : 
     238                 :            : 
     239                 :        270 : bool PreviewRenderer::Initialize (
     240                 :            :     const SdPage* pPage,
     241                 :            :     const Size& rPixelSize,
     242                 :            :     const bool bObeyHighContrastMode)
     243                 :            : {
     244                 :        270 :     bool bSuccess = false;
     245                 :            :     do
     246                 :            :     {
     247         [ +  - ]:        270 :         if (pPage == NULL)
     248                 :            :             break;
     249                 :            : 
     250         [ +  - ]:        270 :         SdrModel* pModel = pPage->GetModel();
     251         [ +  - ]:        270 :         if (pModel == NULL)
     252                 :            :             break;
     253                 :            : 
     254         [ +  - ]:        270 :         SetupOutputSize(*pPage, rPixelSize);
     255                 :            : 
     256                 :            :         SdDrawDocument* pDocument
     257         [ +  - ]:        270 :             = static_cast<SdDrawDocument*>(pPage->GetModel());
     258                 :        270 :         DrawDocShell* pDocShell = pDocument->GetDocSh();
     259                 :            : 
     260                 :            :         // Create view
     261         [ +  - ]:        270 :         ProvideView (pDocShell);
     262         [ +  - ]:        270 :         if (mpView.get() == NULL)
     263                 :            :             break;
     264                 :            : 
     265                 :            :         // Adjust contrast mode.
     266                 :            :         bool bUseContrast (bObeyHighContrastMode
     267 [ +  - ][ +  - ]:        270 :             && Application::GetSettings().GetStyleSettings().GetHighContrastMode());
                 [ -  + ]
     268                 :        270 :         mpPreviewDevice->SetDrawMode (bUseContrast
     269                 :            :             ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
     270 [ -  + ][ +  - ]:        540 :             : ViewShell::OUTPUT_DRAWMODE_COLOR);
     271 [ +  - ][ +  - ]:        270 :         mpPreviewDevice->SetSettings(Application::GetSettings());
     272                 :            : 
     273                 :            :         // Tell the view to show the given page.
     274                 :        270 :         SdPage* pNonConstPage = const_cast<SdPage*>(pPage);
     275         [ +  + ]:        270 :         if (pPage->IsMasterPage())
     276                 :            :         {
     277 [ +  - ][ +  - ]:          9 :             mpView->ShowSdrPage(mpView->GetModel()->GetMasterPage(pPage->GetPageNum()));
                 [ +  - ]
     278                 :            :         }
     279                 :            :         else
     280                 :            :         {
     281         [ +  - ]:        261 :             mpView->ShowSdrPage(pNonConstPage);
     282                 :            :         }
     283                 :            : 
     284                 :            :         // Make sure that a page view exists.
     285                 :        270 :         SdrPageView* pPageView = mpView->GetSdrPageView();
     286         [ +  - ]:        270 :         if (pPageView == NULL)
     287                 :            :             break;
     288                 :            :         // Set background color of page view and outliner.
     289         [ +  - ]:        270 :         svtools::ColorConfig aColorConfig;
     290         [ +  - ]:        270 :         const Color aPageBackgroundColor(pPage->GetPageBackgroundColor(pPageView));
     291         [ +  - ]:        270 :         pPageView->SetApplicationBackgroundColor(aPageBackgroundColor);
     292         [ +  - ]:        270 :         SdrOutliner& rOutliner (pDocument->GetDrawOutliner(NULL));
     293         [ +  - ]:        270 :         rOutliner.SetBackgroundColor(aPageBackgroundColor);
     294 [ +  - ][ +  - ]:        270 :         rOutliner.SetDefaultLanguage(pDocument->GetLanguage(EE_CHAR_LANGUAGE));
     295                 :        270 :         mpView->SetApplicationBackgroundColor(
     296 [ +  - ][ +  - ]:        540 :             Color(aColorConfig.GetColorValue(svtools::APPBACKGROUND).nColor));
     297 [ +  - ][ +  - ]:        270 :         mpPreviewDevice->SetBackground(Wallpaper(aPageBackgroundColor));
                 [ +  - ]
     298         [ +  - ]:        270 :         mpPreviewDevice->Erase();
     299                 :            : 
     300         [ +  - ]:        270 :         bSuccess = true;
     301                 :            :     }
     302                 :            :     while (false);
     303                 :            : 
     304                 :        270 :     return bSuccess;
     305                 :            : }
     306                 :            : 
     307                 :            : 
     308                 :            : 
     309                 :            : 
     310                 :        270 : void PreviewRenderer::Cleanup (void)
     311                 :            : {
     312                 :        270 :     mpView->HideSdrPage();
     313                 :        270 : }
     314                 :            : 
     315                 :            : 
     316                 :            : 
     317                 :            : 
     318                 :        270 : void PreviewRenderer::PaintPage (
     319                 :            :     const SdPage* pPage,
     320                 :            :     const bool bDisplayPresentationObjects)
     321                 :            : {
     322                 :            :     // Paint the page.
     323 [ +  - ][ +  - ]:        270 :     Rectangle aPaintRectangle (Point(0,0), pPage->GetSize());
     324         [ +  - ]:        270 :     Region aRegion (aPaintRectangle);
     325                 :            : 
     326                 :            :     // Turn off online spelling and redlining.
     327                 :        270 :     SdrOutliner* pOutliner = NULL;
     328                 :        270 :     sal_uLong nSavedControlWord (0);
     329 [ +  - ][ +  - ]:        270 :     if (mpDocShellOfView!=NULL && mpDocShellOfView->GetDoc()!=NULL)
         [ +  - ][ +  - ]
     330                 :            :     {
     331 [ +  - ][ +  - ]:        270 :         pOutliner = &mpDocShellOfView->GetDoc()->GetDrawOutliner();
     332         [ +  - ]:        270 :         nSavedControlWord = pOutliner->GetControlWord();
     333         [ +  - ]:        270 :         pOutliner->SetControlWord((nSavedControlWord & ~EE_CNTRL_ONLINESPELLING));
     334                 :            :     }
     335                 :            : 
     336                 :            :     // Use a special redirector to prevent PresObj shapes from being painted.
     337                 :        270 :     boost::scoped_ptr<ViewRedirector> pRedirector;
     338         [ +  - ]:        270 :     if ( ! bDisplayPresentationObjects)
     339 [ +  - ][ +  - ]:        270 :         pRedirector.reset(new ViewRedirector());
           [ +  -  #  # ]
     340                 :            : 
     341                 :            :     try
     342                 :            :     {
     343         [ +  - ]:        270 :         mpView->CompleteRedraw(mpPreviewDevice.get(), aRegion, pRedirector.get());
     344                 :            :     }
     345         [ #  # ]:          0 :     catch (const ::com::sun::star::uno::Exception&)
     346                 :            :     {
     347                 :            :         DBG_UNHANDLED_EXCEPTION();
     348                 :            :     }
     349                 :            : 
     350                 :            :     // Restore the previous online spelling and redlining states.
     351         [ +  - ]:        270 :     if (pOutliner != NULL)
     352 [ +  - ][ +  - ]:        270 :         pOutliner->SetControlWord(nSavedControlWord);
                 [ +  - ]
     353                 :        270 : }
     354                 :            : 
     355                 :            : 
     356                 :            : 
     357                 :            : 
     358                 :        270 : void PreviewRenderer::PaintSubstitutionText (const String& rSubstitutionText)
     359                 :            : {
     360         [ -  + ]:        270 :     if (rSubstitutionText.Len() > 0)
     361                 :            :     {
     362                 :            :         // Set the font size.
     363                 :          0 :         const Font& rOriginalFont (mpPreviewDevice->GetFont());
     364         [ #  # ]:          0 :         Font aFont (mpPreviewDevice->GetSettings().GetStyleSettings().GetAppFont());
     365         [ #  # ]:          0 :         sal_Int32 nHeight (mpPreviewDevice->PixelToLogic(Size(0,snSubstitutionTextSize)).Height());
     366         [ #  # ]:          0 :         aFont.SetHeight(nHeight);
     367         [ #  # ]:          0 :         mpPreviewDevice->SetFont (aFont);
     368                 :            : 
     369                 :            :         // Paint the substitution text.
     370                 :            :         Rectangle aTextBox (
     371                 :            :             Point(0,0),
     372                 :          0 :             mpPreviewDevice->PixelToLogic(
     373 [ #  # ][ #  # ]:          0 :                 mpPreviewDevice->GetOutputSizePixel()));
     374                 :            :         sal_uInt16 nTextStyle =
     375                 :            :             TEXT_DRAW_CENTER
     376                 :            :             | TEXT_DRAW_VCENTER
     377                 :            :             | TEXT_DRAW_MULTILINE
     378                 :          0 :             | TEXT_DRAW_WORDBREAK;
     379         [ #  # ]:          0 :         mpPreviewDevice->DrawText (aTextBox, rSubstitutionText, nTextStyle);
     380                 :            : 
     381                 :            :         // Restore the font.
     382 [ #  # ][ #  # ]:          0 :         mpPreviewDevice->SetFont (rOriginalFont);
     383                 :            :     }
     384                 :        270 : }
     385                 :            : 
     386                 :            : 
     387                 :            : 
     388                 :            : 
     389                 :        270 : void PreviewRenderer::PaintFrame (void)
     390                 :            : {
     391         [ -  + ]:        270 :     if (mbHasFrame)
     392                 :            :     {
     393                 :            :         // Paint a frame arround the preview.
     394                 :            :         Rectangle aPaintRectangle (
     395                 :            :             Point(0,0),
     396         [ #  # ]:          0 :             mpPreviewDevice->GetOutputSizePixel());
     397         [ #  # ]:          0 :         mpPreviewDevice->EnableMapMode(sal_False);
     398         [ #  # ]:          0 :         mpPreviewDevice->SetLineColor(maFrameColor);
     399         [ #  # ]:          0 :         mpPreviewDevice->SetFillColor();
     400         [ #  # ]:          0 :         mpPreviewDevice->DrawRect(aPaintRectangle);
     401         [ #  # ]:          0 :         mpPreviewDevice->EnableMapMode(sal_True);
     402                 :            :      }
     403                 :        270 : }
     404                 :            : 
     405                 :            : 
     406                 :            : 
     407                 :            : 
     408                 :        270 : void PreviewRenderer::SetupOutputSize (
     409                 :            :     const SdPage& rPage,
     410                 :            :     const Size& rFramePixelSize)
     411                 :            : {
     412                 :            :     // First set the map mode to some arbitrary scale that is numerically
     413                 :            :     // stable.
     414         [ +  - ]:        270 :     MapMode aMapMode (mpPreviewDevice->GetMapMode());
     415         [ +  - ]:        270 :     aMapMode.SetMapUnit(MAP_PIXEL);
     416                 :            : 
     417                 :            :     // Adapt it to the desired width.
     418         [ +  - ]:        270 :     const Size aPageModelSize (rPage.GetSize());
     419 [ -  + ][ #  # ]:        270 :     if (aPageModelSize.Width()>0 || aPageModelSize.Height()>0)
                 [ +  - ]
     420                 :            :     {
     421         [ -  + ]:        270 :         const sal_Int32 nFrameWidth (mbHasFrame ? snFrameWidth : 0);
     422                 :            :         aMapMode.SetScaleX(
     423 [ +  - ][ +  - ]:        270 :             Fraction(rFramePixelSize.Width()-2*nFrameWidth-1, aPageModelSize.Width()));
     424                 :            :         aMapMode.SetScaleY(
     425 [ +  - ][ +  - ]:        270 :             Fraction(rFramePixelSize.Height()-2*nFrameWidth-1, aPageModelSize.Height()));
     426 [ +  - ][ +  - ]:        270 :         aMapMode.SetOrigin(mpPreviewDevice->PixelToLogic(Point(nFrameWidth,nFrameWidth),aMapMode));
     427                 :            :     }
     428                 :            :     else
     429                 :            :     {
     430                 :            :         // We should never get here.
     431                 :            :         OSL_ASSERT(false);
     432 [ #  # ][ #  # ]:          0 :         aMapMode.SetScaleX(1.0);
     433 [ #  # ][ #  # ]:          0 :         aMapMode.SetScaleY(1.0);
     434                 :            :     }
     435         [ +  - ]:        270 :     mpPreviewDevice->SetMapMode (aMapMode);
     436 [ +  - ][ +  - ]:        270 :     mpPreviewDevice->SetOutputSizePixel(rFramePixelSize);
     437                 :        270 : }
     438                 :            : 
     439                 :            : 
     440                 :            : 
     441                 :            : 
     442                 :        270 : void PreviewRenderer::ProvideView (DrawDocShell* pDocShell)
     443                 :            : {
     444         [ +  + ]:        270 :     if (pDocShell != mpDocShellOfView)
     445                 :            :     {
     446                 :            :         // Destroy the view that is connected to the current doc shell.
     447                 :        122 :         mpView.reset (NULL);
     448                 :            : 
     449                 :            :         // Switch our attention, i.e. listening for DYING events, to
     450                 :            :         // the new doc shell.
     451         [ -  + ]:        122 :         if (mpDocShellOfView != NULL)
     452                 :          0 :             EndListening (*mpDocShellOfView);
     453                 :        122 :         mpDocShellOfView = pDocShell;
     454         [ +  - ]:        122 :         if (mpDocShellOfView != NULL)
     455                 :        122 :             StartListening (*mpDocShellOfView);
     456                 :            :     }
     457         [ +  + ]:        270 :     if (mpView.get() == NULL)
     458                 :            :     {
     459         [ +  - ]:        122 :         mpView.reset (new DrawView (pDocShell, mpPreviewDevice.get(), NULL));
     460                 :            :     }
     461                 :        270 :     mpView->SetPreviewRenderer(true);
     462                 :            : #if 1
     463                 :        270 :     mpView->SetPageVisible(false);
     464                 :        270 :     mpView->SetPageBorderVisible(true);
     465                 :        270 :     mpView->SetBordVisible(false);
     466                 :            : #else
     467                 :            :     // This works in the slide sorter but prevents the master page
     468                 :            :     // background being painted in the list of current master pages in the
     469                 :            :     // task manager.
     470                 :            :     mpView->SetPagePaintingAllowed(false);
     471                 :            : #endif
     472                 :        270 : }
     473                 :            : 
     474                 :            : 
     475                 :            : 
     476                 :            : 
     477                 :          0 : Image PreviewRenderer::ScaleBitmap (
     478                 :            :     const BitmapEx& rBitmapEx,
     479                 :            :     int nWidth)
     480                 :            : {
     481                 :          0 :     Image aPreview;
     482                 :            : 
     483                 :            :     do
     484                 :            :     {
     485                 :            :         // Adjust contrast mode.
     486         [ #  # ]:          0 :         bool bUseContrast = Application::GetSettings().GetStyleSettings().
     487                 :          0 :             GetHighContrastMode();
     488                 :          0 :         mpPreviewDevice->SetDrawMode (bUseContrast
     489                 :            :             ? ViewShell::OUTPUT_DRAWMODE_CONTRAST
     490 [ #  # ][ #  # ]:          0 :             : ViewShell::OUTPUT_DRAWMODE_COLOR);
     491                 :            : 
     492                 :            :         // Set output size.
     493                 :          0 :         Size aSize (rBitmapEx.GetSizePixel());
     494         [ #  # ]:          0 :         if (aSize.Width() <= 0)
     495                 :            :             break;
     496                 :            :         Size aFrameSize (
     497                 :            :             nWidth,
     498                 :          0 :             (long)((nWidth*1.0 * aSize.Height()) / aSize.Width() + 0.5));
     499                 :          0 :         Size aPreviewSize (aFrameSize.Width()-2,aFrameSize.Height()-2);
     500         [ #  # ]:          0 :         MapMode aMapMode (mpPreviewDevice->GetMapMode());
     501         [ #  # ]:          0 :         aMapMode.SetMapUnit(MAP_PIXEL);
     502         [ #  # ]:          0 :         aMapMode.SetOrigin (Point());
     503 [ #  # ][ #  # ]:          0 :         aMapMode.SetScaleX (1.0);
     504 [ #  # ][ #  # ]:          0 :         aMapMode.SetScaleY (1.0);
     505         [ #  # ]:          0 :         mpPreviewDevice->SetMapMode (aMapMode);
     506         [ #  # ]:          0 :         mpPreviewDevice->SetOutputSize (aFrameSize);
     507                 :            : 
     508                 :            :         // Paint a frame arround the preview.
     509         [ #  # ]:          0 :         mpPreviewDevice->SetLineColor (maFrameColor);
     510         [ #  # ]:          0 :         mpPreviewDevice->SetFillColor ();
     511 [ #  # ][ #  # ]:          0 :         mpPreviewDevice->DrawRect (Rectangle(Point(0,0), aFrameSize));
     512                 :            : 
     513                 :            :         // Paint the bitmap scaled to the desired width.
     514 [ #  # ][ #  # ]:          0 :         BitmapEx aScaledBitmap (rBitmapEx.GetBitmap());
                 [ #  # ]
     515         [ #  # ]:          0 :         aScaledBitmap.Scale (aPreviewSize, BMP_SCALE_BEST);
     516                 :          0 :         mpPreviewDevice->DrawBitmap (
     517                 :            :             Point(1,1),
     518                 :            :             aPreviewSize,
     519 [ #  # ][ #  # ]:          0 :             aScaledBitmap.GetBitmap());
                 [ #  # ]
     520                 :            : 
     521                 :            :         // Get the resulting bitmap.
     522 [ #  # ][ #  # ]:          0 :         aPreview = mpPreviewDevice->GetBitmap (Point(0,0), aFrameSize);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     523                 :            :     }
     524                 :            :     while (false);
     525                 :            : 
     526                 :          0 :     return aPreview;
     527                 :            : }
     528                 :            : 
     529                 :            : 
     530                 :            : 
     531                 :            : 
     532                 :       2585 : void PreviewRenderer::Notify(SfxBroadcaster&, const SfxHint& rHint)
     533                 :            : {
     534 [ +  + ][ +  - ]:       2585 :     if (rHint.IsA(TYPE(SfxSimpleHint))
                 [ +  + ]
     535                 :            :         && mpDocShellOfView != NULL)
     536                 :            :     {
     537 [ +  - ][ +  - ]:       2423 :         const SfxSimpleHint* pSimpleHint = PTR_CAST(SfxSimpleHint, &rHint);
     538   [ +  -  -  + ]:       4846 :         if (pSimpleHint != NULL
                 [ -  + ]
     539                 :       2423 :             && pSimpleHint->GetId() == SFX_HINT_DYING)
     540                 :            :         {
     541                 :            :             // The doc shell is dying.  Our view uses its item pool and
     542                 :            :             // has to be destroyed as well.  The next call to
     543                 :            :             // ProvideView will create a new one (for another
     544                 :            :             // doc shell, of course.)
     545                 :          0 :             mpView.reset (NULL);
     546                 :          0 :             mpDocShellOfView = NULL;
     547                 :            :         }
     548                 :            :     }
     549                 :       2585 : }
     550                 :            : 
     551                 :            : 
     552                 :            : 
     553                 :            : 
     554                 :            : //===== ViewRedirector ========================================================
     555                 :            : 
     556                 :            : namespace {
     557                 :            : 
     558                 :        270 : ViewRedirector::ViewRedirector (void)
     559                 :            : {
     560                 :        270 : }
     561                 :            : 
     562                 :            : 
     563                 :            : 
     564                 :            : 
     565                 :        270 : ViewRedirector::~ViewRedirector (void)
     566                 :            : {
     567         [ -  + ]:        540 : }
     568                 :            : 
     569                 :            : 
     570                 :            : 
     571                 :            : 
     572                 :        626 : drawinglayer::primitive2d::Primitive2DSequence ViewRedirector::createRedirectedPrimitive2DSequence(
     573                 :            :     const sdr::contact::ViewObjectContact& rOriginal,
     574                 :            :     const sdr::contact::DisplayInfo& rDisplayInfo)
     575                 :            : {
     576                 :        626 :     SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject();
     577                 :            : 
     578 [ -  + ][ +  + ]:        626 :     if (pObject==NULL || pObject->GetPage() == NULL)
                 [ +  + ]
     579                 :            :     {
     580                 :            :         // not a SdrObject visualisation (maybe e.g. page) or no page
     581                 :            :         return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(
     582                 :            :             rOriginal,
     583                 :          9 :             rDisplayInfo);
     584                 :            :     }
     585                 :            : 
     586                 :        617 :     const bool bDoCreateGeometry (pObject->GetPage()->checkVisibility( rOriginal, rDisplayInfo, true));
     587                 :            : 
     588 [ +  + ][ +  +  :        699 :     if ( ! bDoCreateGeometry
             +  -  +  - ]
     589                 :         82 :         && (pObject->GetObjInventor() != SdrInventor || pObject->GetObjIdentifier() != OBJ_PAGE))
     590                 :            :     {
     591                 :         41 :         return drawinglayer::primitive2d::Primitive2DSequence();
     592                 :            :     }
     593                 :            : 
     594         [ +  + ]:        576 :     if (pObject->IsEmptyPresObj())
     595                 :         72 :         return drawinglayer::primitive2d::Primitive2DSequence();
     596                 :            : 
     597                 :            :     return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(
     598                 :            :         rOriginal,
     599                 :        626 :         rDisplayInfo);
     600                 :            : }
     601                 :            : 
     602                 :            : } // end of anonymous namespace
     603                 :            : 
     604                 :            : 
     605                 :            : } // end of namespace ::sd
     606                 :            : 
     607                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10