1c45d927aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3c45d927aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4c45d927aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5c45d927aSAndrew Rist * distributed with this work for additional information 6c45d927aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7c45d927aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8c45d927aSAndrew Rist * "License"); you may not use this file except in compliance 9c45d927aSAndrew Rist * with the License. You may obtain a copy of the License at 10c45d927aSAndrew Rist * 11c45d927aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12c45d927aSAndrew Rist * 13c45d927aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14c45d927aSAndrew Rist * software distributed under the License is distributed on an 15c45d927aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16c45d927aSAndrew Rist * KIND, either express or implied. See the License for the 17c45d927aSAndrew Rist * specific language governing permissions and limitations 18c45d927aSAndrew Rist * under the License. 19c45d927aSAndrew Rist * 20c45d927aSAndrew Rist *************************************************************/ 21c45d927aSAndrew Rist 22c45d927aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SD_PREVIEW_RENDERER_HXX 25cdf0e10cSrcweir #define SD_PREVIEW_RENDERER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "drawview.hxx" 28cdf0e10cSrcweir #include <vcl/image.hxx> 29cdf0e10cSrcweir #include <vcl/virdev.hxx> 30cdf0e10cSrcweir #include <svl/listener.hxx> 31cdf0e10cSrcweir #include <memory> 32cdf0e10cSrcweir 33cdf0e10cSrcweir 34cdf0e10cSrcweir class OutputDevice; 35cdf0e10cSrcweir class SdPage; 36cdf0e10cSrcweir class VirtualDevice; 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace sd { 39cdf0e10cSrcweir 40cdf0e10cSrcweir class DrawDocShell; 41cdf0e10cSrcweir class DrawView; 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir class PreviewRenderer 45cdf0e10cSrcweir : public SfxListener 46cdf0e10cSrcweir { 47cdf0e10cSrcweir public: 48*86e1cf34SPedro Giffuni /** Create a new preview renderer that takes some of its initial values 49cdf0e10cSrcweir from the given output device. 50cdf0e10cSrcweir @param pTemplate 51cdf0e10cSrcweir May be NULL. 52cdf0e10cSrcweir @param bPaintFrame 53cdf0e10cSrcweir When <TRUE/> (the default) then a frame is painted around the 54cdf0e10cSrcweir preview. This makes the actual preview smaller. 55cdf0e10cSrcweir */ 56cdf0e10cSrcweir PreviewRenderer ( 57cdf0e10cSrcweir OutputDevice* pTemplate = NULL, 58cdf0e10cSrcweir const bool bPaintFrame = true); 59cdf0e10cSrcweir 60cdf0e10cSrcweir ~PreviewRenderer (void); 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** Render a page with the given pixel size. 63cdf0e10cSrcweir Use this version when only the width of the preview is known to the 64cdf0e10cSrcweir caller. The height is then calculated according to the aspect 65cdf0e10cSrcweir ration of the given page. 66cdf0e10cSrcweir @param pPage 67cdf0e10cSrcweir The page to render. 68cdf0e10cSrcweir @param nWidth 69cdf0e10cSrcweir The width of the preview in device coordinates. 70cdf0e10cSrcweir @param sSubstitutionText 71cdf0e10cSrcweir When the actual preview can not be created for some reason, then 72cdf0e10cSrcweir this text is painted in an empty rectangle of the requested size 73cdf0e10cSrcweir instead. 74cdf0e10cSrcweir @param bObeyHighContrastMode 75cdf0e10cSrcweir When <FALSE/> then the high contrast mode of the application is 76cdf0e10cSrcweir ignored and the preview is rendered in normal mode. When 77cdf0e10cSrcweir <TRUE/> and high contrast mode is active then the preview is 78cdf0e10cSrcweir rendered in high contrast mode. 79cdf0e10cSrcweir @param bDisplayPresentationObjects 80cdf0e10cSrcweir When <FALSE/> then the PresObj place holders are not displayed 81cdf0e10cSrcweir in the returned preview. 82cdf0e10cSrcweir */ 83cdf0e10cSrcweir Image RenderPage ( 84cdf0e10cSrcweir const SdPage* pPage, 85cdf0e10cSrcweir const sal_Int32 nWidth, 86cdf0e10cSrcweir const String& sSubstitutionText, 87cdf0e10cSrcweir const bool bObeyHighContrastMode = true, 88cdf0e10cSrcweir const bool bDisplayPresentationObjects = true); 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** Render a page with the given pixel size. 91cdf0e10cSrcweir @param pPage 92cdf0e10cSrcweir The page to render. 93cdf0e10cSrcweir @param aPreviewPixelSize 94cdf0e10cSrcweir The size in device coordinates of the preview. 95cdf0e10cSrcweir @param sSubstitutionText 96cdf0e10cSrcweir When the actual preview can not be created for some reason, then 97cdf0e10cSrcweir this text is painted in an empty rectangle of the requested size 98cdf0e10cSrcweir instead. 99cdf0e10cSrcweir @param bObeyHighContrastMode 100cdf0e10cSrcweir When <FALSE/> then the high contrast mode of the application is 101cdf0e10cSrcweir ignored and the preview is rendered in normal mode. When 102cdf0e10cSrcweir <TRUE/> and high contrast mode is active then the preview is 103cdf0e10cSrcweir rendered in high contrast mode. 104cdf0e10cSrcweir @param bDisplayPresentationObjects 105cdf0e10cSrcweir When <FALSE/> then the PresObj place holders are not displayed 106cdf0e10cSrcweir in the returned preview. 107cdf0e10cSrcweir */ 108cdf0e10cSrcweir Image RenderPage ( 109cdf0e10cSrcweir const SdPage* pPage, 110cdf0e10cSrcweir const Size aPreviewPixelSize, 111cdf0e10cSrcweir const String& sSubstitutionText, 112cdf0e10cSrcweir const bool bObeyHighContrastMode = true, 113cdf0e10cSrcweir const bool bDisplayPresentationObjects = true); 114cdf0e10cSrcweir 115cdf0e10cSrcweir /** Render an image that contains the given substitution text instead of a 116cdf0e10cSrcweir slide preview. 117cdf0e10cSrcweir @param aPreviewPixelSize 118cdf0e10cSrcweir The size in device coordinates of the image. 119cdf0e10cSrcweir */ 120cdf0e10cSrcweir Image RenderSubstitution ( 121cdf0e10cSrcweir const Size& rPreviewPixelSize, 122cdf0e10cSrcweir const String& sSubstitutionText); 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** Scale the given bitmap by keeping its aspect ratio to the desired 125cdf0e10cSrcweir width. Add a frame to it afterwards. 126cdf0e10cSrcweir */ 127cdf0e10cSrcweir Image ScaleBitmap ( 128cdf0e10cSrcweir const BitmapEx& rBitmap, 129cdf0e10cSrcweir int nWidth); 130cdf0e10cSrcweir 131cdf0e10cSrcweir protected: 132cdf0e10cSrcweir virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint); 133cdf0e10cSrcweir 134cdf0e10cSrcweir private: 135cdf0e10cSrcweir ::std::auto_ptr<VirtualDevice> mpPreviewDevice; 136cdf0e10cSrcweir ::std::auto_ptr<DrawView> mpView; 137cdf0e10cSrcweir DrawDocShell* mpDocShellOfView; 138cdf0e10cSrcweir int mnWidthOfView; 139cdf0e10cSrcweir const Color maFrameColor; 140cdf0e10cSrcweir const bool mbHasFrame; 141cdf0e10cSrcweir static const int snSubstitutionTextSize; 142*86e1cf34SPedro Giffuni // Width of the frame that is painted around the preview. 143cdf0e10cSrcweir static const int snFrameWidth; 144cdf0e10cSrcweir 145cdf0e10cSrcweir bool Initialize ( 146cdf0e10cSrcweir const SdPage* pPage, 147cdf0e10cSrcweir const Size& rPixelSize, 148cdf0e10cSrcweir const bool bObeyHighContrastMode); 149cdf0e10cSrcweir void Cleanup (void); 150cdf0e10cSrcweir void PaintPage ( 151cdf0e10cSrcweir const SdPage* pPage, 152cdf0e10cSrcweir const bool bDisplayPresentationObjects); 153cdf0e10cSrcweir void PaintSubstitutionText (const String& rSubstitutionText); 154cdf0e10cSrcweir void PaintFrame (void); 155cdf0e10cSrcweir 156cdf0e10cSrcweir /** Set up the map mode so that the given page is renderer into a bitmap 157cdf0e10cSrcweir with the specified width. 158cdf0e10cSrcweir @param rPage 159cdf0e10cSrcweir The page for which the preview is created. 160cdf0e10cSrcweir @param rPixelSize 161cdf0e10cSrcweir The size of the resulting preview bitmap. Note that this size 162cdf0e10cSrcweir includes the frame. The actual preview is smaller accordingly. 163cdf0e10cSrcweir */ 164cdf0e10cSrcweir void SetupOutputSize (const SdPage& rPage, const Size& rPixelSize); 165cdf0e10cSrcweir 166cdf0e10cSrcweir /** When mpView is empty then create a new view and initialize it. 167cdf0e10cSrcweir Otherwise just initialize it. 168cdf0e10cSrcweir */ 169cdf0e10cSrcweir void ProvideView (DrawDocShell* pDocShell); 170cdf0e10cSrcweir }; 171cdf0e10cSrcweir 172cdf0e10cSrcweir } // end of namespace ::sd 173cdf0e10cSrcweir 174cdf0e10cSrcweir #endif 175