[Libreoffice-commits] core.git: Branch 'feature/gtkbmptiledviewer' - 3 commits - desktop/inc desktop/qa desktop/source

Andrzej Hunt andrzej.hunt at collabora.com
Tue May 20 23:12:47 PDT 2014


Rebased ref, commits from common ancestor:
commit 26c813ec810d367aa4e0cbd676f8cb0362c5879a
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Sun May 18 08:37:13 2014 +0100

    Draw the whole image for our gtk tiled viewer.
    
    We just draw one huge tile, it doesn't seem to work too well
    for larger documents though where the latter portions can appear
    empty.
    
    Change-Id: Ic527aec377bf2f82a528a04392186d3d8b752762

diff --git a/desktop/qa/gtktiledviewer/gtktiledviewer.cxx b/desktop/qa/gtktiledviewer/gtktiledviewer.cxx
index ead3c24..ee81cbc 100644
--- a/desktop/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/desktop/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -37,11 +37,23 @@ bool drawCallback(GtkWidget* /* The eventbox */, void* /* cairo_t* cr */, gpoint
 
     LODocument* pDocument = static_cast< LODocument* >( pData );
 
-    // Hardcoded tile just to see whether or not we get any sort of output.
-    unsigned char* pBuffer = pDocument->paintTile( 1000, 1000, 0, 0, 10000, 10000 );
+    long nWidth, nHeight;
+    pDocument->getDocumentSize( &nWidth, &nHeight );
+
+    // Draw the whole document at once (for now)
+    int nRenderWidth = nWidth / 10;
+    int nRenderHeight = nHeight / 10;
+    int nRowStride;
+    unsigned char* pBuffer = pDocument->paintTile( nRenderWidth, nRenderHeight,
+                                                   &nRowStride,
+                                                   0, 0, // origin
+                                                   nWidth, nHeight );
+
 
     GdkPixbuf* pBixBuf = gdk_pixbuf_new_from_data( pBuffer, GDK_COLORSPACE_RGB,
-                                                   false, 8, 1000, 1000, 3*1000,
+                                                   false, 8,
+                                                   nRenderWidth, nRenderHeight,
+                                                   nRowStride,
                                                    0, 0 );
     pBixBuf = gdk_pixbuf_flip( pBixBuf, false );
     gtk_image_set_from_pixbuf( GTK_IMAGE(ourCanvas), pBixBuf );
commit fc9d9e224cb9fe16e838336ad7656637d350f9b8
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Sun May 18 08:36:16 2014 +0100

    Implement document size retrieval for LibLO.
    
    Change-Id: Ibd69f8e766fd421b05d2305f967179a969bc5b56

diff --git a/desktop/inc/liblibreoffice.h b/desktop/inc/liblibreoffice.h
index 9644a04..dc001b6 100644
--- a/desktop/inc/liblibreoffice.h
+++ b/desktop/inc/liblibreoffice.h
@@ -75,6 +75,11 @@ struct _LibreOfficeDocument
                      const int nTilePosY,
                      const int nTileWidth,
                      const int nTileHeight);
+
+  // Get the document sizes in twips.
+  void (*getDocumentSize) (LibreOfficeDocument* pThis,
+                           long* pWidth,
+                           long* pHeight);
 #endif // LLO_USE_UNSTABLE_API
 };
 
diff --git a/desktop/inc/liblibreoffice.hxx b/desktop/inc/liblibreoffice.hxx
index 6c8afb7..5ad73f9 100644
--- a/desktop/inc/liblibreoffice.hxx
+++ b/desktop/inc/liblibreoffice.hxx
@@ -76,6 +76,11 @@ public:
         return mpDoc->paintTile(mpDoc, nCanvasWidth, nCanvasHeight, pRowStride,
                                 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
     }
+
+    inline void getDocumentSize(long* pWidth, long* pHeight)
+    {
+        mpDoc->getDocumentSize(mpDoc, pWidth, pHeight);
+    }
 #endif // LLO_USE_UNSTABLE_API
 };
 
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index ba53dcd..7761c3a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -170,6 +170,9 @@ static unsigned char* doc_paintTile(LibreOfficeDocument* pThis,
                           int* pRowStride,
                           const int nTilePosX, const int nTilePosY,
                           const int nTileWidth, const int nTileHeight);
+static void doc_getDocumentSize(LibreOfficeDocument* pThis,
+                                long* pWidth,
+                                long* pHeight);
 
 struct LibLODocument_Impl : public _LibreOfficeDocument
 {
@@ -187,6 +190,7 @@ struct LibLODocument_Impl : public _LibreOfficeDocument
         getNumberOfParts = doc_getNumberOfParts;
         setPart = doc_setPart;
         paintTile = doc_paintTile;
+        getDocumentSize = doc_getDocumentSize;
     }
 };
 
