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_VCL_VIRDEV_HXX 21 #define INCLUDED_VCL_VIRDEV_HXX 22 23 #include <vcl/dllapi.h> 24 #include <vcl/outdev.hxx> 25 #include <vcl/salgtype.hxx> 26 #include <memory> 27 28 class SalVirtualDevice; 29 struct SystemGraphicsData; 30 typedef struct _cairo_surface cairo_surface_t; 31 32 class SAL_WARN_UNUSED VCL_DLLPUBLIC VirtualDevice : public OutputDevice 33 { 34 friend class Application; 35 friend class ::OutputDevice; 36 friend class Printer; 37 friend cairo_surface_t* get_underlying_cairo_surface(const VirtualDevice&); 38 public: 39 // reference device modes for different compatibility levels 40 enum class RefDevMode { NONE = 0, 41 Dpi600 = 1, // 600 dpi 42 MSO1 = 3, 43 PDF1 = 4, 44 Custom = 5 45 }; 46 47 private: 48 std::unique_ptr<SalVirtualDevice> mpVirDev; 49 VclPtr<VirtualDevice> mpPrev; 50 VclPtr<VirtualDevice> mpNext; 51 sal_uInt16 mnBitCount; 52 bool mbScreenComp; 53 const DeviceFormat meFormat; 54 const DeviceFormat meAlphaFormat; 55 RefDevMode meRefDevMode; 56 bool mbForceZeroExtleadBug; 57 58 SAL_DLLPRIVATE void ImplInitVirDev( const OutputDevice* pOutDev, tools::Long nDX, tools::Long nDY, const SystemGraphicsData *pData = nullptr ); 59 SAL_DLLPRIVATE bool InnerImplSetOutputSizePixel( const Size& rNewSize, bool bErase, 60 sal_uInt8* pBuffer ); 61 SAL_DLLPRIVATE bool ImplSetOutputSizePixel( const Size& rNewSize, bool bErase, 62 sal_uInt8* pBuffer ); 63 64 VirtualDevice (const VirtualDevice &) = delete; 65 VirtualDevice & operator= (const VirtualDevice &) = delete; 66 67 /** Used for alpha VDev, to set areas to opaque 68 69 @since \#i32109# 70 */ 71 SAL_DLLPRIVATE void ImplFillOpaqueRectangle( const tools::Rectangle& rRect ); 72 73 protected: 74 virtual bool AcquireGraphics() const override; 75 virtual void ReleaseGraphics( bool bRelease = true ) override; 76 77 /** Create a virtual device of size 1x1 78 79 @param pCompDev 80 The generated vdev will be compatible to this device. 81 If it's the nullptr, it uses Application::GetDefaultDevice(). 82 83 @param eFormat 84 Device format of the generated virtual device. Use DeviceFormat::DEFAULT here, to 85 indicate: take default screen depth. 86 87 @param eAlphaFormat 88 Device format of the generated virtual device. Use DeviceFormat::DEFAULT here, to 89 indicate: take default screen depth. 90 91 @param eOutDevType 92 This real virtual output device type. 93 */ 94 explicit VirtualDevice(const OutputDevice* pCompDev, DeviceFormat eFormat, 95 DeviceFormat eAlphaFormat, OutDevType eOutDevType); 96 97 public: 98 99 /** Create a virtual device of size 1x1 100 101 @param eFormat 102 Device format of the generated virtual device. Use DeviceFormat::DEFAULT here, to 103 indicate: take default screen depth. 104 105 @param eAlphaFormat 106 Device format of the generated virtual device. Use DeviceFormat::DEFAULT here, to 107 indicate: take default screen depth. 108 */ VirtualDevice(DeviceFormat eFormat=DeviceFormat::DEFAULT,DeviceFormat eAlphaFormat=DeviceFormat::NONE)109 explicit VirtualDevice(DeviceFormat eFormat = DeviceFormat::DEFAULT, DeviceFormat eAlphaFormat = DeviceFormat::NONE) 110 : VirtualDevice(nullptr, eFormat, eAlphaFormat, OUTDEV_VIRDEV) {} 111 112 /** Create a virtual device of size 1x1 113 114 @param rCompDev 115 The generated vdev will be compatible to this device. 116 117 @param eFormat 118 Device format of the generated virtual device. Use DeviceFormat::DEFAULT here, to 119 indicate: take default screen depth. 120 */ VirtualDevice(const OutputDevice & rCompDev,DeviceFormat eFormat=DeviceFormat::DEFAULT)121 explicit VirtualDevice(const OutputDevice& rCompDev, 122 DeviceFormat eFormat = DeviceFormat::DEFAULT) 123 : VirtualDevice(&rCompDev, eFormat, DeviceFormat::NONE, OUTDEV_VIRDEV) {} 124 125 /** Create a virtual device of size 1x1 with alpha channel 126 127 @param rCompDev 128 The generated vdev will be compatible to this device. 129 130 @param eFormat 131 Device format of the generated virtual device. Use DeviceFormat::DEFAULT here, to 132 indicate: take default screen depth. 133 134 @param eAlphaFormat 135 Device format of the generated virtual device. Use DeviceFormat::DEFAULT here, to 136 indicate: take default screen depth. 137 */ VirtualDevice(const OutputDevice & rCompDev,DeviceFormat eFormat,DeviceFormat eAlphaFormat)138 explicit VirtualDevice(const OutputDevice& rCompDev, 139 DeviceFormat eFormat, DeviceFormat eAlphaFormat) 140 : VirtualDevice(&rCompDev, eFormat, eAlphaFormat, OUTDEV_VIRDEV) {} 141 142 /** Create a virtual device using an existing system dependent device or graphics context 143 Any rendering will happen directly on the context and not on any intermediate bitmap. 144 Note: This might not be supported on all platforms ! 145 */ 146 explicit VirtualDevice(const SystemGraphicsData& rData, const Size &rSize, 147 DeviceFormat eFormat); 148 149 virtual ~VirtualDevice() override; 150 virtual void dispose() override; 151 152 bool CanEnableNativeWidget() const override; 153 154 virtual void EnableRTL( bool bEnable = true ) override; 155 156 bool SetOutputSizePixel( const Size& rNewSize, bool bErase = true ); 157 bool SetOutputSizePixelScaleOffsetAndBuffer( const Size& rNewSize, 158 const Fraction& rScale, 159 const Point& rNewOffset, 160 sal_uInt8* pBuffer); 161 SetOutputSize(const Size & rNewSize)162 bool SetOutputSize( const Size& rNewSize ) 163 { return SetOutputSizePixel( LogicToPixel( rNewSize ) ); } 164 165 void SetReferenceDevice( RefDevMode ); 166 167 void Compat_ZeroExtleadBug(); // enable workaround for #i60495# 168 169 void SetReferenceDevice( sal_Int32 i_nDPIX, sal_Int32 i_nDPIY ); 170 171 virtual sal_uInt16 GetBitCount() const override; 172 173 bool IsVirtual() const override; 174 IsScreenComp() const175 bool IsScreenComp() const override { return mbScreenComp; } 176 177 private: 178 SAL_DLLPRIVATE void ImplSetReferenceDevice( RefDevMode, sal_Int32 i_nDPIX, sal_Int32 i_nDPIY ); 179 180 protected: 181 virtual bool UsePolyPolygonForComplexGradient() override; 182 183 virtual tools::Long GetFontExtLeading() const override; 184 185 }; 186 187 #endif // INCLUDED_VCL_VIRDEV_HXX 188 189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 190