| 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 |
#ifndef WPS_CELL_H |
| 30 |
# define WPS_CELL_H |
| 31 |
|
| 32 |
#include <iostream> |
| 33 |
#include <vector> |
| 34 |
|
| 35 |
#include "libwps_internal.h" |
| 36 |
|
| 37 |
#include "WPSFont.h" |
| 38 |
|
| 39 |
|
| 40 |
class WPSCellFormat |
| 41 |
{ |
| 42 |
public: |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
enum HorizontalAlignment { HALIGN_LEFT, HALIGN_RIGHT, HALIGN_CENTER, |
| 47 |
HALIGN_FULL, HALIGN_DEFAULT |
| 48 |
}; |
| 49 |
|
| 50 |
enum VerticalAlignment { VALIGN_TOP, VALIGN_CENTER, VALIGN_BOTTOM, VALIGN_DEFAULT }; |
| 51 |
|
| 52 |
enum Wrapping { WRAP_WRAP, WRAP_NO_WRAP, WRAP_DEFAULT }; |
| 53 |
|
| 54 |
enum FormatType { F_TEXT, F_BOOLEAN, F_NUMBER, F_DATE, F_TIME, F_UNKNOWN }; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
WPSCellFormat() |
| 70 |
: m_font() |
| 71 |
, m_hAlign(HALIGN_DEFAULT) |
| 72 |
, m_vAlign(VALIGN_DEFAULT) |
| 73 |
, m_wrapping(WRAP_DEFAULT) |
| 74 |
, m_rotation(0) |
| 75 |
, m_bordersList() |
| 76 |
, m_format(F_UNKNOWN) |
| 77 |
, m_subFormat(0) |
| 78 |
, m_DTFormat("") |
| 79 |
, m_digits(-1000) |
| 80 |
, m_protected(false) |
| 81 |
, m_backgroundColor(WPSColor::white()) { } |
| 82 |
WPSCellFormat(WPSCellFormat const &)=default; |
| 83 |
WPSCellFormat &operator=(WPSCellFormat const &)=default; |
| 84 |
|
| 85 |
virtual ~WPSCellFormat(); |
| 86 |
|
| 87 |
bool hasBasicFormat() const |
| 88 |
{ |
| 89 |
return m_format==F_TEXT || m_format==F_UNKNOWN; |
| 90 |
} |
| 91 |
|
| 92 |
std::string getValueType() const; |
| 93 |
|
| 94 |
void addTo(librevenge::RVNGPropertyList &propList) const; |
| 95 |
|
| 96 |
bool getNumberingProperties(librevenge::RVNGPropertyList &propList) const; |
| 97 |
|
| 98 |
|
| 99 |
WPSFont const &getFont() const |
| 100 |
{ |
| 101 |
return m_font; |
| 102 |
} |
| 103 |
|
| 104 |
void setFont(WPSFont const &font) |
| 105 |
{ |
| 106 |
m_font=font; |
| 107 |
} |
| 108 |
|
| 109 |
HorizontalAlignment hAlignment() const |
| 110 |
{ |
| 111 |
return m_hAlign; |
| 112 |
} |
| 113 |
|
| 114 |
void setHAlignment(HorizontalAlignment align) |
| 115 |
{ |
| 116 |
m_hAlign = align; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
VerticalAlignment vAlignment() const |
| 121 |
{ |
| 122 |
return m_vAlign; |
| 123 |
} |
| 124 |
|
| 125 |
void setVAlignment(VerticalAlignment align) |
| 126 |
{ |
| 127 |
m_vAlign = align; |
| 128 |
} |
| 129 |
|
| 130 |
Wrapping wrapping() const |
| 131 |
{ |
| 132 |
return m_wrapping; |
| 133 |
} |
| 134 |
|
| 135 |
void setWrapping(Wrapping align) |
| 136 |
{ |
| 137 |
m_wrapping = align; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
int getTextRotation() const |
| 142 |
{ |
| 143 |
return m_rotation; |
| 144 |
} |
| 145 |
|
| 146 |
void setTextRotation(int rotation) |
| 147 |
{ |
| 148 |
m_rotation = rotation; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
FormatType getFormat() const |
| 153 |
{ |
| 154 |
return m_format; |
| 155 |
} |
| 156 |
|
| 157 |
int getSubFormat() const |
| 158 |
{ |
| 159 |
return m_subFormat; |
| 160 |
} |
| 161 |
|
| 162 |
std::string getDTFormat() const |
| 163 |
{ |
| 164 |
return m_DTFormat; |
| 165 |
} |
| 166 |
|
| 167 |
void setFormat(FormatType form, int subForm=0) |
| 168 |
{ |
| 169 |
m_format = form; |
| 170 |
m_subFormat = subForm; |
| 171 |
} |
| 172 |
|
| 173 |
void setDTFormat(FormatType form, std::string const &dtFormat="") |
| 174 |
{ |
| 175 |
m_format = form; |
| 176 |
m_subFormat = 0; |
| 177 |
m_DTFormat = dtFormat; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
int digits() const |
| 182 |
{ |
| 183 |
return m_digits; |
| 184 |
} |
| 185 |
|
| 186 |
void setDigits(int newDigit) |
| 187 |
{ |
| 188 |
m_digits = newDigit; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
bool isProtected() const |
| 193 |
{ |
| 194 |
return m_protected; |
| 195 |
} |
| 196 |
|
| 197 |
|
| 198 |
void setProtected(bool fl) |
| 199 |
{ |
| 200 |
m_protected = fl; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
bool hasBorders() const |
| 205 |
{ |
| 206 |
return m_bordersList.size() != 0; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
std::vector<WPSBorder> const &borders() const |
| 211 |
{ |
| 212 |
return m_bordersList; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
void resetBorders() |
| 217 |
{ |
| 218 |
m_bordersList.resize(0); |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
void setBorders(int wh, WPSBorder const &border); |
| 223 |
|
| 224 |
void setBorders(std::vector<WPSBorder> const &newBorders) |
| 225 |
{ |
| 226 |
m_bordersList=newBorders; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
WPSColor backgroundColor() const |
| 231 |
{ |
| 232 |
return m_backgroundColor; |
| 233 |
} |
| 234 |
|
| 235 |
void setBackgroundColor(WPSColor const &color) |
| 236 |
{ |
| 237 |
m_backgroundColor = color; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
int compare(WPSCellFormat const &cell, bool onlyNumbering=false) const; |
| 242 |
|
| 243 |
|
| 244 |
friend std::ostream &operator<<(std::ostream &o, WPSCellFormat const &cell); |
| 245 |
|
| 246 |
|
| 247 |
struct CompareFormat |
| 248 |
{ |
| 249 |
|
| 250 |
CompareFormat() {} |
| 251 |
|
| 252 |
bool operator()(WPSCellFormat const &c1, WPSCellFormat const &c2) const |
| 253 |
{ |
| 254 |
return c1.compare(c2, true) < 0; |
| 255 |
} |
| 256 |
}; |
| 257 |
|
| 258 |
protected: |
| 259 |
|
| 260 |
static bool convertDTFormat(std::string const &dtFormat, librevenge::RVNGPropertyListVector &propListVector); |
| 261 |
|
| 262 |
WPSFont m_font; |
| 263 |
|
| 264 |
HorizontalAlignment m_hAlign; |
| 265 |
|
| 266 |
VerticalAlignment m_vAlign; |
| 267 |
|
| 268 |
Wrapping m_wrapping; |
| 269 |
|
| 270 |
int m_rotation; |
| 271 |
|
| 272 |
std::vector<WPSBorder> m_bordersList; |
| 273 |
|
| 274 |
FormatType m_format; |
| 275 |
|
| 276 |
int m_subFormat; |
| 277 |
|
| 278 |
std::string m_DTFormat; |
| 279 |
|
| 280 |
int m_digits; |
| 281 |
|
| 282 |
bool m_protected; |
| 283 |
|
| 284 |
WPSColor m_backgroundColor; |
| 285 |
}; |
| 286 |
|
| 287 |
class WPSTable; |
| 288 |
|
| 289 |
|
| 290 |
class WPSCell : public WPSCellFormat |
| 291 |
{ |
| 292 |
friend class WPSTable; |
| 293 |
public: |
| 294 |
|
| 295 |
WPSCell() |
| 296 |
: WPSCellFormat() |
| 297 |
, m_box() |
| 298 |
, m_verticalSet(true) |
| 299 |
, m_position(0,0) |
| 300 |
, m_numberCellSpanned(1,1) {} |
| 301 |
WPSCell(WPSCell const &)=default; |
| 302 |
WPSCell &operator=(WPSCell const &)=default; |
| 303 |
|
| 304 |
~WPSCell() override; |
| 305 |
|
| 306 |
|
| 307 |
void addTo(librevenge::RVNGPropertyList &propList) const; |
| 308 |
|
| 309 |
|
| 310 |
void setBox(WPSBox2f const &b) |
| 311 |
{ |
| 312 |
m_box = b; |
| 313 |
} |
| 314 |
|
| 315 |
WPSBox2f const &box() const |
| 316 |
{ |
| 317 |
return m_box; |
| 318 |
} |
| 319 |
|
| 320 |
bool isVerticalSet() const |
| 321 |
{ |
| 322 |
return m_verticalSet; |
| 323 |
} |
| 324 |
|
| 325 |
void setVerticalSet(bool verticalSet) |
| 326 |
{ |
| 327 |
m_verticalSet = verticalSet; |
| 328 |
} |
| 329 |
|
| 330 |
Vec2i &position() |
| 331 |
{ |
| 332 |
return m_position; |
| 333 |
} |
| 334 |
|
| 335 |
Vec2i const &position() const |
| 336 |
{ |
| 337 |
return m_position; |
| 338 |
} |
| 339 |
|
| 340 |
void setPosition(Vec2i posi) |
| 341 |
{ |
| 342 |
m_position = posi; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
Vec2i const &numSpannedCells() const |
| 347 |
{ |
| 348 |
return m_numberCellSpanned; |
| 349 |
} |
| 350 |
|
| 351 |
void setNumSpannedCells(Vec2i numSpanned) |
| 352 |
{ |
| 353 |
m_numberCellSpanned=numSpanned; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
virtual bool send(WPSListenerPtr &listener) = 0; |
| 358 |
|
| 359 |
|
| 360 |
virtual bool sendContent(WPSListenerPtr &listener) = 0; |
| 361 |
|
| 362 |
|
| 363 |
friend std::ostream &operator<<(std::ostream &o, WPSCell const &cell); |
| 364 |
|
| 365 |
protected: |
| 366 |
|
| 367 |
struct Compare |
| 368 |
{ |
| 369 |
explicit Compare(int dim) |
| 370 |
: m_coord(dim) {} |
| 371 |
|
| 372 |
struct Point |
| 373 |
{ |
| 374 |
Point(int wh, WPSCell const *cell) |
| 375 |
: m_which(wh) |
| 376 |
, m_cell(cell) {} |
| 377 |
float getPos(int coord) const |
| 378 |
{ |
| 379 |
if (m_which) |
| 380 |
return m_cell->box().max()[coord]; |
| 381 |
return m_cell->box().min()[coord]; |
| 382 |
} |
| 383 |
float getSize(int coord) const |
| 384 |
{ |
| 385 |
return m_cell->box().size()[coord]; |
| 386 |
} |
| 387 |
int m_which; |
| 388 |
WPSCell const *m_cell; |
| 389 |
}; |
| 390 |
|
| 391 |
|
| 392 |
bool operator()(Point const &c1, Point const &c2) const |
| 393 |
{ |
| 394 |
float diffF = c1.getPos(m_coord)-c2.getPos(m_coord); |
| 395 |
if (diffF < 0) return true; |
| 396 |
if (diffF > 0) return false; |
| 397 |
int diff = c2.m_which - c1.m_which; |
| 398 |
if (diff) return (diff < 0); |
| 399 |
diffF = c1.m_cell->box().size()[m_coord] |
| 400 |
- c2.m_cell->box().size()[m_coord]; |
| 401 |
if (diffF < 0) return true; |
| 402 |
if (diffF > 0) return false; |
| 403 |
if (c1.m_cell->m_verticalSet != c2.m_cell->m_verticalSet) return c1.m_cell->m_verticalSet; |
| 404 |
#ifdef _WIN64 |
| 405 |
return ((__int64)c1.m_cell < (__int64)c2.m_cell); |
| 406 |
#else |
| 407 |
return long(c1.m_cell) < long(c2.m_cell); |
| 408 |
#endif |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
int m_coord; |
| 413 |
}; |
| 414 |
|
| 415 |
|
| 416 |
WPSBox2f m_box; |
| 417 |
|
| 418 |
bool m_verticalSet; |
| 419 |
|
| 420 |
Vec2i m_position; |
| 421 |
|
| 422 |
Vec2i m_numberCellSpanned; |
| 423 |
}; |
| 424 |
|
| 425 |
#endif |
| 426 |
|