From 0ffe9eb48a78bccf3d01a0effd5f2715174d38ff Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Tue, 28 Jun 2016 15:52:59 +0200 Subject: [PATCH] sd draw page: add PreviewMetafile UNO property This allows an unnecessary GDIMetaFile -> WMF -> GDIMetaFile roundtrip, and also avoids the odd black border at the bottom / right of the preview metafile in the PDF import-as-graphic filter. Change-Id: I7e3e782bbe0cf56def352e23b60864bb7773b607 Reviewed-on: https://gerrit.libreoffice.org/26743 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sd/source/ui/inc/unoprnms.hxx | 1 + sd/source/ui/unoidl/unopage.cxx | 15 ++++++++++++--- vcl/source/filter/ipdf/pdfread.cxx | 5 ++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/sd/source/ui/inc/unoprnms.hxx b/sd/source/ui/inc/unoprnms.hxx index d0af59c17a9c..3dd438f0ec28 100644 --- a/sd/source/ui/inc/unoprnms.hxx +++ b/sd/source/ui/inc/unoprnms.hxx @@ -36,6 +36,7 @@ #define UNO_NAME_PAGE_WIDTH "Width" #define UNO_NAME_PAGE_PREVIEW "Preview" #define UNO_NAME_PAGE_PREVIEWBITMAP "PreviewBitmap" +#define UNO_NAME_PAGE_PREVIEWMETAFILE "PreviewMetafile" #define UNO_NAME_PAGE_VISIBLE "Visible" #define UNO_NAME_OBJ_BOOKMARK "Bookmark" diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx index cd550d81b5d6..4ca21d00b953 100644 --- a/sd/source/ui/unoidl/unopage.cxx +++ b/sd/source/ui/unoidl/unopage.cxx @@ -97,7 +97,7 @@ enum WID_PAGE WID_PAGE_PAGENUMBERVISIBLE, WID_PAGE_DATETIMEVISIBLE, WID_PAGE_DATETIMEFIXED, WID_PAGE_DATETIMETEXT, WID_PAGE_DATETIMEFORMAT, WID_TRANSITION_TYPE, WID_TRANSITION_SUBTYPE, WID_TRANSITION_DIRECTION, WID_TRANSITION_FADE_COLOR, WID_TRANSITION_DURATION, WID_LOOP_SOUND, - WID_NAVORDER + WID_NAVORDER, WID_PAGE_PREVIEWMETAFILE }; static sal_Char const sEmptyPageName[sizeof("page")] = "page"; @@ -125,6 +125,7 @@ const SvxItemPropertySet* ImplGetDrawPagePropertySet( bool bImpress, PageKind eP { OUString(UNO_NAME_PAGE_WIDTH), WID_PAGE_WIDTH, ::cppu::UnoType::get(), 0, 0}, { OUString(UNO_NAME_PAGE_PREVIEW), WID_PAGE_PREVIEW, cppu::UnoType>::get(), css::beans::PropertyAttribute::READONLY, 0}, { OUString(UNO_NAME_PAGE_PREVIEWBITMAP), WID_PAGE_PREVIEWBITMAP, cppu::UnoType>::get(), css::beans::PropertyAttribute::READONLY, 0}, + { OUString(UNO_NAME_PAGE_PREVIEWMETAFILE), WID_PAGE_PREVIEWMETAFILE, cppu::UnoType>::get(), css::beans::PropertyAttribute::READONLY, 0}, { OUString(UNO_NAME_PAGE_VISIBLE), WID_PAGE_VISIBLE, cppu::UnoType::get(), 0, 0}, { OUString(UNO_NAME_OBJ_SOUNDFILE), WID_PAGE_SOUNDFILE, cppu::UnoType::get(), 0, 0}, { OUString(sUNO_Prop_IsBackgroundVisible), WID_PAGE_BACKVIS, cppu::UnoType::get(), 0, 0}, @@ -200,6 +201,7 @@ const SvxItemPropertySet* ImplGetDrawPagePropertySet( bool bImpress, PageKind eP { OUString(UNO_NAME_PAGE_WIDTH), WID_PAGE_WIDTH, ::cppu::UnoType::get(), 0, 0}, \ { OUString(UNO_NAME_PAGE_PREVIEW), WID_PAGE_PREVIEW, cppu::UnoType>::get(), css::beans::PropertyAttribute::READONLY, 0}, \ { OUString(UNO_NAME_PAGE_PREVIEWBITMAP), WID_PAGE_PREVIEWBITMAP, cppu::UnoType>::get(), css::beans::PropertyAttribute::READONLY, 0},\ + { OUString(UNO_NAME_PAGE_PREVIEWMETAFILE), WID_PAGE_PREVIEWMETAFILE, cppu::UnoType>::get(), css::beans::PropertyAttribute::READONLY, 0},\ { OUString(sUNO_Prop_UserDefinedAttributes),WID_PAGE_USERATTRIBS, cppu::UnoType::get(), 0, 0}, \ { OUString(sUNO_Prop_BookmarkURL), WID_PAGE_BOOKMARK, ::cppu::UnoType::get(), 0, 0}, \ { OUString("IsBackgroundDark"), WID_PAGE_ISDARK, cppu::UnoType::get(), beans::PropertyAttribute::READONLY, 0}, \ @@ -1017,7 +1019,8 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName ) const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName); - switch( pEntry ? pEntry->nWID : -1 ) + sal_Int16 nEntry = pEntry ? pEntry->nWID : -1; + switch (nEntry) { case WID_NAVORDER: aAny = getNavigationOrder(); @@ -1100,6 +1103,7 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName ) getBackground( aAny ); break; case WID_PAGE_PREVIEW : + case WID_PAGE_PREVIEWMETAFILE : { SdDrawDocument* pDoc = static_cast(GetPage()->GetModel()); if ( pDoc ) @@ -1126,7 +1130,12 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName ) xMetaFile->SetPrefSize( aSize ); SvMemoryStream aDestStrm( 65535, 65535 ); - ConvertGDIMetaFileToWMF( *xMetaFile, aDestStrm, nullptr, false ); + if (nEntry == WID_PAGE_PREVIEW) + // Preview: WMF format. + ConvertGDIMetaFileToWMF(*xMetaFile, aDestStrm, nullptr, false); + else + // PreviewMetafile: SVM format. + xMetaFile->Write(aDestStrm); Sequence aSeq( static_cast(aDestStrm.GetData()), aDestStrm.Tell() ); aAny <<= aSeq; } diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 6bd1f6f524a8..4b0e1eb5afc2 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -85,7 +85,7 @@ VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic) uno::Reference xFirstPage(xDrawPages->getByIndex(0), uno::UNO_QUERY); uno::Sequence aSequence; - if (!(xFirstPage->getPropertyValue("Preview") >>= aSequence)) + if (!(xFirstPage->getPropertyValue("PreviewMetafile") >>= aSequence)) return false; if (!aSequence.hasElements()) @@ -96,8 +96,7 @@ VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic) aPreviewStream.WriteBytes(aSequence.getArray(), aSequence.getLength()); aPreviewStream.Seek(0); GDIMetaFile aMtf; - if (!ConvertWMFToGDIMetaFile(aPreviewStream, aMtf)) - return false; + aMtf.Read(aPreviewStream); rGraphic = aMtf;