LCOV - code coverage report
Current view: top level - libreofficekit/source/gtk - tilebuffer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 43 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "tilebuffer.hxx"
      11             : 
      12             : #if !GLIB_CHECK_VERSION(2,40,0)
      13             : #define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
      14             : #endif
      15             : 
      16             : /* ------------------
      17             :    Utility functions
      18             :    ------------------
      19             : */
      20           0 : float pixelToTwip(float fInput, float zoom)
      21             : {
      22           0 :     return (fInput / DPI / zoom) * 1440.0f;
      23             : }
      24             : 
      25           0 : float twipToPixel(float fInput, float zoom)
      26             : {
      27           0 :     return fInput / 1440.0f * DPI * zoom;
      28             : }
      29             : 
      30             : /* ----------------------------
      31             :    Tile class member functions
      32             :    ----------------------------
      33             : */
      34           0 : GdkPixbuf* Tile::getBuffer()
      35             : {
      36           0 :     return m_pBuffer;
      37             : }
      38             : 
      39           0 : void Tile::release()
      40             : {
      41           0 :     g_object_unref (m_pBuffer);
      42           0 :     m_pBuffer = NULL;
      43           0 : }
      44             : 
      45           0 : void Tile::setPixbuf(GdkPixbuf *buffer)
      46             : {
      47           0 :     m_pBuffer = buffer;
      48           0 : }
      49             : 
      50             : /* ----------------------------------
      51             :    TileBuffer class member functions
      52             :    ----------------------------------
      53             : */
      54           0 : void TileBuffer::resetAllTiles()
      55             : {
      56           0 :     std::map<int, Tile>::iterator it = m_mTiles.begin();
      57           0 :     for (; it != m_mTiles.end(); it++)
      58             :     {
      59           0 :         it->second.release();
      60             :     }
      61           0 :     m_mTiles.clear();
      62           0 : }
      63             : 
      64           0 : void TileBuffer::setInvalid(int x, int y)
      65             : {
      66           0 :     int index = x * m_nWidth + y;
      67           0 :     g_info("Setting tile invalid (%d, %d)", x, y);
      68           0 :     if (m_mTiles.find(index) != m_mTiles.end())
      69             :     {
      70           0 :         m_mTiles[index].valid = false;
      71           0 :         m_mTiles[index].release();
      72           0 :         m_mTiles.erase(index);
      73             :     }
      74           0 : }
      75             : 
      76           0 : Tile& TileBuffer::getTile(int x, int y, float aZoom)
      77             : {
      78           0 :     int index = x * m_nWidth + y;
      79           0 :     if(m_mTiles.find(index) == m_mTiles.end() || !m_mTiles[index].valid)
      80             :     {
      81             : 
      82           0 :         GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, nTileSizePixels, nTileSizePixels);
      83           0 :         if (!pPixBuf)
      84             :         {
      85           0 :             g_info ("Error allocating memory to pixbuf");
      86           0 :             return m_mTiles[index];
      87             :         }
      88             : 
      89           0 :         unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
      90             :         GdkRectangle aTileRectangle;
      91           0 :         aTileRectangle.x = pixelToTwip(nTileSizePixels, aZoom) * y;
      92           0 :         aTileRectangle.y = pixelToTwip(nTileSizePixels, aZoom) * x;
      93             : 
      94           0 :         g_info ("Rendering (%d, %d)", x, y);
      95             :         m_pLOKDocument->pClass->paintTile(m_pLOKDocument,
      96             :                                           pBuffer,
      97             :                                           nTileSizePixels, nTileSizePixels,
      98             :                                           aTileRectangle.x, aTileRectangle.y,
      99           0 :                                           pixelToTwip(nTileSizePixels, aZoom),
     100           0 :                                           pixelToTwip(nTileSizePixels, aZoom));
     101             : 
     102             :         //create a mapping for it
     103           0 :         m_mTiles[index].setPixbuf(pPixBuf);
     104           0 :         m_mTiles[index].valid = true;
     105             :     }
     106             : 
     107           0 :     return m_mTiles[index];
     108             : }
     109             : 
     110             : 
     111             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11