22#include <com/sun/star/frame/XModel.hpp>
38#include <bitmaps.hlst>
48SgaObject::SgaObject(
const SgaObject& aObject)
49 : aThumbBmp(aObject.aThumbBmp)
50 , aThumbMtf(aObject.aThumbMtf)
52 , aTitle(aObject.aTitle)
53 , bIsValid(aObject.bIsValid)
54 , bIsThumbBmp(aObject.bIsThumbBmp)
58BitmapEx SgaObject::createPreviewBitmapEx(
const Size& rSizePixel)
const
66 aRetval =
BitmapEx(RID_SVXBMP_GALLERY_MEDIA);
68 else if(IsThumbBitmap())
70 aRetval = GetThumbBmp();
74 const Graphic aGraphic(GetThumbMtf());
76 aRetval = aGraphic.GetBitmapEx();
82 const double fScaleX(
static_cast<double>(rSizePixel.
Width()) /
static_cast<double>(aCurrentSizePixel.Width()));
83 const double fScaleY(
static_cast<double>(rSizePixel.
Height()) /
static_cast<double>(aCurrentSizePixel.Height()));
84 const double fScale(std::min(fScaleX, fScaleY));
88 if(fScale < 1.0 && fabs(1.0 - fScale) > 0.005)
90 aRetval.
Scale(fScale, fScale, BmpScaleFlag::BestQuality);
98bool SgaObject::CreateThumb(
const Graphic& rGraphic )
102 if( rGraphic.
GetType() == GraphicType::Bitmap )
105 Size aBmpSize( aBmpEx.GetSizePixel() );
107 if( aBmpSize.Width() && aBmpSize.Height() )
109 if( aBmpEx.GetPrefMapMode().GetMapUnit() != MapUnit::MapPixel &&
110 aBmpEx.GetPrefSize().Width() > 0 &&
111 aBmpEx.GetPrefSize().Height() > 0 )
115 if( !aLogSize.IsEmpty() )
117 double fFactorLog =
static_cast< double >( aLogSize.Width() ) / aLogSize.Height();
118 double fFactorPix =
static_cast< double >( aBmpSize.Width() ) / aBmpSize.Height();
120 if( fFactorPix > fFactorLog )
121 aBmpSize.setWidth(
FRound( aBmpSize.Height() * fFactorLog ) );
123 aBmpSize.setHeight(
FRound( aBmpSize.Width() / fFactorLog ) );
125 aBmpEx.Scale(aBmpSize, BmpScaleFlag::BestQuality);
132 if( ( aBmpSize.Width() <=
S_THUMB ) && ( aBmpSize.Height() <=
S_THUMB ) )
134 aThumbBmp.Convert( BmpConversion::N8BitColors );
139 const float fFactor =
static_cast<float>(aBmpSize.Width()) / aBmpSize.Height();
143 static_cast<double>(aNewSize.Width()) / aBmpSize.Width(),
144 static_cast<double>(aNewSize.Height()) / aBmpSize.Height(),
145 BmpScaleFlag::BestQuality ) )
147 aThumbBmp.Convert( BmpConversion::N8BitColors );
153 else if( rGraphic.
GetType() == GraphicType::GdiMetafile )
156 const double fFactor =
static_cast<double>(aPrefSize.Width()) /
static_cast<double>(aPrefSize.Height());
159 aSize.setWidth(
static_cast<sal_Int32
>(
S_THUMB * fFactor ) );
161 aSize.setHeight(
static_cast<sal_Int32
>(
S_THUMB / fFactor ) );
166 if( !aThumbBmp.IsEmpty() )
168 aThumbBmp.
Convert( BmpConversion::N8BitColors );
176void SgaObject::WriteData(
SvStream& rOut,
const OUString& rDestDir )
const
178 static const sal_uInt32 nInventor =
COMPAT_FORMAT(
'S',
'G',
'A',
'3' );
186 const sal_Int32 nOldVersion = rOut.
GetVersion();
201 aWriter.Write(aThumbMtf);
206 aURLWithoutDestDir = aURLWithoutDestDir.replaceFirst(rDestDir,
"");
210void SgaObject::ReadData(
SvStream& rIn, sal_uInt16& rReadVersion )
224 aReader.Read( aThumbMtf );
231OUString
const & SgaObject::GetTitle()
const
236void SgaObject::SetTitle(
const OUString& rTitle )
243 rObj.WriteData( rOut,
"" );
249 sal_uInt16 nReadVersion;
251 rObj.ReadData( rIn, nReadVersion );
267 Init( aGraphic, rURL );
273 Init( rGraphic, rURL );
279 bIsValid = CreateThumb( rGraphic );
285 SgaObject::WriteData( rOut, rDestDir );
286 char const aDummy[ 10 ] = { 0 };
295 SgaObject::ReadData( rIn, rReadVersion );
299 if( rReadVersion >= 5 )
343 sId = RID_SVXBMP_GALLERY_MEDIA;
354 SgaObject::WriteData( rOut, rDestDir );
361 SgaObject::ReadData( rIn, rReadVersion );
363 if( rReadVersion >= 5 )
369 if( rReadVersion >= 6 )
382 bIsValid = CreateThumb( rGraphic );
406: mpFormModel( nullptr )
452 bRet = SgaObject::CreateThumb( aGraphic );
471 bRet = SgaObject::CreateThumb(aGraphic);
481 SgaObject::WriteData( rOut, rDestDir );
487 SgaObject::ReadData( rIn, rReadVersion );
489 if( rReadVersion >= 5 )
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
bool Convert(BmpConversion eConversion)
const Size & GetSizePixel() const
GraphicType GetType() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
BitmapEx GetMarkedObjBitmapEx(bool bNoVDevIfOneBmpMarked=false, const sal_uInt32 nMaximumQuadraticPixels=500000, const std::optional< Size > &rTargetDPI=std::nullopt) const
void MarkAllObj(SdrPageView *pPV=nullptr)
const SdrPage * GetPage(sal_uInt16 nPgNum) const
const tools::Rectangle & GetAllObjBoundRect() const
static SfxObjectShell * CreateObjectByFactoryName(const OUString &rURL, SfxObjectCreateMode=SfxObjectCreateMode::STANDARD)
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual void WriteData(SvStream &rOut, const OUString &rDestDir) const override
void Init(const Graphic &rGraphic, const INetURLObject &rURL)
virtual void ReadData(SvStream &rIn, sal_uInt16 &rReadVersion) override
virtual void ReadData(SvStream &rIn, sal_uInt16 &rReadVersion) override
virtual BitmapEx GetThumbBmp() const override
virtual void WriteData(SvStream &rOut, const OUString &rDestDir) const override
virtual ~SgaObjectSound() override
virtual void ReadData(SvStream &rIn, sal_uInt16 &rReadVersion) override
bool CreateThumb(const FmFormModel &rModel)
virtual void WriteData(SvStream &rOut, const OUString &rDestDir) const override
constexpr tools::Long Height() const
constexpr tools::Long Width() const
SvStream & ReadCharAsBool(bool &rBool)
void SetCompressMode(SvStreamCompressFlags nNewMode)
SvStreamCompressFlags GetCompressMode() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
SvStream & WriteBool(bool b)
SvStream & WriteUInt16(sal_uInt16 nUInt16)
sal_Int32 GetVersion() const
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
void SetVersion(sal_Int32 n)
sal_uInt64 SeekRel(sal_Int64 nPos)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
FmFormModel * GetModel() const
FmFormModel * mpFormModel
static bool FileExists(const INetURLObject &rURL, std::u16string_view rExt)
bool CreateIMapGraphic(const FmFormModel &rModel, Graphic &rGraphic, ImageMap &rImageMap)
bool GallerySvDrawImport(SvStream &rIStm, SdrModel &rModel)
GalleryGraphicImportRet GalleryGraphicImport(const INetURLObject &rURL, Graphic &rGraphic, OUString &rFilterName)
SvStream & ReadSgaObject(SvStream &rIn, SgaObject &rObj)
SvStream & WriteSgaObject(SvStream &rOut, const SgaObject &rObj)
tools::Long FRound(double fVal)
sal_uInt16 GetVersion(sal_uInt16)
OString read_uInt16_lenPrefixed_uInt8s_ToOString(SvStream &rStrm)
OUString read_uInt16_lenPrefixed_uInt8s_ToOUString(SvStream &rStrm, rtl_TextEncoding eEnc)
TOOLS_DLLPUBLIC std::size_t write_uInt16_lenPrefixed_uInt8s_FromOString(SvStream &rStrm, std::string_view rStr)
std::size_t write_uInt16_lenPrefixed_uInt8s_FromOUString(SvStream &rStrm, std::u16string_view rStr, rtl_TextEncoding eEnc)
sal_uInt32 COMPAT_FORMAT(char char1, char char2, char char3, char char4)