[Libreoffice-commits] core.git: 3 commits - sw/source vcl/ios vcl/source

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Tue May 28 19:55:47 UTC 2019


 sw/source/uibase/dochdl/swdtflvr.cxx |   24 +++++-
 vcl/ios/DataFlavorMapping.cxx        |  127 -----------------------------------
 vcl/source/treelist/transfer.cxx     |   18 ++++
 3 files changed, 39 insertions(+), 130 deletions(-)

New commits:
commit 12800a215102435b16fd0e3028f1fdfe8ebeb090
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue May 28 22:10:06 2019 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Tue May 28 22:44:27 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 b57209fd2621..37ff2181d651 100644
--- a/vcl/ios/DataFlavorMapping.cxx
+++ b/vcl/ios/DataFlavorMapping.cxx
@@ -47,65 +47,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)
@@ -397,61 +338,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();
@@ -565,14 +451,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
         {
@@ -602,10 +481,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 edf1f755d40c5423ffb411ff17f024fbafeb02b3
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue May 28 22:03:58 2019 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Tue May 28 22:44:08 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 e5e71a251629..5641758d1bfb 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -826,8 +826,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->GetBitmapEx().IsEmpty())
           AddFormat( SotClipboardFormatId::SVXB );
+#endif
 
         PrepareOLE( m_aObjDesc );
         AddFormat( SotClipboardFormatId::OBJECTDESCRIPTOR );
@@ -835,9 +837,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 );
@@ -857,8 +861,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
@@ -876,6 +881,7 @@ int SwTransferable::PrepareForCopy( bool bIsCut )
                     AddFormat( rItem );
             }
         }
+#endif
         m_eBufferType = TransferBufferType::Ole;
     }
     // Is there anything to provide anyway?
@@ -938,15 +944,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 );
@@ -956,9 +966,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 = static_cast<TransferBufferType>( TransferBufferType::Graphic | m_eBufferType );
 
@@ -975,10 +987,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;
@@ -991,7 +1005,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 );
         }
 
@@ -1002,7 +1018,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 e1cd536edd2636d150ae50b0d44a5aee1b8d4e34
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Tue May 28 21:51:53 2019 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Tue May 28 22:44:00 2019 +0300

    tdf#124752: Use best speed for PNG encoding 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/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx
index c9cf060a4fc7..3f7d7c5a655c 100644
--- a/vcl/source/treelist/transfer.cxx
+++ b/vcl/source/treelist/transfer.cxx
@@ -664,7 +664,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);
         }


More information about the Libreoffice-commits mailing list