svtools/source/misc/transfer.cxx | 18 ++++ sw/source/uibase/dochdl/swdtflvr.cxx | 24 +++++- vcl/ios/DataFlavorMapping.cxx | 127 ----------------------------------- 3 files changed, 39 insertions(+), 130 deletions(-)
New commits: commit 313984a59af43b00cc58c9e13ef9bf3aeccca30f Author: Tor Lillqvist <[email protected]> AuthorDate: Tue May 28 22:10:06 2019 +0300 Commit: Tor Lillqvist <[email protected]> CommitDate: Tue May 28 22:15:58 2019 +0300 tdf#124752: Simplify the iOS DataFlavorMapping thing a lot Now it works to copy and paste images (PNG ones at least) between the iOS Collabora Office app and other apps. We don't seem to need the PNGDataProvider after all, as we use it only for data that is already in PNG format. Possibly I am missing somethin, though. Change-Id: Ia6bcc8aefbe1a6687f13e28454b96658fc66c856 diff --git a/vcl/ios/DataFlavorMapping.cxx b/vcl/ios/DataFlavorMapping.cxx index c42677f70b6b..e90a8f9b245c 100644 --- a/vcl/ios/DataFlavorMapping.cxx +++ b/vcl/ios/DataFlavorMapping.cxx @@ -46,65 +46,6 @@ using namespace cppu; namespace { -bool ImageToPNG(css::uno::Sequence<sal_Int8> const& rImgData, - css::uno::Sequence<sal_Int8>& rPngData) -{ -#if 1 - // Skip this complexity for now. Work in progress. - (void)rImgData; - (void)rPngData; - return false; -#else - NSData* pData = [NSData dataWithBytesNoCopy:const_cast<sal_Int8*>(rImgData.getConstArray()) - length:rImgData.getLength() - freeWhenDone:0]; - if (!pData) - return false; - - NSBitmapImageRep* pRep = [NSBitmapImageRep imageRepWithData:pData]; - if (!pRep) - return false; - - NSData* pOut = [pRep representationUsingType:NSPNGFileType properties:@{}]; - if (!pOut) - return false; - - const size_t nPngSize = [pOut length]; - rPngData.realloc(nPngSize); - [pOut getBytes:rPngData.getArray() length:nPngSize]; - return (nPngSize > 0); -#endif -} - -bool PNGToImage(css::uno::Sequence<sal_Int8> const& rPngData, - css::uno::Sequence<sal_Int8>& rImgData) -{ -#if 1 - (void)rPngData; - (void)rImgData; - return false; -#else - NSData* pData = [NSData dataWithBytesNoCopy:const_cast<sal_Int8*>(rPngData.getConstArray()) - length:rPngData.getLength() - freeWhenDone:0]; - if (!pData) - return false; - - NSBitmapImageRep* pRep = [NSBitmapImageRep imageRepWithData:pData]; - if (!pRep) - return false; - - NSData* pOut = [pRep representationUsingType:eOutFormat properties:@{}]; - if (!pOut) - return false; - - const size_t nImgSize = [pOut length]; - rImgData.realloc(nImgSize); - [pOut getBytes:rImgData.getArray() length:nImgSize]; - return (nImgSize > 0); -#endif -} - /* Determine whether or not a DataFlavor is valid. */ bool isValidFlavor(const DataFlavor& aFlavor) @@ -396,61 +337,6 @@ Any HTMLFormatDataProvider::getOOoData() return oOOData; } -class PNGDataProvider : public DataProviderBaseImpl -{ -public: - PNGDataProvider(const Any&); - PNGDataProvider(NSData*); - - NSData* getSystemData() override; - Any getOOoData() override; -}; - -PNGDataProvider::PNGDataProvider(const Any& data) - : DataProviderBaseImpl(data) -{ -} - -PNGDataProvider::PNGDataProvider(NSData* data) - : DataProviderBaseImpl(data) -{ -} - -NSData* PNGDataProvider::getSystemData() -{ - Sequence<sal_Int8> pngData; - mData >>= pngData; - - Sequence<sal_Int8> imgData; - NSData* sysData = nullptr; - if (PNGToImage(pngData, imgData)) - sysData = [NSData dataWithBytes:imgData.getArray() length:imgData.getLength()]; - - return sysData; -} - -Any PNGDataProvider::getOOoData() -{ - Any oOOData; - - if (mSystemData) - { - const unsigned int flavorDataLength = [mSystemData length]; - Sequence<sal_Int8> imgData(flavorDataLength); - memcpy(imgData.getArray(), [mSystemData bytes], flavorDataLength); - - Sequence<sal_Int8> pngData; - if (ImageToPNG(imgData, pngData)) - oOOData <<= pngData; - } - else - { - oOOData = mData; - } - - return oOOData; -} - DataFlavorMapper::DataFlavorMapper() { Reference<XComponentContext> xContext = comphelper::getProcessComponentContext(); @@ -564,14 +450,7 @@ DataFlavorMapper::getDataProvider(const NSString* systemFlavor, if (isByteSequenceType(data.getValueType())) { - if ([systemFlavor caseInsensitiveCompare:PBTYPE_PNG] == NSOrderedSame) - { - dp = DataProviderPtr_t(new PNGDataProvider(data)); - } - else - { - dp = DataProviderPtr_t(new ByteSequenceDataProvider(data)); - } + dp = DataProviderPtr_t(new ByteSequenceDataProvider(data)); } else // Must be OUString type { @@ -601,10 +480,6 @@ DataProviderPtr_t DataFlavorMapper::getDataProvider(const NSString* systemFlavor { dp = DataProviderPtr_t(new HTMLFormatDataProvider(systemData)); } - else if ([systemFlavor caseInsensitiveCompare:PBTYPE_PNG] == NSOrderedSame) - { - dp = DataProviderPtr_t(new PNGDataProvider(systemData)); - } else { dp = DataProviderPtr_t(new ByteSequenceDataProvider(systemData)); commit d19b69b3a9011af129dfe1f0c73c3a84416d78df Author: Tor Lillqvist <[email protected]> AuthorDate: Tue May 28 22:03:58 2019 +0300 Commit: Tor Lillqvist <[email protected]> CommitDate: Tue May 28 22:15:58 2019 +0300 tdf#124752: Reduce number of formats offered on clipboard on mobile devices It seems a bit pointless to offer formats that no other app will use. Change-Id: I54474a4ba40d91c184592cede4224cbfbb78d518 diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 1a2de3a86a9c..d9f35769d070 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -797,8 +797,10 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) SwDoc *const pDoc = lcl_GetDoc(*m_pClpDocFac); m_pWrtShell->Copy( pDoc ); +#if HAVE_FEATURE_DESKTOP if (m_pOrigGraphic && !m_pOrigGraphic->GetBitmap().IsEmpty()) AddFormat( SotClipboardFormatId::SVXB ); +#endif PrepareOLE( m_aObjDesc ); AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ); @@ -806,9 +808,11 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) const Graphic* pGrf = m_pWrtShell->GetGraphic(); if( pGrf && pGrf->IsSupportedGraphic() ) { - AddFormat( SotClipboardFormatId::GDIMETAFILE ); AddFormat( SotClipboardFormatId::PNG ); +#if HAVE_FEATURE_DESKTOP + AddFormat( SotClipboardFormatId::GDIMETAFILE ); AddFormat( SotClipboardFormatId::BITMAP ); +#endif } m_eBufferType = TransferBufferType::Graphic; m_pWrtShell->GetGrfNms( &sGrfNm, nullptr ); @@ -828,8 +832,9 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) m_aObjDesc.maSize = OutputDevice::LogicToLogic(m_pWrtShell->GetObjSize(), MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM)); // <-- PrepareOLE( m_aObjDesc ); - AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ); +#if HAVE_FEATURE_DESKTOP + AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ); AddFormat( SotClipboardFormatId::GDIMETAFILE ); // Fetch the formats supported via embedtransferhelper as well @@ -848,6 +853,7 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) AddFormat( *aIter++ ); } } +#endif m_eBufferType = TransferBufferType::Ole; } // Is there anything to provide anyway? @@ -912,15 +918,19 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) bDDELink = m_pWrtShell->HasWholeTabSelection(); } +#if HAVE_FEATURE_DESKTOP //When someone needs it, we 'OLE' him something AddFormat( SotClipboardFormatId::EMBED_SOURCE ); +#endif //put RTF ahead of the OLE's Metafile to have less loss if( !m_pWrtShell->IsObjSelected() ) { AddFormat( SotClipboardFormatId::RTF ); +#if HAVE_FEATURE_DESKTOP AddFormat( SotClipboardFormatId::RICHTEXT ); AddFormat( SotClipboardFormatId::HTML ); +#endif } if( m_pWrtShell->IsSelection() ) AddFormat( SotClipboardFormatId::STRING ); @@ -930,9 +940,11 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) AddFormat( SotClipboardFormatId::DRAWING ); if ( nSelection & SelectionType::DrawObject ) { +#if HAVE_FEATURE_DESKTOP AddFormat( SotClipboardFormatId::GDIMETAFILE ); - AddFormat( SotClipboardFormatId::PNG ); AddFormat( SotClipboardFormatId::BITMAP ); +#endif + AddFormat( SotClipboardFormatId::PNG ); } m_eBufferType = (TransferBufferType)( TransferBufferType::Graphic | m_eBufferType ); @@ -949,10 +961,12 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) if( m_pWrtShell->GetURLFromButton( sURL, sDesc ) ) { AddFormat( SotClipboardFormatId::STRING ); +#if HAVE_FEATURE_DESKTOP AddFormat( SotClipboardFormatId::SOLK ); AddFormat( SotClipboardFormatId::NETSCAPE_BOOKMARK ); AddFormat( SotClipboardFormatId::FILECONTENT ); AddFormat( SotClipboardFormatId::FILEGRPDESCRIPTOR ); +#endif AddFormat( SotClipboardFormatId::UNIFORMRESOURCELOCATOR ); m_eBufferType = TransferBufferType::InetField | m_eBufferType; nRet = 1; @@ -965,7 +979,9 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) nullptr != ( pDShell = m_pWrtShell->GetDoc()->GetDocShell()) && SfxObjectCreateMode::STANDARD == pDShell->GetCreateMode() ) { +#if HAVE_FEATURE_DESKTOP AddFormat( SotClipboardFormatId::LINK ); +#endif m_xDdeLink = new SwTrnsfrDdeLink( *this, *m_pWrtShell ); } @@ -976,7 +992,9 @@ int SwTransferable::PrepareForCopy( bool bIsCut ) m_aObjDesc.maSize = OutputDevice::LogicToLogic(aSz, MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM)); PrepareOLE( m_aObjDesc ); +#if HAVE_FEATURE_DESKTOP AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ); +#endif } else nRet = 0; commit 5a3fa45eeaa4e3b001bb5e6a0015aaccf2798762 Author: Tor Lillqvist <[email protected]> AuthorDate: Tue May 28 21:51:53 2019 +0300 Commit: Tor Lillqvist <[email protected]> CommitDate: Tue May 28 22:14:49 2019 +0300 tdf#124752: Use best speed for PNG encofing on iOS Still awfully slow for "realistic" images as taken by modern digital cameras, though. It would be much better to not encode the PNG to put on the clipboard from the internal bitmap representation, but use the ooriginal PNG or JPEG data. Change-Id: Ib72a573bd31d4ae7380dacccb4287e19afabb0d4 diff --git a/svtools/source/misc/transfer.cxx b/svtools/source/misc/transfer.cxx index 03b306daed8b..888626d3ceb0 100644 --- a/svtools/source/misc/transfer.cxx +++ b/svtools/source/misc/transfer.cxx @@ -674,7 +674,23 @@ bool TransferableHelper::SetBitmapEx( const BitmapEx& rBitmapEx, const DataFlavo if(rFlavor.MimeType.equalsIgnoreAsciiCase("image/png")) { // write a PNG - vcl::PNGWriter aPNGWriter(rBitmapEx); + css::uno::Sequence<css::beans::PropertyValue> aFilterData; + +#ifdef IOS + // Use faster compression on slow devices + aFilterData.realloc(aFilterData.getLength() + 1); + aFilterData[aFilterData.getLength() - 1].Name = "Compression"; + + // We "know" that this gets passed to zlib's deflateInit2_(). 1 means best speed. For a + // typical 15 megapixel image from a DSLR, we are talking about a difference of 17 s for + // the default compression level vs 4 s for best speed, on an iPad Pro from 2017. + // + // Sure, the best would be to not have to re-encode the image at all, but have access to + // the original JPEG or PNG when there is a such. + + aFilterData[aFilterData.getLength() - 1].Value <<= 1; +#endif + vcl::PNGWriter aPNGWriter(rBitmapEx, &aFilterData); aPNGWriter.Write(aMemStm); } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
