Kaydet (Commit) 58959bd1 authored tarafından Miklos Vajna's avatar Miklos Vajna

lokdocview: stop rendering a single huge tile

The primary purpose of gtktiledviewer is to see the same features / bugs
than on mobile devices. On Android we already render 256x256px tiles, do
the same in gtktiledviewer instead of a single huge tile.

Change-Id: I377dcab59e7019dcf1d15a27ccba117eb53d0d5b
üst 1e3b09d3
...@@ -34,8 +34,8 @@ struct _LOKDocView ...@@ -34,8 +34,8 @@ struct _LOKDocView
GtkScrolledWindow scrollWindow; GtkScrolledWindow scrollWindow;
GtkWidget* pEventBox; GtkWidget* pEventBox;
GtkWidget* pCanvas; GtkWidget* pTable;
GdkPixbuf* pPixBuf; GtkWidget** pCanvas;
float fZoom; float fZoom;
......
...@@ -21,6 +21,7 @@ $(eval $(call gb_Library_add_cobjects,libreofficekitgtk,\ ...@@ -21,6 +21,7 @@ $(eval $(call gb_Library_add_cobjects,libreofficekitgtk,\
ifeq ($(OS),LINUX) ifeq ($(OS),LINUX)
$(eval $(call gb_Library_add_libs,libreofficekitgtk,\ $(eval $(call gb_Library_add_libs,libreofficekitgtk,\
-ldl \ -ldl \
-lm \
)) ))
endif endif
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
#include <sal/types.h> #include <sal/types.h>
#include <math.h>
#define LOK_USE_UNSTABLE_API #define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.h> #include <LibreOfficeKit/LibreOfficeKit.h>
...@@ -74,13 +75,10 @@ static void lok_docview_init( LOKDocView* pDocView ) ...@@ -74,13 +75,10 @@ static void lok_docview_init( LOKDocView* pDocView )
// Allow reacting to button press events. // Allow reacting to button press events.
gtk_widget_set_events(pDocView->pEventBox, GDK_BUTTON_PRESS_MASK); gtk_widget_set_events(pDocView->pEventBox, GDK_BUTTON_PRESS_MASK);
pDocView->pCanvas = gtk_image_new();
gtk_container_add( GTK_CONTAINER( pDocView->pEventBox ), pDocView->pCanvas );
gtk_widget_show( pDocView->pCanvas );
gtk_widget_show( pDocView->pEventBox ); gtk_widget_show( pDocView->pEventBox );
pDocView->pPixBuf = 0; pDocView->pTable = 0;
pDocView->pCanvas = 0;
// TODO: figure out a clever view of getting paths set up. // TODO: figure out a clever view of getting paths set up.
pDocView->pOffice = 0; pDocView->pOffice = 0;
...@@ -109,41 +107,75 @@ static float twipToPixel(float nInput) ...@@ -109,41 +107,75 @@ static float twipToPixel(float nInput)
return nInput / 1440.0f * g_nDPI; return nInput / 1440.0f * g_nDPI;
} }
void renderDocument( LOKDocView* pDocView ) /// Converts from screen pixels to document coordinates
static float pixelToTwip(float nInput)
{ {
long nDocumentWidthTwips, nDocumentHeightTwips, nBufferWidthPixels, nBufferHeightPixels; return (nInput / g_nDPI) * 1440.0f;
unsigned char* pBuffer; }
int nRowStride;
g_assert( pDocView->pDocument ); void renderDocument( LOKDocView* pDocView )
{
long nDocumentWidthTwips, nDocumentHeightTwips, nDocumentWidthPixels, nDocumentHeightPixels;
const int nTileSizePixels = 256;
long nRow, nColumn, nRows, nColumns;
if ( pDocView->pPixBuf ) // Get document size and find out how many rows / columns we need.
pDocView->pDocument->pClass->getDocumentSize(pDocView->pDocument, &nDocumentWidthTwips, &nDocumentHeightTwips);
nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips) * pDocView->fZoom;
nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips) * pDocView->fZoom;
nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
// Set up our table and the tile pointers.
if (pDocView->pTable)
gtk_container_remove(GTK_CONTAINER( pDocView->pEventBox ), pDocView->pTable);
pDocView->pTable = gtk_table_new(nRows, nColumns, FALSE);
gtk_container_add(GTK_CONTAINER(pDocView->pEventBox), pDocView->pTable);
gtk_widget_show(pDocView->pTable);
if (pDocView->pCanvas)
g_free(pDocView->pCanvas);
pDocView->pCanvas = g_malloc0(sizeof(GtkWidget*) * nRows * nColumns);
// Render the tiles.
for (nRow = 0; nRow < nRows; ++nRow)
{ {
g_object_unref( G_OBJECT( pDocView->pPixBuf ) ); for (nColumn = 0; nColumn < nColumns; ++nColumn)
{
int nTileWidthPixels, nTileHeightPixels;
GdkPixbuf* pPixBuf;
unsigned char* pBuffer;
int nRowStride;
// The rightmost/bottommost tiles may be smaller.
if (nColumn == nColumns - 1)
nTileWidthPixels = nDocumentWidthPixels - nColumn * nTileSizePixels;
else
nTileWidthPixels = nTileSizePixels;
if (nRow == nRows - 1)
nTileHeightPixels = nDocumentHeightPixels - nRow * nTileSizePixels;
else
nTileHeightPixels = nTileSizePixels;
pPixBuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, nTileWidthPixels, nTileHeightPixels);
pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
// Buffer and its size, this is always the same.
pBuffer,
nTileWidthPixels, nTileHeightPixels,
&nRowStride,
// Position of the tile.
pixelToTwip(nTileSizePixels) / pDocView->fZoom * nColumn, pixelToTwip(nTileSizePixels) / pDocView->fZoom * nRow,
// Size of the tile, depends on the zoom factor and the tile position only.
pixelToTwip(nTileWidthPixels) / pDocView->fZoom, pixelToTwip(nTileHeightPixels) / pDocView->fZoom );
(void) nRowStride;
pDocView->pCanvas[nRow * nColumns + nColumn] = gtk_image_new();
gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas[nRow * nColumns + nColumn] ), pPixBuf );
g_object_unref(G_OBJECT(pPixBuf));
gtk_table_attach_defaults(GTK_TABLE(pDocView->pTable), pDocView->pCanvas[nRow * nColumns + nColumn], nColumn, nColumn + 1, nRow, nRow + 1);
gtk_widget_show(pDocView->pCanvas[nRow * nColumns + nColumn]);
}
} }
pDocView->pDocument->pClass->getDocumentSize(pDocView->pDocument, &nDocumentWidthTwips, &nDocumentHeightTwips);
// Draw the whole document at once (for now)
nBufferWidthPixels = twipToPixel(nDocumentWidthTwips) * pDocView->fZoom;
nBufferHeightPixels = twipToPixel(nDocumentHeightTwips) * pDocView->fZoom;
pDocView->pPixBuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB,
TRUE, 8,
nBufferWidthPixels, nBufferHeightPixels);
pBuffer = gdk_pixbuf_get_pixels( pDocView->pPixBuf );
pDocView->pDocument->pClass->paintTile( pDocView->pDocument,
pBuffer,
nBufferWidthPixels, nBufferHeightPixels,
&nRowStride,
0, 0, // origin
nDocumentWidthTwips, nDocumentHeightTwips );
(void) nRowStride;
gtk_image_set_from_pixbuf( GTK_IMAGE( pDocView->pCanvas ), pDocView->pPixBuf );
} }
/// Invoked on the main thread if lok_docview_callback_worker() requests so. /// Invoked on the main thread if lok_docview_callback_worker() requests so.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment