libreofficekit/source/gtk/tilebuffer.cxx | 104 +++++++++++++++---------------- libreofficekit/source/gtk/tilebuffer.hxx | 69 ++++++++++---------- 2 files changed, 86 insertions(+), 87 deletions(-)
New commits: commit 767797a89db147f0baa42d997a1421de1b5bcebc Author: Pranav Kant <pran...@gnome.org> Date: Thu Jun 4 03:53:00 2015 +0530 TileBuffer: style fixes Change-Id: I6b1e64f1ad75acd53aa20cf45aa46a4e172d76cb diff --git a/libreofficekit/source/gtk/tilebuffer.cxx b/libreofficekit/source/gtk/tilebuffer.cxx index f932e4f..e13f5b0 100644 --- a/libreofficekit/source/gtk/tilebuffer.cxx +++ b/libreofficekit/source/gtk/tilebuffer.cxx @@ -23,82 +23,82 @@ static float twipToPixel(float fInput, float zoom) GdkPixbuf* Tile::tile_get_buffer() { - return m_pBuffer; + return m_pBuffer; } void Tile::tile_release() { - gdk_pixbuf_unref(m_pBuffer); - m_pBuffer = NULL; + g_object_unref (m_pBuffer); + m_pBuffer = NULL; } void TileBuffer::tile_buffer_set_zoom(float newZoomFactor, int rows, int columns) { - m_fZoomFactor = newZoomFactor; + m_fZoomFactor = newZoomFactor; - tile_buffer_reset_all_tiles(); + tile_buffer_reset_all_tiles(); - // set new buffer width and height - m_nWidth = columns; - m_nHeight = rows; + // set new buffer width and height + m_nWidth = columns; + m_nHeight = rows; } void TileBuffer::tile_buffer_reset_all_tiles() { - std::map<int, Tile>::iterator it = m_mTiles.begin(); - for (; it != m_mTiles.end(); it++) - { - it->second.tile_release(); - } - m_mTiles.clear(); + std::map<int, Tile>::iterator it = m_mTiles.begin(); + for (; it != m_mTiles.end(); it++) + { + it->second.tile_release(); + } + m_mTiles.clear(); } void TileBuffer::tile_buffer_set_invalid(int x, int y) { - int index = x * m_nWidth + y; - g_info("setting invalid : %d %d",x, y); - if (m_mTiles.find(index) != m_mTiles.end()) - { - m_mTiles[index].valid = 0; - m_mTiles[index].tile_release(); - m_mTiles.erase(index); - } + int index = x * m_nWidth + y; + g_info("setting invalid : %d %d",x, y); + if (m_mTiles.find(index) != m_mTiles.end()) + { + m_mTiles[index].valid = 0; + m_mTiles[index].tile_release(); + m_mTiles.erase(index); + } } Tile& TileBuffer::tile_buffer_get_tile(int x, int y) { - int index = x * m_nWidth + y; - if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid) - { - - GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize); - if (!pPixBuf){ - g_info ("error allocating memory to pixbuf"); - } - unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf); - GdkRectangle aTileRectangle; - aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y; - aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x; - - g_info ("rendering (%d %d)", x, y); - m_pLOKDocument->pClass->paintTile(m_pLOKDocument, - // Buffer and its size, depends on the position only. - pBuffer, - m_nTileSize, m_nTileSize, - // Position of the tile. - aTileRectangle.x, aTileRectangle.y, - // Size of the tile, depends on the zoom factor and the tile position only. - pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor)); - - //create a mapping for it - m_mTiles[index].tile_set_pixbuf(pPixBuf); - m_mTiles[index].valid = 1; - } - - return m_mTiles[index]; + int index = x * m_nWidth + y; + if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid) + { + + GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, m_nTileSize, m_nTileSize); + if (!pPixBuf){ + g_info ("error allocating memory to pixbuf"); + } + unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf); + GdkRectangle aTileRectangle; + aTileRectangle.x = pixelToTwip(m_nTileSize, m_fZoomFactor) * y; + aTileRectangle.y = pixelToTwip(m_nTileSize, m_fZoomFactor) * x; + + g_info ("rendering (%d %d)", x, y); + m_pLOKDocument->pClass->paintTile(m_pLOKDocument, + // Buffer and its size, depends on the position only. + pBuffer, + m_nTileSize, m_nTileSize, + // Position of the tile. + aTileRectangle.x, aTileRectangle.y, + // Size of the tile, depends on the zoom factor and the tile position only. + pixelToTwip(m_nTileSize, m_fZoomFactor), pixelToTwip(m_nTileSize, m_fZoomFactor)); + + //create a mapping for it + m_mTiles[index].tile_set_pixbuf(pPixBuf); + m_mTiles[index].valid = 1; + } + + return m_mTiles[index]; } void Tile::tile_set_pixbuf(GdkPixbuf *buffer) { - m_pBuffer = buffer; + m_pBuffer = buffer; } diff --git a/libreofficekit/source/gtk/tilebuffer.hxx b/libreofficekit/source/gtk/tilebuffer.hxx index a153247..088df93 100644 --- a/libreofficekit/source/gtk/tilebuffer.hxx +++ b/libreofficekit/source/gtk/tilebuffer.hxx @@ -25,18 +25,17 @@ */ class Tile { -public: - Tile() : valid(0) {} - ~Tile() { - tile_release(); - } + public: + Tile() : valid(0) {} + ~Tile() { + } - GdkPixbuf* tile_get_buffer(); - void tile_release(); - void tile_set_pixbuf(GdkPixbuf*); - bool valid; -private: - GdkPixbuf *m_pBuffer; + GdkPixbuf* tile_get_buffer(); + void tile_release(); + void tile_set_pixbuf(GdkPixbuf*); + bool valid; + private: + GdkPixbuf *m_pBuffer; }; /* @@ -45,33 +44,33 @@ private: */ class TileBuffer { -public: - TileBuffer(LibreOfficeKitDocument *document, - int tileSize, - int rows, - int columns) - : m_pLOKDocument(document) - , m_nTileSize(tileSize) - , m_fZoomFactor(1) - , m_nWidth(columns) - , m_nHeight(rows) + public: + TileBuffer(LibreOfficeKitDocument *document, + int tileSize, + int rows, + int columns) + : m_pLOKDocument(document) + , m_nTileSize(tileSize) + , m_fZoomFactor(1) + , m_nWidth(columns) + , m_nHeight(rows) { } - ~TileBuffer() {} + ~TileBuffer() {} - void tile_buffer_set_zoom(float zoomFactor, int rows, int columns); - Tile& tile_buffer_get_tile(int x, int y); - void tile_buffer_update(); - void tile_buffer_reset_all_tiles(); - void tile_buffer_set_invalid(int x, int y); -private: - LibreOfficeKitDocument *m_pLOKDocument; - int m_nTileSize; - float m_fZoomFactor; - std::map<int, Tile> m_mTiles; - //TODO: Also set width and height when document size changes - int m_nWidth; - int m_nHeight; + void tile_buffer_set_zoom(float zoomFactor, int rows, int columns); + Tile& tile_buffer_get_tile(int x, int y); + void tile_buffer_update(); + void tile_buffer_reset_all_tiles(); + void tile_buffer_set_invalid(int x, int y); + private: + LibreOfficeKitDocument *m_pLOKDocument; + int m_nTileSize; + float m_fZoomFactor; + std::map<int, Tile> m_mTiles; + //TODO: Also set width and height when document size changes + int m_nWidth; + int m_nHeight; }; #endif // INCLUDED_TILEBUFFER_HXX _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits