25 #include <osl/diagnose.h>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/graphic/XGraphic.hpp>
42 using com::sun::star::uno::XInterface;
43 using com::sun::star::uno::UNO_QUERY;
45 using com::sun::star::container::XNameContainer;
48 #define WATERMARK_LUM_OFFSET 50
49 #define WATERMARK_CON_OFFSET -70
55 std::vector<uno::Reference<css::graphic::XGraphic>> & raGraphicList)
57 uno::Reference<beans::XPropertySet> xPropertySet(xInterface, UNO_QUERY);
58 if (xPropertySet.is())
60 if (xPropertySet->getPropertySetInfo()->hasPropertyByName(
"ImageURL"))
63 xPropertySet->getPropertyValue(
"ImageURL") >>= sURL;
72 }
else if (xPropertySet->getPropertySetInfo()->hasPropertyByName(
"Graphic"))
74 uno::Reference<css::graphic::XGraphic> xGraphic;
75 xPropertySet->getPropertyValue(
"Graphic") >>= xGraphic;
78 raGraphicList.push_back(xGraphic);
85 const css::uno::Sequence<OUString> aElementNames = xContainer->getElementNames();
86 for (OUString
const & rName : aElementNames)
88 uno::Reference<XInterface> xInnerInterface;
89 xContainer->getByName(rName) >>= xInnerInterface;
112 if( aGraphic.IsSupportedGraphic() )
120 aPoly.Rotate( aPt, nRot10 );
123 aSz = aRotBoundRect.GetSize();
126 aGraphic.Draw(rOut, aPt, aSz);
141 switch( aAttr.GetDrawMode() )
165 rBmpEx.
Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
166 aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
167 aAttr.GetGamma(), aAttr.IsInvert() );
172 rBmpEx.
Mirror( aAttr.GetMirrorFlags() );
190 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::DRAWMODE ) && aAttr.IsSpecialDrawMode() )
192 switch( aAttr.GetDrawMode() )
214 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && aAttr.IsAdjusted() )
216 rMtf.
Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
217 aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
218 aAttr.GetGamma(), aAttr.IsInvert() );
221 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && aAttr.IsMirrored() )
223 rMtf.
Mirror( aAttr.GetMirrorFlags() );
226 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && aAttr.IsRotated() )
228 rMtf.
Rotate( aAttr.GetRotation() );
231 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
233 OSL_FAIL(
"Missing implementation: Mtf-Transparency" );
241 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::DRAWMODE ) && aAttr.IsSpecialDrawMode() )
243 switch( aAttr.GetDrawMode() )
265 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::COLORS ) && aAttr.IsAdjusted() )
267 rAnimation.
Adjust( aAttr.GetLuminance(), aAttr.GetContrast(),
268 aAttr.GetChannelR(), aAttr.GetChannelG(), aAttr.GetChannelB(),
269 aAttr.GetGamma(), aAttr.IsInvert() );
272 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::MIRROR ) && aAttr.IsMirrored() )
274 rAnimation.
Mirror( aAttr.GetMirrorFlags() );
277 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::ROTATE ) && aAttr.IsRotated() )
279 OSL_FAIL(
"Missing implementation: Animation-Rotation" );
282 if( ( nAdjustmentFlags & GraphicAdjustmentFlags::TRANSPARENCY ) && aAttr.IsTransparent() )
284 OSL_FAIL(
"Missing implementation: Animation-Transparency" );
296 maGraphic( rGraphic ), maAttr( rAttr ) {}
310 , maAttr(rGraphicObj.maAttr)
358 const Point aOldOrigin( rPt );
359 const MapMode aMap100( MapUnit::Map100thMM );
365 aClipPoly.
Rotate( rPt, nRot10 );
366 bRectClipRegion =
false;
369 bRectClipRegion =
true;
371 rClipPolyPoly = aClipPoly;
384 if( !aSize100.
IsEmpty() && nTotalWidth > 0 && nTotalHeight > 0 )
386 double fScale =
static_cast<double>(aSize100.
Width()) / nTotalWidth;
390 fScale =
static_cast<double>(rSz.
Width()) / aSize100.
Width();
391 rPt.AdjustX(
FRound( nNewLeft * fScale ) );
394 fScale =
static_cast<double>(aSize100.
Height()) / nTotalHeight;
398 fScale =
static_cast<double>(rSz.
Height()) / aSize100.
Height();
399 rPt.AdjustY(
FRound( nNewTop * fScale ) );
406 aOriginPoly[ 0 ] = rPt;
407 aOriginPoly.
Rotate( aOldOrigin, nRot10 );
408 rPt = aOriginPoly[ 0 ];
420 if( &rGraphicObj !=
this )
473 if( aSz.
Width() < 0 )
475 aPt.AdjustX(aSz.
Width() + 1 );
483 aPt.AdjustY(aSz.
Height() + 1 );
492 const bool bCrop =
ImplGetCropParams(rOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip);
512 bRet = lclDrawObj(rOut, aPt, aSz, *
this, aAttr);
523 const Size& rOffset,
int nTileCacheSize1D)
536 nTileCacheSize1D /= 2;
538 nTileCacheSize1D /= 2;
540 ImplDrawTiled(rOut, rArea, aOutTileSize, rOffset,
nullptr, nTileCacheSize1D);
563 const bool bCrop =
ImplGetCropParams(rOut, aPt, aSz, &aAttr, aClipPolyPoly, bRectClip);
582 mxSimpleCache->maGraphic.StartAnimation(rOut, aPt, aSz, nExtraData, pFirstFrameOutDev);
590 bRet =
Draw(rOut, rPt, rSz, &aAttr);
620 const MapMode aMap100( MapUnit::Map100thMM );
623 Size aCropRightBottom;
629 if (aMapGraph.GetMapUnit() == MapUnit::MapPixel)
658 const MapMode aMtfMapMode( aMtf.GetPrefMapMode() );
661 aMtfMapMode.GetOrigin().Y() + aCropLeftTop.
Height(),
662 aMtfMapMode.GetOrigin().X() + aSrcSize.Width() - aCropRightBottom.
Width(),
663 aMtfMapMode.GetOrigin().Y() + aSrcSize.Height() - aCropRightBottom.
Height() );
669 aMtf.Scale( static_cast<double>(rDestSize.
Width()) / (aSrcSize.Width() - aCropLeftTop.
Width() - aCropRightBottom.
Width()),
670 static_cast<double>(rDestSize.
Height()) / (aSrcSize.Height() - aCropLeftTop.
Height() - aCropRightBottom.
Height()) );
675 aMtf.SetPrefSize(
Size( static_cast<tools::Long>(static_cast<double>(rDestSize.
Width()) * (1.0 + (aCropLeftTop.
Width() + aCropRightBottom.
Width()) / aSrcSize.Width()) + .5),
676 static_cast<tools::Long>(
static_cast<double>(rDestSize.
Height()) * (1.0 + (aCropLeftTop.
Height() + aCropRightBottom.
Height()) / aSrcSize.Height()) + .5) ) );
680 Point aNewOrigin( static_cast<tools::Long>(static_cast<double>(aMtfMapMode.GetOrigin().X()) + rDestSize.
Width() * aCropLeftTop.
Width() / (aSrcSize.Width() - aCropLeftTop.
Width() - aCropRightBottom.
Width()) + .5),
681 static_cast<tools::Long>(
static_cast<double>(aMtfMapMode.GetOrigin().Y()) + rDestSize.
Height() * aCropLeftTop.
Height() / (aSrcSize.Height() - aCropLeftTop.
Height() - aCropRightBottom.
Height()) + .5) );
684 aMtf.SetPrefMapMode( aNewMap );
689 aMtf.SetPrefMapMode( rDestMap );
692 aTransGraphic = aMtf;
702 if (aMapGraph.GetMapUnit() == MapUnit::MapPixel)
730 && (aSrcSizePixel.
Width() != aBitmapEx.GetSizePixel().Width() || aSrcSizePixel.
Height() != aBitmapEx.GetSizePixel().Height())
731 && aSrcSizePixel.
Width())
742 const double fFactorX(static_cast<double>(aBitmapEx.GetSizePixel().Width()) / aSrcSizePixel.
Width());
743 const double fFactorY(static_cast<double>(aBitmapEx.GetSizePixel().Height()) / aSrcSizePixel.
Height());
750 aSrcSizePixel = aBitmapEx.GetSizePixel();
755 aSrcSizePixel.
Width() - aCropRightBottom.
Width(),
764 for(
size_t nFrame=0; nFrame<aAnim.Count(); ++nFrame )
768 if( !aCropRect.Contains(
tools::Rectangle(aAnimationBitmap.maPositionPixel, aAnimationBitmap.maSizePixel) ) )
772 aCropRectRel.
Move( -aAnimationBitmap.maPositionPixel.X(),
773 -aAnimationBitmap.maPositionPixel.Y() );
778 aCropRectRel, rDestSize,
false );
780 aAnim.Replace( aAnimationBitmap, nFrame );
787 if( aCropLeftTop.
Width() < 0 ||
788 aCropLeftTop.
Height() < 0 ||
789 aCropRightBottom.
Width() < 0 ||
790 aCropRightBottom.
Height() < 0 )
792 Size aNewSize( aAnim.GetDisplaySizePixel() );
794 aNewSize.AdjustWidth(aCropLeftTop.
Width() < 0 ? -aCropLeftTop.
Width() : 0 );
795 aNewSize.AdjustHeight(aCropRightBottom.
Height() < 0 ? -aCropRightBottom.
Height() : 0 );
796 aNewSize.AdjustHeight(aCropLeftTop.
Height() < 0 ? -aCropLeftTop.
Height() : 0 );
797 aAnim.SetDisplaySizePixel( aNewSize );
802 if( aCropLeftTop.
Width() < 0 ||
803 aCropLeftTop.
Height() < 0 )
805 Point aPosOffset( aCropLeftTop.
Width() < 0 ? -aCropLeftTop.
Width() : 0,
806 aCropLeftTop.
Height() < 0 ? -aCropLeftTop.
Height() : 0 );
808 for(
size_t nFrame=0; nFrame<aAnim.Count(); ++nFrame )
814 aAnim.Replace( aAnimationBitmap, nFrame );
818 aTransGraphic = aAnim;
823 aCropRect, rDestSize,
true );
825 aTransGraphic = aBitmapEx;
835 return aTransGraphic;
856 aGraphic = aAnimation;
878 aGraphic = aAnimation;
901 double fBottomCrop)
const
903 const MapMode aMapMode100thmm(MapUnit::Map100thMM);
905 double fFactorX(1.0);
906 double fFactorY(1.0);
917 const double fDivX(aBitmapSize.
Width() - fLeftCrop - fRightCrop);
918 const double fDivY(aBitmapSize.
Height() - fTopCrop - fBottomCrop);
922 fFactorX = fabs(fWidth) / fDivX;
927 fFactorY = fabs(fHeight) / fDivY;
tools::Long GetBottomCrop() const
void SetLoopCount(const sal_uInt32 nLoopCount)
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.
SAL_WARN_UNUSED_RESULT 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)
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
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.
bool operator==(const GraphicObject &rCacheObj) const
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
void SetDrawMode(DrawModeFlags nDrawMode)
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
constexpr tools::Long Width() const
bool Draw(OutputDevice &rOut, const Point &rPt, const Size &rSz, const GraphicAttr *pAttr=nullptr) const
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)
static bool isGraphicObjectUniqueIdURL(std::u16string_view rURL)
bool VCL_DLLPRIVATE ImplDrawTiled(OutputDevice &rOut, const tools::Rectangle &rArea, const Size &rSizePixel, const Size &rOffset, const GraphicAttr *pAttr, int nTileCacheSize1D)
bool IsSpecialDrawMode() const
GraphicType GetType() const
bool StartAnimation(OutputDevice &rOut, const Point &rPt, const Size &rSz, tools::Long nExtraData=0, OutputDevice *pFirstFrameOutDev=nullptr)
class SAL_NO_VTABLE XPropertySet
tools::Long FRound(double fVal)
const GraphicAttr & GetAttr() const
tools::Long GetRightCrop() 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 DrawTiled(OutputDevice &rOut, const tools::Rectangle &rArea, const Size &rSize, const Size &rOffset, int nTileCacheSize1D=128)
Draw the graphic repeatedly into the given output rectangle.
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.
GraphicType GetType() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
const Graphic & GetGraphic() const
MapMode GetPrefMapMode() const
constexpr tools::Long Height() const
sal_uInt32 GetAnimationLoopCount() const
void SetGraphic(const Graphic &rGraphic)
OString getUniqueID() const
tools::Long GetLeftCrop() const
tools::Long AdjustWidth(tools::Long n)
std::unique_ptr< GrfSimpleCacheObj > mxSimpleCache
void SetPrefSize(const Size &rPrefSize)
GraphicObject & operator=(const GraphicObject &rCacheObj)
void setHeight(tools::Long nHeight)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
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 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
Degree10 GetRotation() const
bool VCL_DLLPRIVATE ImplGetCropParams(const OutputDevice &rOut, Point &rPt, Size &rSz, const GraphicAttr *pAttr, tools::PolyPolygon &rClipPolyPoly, bool &bRectClipRegion) const