24 #include <osl/diagnose.h>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/graphic/XGraphic.hpp>
41 using com::sun::star::uno::XInterface;
42 using com::sun::star::uno::UNO_QUERY;
44 using com::sun::star::container::XNameContainer;
47 #define WATERMARK_LUM_OFFSET 50
48 #define WATERMARK_CON_OFFSET -70
54 std::vector<uno::Reference<css::graphic::XGraphic>> & raGraphicList)
56 uno::Reference<beans::XPropertySet> xPropertySet(xInterface, UNO_QUERY);
57 if (xPropertySet.is())
59 if (xPropertySet->getPropertySetInfo()->hasPropertyByName(
"ImageURL"))
62 xPropertySet->getPropertyValue(
"ImageURL") >>= sURL;
71 }
else if (xPropertySet->getPropertySetInfo()->hasPropertyByName(
"Graphic"))
73 uno::Reference<css::graphic::XGraphic>
xGraphic;
74 xPropertySet->getPropertyValue(
"Graphic") >>= xGraphic;
77 raGraphicList.push_back(xGraphic);
84 const css::uno::Sequence<OUString> aElementNames = xContainer->getElementNames();
85 for (OUString
const & rName : aElementNames)
87 uno::Reference<XInterface> xInnerInterface;
88 xContainer->getByName(rName) >>= xInnerInterface;
111 if( aGraphic.IsSupportedGraphic() )
119 aPoly.Rotate( aPt, nRot10 );
122 aSz = aRotBoundRect.GetSize();
125 aGraphic.Draw( pOut, aPt, aSz );
140 switch( aAttr.GetDrawMode() )
164 rBmpEx.
Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
165 aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
166 aAttr.GetGamma(), aAttr.IsInvert() );
171 rBmpEx.
Mirror( aAttr.GetMirrorFlags() );
189 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::DRAWMODE ) && aAttr.IsSpecialDrawMode() )
191 switch( aAttr.GetDrawMode() )
213 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && aAttr.IsAdjusted() )
215 rMtf.
Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
216 aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
217 aAttr.GetGamma(), aAttr.IsInvert() );
220 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && aAttr.IsMirrored() )
222 rMtf.
Mirror( aAttr.GetMirrorFlags() );
225 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && aAttr.IsRotated() )
227 rMtf.
Rotate( aAttr.GetRotation() );
230 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
232 OSL_FAIL(
"Missing implementation: Mtf-Transparency" );
240 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::DRAWMODE ) && aAttr.IsSpecialDrawMode() )
242 switch( aAttr.GetDrawMode() )
264 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && aAttr.IsAdjusted() )
266 rAnimation.
Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
267 aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
268 aAttr.GetGamma(), aAttr.IsInvert() );
271 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && aAttr.IsMirrored() )
273 rAnimation.
Mirror( aAttr.GetMirrorFlags() );
276 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && aAttr.IsRotated() )
278 OSL_FAIL(
"Missing implementation: Animation-Rotation" );
281 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
283 OSL_FAIL(
"Missing implementation: Animation-Transparency" );
295 maGraphic( rGraphic ), maAttr( rAttr ) {}
309 , maAttr(rGraphicObj.maAttr)
357 const Point aOldOrigin( rPt );
358 const MapMode aMap100( MapUnit::Map100thMM );
364 aClipPoly.
Rotate( rPt, nRot10 );
365 bRectClipRegion =
false;
368 bRectClipRegion =
true;
370 rClipPolyPoly = aClipPoly;
383 if( !aSize100.
IsEmpty() && nTotalWidth > 0 && nTotalHeight > 0 )
385 double fScale =
static_cast<double>(aSize100.
Width()) / nTotalWidth;
389 fScale =
static_cast<double>(rSz.
Width()) / aSize100.
Width();
390 rPt.AdjustX(
FRound( nNewLeft * fScale ) );
393 fScale =
static_cast<double>(aSize100.
Height()) / nTotalHeight;
397 fScale =
static_cast<double>(rSz.
Height()) / aSize100.
Height();
398 rPt.AdjustY(
FRound( nNewTop * fScale ) );
405 aOriginPoly[ 0 ] = rPt;
406 aOriginPoly.
Rotate( aOldOrigin, nRot10 );
407 rPt = aOriginPoly[ 0 ];
419 if( &rGraphicObj !=
this )
472 if( aSz.
Width() < 0 )
474 aPt.AdjustX(aSz.
Width() + 1 );
482 aPt.AdjustY(aSz.
Height() + 1 );
491 const bool bCrop =
ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
511 bRet = lclDrawObj(pOut, aPt, aSz, *
this, aAttr);
522 const Size& rOffset,
int nTileCacheSize1D )
524 if( pOut ==
nullptr || rSize.
IsEmpty() )
535 nTileCacheSize1D /= 2;
537 nTileCacheSize1D /= 2;
539 ImplDrawTiled( pOut, rArea, aOutTileSize, rOffset,
nullptr, nTileCacheSize1D );
562 const bool bCrop =
ImplGetCropParams( pOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip );
581 mxSimpleCache->maGraphic.StartAnimation(pOut, aPt, aSz, nExtraData, pFirstFrameOutDev);
589 bRet =
Draw( pOut, rPt, rSz, &aAttr );
619 const MapMode aMap100( MapUnit::Map100thMM );
622 Size aCropRightBottom;
628 if (aMapGraph.GetMapUnit() == MapUnit::MapPixel)
657 const MapMode aMtfMapMode( aMtf.GetPrefMapMode() );
660 aMtfMapMode.GetOrigin().Y() + aCropLeftTop.
Height(),
661 aMtfMapMode.GetOrigin().X() + aSrcSize.Width() - aCropRightBottom.
Width(),
662 aMtfMapMode.GetOrigin().Y() + aSrcSize.Height() - aCropRightBottom.
Height() );
665 aMtf.AddAction(
new MetaISectRectClipRegionAction( aClipRect ), 0 );
668 aMtf.Scale( static_cast<double>(rDestSize.
Width()) / (aSrcSize.Width() - aCropLeftTop.
Width() - aCropRightBottom.
Width()),
669 static_cast<double>(rDestSize.
Height()) / (aSrcSize.Height() - aCropLeftTop.
Height() - aCropRightBottom.
Height()) );
674 aMtf.SetPrefSize(
Size( static_cast<tools::Long>(static_cast<double>(rDestSize.
Width()) * (1.0 + (aCropLeftTop.
Width() + aCropRightBottom.
Width()) / aSrcSize.Width()) + .5),
675 static_cast<tools::Long>(
static_cast<double>(rDestSize.
Height()) * (1.0 + (aCropLeftTop.
Height() + aCropRightBottom.
Height()) / aSrcSize.Height()) + .5) ) );
679 Point aNewOrigin( static_cast<tools::Long>(static_cast<double>(aMtfMapMode.GetOrigin().X()) + rDestSize.
Width() * aCropLeftTop.
Width() / (aSrcSize.Width() - aCropLeftTop.
Width() - aCropRightBottom.
Width()) + .5),
680 static_cast<tools::Long>(
static_cast<double>(aMtfMapMode.GetOrigin().Y()) + rDestSize.
Height() * aCropLeftTop.
Height() / (aSrcSize.Height() - aCropLeftTop.
Height() - aCropRightBottom.
Height()) + .5) );
683 aMtf.SetPrefMapMode( aNewMap );
688 aMtf.SetPrefMapMode( rDestMap );
691 aTransGraphic = aMtf;
701 if (aMapGraph.GetMapUnit() == MapUnit::MapPixel)
729 && (aSrcSizePixel.
Width() != aBitmapEx.GetSizePixel().Width() || aSrcSizePixel.
Height() != aBitmapEx.GetSizePixel().Height())
730 && aSrcSizePixel.
Width())
741 const double fFactorX(static_cast<double>(aBitmapEx.GetSizePixel().Width()) / aSrcSizePixel.
Width());
742 const double fFactorY(static_cast<double>(aBitmapEx.GetSizePixel().Height()) / aSrcSizePixel.
Height());
749 aSrcSizePixel = aBitmapEx.GetSizePixel();
754 aSrcSizePixel.
Width() - aCropRightBottom.
Width(),
763 for(
size_t nFrame=0; nFrame<aAnim.Count(); ++nFrame )
767 if( !aCropRect.IsInside(
tools::Rectangle(aAnimationBitmap.maPositionPixel, aAnimationBitmap.maSizePixel) ) )
771 aCropRectRel.
Move( -aAnimationBitmap.maPositionPixel.X(),
772 -aAnimationBitmap.maPositionPixel.Y() );
777 aCropRectRel, rDestSize,
false );
779 aAnim.Replace( aAnimationBitmap, nFrame );
786 if( aCropLeftTop.
Width() < 0 ||
787 aCropLeftTop.
Height() < 0 ||
788 aCropRightBottom.
Width() < 0 ||
789 aCropRightBottom.
Height() < 0 )
791 Size aNewSize( aAnim.GetDisplaySizePixel() );
793 aNewSize.AdjustWidth(aCropLeftTop.
Width() < 0 ? -aCropLeftTop.
Width() : 0 );
794 aNewSize.AdjustHeight(aCropRightBottom.
Height() < 0 ? -aCropRightBottom.
Height() : 0 );
795 aNewSize.AdjustHeight(aCropLeftTop.
Height() < 0 ? -aCropLeftTop.
Height() : 0 );
796 aAnim.SetDisplaySizePixel( aNewSize );
801 if( aCropLeftTop.
Width() < 0 ||
802 aCropLeftTop.
Height() < 0 )
804 Point aPosOffset( aCropLeftTop.
Width() < 0 ? -aCropLeftTop.
Width() : 0,
805 aCropLeftTop.
Height() < 0 ? -aCropLeftTop.
Height() : 0 );
807 for(
size_t nFrame=0; nFrame<aAnim.Count(); ++nFrame )
813 aAnim.Replace( aAnimationBitmap, nFrame );
817 aTransGraphic = aAnim;
822 aCropRect, rDestSize,
true );
824 aTransGraphic = aBitmapEx;
834 return aTransGraphic;
855 aGraphic = aAnimation;
877 aGraphic = aAnimation;
889 return rURL.startsWith(
"vnd.sun.star.GraphicObject:");
900 double fBottomCrop)
const
902 const MapMode aMapMode100thmm(MapUnit::Map100thMM);
904 double fFactorX(1.0);
905 double fFactorY(1.0);
916 const double fDivX(aBitmapSize.
Width() - fLeftCrop - fRightCrop);
917 const double fDivY(aBitmapSize.
Height() - fTopCrop - fBottomCrop);
921 fFactorX = fabs(fWidth) / fDivX;
926 fFactorY = fabs(fHeight) / fDivY;
tools::Long GetBottomCrop() const
void SetLoopCount(const sal_uInt32 nLoopCount)
bool Draw(OutputDevice *pOut, const Point &rPt, const Size &rSz, const GraphicAttr *pAttr=nullptr)
BmpMirrorFlags GetMirrorFlags() const
void setWidth(tools::Long nWidth)
bool Adjust(short nLuminancePercent, short nContrastPercent, short nChannelRPercent, short nChannelGPercent, short nChannelBPercent, double fGamma=1.0, bool bInvert=false, bool msoBrightness=false)
Change various global color characteristics.
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void SetPrefMapMode(const MapMode &rPrefMapMode)
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
static bool isGraphicObjectUniqueIdURL(OUString const &rURL)
bool IsSupportedGraphic() const
void SetMirrorFlags(BmpMirrorFlags nMirrFlags)
const MapMode & GetMapMode() const
void IntersectClipRegion(const tools::Rectangle &rRect)
tools::Long GetTopCrop() const
bool IsTransparent() const
#define WATERMARK_CON_OFFSET
Graphic loadFromURL(OUString const &rURL, weld::Window *pParentWin)
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Graphic GetTransformedGraphic(const Size &rDestSize, const MapMode &rDestMap, const GraphicAttr &rAttr) const
Get graphic transformed according to given attributes.
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
bool operator==(const GraphicObject &rCacheObj) const
void SetDrawMode(DrawModeFlags nDrawMode)
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
OString GetUniqueID() const
const GDIMetaFile & GetGDIMetaFile() const
void StopAnimation(const OutputDevice *pOut=nullptr, tools::Long nExtraData=0)
bool IsTransparent() const
Sequence< NamedValue > maUserData
B2IRange fround(const B2DRange &rRange)
MapMode GetPrefMapMode() const
void Mirror(BmpMirrorFlags nMirrorFlags)
Animation GetAnimation() const
bool Mirror(BmpMirrorFlags nMirrorFlags)
Mirror the bitmap.
void AdjustTransparency(sal_uInt8 cTrans)
bool IsSpecialDrawMode() const
GraphicType GetType() const
class SAL_NO_VTABLE XPropertySet
tools::Long FRound(double fVal)
const GraphicAttr & GetAttr() const
tools::Long GetRightCrop() const
tools::Long Width() const
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
#define WATERMARK_LUM_OFFSET
GrfSimpleCacheObj(const Graphic &rGraphic, const GraphicAttr &rAttr)
void SetAttr(const GraphicAttr &rAttr)
MapUnit GetMapUnit() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
DrawModeFlags GetDrawMode() const
bool Rotate(Degree10 nAngle10, const Color &rFillColor)
Rotate bitmap by the specified angle.
bool VCL_DLLPRIVATE ImplGetCropParams(OutputDevice const *pOut, Point &rPt, Size &rSz, const GraphicAttr *pAttr, tools::PolyPolygon &rClipPolyPoly, bool &bRectClipRegion) const
GraphicType GetType() const
Point PixelToLogic(const Point &rDevicePt) const
Point LogicToPixel(const Point &rLogicPt) const
bool StartAnimation(OutputDevice *pOut, const Point &rPt, const Size &rSz, tools::Long nExtraData=0, OutputDevice *pFirstFrameOutDev=nullptr)
const Graphic & GetGraphic() const
MapMode GetPrefMapMode() const
sal_uInt32 GetAnimationLoopCount() const
void SetGraphic(const Graphic &rGraphic)
void DrawTiled(OutputDevice *pOut, const tools::Rectangle &rArea, const Size &rSize, const Size &rOffset, int nTileCacheSize1D=128)
Draw the graphic repeatedly into the given output rectangle.
OString getUniqueID() const
tools::Long GetLeftCrop() const
tools::Long AdjustWidth(tools::Long n)
std::unique_ptr< GrfSimpleCacheObj > mxSimpleCache
tools::Long Height() const
bool VCL_DLLPRIVATE ImplDrawTiled(OutputDevice *pOut, const tools::Rectangle &rArea, const Size &rSizePixel, const Size &rOffset, const GraphicAttr *pAttr, int nTileCacheSize1D)
void SetPrefSize(const Size &rPrefSize)
GraphicObject & operator=(const GraphicObject &rCacheObj)
void setHeight(tools::Long nHeight)
void SearchForGraphics(uno::Reference< uno::XInterface > const &xInterface, std::vector< uno::Reference< css::graphic::XGraphic >> &raGraphicList)
void VCL_DLLPRIVATE ImplTransformBitmap(BitmapEx &rBmpEx, const GraphicAttr &rAttr, const Size &rCropLeftTop, const Size &rCropRightBottom, const tools::Rectangle &rCropRect, const Size &rDstSize, bool bEnlarge) const
basegfx::B2DVector calculateCropScaling(double fWidth, double fHeight, double fLeftCrop, double fTopCrop, double fRightCrop, double fBottomCrop) const
void Push(PushFlags nFlags=PushFlags::ALL)
void Convert(BmpConversion eConversion)
void Adjust(short nLuminancePercent, short nContrastPercent, short nChannelRPercent, short nChannelGPercent, short nChannelBPercent, double fGamma=1.0, bool bInvert=false)
bool IsTransparent() const
Reference< XGraphic > xGraphic
Degree10 GetRotation() const