[Libreoffice-commits] core.git: Branch 'feature/calctiledrendering3' - include/LibreOfficeKit libreofficekit/source
Andrzej Hunt
andrzej.hunt at collabora.com
Wed Jul 2 10:00:21 PDT 2014
include/LibreOfficeKit/LibreOfficeKitGtk.h | 7 +
libreofficekit/source/gtk/lokdocview.c | 114 ++++++++++++++++++++++++-----
2 files changed, 101 insertions(+), 20 deletions(-)
New commits:
commit 0d70e5f95a9dceb05fe14dc63063a404f6916909
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date: Wed Jul 2 18:57:41 2014 +0200
gtktiledviewer: Show 4 tiles at varying scale factors. DON'T MERGE
I.e. subdivide the document into 4 tiles: one at 100% scaling,
one at 200%, one at 50%, one at 25% -- these are then post-scaled
(in gdk) and assembled to show as one document again.
This is only for test purposes, and shouldnt go into master. Could probably
be useful as a separate test widget though.
Change-Id: Id26a5418d88ce17525358d27d313cf9884fa1494
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index f160925..724f7ad 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -34,8 +34,9 @@ struct _LOKDocView
GtkScrolledWindow scrollWindow;
GtkWidget* pEventBox;
- GtkWidget* pCanvas;
- GdkPixbuf* pPixBuf;
+ GtkWidget* pGrid;
+ GtkWidget* pCanvas[2][2];
+ GdkPixbuf* pPixBuf[2][2];
float fZoom;
@@ -62,4 +63,4 @@ float lok_docview_get_zoom (LOKDocView* pDocView);
}
#endif
-#endif
\ No newline at end of file
+#endif
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index f813e68..296155f 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -57,6 +57,8 @@ static void lok_docview_class_init( LOKDocViewClass* pClass )
static void lok_docview_init( LOKDocView* pDocView )
{
+ int x, y;
+
// Gtk ScrolledWindow is apparently not fully initialised yet, we specifically
// have to set the [hv]adjustment to prevent GTK assertions from firing, see
// https://bugzilla.gnome.org/show_bug.cgi?id=438114 for more info.
@@ -67,13 +69,24 @@ static void lok_docview_init( LOKDocView* pDocView )
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView),
pDocView->pEventBox );
- pDocView->pCanvas = gtk_image_new();
- gtk_container_add( GTK_CONTAINER( pDocView->pEventBox ), pDocView->pCanvas );
+ pDocView->pGrid = gtk_table_new( 2, 2, TRUE );
+ gtk_container_add( GTK_CONTAINER( pDocView->pEventBox ), pDocView->pGrid );
- gtk_widget_show( pDocView->pCanvas );
- gtk_widget_show( pDocView->pEventBox );
+ for ( x = 0; x < 2; x++ )
+ {
+ for ( y = 0; y < 2; y++ )
+ {
+ pDocView->pCanvas[x][y] = gtk_image_new();
+ gtk_table_attach_defaults( GTK_TABLE( pDocView->pGrid ), pDocView->pCanvas[x][y], x, x+1, y, y+1 );
+ //gtk_container_add( GTK_CONTAINER( pDocView->pEventBox ), pDocView->pCanvas );
+ gtk_widget_show( pDocView->pCanvas[x][y] );
+
+ pDocView->pPixBuf[x][y] = 0;
+ }
+ }
- pDocView->pPixBuf = 0;
+ gtk_widget_show( pDocView->pGrid );
+ gtk_widget_show( pDocView->pEventBox );
// TODO: figure out a clever view of getting paths set up.
pDocView->pOffice = 0;
@@ -96,14 +109,21 @@ void renderDocument( LOKDocView* pDocView )
{
long nWidth, nHeight;
int nRenderWidth, nRenderHeight;
- unsigned char* pBuffer;
int nRowStride;
+ int x, y;
+ GdkPixbuf* pTempBuf;
g_assert( pDocView->pDocument );
- if ( pDocView->pPixBuf )
+ for ( x = 0; x < 2; x++ )
{
- g_object_unref( G_OBJECT( pDocView->pPixBuf ) );
+ for ( y = 0; y < 2; y++ )
+ {
+ if ( pDocView->pPixBuf[x][y] )
+ {
+ g_object_unref( G_OBJECT( pDocView->pPixBuf[x][y] ) );
+ }
+ }
}
pDocView->pDocument->pClass->getDocumentSize( pDocView->pDocument, &nWidth, &nHeight );
@@ -115,24 +135,84 @@ void renderDocument( LOKDocView* pDocView )
nRenderWidth = nWidth * pDocView->fZoom / 10;
nRenderHeight = nHeight * pDocView->fZoom / 10;
- pDocView->pPixBuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
- TRUE, 8,
- nRenderWidth, nRenderHeight);
-
+ // TOP-LEFT: standard
+ // TOP-RIGHT: 2x resolution rendered (post-scaled to 50%)
+ // BOTTOM-LEFT: 1/2 resolution rendered (post-scaled 200%)
+ // BOTTOM-RIGHT: 1/2 resolution rendered (post-scaled 400%)
+ pDocView->pPixBuf[0][0] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
+ TRUE, 8,
+ nRenderWidth / 2, nRenderHeight / 2 );
+ pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
+ gdk_pixbuf_get_pixels( pDocView->pPixBuf[0][0] ),
+ nRenderWidth / 2, nRenderHeight / 2,
+ &nRowStride,
+ 0, 0, // origin
+ nWidth / 2, nHeight / 2 );
- pBuffer = gdk_pixbuf_get_pixels( pDocView->pPixBuf );
+ pDocView->pPixBuf[1][0] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
+ TRUE, 8,
+ nRenderWidth, nRenderHeight );
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
- pBuffer,
+ gdk_pixbuf_get_pixels( pDocView->pPixBuf[1][0] ),
nRenderWidth, nRenderHeight,
&nRowStride,
- 0, 0, // origin
- nWidth, nHeight );
+ nWidth / 2, 0,
+ nWidth / 2, nHeight / 2 );
+ pTempBuf = gdk_pixbuf_scale_simple( GDK_PIXBUF( pDocView->pPixBuf[1][0] ),
+ nRenderWidth / 2,
+ nRenderHeight / 2,
+ GDK_INTERP_BILINEAR );
+ g_object_unref( G_OBJECT( pDocView->pPixBuf[1][0] ) );
+ pDocView->pPixBuf[1][0] = pTempBuf;
+
+
+ pDocView->pPixBuf[0][1] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
+ TRUE, 8,
+ nRenderWidth / 4, nRenderHeight / 4 );
+ pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
+ gdk_pixbuf_get_pixels( pDocView->pPixBuf[0][1] ),
+ nRenderWidth / 4, nRenderHeight / 4,
+ &nRowStride,
+ 0, nHeight / 2,
+ nWidth / 2, nHeight / 2 );
+ pTempBuf = gdk_pixbuf_scale_simple( GDK_PIXBUF( pDocView->pPixBuf[0][1] ),
+ nRenderWidth / 2,
+ nRenderHeight / 2,
+ GDK_INTERP_BILINEAR );
+ g_object_unref( G_OBJECT( pDocView->pPixBuf[0][1] ) );
+ pDocView->pPixBuf[0][1] = pTempBuf;
+
+ pDocView->pPixBuf[1][1] = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
+ TRUE, 8,
+ nRenderWidth / 8, nRenderHeight / 8 );
+ pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
+ gdk_pixbuf_get_pixels( pDocView->pPixBuf[1][1] ),
+ nRenderWidth / 8, nRenderHeight / 8,
+ &nRowStride,
+ nWidth / 2, nHeight / 2,
+ nWidth / 2, nHeight / 2 );
+ pTempBuf = gdk_pixbuf_scale_simple( GDK_PIXBUF( pDocView->pPixBuf[1][1] ),
+ nRenderWidth / 2,
+ nRenderHeight / 2,
+ GDK_INTERP_BILINEAR );
+ g_object_unref( G_OBJECT( pDocView->pPixBuf[1][1] ) );
+ pDocView->pPixBuf[1][1] = pTempBuf;
+
+
+
// TODO: double check that the rowstride really matches what we expected,
// although presumably we'd already be crashing by now if things were
// wrong.
(void) nRowStride;
- gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas ), pDocView->pPixBuf );
+ // gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas ), pDocView->pPixBuf );
+ for ( x = 0; x < 2; x++ )
+ {
+ for ( y = 0; y < 2; y++ )
+ {
+ gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas[x][y] ), pDocView->pPixBuf[x][y] );
+ }
+ }
}
SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, char* pPath )
More information about the Libreoffice-commits
mailing list