1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SD_SOURCE_UI_INC_PREVIEWRENDERER_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_PREVIEWRENDERER_HXX
22 
23 #include <vcl/image.hxx>
24 #include <memory>
25 
26 #include <svl/lstner.hxx>
27 
28 class SdPage;
29 class VirtualDevice;
30 
31 namespace sd {
32 
33 class DrawDocShell;
34 class DrawView;
35 
36 class PreviewRenderer
37     : public SfxListener
38 {
39 public:
40     /** Create a new preview renderer that takes some of its initial values
41         from the given output device.
42         @param bPaintFrame
43             When <TRUE/> (the default) then a frame is painted around the
44             preview.  This makes the actual preview smaller.
45     */
46     PreviewRenderer(const bool bPaintFrame = true);
47 
48     virtual ~PreviewRenderer() override;
49 
50     /** Render a page with the given pixel size.
51         Use this version when only the width of the preview is known to the
52         caller. The height is then calculated according to the aspect
53         ratio of the given page.
54         @param pPage
55             The page to render.
56         @param nWidth
57             The width of the preview in device coordinates.
58          The high contrast mode of the application is
59          ignored and the preview is rendered in normal mode.
60     */
61     Image RenderPage (
62         const SdPage* pPage,
63         const sal_Int32 nWidth);
64 
65     /** Render a page with the given pixel size.
66         @param pPage
67             The page to render.
68         @param aPreviewPixelSize
69             The size in device coordinates of the preview.
70         @param bObeyHighContrastMode
71             When <FALSE/> then the high contrast mode of the application is
72             ignored and the preview is rendered in normal mode.  When
73             <TRUE/> and high contrast mode is active then the preview is
74             rendered in high contrast mode.
75         @param bDisplayPresentationObjects
76             When <FALSE/> then the PresObj place holders are not displayed
77             in the returned preview.
78     */
79     Image RenderPage (
80         const SdPage* pPage,
81         const Size aPreviewPixelSize,
82         const bool bObeyHighContrastMode,
83         const bool bDisplayPresentationObjects = true);
84 
85     /** Render an image that contains the given substitution text instead of a
86         slide preview.
87         @param aPreviewPixelSize
88             The size in device coordinates of the image.
89     */
90     Image RenderSubstitution (
91         const Size& rPreviewPixelSize,
92         const OUString& sSubstitutionText);
93 
94     /** Scale the given bitmap by keeping its aspect ratio to the desired
95         width.  Add a frame to it afterwards.
96     */
97     Image ScaleBitmap (
98         const BitmapEx& rBitmap,
99         int nWidth);
100 
101 protected:
102     virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
103 
104 private:
105     ScopedVclPtr<VirtualDevice> mpPreviewDevice;
106     ::std::unique_ptr<DrawView> mpView;
107     DrawDocShell* mpDocShellOfView;
108     const Color maFrameColor;
109     const bool mbHasFrame;
110     static const int snSubstitutionTextSize;
111     // Width of the frame that is painted around the preview.
112     static const int snFrameWidth;
113 
114     bool Initialize (
115         const SdPage* pPage,
116         const Size& rPixelSize,
117         const bool bObeyHighContrastMode);
118     void PaintPage (
119         const SdPage* pPage,
120         const bool bDisplayPresentationObjects);
121     void PaintSubstitutionText (const OUString& rSubstitutionText);
122     void PaintFrame();
123 
124     /** Set up the map mode so that the given page is renderer into a bitmap
125         with the specified width.
126         @param rPage
127             The page for which the preview is created.
128         @param rPixelSize
129             The size of the resulting preview bitmap.  Note that this size
130             includes the frame.  The actual preview is smaller accordingly.
131      */
132     void SetupOutputSize (const SdPage& rPage, const Size& rPixelSize);
133 
134     /** When mpView is empty then create a new view and initialize it.
135         Otherwise just initialize it.
136     */
137     void ProvideView (DrawDocShell* pDocShell);
138 };
139 
140 } // end of namespace ::sd
141 
142 #endif
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
145