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