summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-08-25 14:01:43 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-08-29 15:29:43 +0200
commit2a0c3f70aca0493f334d2af59a2dc23727e571ff (patch)
tree797ec25e37ac731dc697b661a773ec777a5b6258 /svx
parent91653df0bf9abad5d67635db6576a559f742576c (diff)
Related: tdf#149971 avmedia: add doc model and render for crop of media objects
It is possible to provide an explicit preview of media objects since commit 8fa1d453c94cdbb03dac646fb8db2ebd1a0e84bd (Related: tdf#149971 svx: support explicitly provided snapshots for media shapes, 2022-08-24), however they can't be cropped. This means that media shapes from PPTX with cropping show unexpected content and can also have a buggy aspect ratio. Extend avmedia::MediaItem to store cropping and take it into account when returning the preview bitmap in SdrMediaObj::getSnapshot(). PPTX import works out of the box, as oox/ already tried to set a cropping property on the media shape. This is just the preview, the cropping of the video itself is not yet implemented. (cherry picked from commit b6f0fd6a2f459ead2268e07bfd86db7e303b323f) Conflicts: svx/source/unodraw/unoprov.cxx Change-Id: I8db3e0dcf252613d56eb0e6139adf097e53b15cc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138968 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/qa/unit/data/video-snapshot.pptxbin40194 -> 40759 bytes
-rw-r--r--svx/qa/unit/svdraw.cxx6
-rw-r--r--svx/source/svdraw/svdomedia.cxx21
-rw-r--r--svx/source/unodraw/unoprov.cxx1
-rw-r--r--svx/source/unodraw/unoshap4.cxx28
5 files changed, 54 insertions, 2 deletions
diff --git a/svx/qa/unit/data/video-snapshot.pptx b/svx/qa/unit/data/video-snapshot.pptx
index 9a0ec9ebd867..a212f105200f 100644
--- a/svx/qa/unit/data/video-snapshot.pptx
+++ b/svx/qa/unit/data/video-snapshot.pptx
Binary files differ
diff --git a/svx/qa/unit/svdraw.cxx b/svx/qa/unit/svdraw.cxx
index 17376b8e74d5..66400c375cf1 100644
--- a/svx/qa/unit/svdraw.cxx
+++ b/svx/qa/unit/svdraw.cxx
@@ -493,6 +493,12 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testVideoSnapshot)
// i.e. the preview was black, not red; since we seeked 3 secs into the video, while PowerPoint
// doesn't do that.
CPPUNIT_ASSERT_EQUAL(Color(0xff, 0x0, 0x0), rBitmap.GetPixelColor(0, 0));
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 321
+ // - Actual : 640
+ // i.e. ~25% crop from left and right should result in half width, but it was not reduced.
+ CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(321), rBitmap.GetSizePixel().getWidth());
}
}
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index 96d12027a060..cb78eee47766 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -21,6 +21,8 @@
#include <svx/svdomedia.hxx>
+#include <com/sun/star/text/GraphicCrop.hpp>
+
#include <rtl/ustring.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -146,6 +148,20 @@ uno::Reference< graphic::XGraphic > const & SdrMediaObj::getSnapshot() const
Graphic aGraphic = m_xImpl->m_MediaProperties.getGraphic();
if (!aGraphic.IsNone())
{
+ Size aPref = aGraphic.GetPrefSize();
+ Size aPixel = aGraphic.GetSizePixel();
+ const text::GraphicCrop& rCrop = m_xImpl->m_MediaProperties.getCrop();
+ if (rCrop.Bottom > 0 || rCrop.Left > 0 || rCrop.Right > 0 || rCrop.Top > 0)
+ {
+ tools::Long nLeft = aPixel.getWidth() * rCrop.Left / aPref.getWidth();
+ tools::Long nTop = aPixel.getHeight() * rCrop.Top / aPref.getHeight();
+ tools::Long nRight = aPixel.getWidth() * rCrop.Right / aPref.getWidth();
+ tools::Long nBottom = aPixel.getHeight() * rCrop.Bottom / aPref.getHeight();
+ BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
+ aBitmapEx.Crop({nLeft, nTop, aPixel.getWidth() - nRight, aPixel.getHeight() - nBottom});
+ aGraphic = aBitmapEx;
+ }
+
// We have an explicit graphic for this media object, then go with that instead of
// generating our own one.
m_xImpl->m_xCachedSnapshot = aGraphic.GetXGraphic();
@@ -338,6 +354,11 @@ void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProper
m_xImpl->m_MediaProperties.setGraphic(rNewProperties.getGraphic());
}
+ if (nMaskSet & AVMediaSetMask::CROP)
+ {
+ m_xImpl->m_MediaProperties.setCrop(rNewProperties.getCrop());
+ }
+
if( ( AVMediaSetMask::URL & nMaskSet ) &&
( rNewProperties.getURL() != getURL() ))
{
diff --git a/svx/source/unodraw/unoprov.cxx b/svx/source/unodraw/unoprov.cxx
index b459280c8b01..55631bdbc200 100644
--- a/svx/source/unodraw/unoprov.cxx
+++ b/svx/source/unodraw/unoprov.cxx
@@ -736,6 +736,7 @@ static SfxItemPropertyMapEntry const * ImplGetSvxMediaShapePropertyMap()
{ u"MediaMimeType", OWN_ATTR_MEDIA_MIMETYPE, cppu::UnoType<OUString>::get(), 0, 0},
{ u"FallbackGraphic", OWN_ATTR_FALLBACK_GRAPHIC, cppu::UnoType<css::graphic::XGraphic>::get(), css::beans::PropertyAttribute::READONLY, 0},
{ u"" UNO_NAME_GRAPHOBJ_GRAPHIC, OWN_ATTR_VALUE_GRAPHIC , cppu::UnoType<css::graphic::XGraphic>::get(), 0, 0},
+ { u"" UNO_NAME_GRAPHIC_GRAPHICCROP, SDRATTR_GRAFCROP , cppu::UnoType<css::text::GraphicCrop>::get(), 0, 0},
{ u"", 0, css::uno::Type(), 0, 0 }
};
diff --git a/svx/source/unodraw/unoshap4.cxx b/svx/source/unodraw/unoshap4.cxx
index 865ce0a3ee5b..50a2a7a09a12 100644
--- a/svx/source/unodraw/unoshap4.cxx
+++ b/svx/source/unodraw/unoshap4.cxx
@@ -783,7 +783,8 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPr
if( ((pProperty->nWID >= OWN_ATTR_MEDIA_URL) && (pProperty->nWID <= OWN_ATTR_MEDIA_ZOOM))
|| (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
|| (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
- || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC))
+ || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC)
+ || (pProperty->nWID == SDRATTR_GRAFCROP))
{
SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
::avmedia::MediaItem aItem;
@@ -886,6 +887,19 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPr
#endif
break;
+ case SDRATTR_GRAFCROP:
+#if HAVE_FEATURE_AVMEDIA
+ {
+ text::GraphicCrop aCrop;
+ if (rValue >>= aCrop)
+ {
+ bOk = true;
+ aItem.setCrop(aCrop);
+ }
+ }
+#endif
+ break;
+
case OWN_ATTR_MEDIA_STREAM:
#if HAVE_FEATURE_AVMEDIA
try
@@ -942,7 +956,8 @@ bool SvxMediaShape::getPropertyValueImpl( const OUString& rName, const SfxItemPr
|| (pProperty->nWID == OWN_ATTR_MEDIA_TEMPFILEURL)
|| (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
|| (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC)
- || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC))
+ || (pProperty->nWID == OWN_ATTR_VALUE_GRAPHIC)
+ || (pProperty->nWID == SDRATTR_GRAFCROP))
{
SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );
@@ -1025,6 +1040,15 @@ bool SvxMediaShape::getPropertyValueImpl( const OUString& rName, const SfxItemPr
#endif
break;
+ case SDRATTR_GRAFCROP:
+#if HAVE_FEATURE_AVMEDIA
+ {
+ text::GraphicCrop aCrop = aItem.getCrop();
+ rValue <<= aCrop;
+ }
+#endif
+ break;
+
case OWN_ATTR_FALLBACK_GRAPHIC:
rValue <<= pMedia->getSnapshot();
break;