26#include <com/sun/star/beans/PropertyValue.hpp>
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/graphic/GraphicProvider.hpp>
29#include <com/sun/star/graphic/XGraphicProvider.hpp>
30#include <com/sun/star/io/XInputStream.hpp>
31#include <com/sun/star/uno/Reference.hxx>
37using namespace css::beans;
38using namespace css::graphic;
39using namespace css::io;
40using namespace css::uno;
46 struct XMLGraphicMimeTypeMapper
49 const char* pMimeType;
52 static const XMLGraphicMimeTypeMapper aMapper[]
53 = { {
"gif",
"image/gif" }, {
"png",
"image/png" }, {
"jpg",
"image/jpeg" },
54 {
"tif",
"image/tiff" }, {
"svg",
"image/svg+xml" }, {
"pdf",
"application/pdf" },
55 {
"wmf",
"image/x-wmf" }, {
"emf",
"image/x-emf" }, {
"eps",
"image/x-eps" },
56 {
"bmp",
"image/bmp" }, {
"pct",
"image/x-pict" }, {
"svm",
"image/x-svm" } };
60 size_t const nCount = std::size(aMapper);
63 if (rExt == aMapper[
i].
pExt)
64 aMimeType = OUString(aMapper[
i].pMimeType, strlen(aMapper[
i].pMimeType),
65 RTL_TEXTENCODING_ASCII_US);
73 OUString aSourceMimeType;
74 Reference<XPropertySet>
const xGraphicPropertySet(xGraphic, UNO_QUERY);
75 if (xGraphicPropertySet.is() &&
76 (xGraphicPropertySet->getPropertyValue(
"MimeType") >>= aSourceMimeType))
78 return aSourceMimeType;
87 Reference<XGraphicProvider> xProvider
91 Reference<XGraphic> xGraphic(xProvider->queryGraphic(aMediaProperties));
98 switch (convertDataFormat)
100 case ConvertDataFormat::BMP:
102 case ConvertDataFormat::GIF:
104 case ConvertDataFormat::JPG:
106 case ConvertDataFormat::PCT:
107 return "image/x-pict";
108 case ConvertDataFormat::PNG:
110 case ConvertDataFormat::SVM:
111 return "image/x-svm";
112 case ConvertDataFormat::TIF:
114 case ConvertDataFormat::WMF:
115 return "image/x-wmf";
116 case ConvertDataFormat::EMF:
117 return "image/x-emf";
118 case ConvertDataFormat::SVG:
119 return "image/svg+xml";
120 case ConvertDataFormat::MET:
121 case ConvertDataFormat::Unknown:
129 char const*
pExt =
nullptr;
131 if (nFormat != ConvertDataFormat::Unknown)
135 case ConvertDataFormat::BMP:
138 case ConvertDataFormat::GIF:
141 case ConvertDataFormat::JPG:
144 case ConvertDataFormat::MET:
147 case ConvertDataFormat::PCT:
150 case ConvertDataFormat::PNG:
153 case ConvertDataFormat::SVM:
156 case ConvertDataFormat::TIF:
159 case ConvertDataFormat::WMF:
162 case ConvertDataFormat::EMF:
176 static std::map<OString, OString>
const mimes = {
177 {
"mp4",
"video/mp4" },
178 {
"ts",
"video/MP2T" },
179 {
"mpeg",
"video/mpeg" },
180 {
"mpg",
"video/mpeg" },
181 {
"mkv",
"video/x-matroska" },
182 {
"webm",
"video/webm" },
183 {
"ogv",
"video/ogg" },
184 {
"mov",
"video/quicktime" },
185 {
"wmv",
"video/x-ms-wmv" },
186 {
"avi",
"video/x-msvideo" },
187 {
"m4a",
"audio/mp4" },
188 {
"aac",
"audio/aac" },
189 {
"mp3",
"audio/mpeg" },
190 {
"ogg",
"audio/ogg" },
191 {
"oga",
"audio/ogg" },
192 {
"opus",
"audio/ogg" },
193 {
"flac",
"audio/flac" },
198 {
"wav",
"audio/x-wav" },
205 return IsMediaMimeType(OStringToOUString(rMimeType, RTL_TEXTENCODING_UTF8));
210 static std::set<OUString> mimes;
214 for (
auto const& it : rMap)
216 mimes.insert(OStringToOUString(it.second, RTL_TEXTENCODING_UTF8));
224 if (
auto const i = rFileName.rfind(
'.');
i != ::std::string_view::npos)
228 auto const it(rMap.find(ext));
229 if (it != rMap.end())
231 return OStringToOUString(it->second, RTL_TEXTENCODING_ASCII_US);
static OUString GetMimeTypeForXGraphic(const css::uno::Reference< css::graphic::XGraphic > &xGraphic)
static OUString GetMimeTypeForImageStream(const css::uno::Reference< css::io::XInputStream > &xInputStream)
static char const * GetExtensionForConvertDataFormat(ConvertDataFormat nFormat)
static OUString GetMimeTypeForConvertDataFormat(ConvertDataFormat convertDataFormat)
static OUString GetMimeTypeForExtension(std::string_view rExt)
static auto GetMediaMimes() -> std::map< OString, OString > const &
auto GuessMediaMimeType(::std::u16string_view rFileName) -> OUString
auto IsMediaMimeType(::std::string_view const rMimeType) -> bool
Reference< XComponentContext > getProcessComponentContext()
This function gets the process service factory's default component context.
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
Creates a beans::PropertyValue easily, i.e.
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
const sal_Unicode *const aMimeType[]