LibreOffice Module vcl (master)  1
mask.cxx
Go to the documentation of this file.
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 #include <cassert>
21 
22 #include <vcl/gdimtf.hxx>
23 #include <vcl/metaact.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/virdev.hxx>
26 
27 #include <salgdi.hxx>
28 #include <salbmp.hxx>
29 
30 void OutputDevice::DrawMask( const Point& rDestPt,
31  const Bitmap& rBitmap, const Color& rMaskColor )
32 {
33  assert(!is_double_buffered_window());
34 
35  const Size aSizePix( rBitmap.GetSizePixel() );
36  DrawMask( rDestPt, PixelToLogic( aSizePix ), Point(), aSizePix, rBitmap, rMaskColor, MetaActionType::MASK );
37 }
38 
39 void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
40  const Bitmap& rBitmap, const Color& rMaskColor )
41 {
42  assert(!is_double_buffered_window());
43 
44  DrawMask( rDestPt, rDestSize, Point(), rBitmap.GetSizePixel(), rBitmap, rMaskColor, MetaActionType::MASKSCALE );
45 }
46 
47 void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
48  const Point& rSrcPtPixel, const Size& rSrcSizePixel,
49  const Bitmap& rBitmap, const Color& rMaskColor,
50  const MetaActionType nAction )
51 {
52  assert(!is_double_buffered_window());
53 
54  if( ImplIsRecordLayout() )
55  return;
56 
58  {
59  DrawRect( tools::Rectangle( rDestPt, rDestSize ) );
60  return;
61  }
62 
63  if ( mpMetaFile )
64  {
65  switch( nAction )
66  {
68  mpMetaFile->AddAction( new MetaMaskAction( rDestPt,
69  rBitmap, rMaskColor ) );
70  break;
71 
74  rDestSize, rBitmap, rMaskColor ) );
75  break;
76 
78  mpMetaFile->AddAction( new MetaMaskScalePartAction( rDestPt, rDestSize,
79  rSrcPtPixel, rSrcSizePixel, rBitmap, rMaskColor ) );
80  break;
81 
82  default: break;
83  }
84  }
85 
86  if ( !IsDeviceOutputNecessary() )
87  return;
88 
89  if ( !mpGraphics && !AcquireGraphics() )
90  return;
91 
92  if ( mbInitClipRegion )
94 
95  if ( mbOutputClipped )
96  return;
97 
98  DrawDeviceMask( rBitmap, rMaskColor, rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel );
99 
100 }
101 
102 void OutputDevice::DrawDeviceMask( const Bitmap& rMask, const Color& rMaskColor,
103  const Point& rDestPt, const Size& rDestSize,
104  const Point& rSrcPtPixel, const Size& rSrcSizePixel )
105 {
106  assert(!is_double_buffered_window());
107 
108  const std::shared_ptr<SalBitmap>& xImpBmp = rMask.ImplGetSalBitmap();
109  if (xImpBmp)
110  {
111  SalTwoRect aPosAry(rSrcPtPixel.X(), rSrcPtPixel.Y(), rSrcSizePixel.Width(), rSrcSizePixel.Height(),
112  ImplLogicXToDevicePixel(rDestPt.X()), ImplLogicYToDevicePixel(rDestPt.Y()),
113  ImplLogicWidthToDevicePixel(rDestSize.Width()),
114  ImplLogicHeightToDevicePixel(rDestSize.Height()));
115 
116  // we don't want to mirror via coordinates
117  const BmpMirrorFlags nMirrFlags = AdjustTwoRect( aPosAry, xImpBmp->GetSize() );
118 
119  // check if output is necessary
120  if( aPosAry.mnSrcWidth && aPosAry.mnSrcHeight && aPosAry.mnDestWidth && aPosAry.mnDestHeight )
121  {
122 
123  if( nMirrFlags != BmpMirrorFlags::NONE )
124  {
125  Bitmap aTmp( rMask );
126  aTmp.Mirror( nMirrFlags );
127  mpGraphics->DrawMask( aPosAry, *aTmp.ImplGetSalBitmap(),
128  rMaskColor, this);
129  }
130  else
131  mpGraphics->DrawMask( aPosAry, *xImpBmp, rMaskColor, this );
132 
133  }
134  }
135 
136  // TODO: Use mask here
137  if( mpAlphaVDev )
138  {
139  const Bitmap& rAlphaMask( rMask.CreateMask( rMaskColor ) );
140 
141  // #i25167# Restrict mask painting to _opaque_ areas
142  // of the mask, otherwise we spoil areas where no
143  // bitmap content was ever visible. Interestingly
144  // enough, this can be achieved by taking the mask as
145  // the transparency mask of itself
146  mpAlphaVDev->DrawBitmapEx( rDestPt,
147  rDestSize,
148  rSrcPtPixel,
149  rSrcSizePixel,
150  BitmapEx( rAlphaMask, rMask ) );
151  }
152 }
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
long mnSrcWidth
Definition: salgtype.hxx:52
SAL_DLLPRIVATE bool ImplIsRecordLayout() const
Definition: outdev.cxx:657
long mnSrcHeight
Definition: salgtype.hxx:53
void DrawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor, const OutputDevice *pOutDev)
long Height() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
Definition: bitmap.hxx:518
BmpMirrorFlags AdjustTwoRect(SalTwoRect &rTwoRect, const Size &rSizePix)
Definition: rect.cxx:317
bool mbOutputClipped
Definition: outdev.hxx:381
SAL_DLLPRIVATE bool is_double_buffered_window() const
long mnDestWidth
Definition: salgtype.hxx:56
Size GetSizePixel() const
void DrawMask(const Point &rDestPt, const Bitmap &rBitmap, const Color &rMaskColor)
Definition: mask.cxx:30
virtual void DrawDeviceMask(const Bitmap &rMask, const Color &rMaskColor, const Point &rDestPt, const Size &rDestSize, const Point &rSrcPtPixel, const Size &rSrcSizePixel)
Definition: mask.cxx:102
bool Mirror(BmpMirrorFlags nMirrorFlags)
Mirror the bitmap.
MetaActionType
SAL_DLLPRIVATE long ImplLogicXToDevicePixel(long nX) const
Convert a logical X coordinate to a device pixel's X coordinate.
Definition: map.cxx:410
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:32
SalGraphics * mpGraphics
Graphics context to draw on.
Definition: outdev.hxx:316
SAL_DLLPRIVATE long ImplLogicYToDevicePixel(long nY) const
Convert a logical Y coordinate to a device pixel's Y coordinate.
Definition: map.cxx:420
virtual bool AcquireGraphics() const =0
Acquire a graphics device that the output device uses to draw on.
BmpMirrorFlags
Definition: bitmap.hxx:36
RasterOp meRasterOp
Definition: outdev.hxx:368
long X() const
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1185
VclPtr< VirtualDevice > mpAlphaVDev
Definition: outdev.hxx:331
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:539
bool mbInitClipRegion
Definition: outdev.hxx:388
virtual void InitClipRegion()
SAL_DLLPRIVATE long ImplLogicWidthToDevicePixel(long nWidth) const
Convert a logical width to a width in units of device pixels.
Definition: map.cxx:430
SAL_DLLPRIVATE long ImplLogicHeightToDevicePixel(long nHeight) const
Convert a logical height to a height in units of device pixels.
Definition: map.cxx:440
long mnDestHeight
Definition: salgtype.hxx:57
bool IsDeviceOutputNecessary() const
Definition: outdev.hxx:589
Bitmap CreateMask(const Color &rTransColor, sal_uInt8 nTol=0) const
Create on-off mask from bitmap.
long Y() const
GDIMetaFile * mpMetaFile
Definition: outdev.hxx:319