1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
/*
* page.h (C) 2006-2008, Aurélien Croc (AP²C)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id: page.h 186 2008-02-09 16:18:52Z ap2c $
*
*/
#ifndef _PAGE_H_
#define _PAGE_H_
#include <stddef.h>
class Band;
/**
* @brief This class contains a page representation.
*
* There are two steps. During the first step, the instance contains the bitmap
* representation of the page. During the second step, the bitmap
* representation is freed and is replaced by bands representations.
* Each band is linked to this instance and will be used by the QPDL render.
*
* When the page will be compressed this instance have to be sent to the cache
* manager for waiting its use by the render code.
*/
class Page
{
protected:
unsigned long _xResolution;
unsigned long _yResolution;
unsigned long _width;
unsigned long _height;
unsigned char _colors;
unsigned long _pageNr;
unsigned long _copiesNr;
unsigned long _compression;
unsigned char* _planes[4];
bool _empty;
unsigned long _bandsNr;
Band* _firstBand;
Band* _lastBand;
public:
/**
* Initialize the page instance.
*/
Page();
/**
* Destroy the instance
*/
virtual ~Page();
public:
/**
* Convert a length (given for 72DPI) in the X resolution.
* @param f the float to convert.
* @return the converted value.
*/
long double convertToXResolution(long double f)
{return f * _xResolution / 72.;}
/**
* Convert a length (given for 72DPI) in the Y resolution.
* @param f the float to convert.
* @return the converted value.
*/
long double convertToYResolution(long double f)
{return f * _yResolution / 72.;}
/**
* Delete all planes registered and free the used memory.
* This function has to be called when planes are no longer
* used to free the huge amount of memory required for them.
*/
void flushPlanes();
/**
* Make a 180° rotation of the bitmap planes
*/
void rotate();
public:
/**
* Set the X resolution.
* @param xRes the X resolution
*/
void setXResolution(unsigned long xRes)
{_xResolution = xRes;}
/**
* Set the Y resolution.
* @param xRes the Y resolution
*/
void setYResolution(unsigned long yRes)
{_yResolution = yRes;}
/**
* Set the page width.
* @param width the page width
*/
void setWidth(unsigned long width)
{_width = width;}
/**
* Set the page height.
* @param height the page height
*/
void setHeight(unsigned long height)
{_height = height;}
/**
* Set the number of colors.
* @param nr the number of colors
*/
void setColorsNr(unsigned char nr) {_colors = nr;}
/**
* Set this page number.
* @param nr this page number
*/
void setPageNr(unsigned long nr) {_pageNr = nr;}
/**
* Set the number of copies needed.
* @param nr the number of copies to do
*/
void setCopiesNr(unsigned long nr)
{_copiesNr = nr;}
/**
* Set the compression algorithm number to use.
* @param nr this compression algorithm number
*/
void setCompression(unsigned long nr)
{_compression = nr;}
/**
* Register a new color plane.
* @param color the color number
* @param buffer the plane buffer.
*/
void setPlaneBuffer(unsigned char color,
unsigned char* buffer)
{_planes[color] = buffer; _empty = false;}
/**
* Register a new band.
* Note that band instances will be destroyed when this instance will
* be destroyed.
* @param band the band instance.
*/
void registerBand(Band *band);
/**
* Set this page empty.
* This is useful in case of compression error.
*/
void setEmpty() {_empty = true;}
/**
* @return the X resolution.
*/
unsigned long xResolution() const {return _xResolution;}
/**
* @return the Y resolution.
*/
unsigned long yResolution() const {return _yResolution;}
/**
* @return the page width.
*/
unsigned long width() const {return _width;}
/**
* @return the page height.
*/
unsigned long height() const {return _height;}
/**
* @return the number of colors.
*/
unsigned char colorsNr() const {return _colors;}
/**
* @return this page number.
*/
unsigned long pageNr() const {return _pageNr;}
/**
* @return the number of copies to do.
*/
unsigned long copiesNr() const {return _copiesNr;}
/**
* @return the compression algorithm number.
*/
unsigned long compression() const {return _compression;}
/**
* Get the buffer associated to a plane.
* @param color the color plane number.
* @return the plane buffer. Otherwise it returns NULL if the color
* plane number is incorrect or if there is no plane
* associated.
*/
unsigned char* planeBuffer(unsigned char color) const
{return color < _colors ? _planes[color] :
NULL;}
/**
* @return TRUE if no planes has been set. Otherwise it returns FALSE.
*/
bool isEmpty() const {return _empty;}
/**
* @return the first band or NULL if no bands has been registered.
*/
const Band* firstBand() const {return _firstBand;}
public:
/**
* Swap this instance on the disk.
* @param fd the file descriptor where the instance has to be swapped
* @return TRUE if the instance has been successfully swapped.
* Otherwise it returns FALSE.
*/
bool swapToDisk(int fd);
/**
* Restore an instance from the disk into memory.
* @param fd the file descriptor where the instance has been swapped
* @return a page instance if it has been successfully restored.
* Otherwise it returns NULL.
*/
static Page* restoreIntoMemory(int fd);
};
#endif /* _PAGE_H_ */
/* vim: set expandtab tabstop=4 shiftwidth=4 smarttab tw=80 cin enc=utf8: */
|