| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* libwps |
| 4 | * Version: MPL 2.0 / LGPLv2.1+ |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * Major Contributor(s): |
| 11 | * Copyright (C) 2002, 2005 William Lachance ([email protected]) |
| 12 | * Copyright (C) 2002, 2004 Marc Maurer ([email protected]) |
| 13 | * |
| 14 | * For minor contributions see the git repository. |
| 15 | * |
| 16 | * Alternatively, the contents of this file may be used under the terms |
| 17 | * of the GNU Lesser General Public License Version 2.1 or later |
| 18 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 19 | * applicable instead of those above. |
| 20 | * |
| 21 | * For further information visit http://libwps.sourceforge.net |
| 22 | */ |
| 23 | |
| 24 | #include <string.h> |
| 25 | |
| 26 | #include <iomanip> |
| 27 | #include <iostream> |
| 28 | #include <sstream> |
| 29 | #include <string> |
| 30 | |
| 31 | #include <librevenge/librevenge.h> |
| 32 | #include <libwps/libwps.h> |
| 33 | |
| 34 | #include "libwps_internal.h" |
| 35 | |
| 36 | #include "WPSGraphicStyle.h" |
| 37 | |
| 38 | //////////////////////////////////////////////////////////// |
| 39 | // pattern |
| 40 | //////////////////////////////////////////////////////////// |
| 41 | WPSGraphicStyle::Pattern::~Pattern() |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | bool WPSGraphicStyle::Pattern::getUniqueColor(WPSColor &col) const |
| 46 | { |
| 47 | if (empty() || m_picture.size() || m_data.empty()) return false; |
| 48 | if (m_colors[0]==m_colors[1]) |
| 49 | { |
| 50 | col = m_colors[0]; |
| 51 | return true; |
| 52 | } |
| 53 | unsigned char def=m_data[0]; |
| 54 | if (def!=0 && def!=0xFF) return false; |
| 55 | for (size_t c=1; c < m_data.size(); ++c) |
| 56 | if (m_data[c]!=def) return false; |
| 57 | col = m_colors[def ? 1 : 0]; |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | bool WPSGraphicStyle::Pattern::getAverageColor(WPSColor &color) const |
| 62 | { |
| 63 | if (empty()) return false; |
| 64 | if (m_picture.size()) |
| 65 | { |
| 66 | color=m_pictureAverageColor; |
| 67 | return true; |
| 68 | } |
| 69 | if (m_data.empty()) return false; |
| 70 | if (m_colors[0]==m_colors[1]) |
| 71 | { |
| 72 | color = m_colors[0]; |
| 73 | return true; |
| 74 | } |
| 75 | int numOne=0, numZero=0; |
| 76 | for (auto const &data : m_data) |
| 77 | { |
| 78 | for (int depl=1, b=0; b < 8; ++b, depl*=2) |
| 79 | { |
| 80 | if (data & depl) |
| 81 | numOne++; |
| 82 | else |
| 83 | numZero++; |
| 84 | } |
| 85 | } |
| 86 | if (!numOne && !numZero) return false; |
| 87 | float percent=float(numOne)/float(numOne+numZero); |
| 88 | color = WPSColor::barycenter(1.f-percent,m_colors[0],percent,m_colors[1]); |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | bool WPSGraphicStyle::Pattern::getBinary(librevenge::RVNGBinaryData &data, std::string &type) const |
| 93 | { |
| 94 | if (empty()) |
| 95 | { |
| 96 | WPS_DEBUG_MSG(("WPSGraphicStyle::Pattern::getBinary: called on invalid pattern\n")); |
| 97 | return false; |
| 98 | } |
| 99 | if (m_picture.size()) |
| 100 | { |
| 101 | data=m_picture; |
| 102 | type=m_pictureMime; |
| 103 | return true; |
| 104 | } |
| 105 | /* We create a indexed bitmap to obtain a final binary data. |
| 106 | |
| 107 | But it will probably better to recode that differently |
| 108 | */ |
| 109 | data.clear(); |
| 110 | std::stringstream f; |
| 111 | f << "P6\n" << m_dim[0] << " " << m_dim[1] << " 255\n"; |
| 112 | std::string const &header = f.str(); |
| 113 | data.append(reinterpret_cast<const unsigned char *>(header.c_str()), header.size()); |
| 114 | |
| 115 | int numBytesByLines = m_dim[0]/8; |
| 116 | unsigned char const *ptr = &m_data[0]; |
| 117 | for (int j = 0; j < m_dim[1]; j++) |
| 118 | { |
| 119 | for (int b=0; b < numBytesByLines; ++b) |
| 120 | { |
| 121 | unsigned char c=*(ptr++); |
| 122 | unsigned char depl=0x80; |
| 123 | for (int byt=0; byt<8; ++byt) |
| 124 | { |
| 125 | int ind = (c&depl) ? 1 : 0; |
| 126 | depl=static_cast<unsigned char>(depl>>1); |
| 127 | |
| 128 | uint32_t col = m_colors[size_t(ind)].value(); |
| 129 | for (int cBytes = 0, dpl=16; cBytes < 3; cBytes++, dpl-=8) |
| 130 | data.append(static_cast<unsigned char>((col>>dpl)&0xFF)); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return true; |
| 135 | } |
| 136 | |
| 137 | //////////////////////////////////////////////////////////// |
| 138 | // style |
| 139 | //////////////////////////////////////////////////////////// |
| 140 | WPSGraphicStyle::~WPSGraphicStyle() |
| 141 | { |
| 142 | } |
| 143 | |
| 144 | void WPSGraphicStyle::setBorders(int wh, WPSBorder const &border) |
| 145 | { |
| 146 | int const allBits = WPSBorder::LeftBit|WPSBorder::RightBit|WPSBorder::TopBit|WPSBorder::BottomBit; |
| 147 | if (wh & (~allBits)) |
| 148 | { |
| 149 | WPS_DEBUG_MSG(("WPSGraphicStyle::setBorders: unknown borders\n")); |
| 150 | return; |
| 151 | } |
| 152 | size_t numData = 4; |
| 153 | if (m_bordersList.size() < numData) |
| 154 | { |
| 155 | WPSBorder emptyBorder; |
| 156 | emptyBorder.m_style = WPSBorder::None; |
| 157 | m_bordersList.resize(numData, emptyBorder); |
| 158 | } |
| 159 | if (wh & WPSBorder::LeftBit) m_bordersList[WPSBorder::Left] = border; |
| 160 | if (wh & WPSBorder::RightBit) m_bordersList[WPSBorder::Right] = border; |
| 161 | if (wh & WPSBorder::TopBit) m_bordersList[WPSBorder::Top] = border; |
| 162 | if (wh & WPSBorder::BottomBit) m_bordersList[WPSBorder::Bottom] = border; |
| 163 | } |
| 164 | |
| 165 | void WPSGraphicStyle::addTo(librevenge::RVNGPropertyList &list, bool only1D) const |
| 166 | { |
| 167 | if (!hasLine()) |
| 168 | list.insert("draw:stroke", "none"); |
| 169 | else if (m_lineDashWidth.size()>=2) |
| 170 | { |
| 171 | int nDots1=0, nDots2=0; |
| 172 | float size1=0, size2=0, totalGap=0.0; |
| 173 | for (size_t c=0; c+1 < m_lineDashWidth.size();) |
| 174 | { |
| 175 | float sz=m_lineDashWidth[c++]; |
| 176 | if (nDots2 && (sz<size2||sz>size2)) |
| 177 | { |
| 178 | static bool first=true; |
| 179 | if (first) |
| 180 | { |
| 181 | WPS_DEBUG_MSG(("WPSGraphicStyle::addTo: can set all dash\n")); |
| 182 | first = false; |
| 183 | } |
| 184 | break; |
| 185 | } |
| 186 | if (nDots2) |
| 187 | nDots2++; |
| 188 | else if (!nDots1 || (sz>=size1 && sz <= size1)) |
| 189 | { |
| 190 | nDots1++; |
| 191 | size1=sz; |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | nDots2=1; |
| 196 | size2=sz; |
| 197 | } |
| 198 | totalGap += m_lineDashWidth[c++]; |
| 199 | } |
| 200 | list.insert("draw:stroke", "dash"); |
| 201 | list.insert("draw:dots1", nDots1); |
| 202 | list.insert("draw:dots1-length", double(size1), librevenge::RVNG_POINT); |
| 203 | if (nDots2) |
| 204 | { |
| 205 | list.insert("draw:dots2", nDots2); |
| 206 | list.insert("draw:dots2-length", double(size2), librevenge::RVNG_POINT); |
| 207 | } |
| 208 | const auto distance = double(nDots1 + nDots2 > 0 ? totalGap/float(nDots1+nDots2) : totalGap); |
| 209 | list.insert("draw:distance", distance, librevenge::RVNG_POINT);; |
| 210 | } |
| 211 | else |
| 212 | list.insert("draw:stroke", "solid"); |
| 213 | list.insert("svg:stroke-color", m_lineColor.str().c_str()); |
| 214 | list.insert("svg:stroke-width", double(m_lineWidth),librevenge::RVNG_POINT); |
| 215 | |
| 216 | if (m_lineOpacity < 1) |
| 217 | list.insert("svg:stroke-opacity", double(m_lineOpacity), librevenge::RVNG_PERCENT); |
| 218 | switch (m_lineCap) |
| 219 | { |
| 220 | case C_Round: |
| 221 | list.insert("svg:stroke-linecap", "round"); |
| 222 | break; |
| 223 | case C_Square: |
| 224 | list.insert("svg:stroke-linecap", "square"); |
| 225 | break; |
| 226 | case C_Butt: |
| 227 | default: |
| 228 | break; |
| 229 | } |
| 230 | switch (m_lineJoin) |
| 231 | { |
| 232 | case J_Round: |
| 233 | list.insert("svg:stroke-linejoin", "round"); |
| 234 | break; |
| 235 | case J_Bevel: |
| 236 | list.insert("svg:stroke-linejoin", "bevel"); |
| 237 | break; |
| 238 | case J_Miter: |
| 239 | default: |
| 240 | break; |
| 241 | } |
| 242 | if (m_arrows[0]) |
| 243 | { |
| 244 | list.insert("draw:marker-start-path", "m10 0-10 30h20z"); |
| 245 | list.insert("draw:marker-start-viewbox", "0 0 20 30"); |
| 246 | list.insert("draw:marker-start-center", "false"); |
| 247 | list.insert("draw:marker-start-width", "5pt"); |
| 248 | } |
| 249 | if (m_arrows[1]) |
| 250 | { |
| 251 | list.insert("draw:marker-end-path", "m10 0-10 30h20z"); |
| 252 | list.insert("draw:marker-end-viewbox", "0 0 20 30"); |
| 253 | list.insert("draw:marker-end-center", "false"); |
| 254 | list.insert("draw:marker-end-width", "5pt"); |
| 255 | } |
| 256 | if (hasShadow()) |
| 257 | { |
| 258 | list.insert("draw:shadow", "visible"); |
| 259 | list.insert("draw:shadow-color", m_shadowColor.str().c_str()); |
| 260 | list.insert("draw:shadow-opacity", double(m_shadowOpacity), librevenge::RVNG_PERCENT); |
| 261 | // in cm |
| 262 | list.insert("draw:shadow-offset-x", double(m_shadowOffset[0])/72.*2.54, librevenge::RVNG_GENERIC); // cm |
| 263 | list.insert("draw:shadow-offset-y", double(m_shadowOffset[1])/72.*2.54, librevenge::RVNG_GENERIC); // cm |
| 264 | } |
| 265 | if (only1D || !hasSurface()) |
| 266 | { |
| 267 | list.insert("draw:fill", "none"); |
| 268 | return; |
| 269 | } |
| 270 | list.insert("svg:fill-rule", m_fillRuleEvenOdd ? "evenodd" : "nonzero"); |
| 271 | if (hasGradient()) |
| 272 | { |
| 273 | list.insert("draw:fill", "gradient"); |
| 274 | switch (m_gradientType) |
| 275 | { |
| 276 | case G_Axial: |
| 277 | list.insert("draw:style", "axial"); |
| 278 | break; |
| 279 | case G_Radial: |
| 280 | list.insert("draw:style", "radial"); |
| 281 | break; |
| 282 | case G_Rectangular: |
| 283 | list.insert("draw:style", "rectangular"); |
| 284 | break; |
| 285 | case G_Square: |
| 286 | list.insert("draw:style", "square"); |
| 287 | break; |
| 288 | case G_Ellipsoid: |
| 289 | list.insert("draw:style", "ellipsoid"); |
| 290 | break; |
| 291 | case G_Linear: |
| 292 | case G_None: |
| 293 | default: |
| 294 | list.insert("draw:style", "linear"); |
| 295 | break; |
| 296 | } |
| 297 | if (m_gradientStopList.size()==2 && m_gradientStopList[0].m_offset <= 0 && |
| 298 | m_gradientStopList[1].m_offset >=1) |
| 299 | { |
| 300 | size_t first=(m_gradientType==G_Linear || m_gradientType==G_Axial) ? 0 : 1; |
| 301 | list.insert("draw:start-color", m_gradientStopList[first].m_color.str().c_str()); |
| 302 | list.insert("librevenge:start-opacity", double(m_gradientStopList[first].m_opacity), librevenge::RVNG_PERCENT); |
| 303 | list.insert("draw:end-color", m_gradientStopList[1-first].m_color.str().c_str()); |
| 304 | list.insert("librevenge:end-opacity", double(m_gradientStopList[1-first].m_opacity), librevenge::RVNG_PERCENT); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | librevenge::RVNGPropertyListVector gradient; |
| 309 | for (auto const &s : m_gradientStopList) |
| 310 | { |
| 311 | librevenge::RVNGPropertyList grad; |
| 312 | grad.insert("svg:offset", double(s.m_offset), librevenge::RVNG_PERCENT); |
| 313 | grad.insert("svg:stop-color", s.m_color.str().c_str()); |
| 314 | grad.insert("svg:stop-opacity", double(s.m_opacity), librevenge::RVNG_PERCENT); |
| 315 | gradient.append(grad); |
| 316 | } |
| 317 | list.insert("svg:linearGradient", gradient); |
| 318 | } |
| 319 | list.insert("draw:angle", double(m_gradientAngle), librevenge::RVNG_GENERIC); |
| 320 | list.insert("draw:border", double(m_gradientBorder), librevenge::RVNG_PERCENT); |
| 321 | if (m_gradientType != G_Linear) |
| 322 | { |
| 323 | list.insert("svg:cx", double(m_gradientPercentCenter[0]), librevenge::RVNG_PERCENT); |
| 324 | list.insert("svg:cy", double(m_gradientPercentCenter[1]), librevenge::RVNG_PERCENT); |
| 325 | } |
| 326 | if (m_gradientType == G_Radial) |
| 327 | list.insert("svg:r", double(m_gradientRadius), librevenge::RVNG_PERCENT); // checkme |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | bool done = false; |
| 332 | WPSColor surfaceColor=m_surfaceColor; |
| 333 | float surfaceOpacity = m_surfaceOpacity; |
| 334 | if (hasPattern()) |
| 335 | { |
| 336 | WPSColor col; |
| 337 | if (m_pattern.getUniqueColor(col)) |
| 338 | { |
| 339 | // no need to create a uniform pattern |
| 340 | surfaceColor = col; |
| 341 | surfaceOpacity = 1; |
| 342 | } |
| 343 | else |
| 344 | { |
| 345 | librevenge::RVNGBinaryData data; |
| 346 | std::string mimeType; |
| 347 | if (m_pattern.getBinary(data, mimeType)) |
| 348 | { |
| 349 | list.insert("draw:fill", "bitmap"); |
| 350 | list.insert("draw:fill-image", data.getBase64Data()); |
| 351 | list.insert("draw:fill-image-width", m_pattern.m_dim[0], librevenge::RVNG_POINT); |
| 352 | list.insert("draw:fill-image-height", m_pattern.m_dim[1], librevenge::RVNG_POINT); |
| 353 | list.insert("draw:fill-image-ref-point-x",0, librevenge::RVNG_POINT); |
| 354 | list.insert("draw:fill-image-ref-point-y",0, librevenge::RVNG_POINT); |
| 355 | list.insert("librevenge:mime-type", mimeType.c_str()); |
| 356 | done = true; |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | if (!done) |
| 361 | { |
| 362 | list.insert("draw:fill", "solid"); |
| 363 | list.insert("draw:fill-color", surfaceColor.str().c_str()); |
| 364 | list.insert("draw:opacity", double(surfaceOpacity), librevenge::RVNG_PERCENT); |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | void WPSGraphicStyle::addFrameTo(librevenge::RVNGPropertyList &list) const |
| 370 | { |
| 371 | if (m_backgroundOpacity>=0) |
| 372 | { |
| 373 | if (m_backgroundOpacity>0) |
| 374 | list.insert("fo:background-color", m_backgroundColor.str().c_str()); |
| 375 | if (m_backgroundOpacity<1) |
| 376 | list.insert("style:background-transparency", 1.-double(m_backgroundOpacity), librevenge::RVNG_PERCENT); |
| 377 | } |
| 378 | if (hasBorders()) |
| 379 | { |
| 380 | if (hasSameBorders()) |
| 381 | m_bordersList[0].addTo(list, ""); |
| 382 | else |
| 383 | { |
| 384 | for (size_t c = 0; c < m_bordersList.size(); c++) |
| 385 | { |
| 386 | if (c >= 4) break; |
| 387 | switch (c) |
| 388 | { |
| 389 | case WPSBorder::Left: |
| 390 | m_bordersList[c].addTo(list, "left"); |
| 391 | break; |
| 392 | case WPSBorder::Right: |
| 393 | m_bordersList[c].addTo(list, "right"); |
| 394 | break; |
| 395 | case WPSBorder::Top: |
| 396 | m_bordersList[c].addTo(list, "top"); |
| 397 | break; |
| 398 | case WPSBorder::Bottom: |
| 399 | m_bordersList[c].addTo(list, "bottom"); |
| 400 | break; |
| 401 | default: |
| 402 | WPS_DEBUG_MSG(("WPSGraphicStyle::addFrameTo: can not send %d border\n",int(c))); |
| 403 | break; |
| 404 | } |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | if (hasShadow()) |
| 409 | { |
| 410 | list.insert("draw:shadow", "visible"); |
| 411 | list.insert("draw:shadow-color", m_shadowColor.str().c_str()); |
| 412 | list.insert("draw:shadow-opacity", double(m_shadowOpacity), librevenge::RVNG_PERCENT); |
| 413 | // in cm |
| 414 | list.insert("draw:shadow-offset-x", double(m_shadowOffset[0])/72.*2.54, librevenge::RVNG_GENERIC); // cm |
| 415 | list.insert("draw:shadow-offset-y", double(m_shadowOffset[1])/72.*2.54, librevenge::RVNG_GENERIC); // cm |
| 416 | } |
| 417 | if (!m_frameName.empty()) |
| 418 | list.insert("librevenge:frame-name",m_frameName); |
| 419 | } |
| 420 | |
| 421 | int WPSGraphicStyle::cmp(WPSGraphicStyle const &a) const |
| 422 | { |
| 423 | if (m_lineWidth < a.m_lineWidth) return -1; |
| 424 | if (m_lineWidth > a.m_lineWidth) return 1; |
| 425 | if (m_lineCap < a.m_lineCap) return -1; |
| 426 | if (m_lineCap > a.m_lineCap) return 1; |
| 427 | if (m_lineJoin < a.m_lineJoin) return -1; |
| 428 | if (m_lineJoin > a.m_lineJoin) return 1; |
| 429 | if (m_lineOpacity < a.m_lineOpacity) return -1; |
| 430 | if (m_lineOpacity > a.m_lineOpacity) return 1; |
| 431 | if (m_lineColor < a.m_lineColor) return -1; |
| 432 | if (m_lineColor > a.m_lineColor) return 1; |
| 433 | |
| 434 | if (m_lineDashWidth.size() < a.m_lineDashWidth.size()) return -1; |
| 435 | if (m_lineDashWidth.size() > a.m_lineDashWidth.size()) return 1; |
| 436 | for (size_t d=0; d < m_lineDashWidth.size(); ++d) |
| 437 | { |
| 438 | if (m_lineDashWidth[d] > a.m_lineDashWidth[d]) return -1; |
| 439 | if (m_lineDashWidth[d] < a.m_lineDashWidth[d]) return 1; |
| 440 | } |
| 441 | for (int i=0; i<2; ++i) |
| 442 | { |
| 443 | if (m_arrows[i]!=a.m_arrows[i]) |
| 444 | return m_arrows[i] ? 1 : -1; |
| 445 | if (m_flip[i]!=a.m_flip[i]) |
| 446 | return m_flip[i] ? 1 : -1; |
| 447 | } |
| 448 | |
| 449 | if (m_fillRuleEvenOdd != a.m_fillRuleEvenOdd) return m_fillRuleEvenOdd ? 1: -1; |
| 450 | |
| 451 | if (m_surfaceColor < a.m_surfaceColor) return -1; |
| 452 | if (m_surfaceColor > a.m_surfaceColor) return 1; |
| 453 | if (m_surfaceOpacity < a.m_surfaceOpacity) return -1; |
| 454 | if (m_surfaceOpacity > a.m_surfaceOpacity) return 1; |
| 455 | |
| 456 | if (m_shadowColor < a.m_shadowColor) return -1; |
| 457 | if (m_shadowColor > a.m_shadowColor) return 1; |
| 458 | if (m_shadowOpacity < a.m_shadowOpacity) return -1; |
| 459 | if (m_shadowOpacity > a.m_shadowOpacity) return 1; |
| 460 | int diff=m_shadowOffset.cmp(a.m_shadowOffset); |
| 461 | if (diff) return diff; |
| 462 | |
| 463 | diff = m_pattern.cmp(a.m_pattern); |
| 464 | if (diff) return diff; |
| 465 | |
| 466 | if (m_gradientType < a.m_gradientType) return -1; |
| 467 | if (m_gradientType > a.m_gradientType) return 1; |
| 468 | if (m_gradientAngle < a.m_gradientAngle) return -1; |
| 469 | if (m_gradientAngle > a.m_gradientAngle) return 1; |
| 470 | if (m_gradientStopList.size() < a.m_gradientStopList.size()) return 1; |
| 471 | if (m_gradientStopList.size() > a.m_gradientStopList.size()) return -1; |
| 472 | for (auto const &c : m_gradientStopList) |
| 473 | { |
| 474 | diff = c.cmp(c); |
| 475 | if (diff) return diff; |
| 476 | } |
| 477 | if (m_gradientBorder < a.m_gradientBorder) return -1; |
| 478 | if (m_gradientBorder > a.m_gradientBorder) return 1; |
| 479 | diff=m_gradientPercentCenter.cmp(a.m_gradientPercentCenter); |
| 480 | if (diff) return diff; |
| 481 | |
| 482 | size_t numBorders=m_bordersList.size(); |
| 483 | if (a.m_bordersList.size()>numBorders) |
| 484 | numBorders=a.m_bordersList.size(); |
| 485 | for (size_t b=0; b<numBorders; ++b) |
| 486 | { |
| 487 | bool empty=b>=m_bordersList.size() || m_bordersList[b].isEmpty(); |
| 488 | bool aEmpty=b>=a.m_bordersList.size() || a.m_bordersList[b].isEmpty(); |
| 489 | if (empty!=aEmpty) return empty ? 1 : -1; |
| 490 | diff=m_bordersList[b].compare(a.m_bordersList[b]); |
| 491 | if (diff) return diff; |
| 492 | } |
| 493 | if (m_backgroundColor < a.m_backgroundColor) return -1; |
| 494 | if (m_backgroundColor > a.m_backgroundColor) return 1; |
| 495 | if (m_backgroundOpacity < a.m_backgroundOpacity) return -1; |
| 496 | if (m_backgroundOpacity > a.m_backgroundOpacity) return 1; |
| 497 | if (m_frameName < a.m_frameName) return -1; |
| 498 | if (m_frameName > a.m_frameName) return 1; |
| 499 | if (m_frameNextName < a.m_frameNextName) return -1; |
| 500 | if (m_frameNextName > a.m_frameNextName) return 1; |
| 501 | |
| 502 | if (m_gradientRadius < a.m_gradientRadius) return -1; |
| 503 | if (m_gradientRadius > a.m_gradientRadius) return 1; |
| 504 | if (m_rotate < a.m_rotate) return -1; |
| 505 | if (m_rotate > a.m_rotate) return 1; |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | std::ostream &operator<<(std::ostream &o, WPSGraphicStyle const &st) |
| 510 | { |
| 511 | if (st.m_rotate<0 || st.m_rotate>0) |
| 512 | o << "rot=" << st.m_rotate << ","; |
| 513 | if (st.m_flip[0]) o << "flipX,"; |
| 514 | if (st.m_flip[1]) o << "flipY,"; |
| 515 | o << "line=["; |
| 516 | if (st.m_lineWidth<1 || st.m_lineWidth>1) |
| 517 | o << "width=" << st.m_lineWidth << ","; |
| 518 | if (!st.m_lineDashWidth.empty()) |
| 519 | { |
| 520 | o << "dash=["; |
| 521 | for (auto const &w : st.m_lineDashWidth) |
| 522 | o << w << ","; |
| 523 | o << "],"; |
| 524 | } |
| 525 | switch (st.m_lineCap) |
| 526 | { |
| 527 | case WPSGraphicStyle::C_Square: |
| 528 | o << "cap=square,"; |
| 529 | break; |
| 530 | case WPSGraphicStyle::C_Round: |
| 531 | o << "cap=round,"; |
| 532 | break; |
| 533 | case WPSGraphicStyle::C_Butt: |
| 534 | default: |
| 535 | break; |
| 536 | } |
| 537 | switch (st.m_lineJoin) |
| 538 | { |
| 539 | case WPSGraphicStyle::J_Bevel: |
| 540 | o << "join=bevel,"; |
| 541 | break; |
| 542 | case WPSGraphicStyle::J_Round: |
| 543 | o << "join=round,"; |
| 544 | break; |
| 545 | case WPSGraphicStyle::J_Miter: |
| 546 | default: |
| 547 | break; |
| 548 | } |
| 549 | if (st.m_lineOpacity<1) |
| 550 | o << "opacity=" << st.m_lineOpacity << ","; |
| 551 | if (!st.m_lineColor.isBlack()) |
| 552 | o << "color=" << st.m_lineColor << ","; |
| 553 | if (st.m_arrows[0]) o << "arrow[start],"; |
| 554 | if (st.m_arrows[1]) o << "arrow[end],"; |
| 555 | o << "],"; |
| 556 | if (st.hasSurfaceColor()) |
| 557 | { |
| 558 | o << "surf=["; |
| 559 | if (!st.m_surfaceColor.isWhite()) |
| 560 | o << "color=" << st.m_surfaceColor << ","; |
| 561 | if (st.m_surfaceOpacity > 0) |
| 562 | o << "opacity=" << st.m_surfaceOpacity << ","; |
| 563 | o << "],"; |
| 564 | if (st.m_fillRuleEvenOdd) |
| 565 | o << "fill[evenOdd],"; |
| 566 | } |
| 567 | if (st.hasPattern()) |
| 568 | o << "pattern=[" << st.m_pattern << "],"; |
| 569 | if (st.hasGradient()) |
| 570 | { |
| 571 | o << "grad=["; |
| 572 | switch (st.m_gradientType) |
| 573 | { |
| 574 | case WPSGraphicStyle::G_Axial: |
| 575 | o << "axial,"; |
| 576 | break; |
| 577 | case WPSGraphicStyle::G_Linear: |
| 578 | o << "linear,"; |
| 579 | break; |
| 580 | case WPSGraphicStyle::G_Radial: |
| 581 | o << "radial,"; |
| 582 | break; |
| 583 | case WPSGraphicStyle::G_Rectangular: |
| 584 | o << "rectangular,"; |
| 585 | break; |
| 586 | case WPSGraphicStyle::G_Square: |
| 587 | o << "square,"; |
| 588 | break; |
| 589 | case WPSGraphicStyle::G_Ellipsoid: |
| 590 | o << "ellipsoid,"; |
| 591 | break; |
| 592 | case WPSGraphicStyle::G_None: |
| 593 | default: |
| 594 | break; |
| 595 | } |
| 596 | if (st.m_gradientAngle>0 || st.m_gradientAngle<0) o << "angle=" << st.m_gradientAngle << ","; |
| 597 | if (st.m_gradientStopList.size() >= 2) |
| 598 | { |
| 599 | o << "stops=["; |
| 600 | for (auto const &stop : st.m_gradientStopList) |
| 601 | o << "[" << stop << "],"; |
| 602 | o << "],"; |
| 603 | } |
| 604 | if (st.m_gradientBorder>0) o << "border=" << st.m_gradientBorder*100 << "%,"; |
| 605 | if (st.m_gradientPercentCenter != Vec2f(0.5f,0.5f)) o << "center=" << st.m_gradientPercentCenter << ","; |
| 606 | if (st.m_gradientRadius<1) o << "radius=" << st.m_gradientRadius << ","; |
| 607 | o << "],"; |
| 608 | } |
| 609 | if (st.hasShadow()) |
| 610 | { |
| 611 | o << "shadow=["; |
| 612 | if (!st.m_shadowColor.isBlack()) |
| 613 | o << "color=" << st.m_shadowColor << ","; |
| 614 | if (st.m_shadowOpacity > 0) |
| 615 | o << "opacity=" << st.m_shadowOpacity << ","; |
| 616 | o << "offset=" << st.m_shadowOffset << ","; |
| 617 | o << "],"; |
| 618 | } |
| 619 | if (st.hasBorders()) |
| 620 | { |
| 621 | for (size_t i = 0; i < st.m_bordersList.size(); i++) |
| 622 | { |
| 623 | if (st.m_bordersList[i].m_style == WPSBorder::None) |
| 624 | continue; |
| 625 | o << "bord"; |
| 626 | if (i < 4) |
| 627 | { |
| 628 | static char const *wh[] = { "L", "R", "T", "B"}; |
| 629 | o << wh[i]; |
| 630 | } |
| 631 | else o << "[#wh=" << i << "]"; |
| 632 | o << "=" << st.m_bordersList[i] << ","; |
| 633 | } |
| 634 | } |
| 635 | if (!st.m_backgroundColor.isWhite()) |
| 636 | o << "background[color]=" << st.m_backgroundColor << ","; |
| 637 | if (st.m_backgroundOpacity>=0) |
| 638 | o << "background[opacity]=" << 100.f *st.m_backgroundOpacity << "%,"; |
| 639 | if (!st.m_frameName.empty()) |
| 640 | o << "frame[name]=" << st.m_frameName.cstr() << ","; |
| 641 | if (!st.m_frameNextName.empty()) |
| 642 | o << "frame[linkedto]=" << st.m_frameNextName.cstr() << ","; |
| 643 | o << st.m_extra; |
| 644 | return o; |
| 645 | } |
| 646 | |
| 647 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |