LCOV - code coverage report
Current view: top level - libreofficekit/source/gtk - tilebuffer.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 7 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 5 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             : #ifndef INCLUDED_TILEBUFFER_HXX
      11             : #define INCLUDED_TILEBUFFER_HXX
      12             : 
      13             : #include <gdk/gdkkeysyms.h>
      14             : #include <gdk-pixbuf/gdk-pixbuf.h>
      15             : #include <map>
      16             : 
      17             : #define LOK_USE_UNSTABLE_API
      18             : #include <LibreOfficeKit/LibreOfficeKit.h>
      19             : #include <LibreOfficeKit/LibreOfficeKitEnums.h>
      20             : #include <LibreOfficeKit/LibreOfficeKitGtk.h>
      21             : 
      22             : // We know that VirtualDevices use a DPI of 96.
      23             : const int DPI = 96;
      24             : // Lets use a square of side 256 pixels for each tile.
      25             : const int nTileSizePixels = 256;
      26             : 
      27             : /**
      28             :    Converts the pixel value to zoom independent twip value.
      29             : 
      30             :    @param fInput value to convert
      31             :    @param zoom the current zoom level
      32             : 
      33             :    @return the pixels value corresponding to given twip value
      34             : */
      35             : float pixelToTwip(float fInput, float zoom);
      36             : 
      37             : /**
      38             :    Converts the zoom independent twip value pixel value.
      39             : 
      40             :    @param fInput value to convert
      41             :    @param zoom the current zoom level
      42             : 
      43             :    @return the twip value corresponding to given pixel value
      44             : */
      45             : float twipToPixel(float fInput, float zoom);
      46             : 
      47             : /**
      48             :    This class represents a single tile in the tile buffer.
      49             :    It encloses a reference to GdkPixBuf containing the pixel data of the tile.
      50             : */
      51             : class Tile
      52             : {
      53             :  public:
      54           0 :     Tile() : valid(false) {}
      55           0 :     ~Tile() { }
      56             : 
      57             :     /**
      58             :        Tells if this tile is valid or not. Initialised to 0 (invalid) during
      59             :        object creation.
      60             :     */
      61             :     bool valid;
      62             : 
      63             :     /// Function to get the pointer to enclosing GdkPixbuf
      64             :     GdkPixbuf* getBuffer();
      65             :     /// Destroys the enclosing GdkPixbuf object pointed to by m_pBuffer
      66             :     void release();
      67             :     /// Used to set the pixel buffer of this object
      68             :     void setPixbuf(GdkPixbuf*);
      69             : 
      70             : private:
      71             :     /// Pixel buffer data for this tile
      72             :     GdkPixbuf *m_pBuffer;
      73             : };
      74             : 
      75             : /**
      76             :    This class represents the tile buffer which is responsible for managing,
      77             :    reusing and caching all the already rendered tiles. If the given tile is not
      78             :    present in the buffer, call to LOK Document's (m_pLOKDocument) paintTile
      79             :    method is made which fetches the rendered tile from LO core and store it in
      80             :    buffer for future reuse.
      81             : */
      82           0 : class TileBuffer
      83             : {
      84             :  public:
      85           0 :  TileBuffer(LibreOfficeKitDocument *document,
      86             :             int columns)
      87             :      : m_pLOKDocument(document)
      88           0 :         , m_nWidth(columns)
      89           0 :     {  }
      90             : 
      91           0 :     ~TileBuffer() {}
      92             : 
      93             :     /**
      94             :        Gets the underlying Tile object for given position. The position (0, 0)
      95             :        points to the left top most tile of the buffer.
      96             : 
      97             :        If the tile is not cached by the tile buffer, it makes a paintTile call
      98             :        to LO core asking to render the given tile. It then stores the tile for
      99             :        future reuse.
     100             : 
     101             :        @param x the tile along the x-axis of the buffer
     102             :        @param y the tile along the y-axis of the buffer
     103             :        @param aZoom This function needs the zoom factor to draw the tile using paintTile()
     104             : 
     105             :        @return the tile at the mentioned position (x, y)
     106             :      */
     107             :     Tile& getTile(int x, int y, float aZoom);
     108             :     /// Destroys all the tiles in the tile buffer; also frees the memory allocated
     109             :     /// for all the Tile objects.
     110             :     void resetAllTiles();
     111             :     /**
     112             :        Marks the tile as invalid. The tile (0, 0) is the left topmost tile in
     113             :        the tile buffer.
     114             : 
     115             :        @param x the position of tile along x-axis
     116             :        @param y the position of tile along y-axis
     117             :      */
     118             :     void setInvalid(int x, int y);
     119             : 
     120             :  private:
     121             :     /// Contains the reference to the LOK Document that this tile buffer is for.
     122             :     LibreOfficeKitDocument *m_pLOKDocument;
     123             :     /// Stores all the tiles cached by this tile buffer.
     124             :     std::map<int, Tile> m_mTiles;
     125             :     /// Width of the current tile buffer (number of columns)
     126             :     int m_nWidth;
     127             : };
     128             : 
     129             : #endif // INCLUDED_TILEBUFFER_HXX
     130             : 
     131             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11