2015-06-04 22:09:57 +05:30
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2015-06-04 00:06:46 +05:30
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tilebuffer.hxx"
|
|
|
|
|
2015-06-08 08:02:37 +02:00
|
|
|
#if !GLIB_CHECK_VERSION(2,40,0)
|
|
|
|
#define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/* ------------------
|
|
|
|
Utility functions
|
|
|
|
------------------
|
|
|
|
*/
|
2015-06-04 13:56:46 +05:30
|
|
|
float pixelToTwip(float fInput, float zoom)
|
2015-06-04 00:06:46 +05:30
|
|
|
{
|
|
|
|
return (fInput / DPI / zoom) * 1440.0f;
|
|
|
|
}
|
|
|
|
|
2015-06-04 13:56:46 +05:30
|
|
|
float twipToPixel(float fInput, float zoom)
|
2015-06-04 00:06:46 +05:30
|
|
|
{
|
|
|
|
return fInput / 1440.0f * DPI * zoom;
|
|
|
|
}
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
/* ----------------------------
|
|
|
|
Tile class member functions
|
|
|
|
----------------------------
|
|
|
|
*/
|
|
|
|
GdkPixbuf* Tile::getBuffer()
|
2015-06-04 00:06:46 +05:30
|
|
|
{
|
2015-06-04 03:32:18 +05:30
|
|
|
return m_pBuffer;
|
2015-06-04 00:06:46 +05:30
|
|
|
}
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
void Tile::release()
|
2015-06-04 00:06:46 +05:30
|
|
|
{
|
2015-06-04 03:32:18 +05:30
|
|
|
g_object_unref (m_pBuffer);
|
|
|
|
m_pBuffer = NULL;
|
2015-06-04 00:06:46 +05:30
|
|
|
}
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
void Tile::setPixbuf(GdkPixbuf *buffer)
|
|
|
|
{
|
|
|
|
m_pBuffer = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------
|
|
|
|
TileBuffer class member functions
|
|
|
|
----------------------------------
|
|
|
|
*/
|
|
|
|
void TileBuffer::resetAllTiles()
|
2015-06-04 00:06:46 +05:30
|
|
|
{
|
2015-06-04 03:32:18 +05:30
|
|
|
std::map<int, Tile>::iterator it = m_mTiles.begin();
|
|
|
|
for (; it != m_mTiles.end(); it++)
|
2015-06-04 22:09:57 +05:30
|
|
|
{
|
|
|
|
it->second.release();
|
|
|
|
}
|
2015-06-04 03:32:18 +05:30
|
|
|
m_mTiles.clear();
|
|
|
|
}
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
void TileBuffer::setInvalid(int x, int y)
|
2015-06-04 03:32:18 +05:30
|
|
|
{
|
|
|
|
int index = x * m_nWidth + y;
|
2015-06-04 22:09:57 +05:30
|
|
|
g_info("Setting tile invalid (%d, %d)", x, y);
|
2015-06-04 03:32:18 +05:30
|
|
|
if (m_mTiles.find(index) != m_mTiles.end())
|
2015-06-04 22:09:57 +05:30
|
|
|
{
|
2015-06-09 11:48:12 +02:00
|
|
|
m_mTiles[index].valid = false;
|
2015-06-04 22:09:57 +05:30
|
|
|
m_mTiles[index].release();
|
|
|
|
m_mTiles.erase(index);
|
|
|
|
}
|
2015-06-04 00:06:46 +05:30
|
|
|
}
|
|
|
|
|
2015-06-08 15:08:44 +05:30
|
|
|
Tile& TileBuffer::getTile(int x, int y, float aZoom)
|
2015-06-04 00:06:46 +05:30
|
|
|
{
|
2015-06-04 03:32:18 +05:30
|
|
|
int index = x * m_nWidth + y;
|
|
|
|
if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
|
2015-06-04 22:09:57 +05:30
|
|
|
{
|
2015-06-04 03:32:18 +05:30
|
|
|
|
2015-06-08 15:24:12 +05:30
|
|
|
GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
|
2015-06-04 22:09:57 +05:30
|
|
|
if (!pPixBuf)
|
|
|
|
{
|
|
|
|
g_info ("Error allocating memory to pixbuf");
|
|
|
|
return m_mTiles[index];
|
2015-06-04 03:32:18 +05:30
|
|
|
}
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
|
|
|
|
GdkRectangle aTileRectangle;
|
2015-06-08 15:24:12 +05:30
|
|
|
aTileRectangle.x = pixelToTwip(nTileSizePixels, aZoom) * y;
|
|
|
|
aTileRectangle.y = pixelToTwip(nTileSizePixels, aZoom) * x;
|
2015-06-04 22:09:57 +05:30
|
|
|
|
|
|
|
g_info ("Rendering (%d, %d)", x, y);
|
|
|
|
m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
|
|
|
|
pBuffer,
|
2015-06-08 15:24:12 +05:30
|
|
|
nTileSizePixels, nTileSizePixels,
|
2015-06-04 22:09:57 +05:30
|
|
|
aTileRectangle.x, aTileRectangle.y,
|
2015-06-08 15:24:12 +05:30
|
|
|
pixelToTwip(nTileSizePixels, aZoom),
|
|
|
|
pixelToTwip(nTileSizePixels, aZoom));
|
2015-06-04 22:09:57 +05:30
|
|
|
|
|
|
|
//create a mapping for it
|
|
|
|
m_mTiles[index].setPixbuf(pPixBuf);
|
2015-06-09 11:48:12 +02:00
|
|
|
m_mTiles[index].valid = true;
|
2015-06-04 22:09:57 +05:30
|
|
|
}
|
|
|
|
|
2015-06-04 03:32:18 +05:30
|
|
|
return m_mTiles[index];
|
2015-06-04 00:06:46 +05:30
|
|
|
}
|
|
|
|
|
2015-06-04 22:09:57 +05:30
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|