@@ -422,7 +426,23 @@ static unsigned char* doc_paintTile (LibreOfficeDocument* pThis,
     return pRet;
 }
 
+static void doc_getDocumentSize(LibreOfficeDocument* pThis,
+                                long* pWidth,
+                                long* pHeight)
+{
+    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
 
+    if (true) // TODO: test that we have a writer document here (vs calc/impress/etc.)
+    {
+        SwXTextDocument* pTxtDoc = dynamic_cast< SwXTextDocument* >( pDocument->mxComponent.get() );
+        SwDocShell* pDocShell = pTxtDoc->GetDocShell();
+        SwDoc* pDoc = pDocShell->GetDoc();
+        SwViewShell* pViewShell = pDoc->GetCurrentViewShell();
+        Size aDocumentSize = pViewShell->GetDocSize();
+        *pWidth = aDocumentSize.Width();
+        *pHeight = aDocumentSize.Height();
+    }
+}
 
 static char* lo_getError (LibreOffice *pThis)
 {
commit cbdbaaffc51c554dde9e7986aed73b8b80ed0176
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Sun May 18 08:30:15 2014 +0100

    Add rowstride to tiled rendering via LibLO.
    
    The buffer width could be larger than the desired rendering
    width, hence we need to give the client access to the rowstride.
    
    Change-Id: Ic63c1f455c89960164e076ed2528d43e64e81a40

diff --git a/desktop/inc/liblibreoffice.h b/desktop/inc/liblibreoffice.h
index c5cac81..9644a04 100644
--- a/desktop/inc/liblibreoffice.h
+++ b/desktop/inc/liblibreoffice.h
@@ -63,9 +63,14 @@ struct _LibreOfficeDocument
                               int nPart);
 
   // Get a pointer to a raw array, of size 3*nCanvasWidth*nCanvasHeight
+  // Basebmp's bitmap device seems to round the width up if needed
+  // for its internal buffer, i.e. the rowstride for the buffer may be larger
+  // than the desired width, hence we need to be able to return the
+  // rowstride too.
   unsigned char* (*paintTile)  (LibreOfficeDocument* pThis,
                      const int nCanvasWidth,
                      const int nCanvasHeight,
+                     int* pRowStride,
                      const int nTilePosX,
                      const int nTilePosY,
                      const int nTileWidth,
diff --git a/desktop/inc/liblibreoffice.hxx b/desktop/inc/liblibreoffice.hxx
index e846c03..6c8afb7 100644
--- a/desktop/inc/liblibreoffice.hxx
+++ b/desktop/inc/liblibreoffice.hxx
@@ -67,12 +67,13 @@ public:
 
     inline unsigned char* paintTile(const int nCanvasWidth,
                           const int nCanvasHeight,
+                          int* pRowStride,
                           const int nTilePosX,
                           const int nTilePosY,
                           const int nTileWidth,
                           const int nTileHeight)
     {
-        return mpDoc->paintTile(mpDoc, nCanvasWidth, nCanvasHeight,
+        return mpDoc->paintTile(mpDoc, nCanvasWidth, nCanvasHeight, pRowStride,
                                 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
     }
 #endif // LLO_USE_UNSTABLE_API
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index af416f3..ba53dcd 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -167,6 +167,7 @@ static int doc_getNumberOfParts(LibreOfficeDocument* pThis);
 static void doc_setPart(LibreOfficeDocument* pThis, int nPart);
 static unsigned char* doc_paintTile(LibreOfficeDocument* pThis,
                           const int nCanvasWidth, const int nCanvasHeight,
+                          int* pRowStride,
                           const int nTilePosX, const int nTilePosY,
                           const int nTileWidth, const int nTileHeight);
 
@@ -388,6 +389,7 @@ boost::shared_array< sal_uInt8 > ourBuffer;
 // which /shouldn't/ apply in our case, but better to be safe here.
 static unsigned char* doc_paintTile (LibreOfficeDocument* pThis,
                            const int nCanvasWidth, const int nCanvasHeight,
+                           int* pRowStride,
                            const int nTilePosX, const int nTilePosY,
                            const int nTileWidth, const int nTileHeight)
 {
@@ -410,6 +412,7 @@ static unsigned char* doc_paintTile (LibreOfficeDocument* pThis,
         SvpSalVirtualDevice* pSalDev = static_cast< SvpSalVirtualDevice* >(aDevice.getSalVirtualDevice());
         basebmp::BitmapDeviceSharedPtr pBmpDev = pSalDev->getBitmapDevice();
 
+        *pRowStride = pBmpDev->getScanlineStride();
         ourBuffer = pBmpDev->getBuffer();
 
         pRet = ourBuffer.get();


More information about the Libreoffice-commits mailing list