46
46
#include "ColorConversions.h"
47
47
//! @todo only include for TINY target
49
const int HLSMAX = 255; //!< Used for computing tint
51
49
//! @return tinted value for @a color
52
50
//! Alpha value is left unchanged.
53
51
/*! @param color to be converted
76
75
//kDebug() << "rgb:" << r << g << b << QColor(r, g, b, color.alpha()).name();
77
76
return QColor(r, g, b, color.alpha());
79
static QColor tintedColor( const QColor & color, qreal tintfactor )
82
const qreal nonTindedPart = 1.0 - tintfactor;
83
const int tintedColor = 255 * nonTindedPart;
84
retColor.setRed( tintedColor + tintfactor * color.red() );
85
retColor.setGreen( tintedColor + tintfactor * color.green() );
86
retColor.setBlue( tintedColor + tintfactor * color.blue() );
80
91
/*! @return color decoded from a "rgb" attribute of the current element
81
92
or invalid QColor when reading was not possible.
108
119
//----------------------------------------------------------
121
// This is default array of colors from MS
122
const char* INDEXED_ARRAY[64] = {
123
"000000", "FFFFFF", "FF0000", "00FF00", "0000FF",
124
"FFFF00", "FF00FF", "00FFFF", "000000", "FFFFFF",
125
"FF0000", "00FF00", "0000FF", "FFFF00", "FF00FF",
126
"00FFFF", "800000", "008000", "000080", "808000",
127
"800080", "008080", "C0C0C0", "808080", "9999FF",
128
"993366", "FFFFCC", "CCFFFF", "660066", "FF8080",
129
"0066CC", "CCCCFF", "000080", "FF00FF", "FFFF00",
130
"00FFFF", "800080", "800000", "008080", "0000FF",
131
"00CCFF", "CCFFFF", "CCFFCC", "FFFF99", "99CCFF",
132
"FF99CC", "CC99FF", "FFCC99", "3366FF", "33CCCC",
133
"99CC00", "FFCC00", "FF9900", "FF6600", "666699",
134
"969696", "003366", "339966", "003300", "333300",
135
"993300", "993366", "333399", "333333"
110
138
XlsxColorStyle::XlsxColorStyle()
130
158
return rgb.isValid();
133
QColor XlsxColorStyle::themeColor(const QMap<QString, MSOOXML::DrawingMLTheme*> *themes) const
161
QColor XlsxColorStyle::themeColor(const/* QMap<QString,*/ MSOOXML::DrawingMLTheme*/*> **/themes) const
135
163
Q_ASSERT(themes);
136
164
//! @todo find proper theme, not just any
137
MSOOXML::DrawingMLTheme *themeObject = themes->constBegin().value();
165
const MSOOXML::DrawingMLTheme *themeObject = themes;
138
166
kDebug() << themeObject;
139
167
if (themeObject) {
140
168
MSOOXML::DrawingMLColorSchemeItemBase *colorItemBase = themeObject->colorScheme.value(theme);
172
199
QString indexedStr;
173
200
TRY_READ_ATTR_WITHOUT_NS_INTO(indexed, indexedStr)
174
201
STRING_TO_INT(indexedStr, indexed, QLatin1String(debugElement) + "@indexed")
175
//! @todo handle indexed
176
rgb = readRgbAttribute(attrs);
202
if (indexed >= 0 && indexed < 64) {
203
rgb = QString("#%1").arg(INDEXED_ARRAY[indexed]);
206
rgb = readRgbAttribute(attrs);
177
208
tint = readTintAttribute(attrs, debugElement);
178
209
QString themeStr;
179
210
TRY_READ_ATTR_WITHOUT_NS_INTO(theme, themeStr)
286
static QColor applyPatternDensity( const XlsxColorStyle& bg, const XlsxColorStyle& fg, qreal percent, const QMap<QString, MSOOXML::DrawingMLTheme*> *themes )
317
static QColor applyPatternDensity( const XlsxColorStyle& bg, const XlsxColorStyle& fg, qreal percent, const /*QMap<QString, */MSOOXML::DrawingMLTheme/**>*/ *themes )
288
319
const QColor bgColor = bg.theme >= 0 ? bg.themeColor( themes ) : bg.rgb.isValid() ? bg.rgb : QColor( Qt::white );
289
320
const QColor fgColor = fg.theme >= 0 ? fg.themeColor( themes ) : fg.rgb;//.isValid() ? fg.rgb : QColor( Qt::black );
291
322
QColor result( Qt::white );
292
323
if( bgColor.isValid() ) {
293
result = QColor( bgColor.red() * percent,
294
bgColor.green() * percent,
295
bgColor.blue() * percent,
324
result = QColor( bgColor.red() * percent,
325
bgColor.green() * percent,
326
bgColor.blue() * percent,
296
327
bgColor.alpha() );
298
329
if( fgColor.isValid() ) {
299
result = QColor( result.red() + fgColor.red() * ( 1.0 - percent ),
300
result.green() + fgColor.green() * ( 1.0 - percent ),
330
result = QColor( result.red() + fgColor.red() * ( 1.0 - percent ),
331
result.green() + fgColor.green() * ( 1.0 - percent ),
301
332
result.blue() + fgColor.blue() * ( 1.0 - percent ),
302
333
bgColor.isValid() ? bgColor.alpha() : fgColor.alpha() );
307
const XlsxColorStyle* XlsxFillStyle::realBackgroundColor( const QMap<QString, MSOOXML::DrawingMLTheme*> *themes) const
338
const XlsxColorStyle* XlsxFillStyle::realBackgroundColor( const /*QMap<QString,*/ MSOOXML::DrawingMLTheme/**>*/ *themes) const
309
340
delete cachedRealBackgroundColor;
310
341
cachedRealBackgroundColor = new XlsxColorStyle;
367
void XlsxFillStyle::setupCellStyle(KoGenStyle* cellStyle, const QMap<QString, MSOOXML::DrawingMLTheme*> *themes) const
398
void XlsxFillStyle::setupCellStyle(KoGenStyle* cellStyle, const /*QMap<QString, */MSOOXML::DrawingMLTheme/**>*/ *themes) const
369
400
//! @todo implement more styling;
370
401
//! use XlsxColorStyle::automatic, XlsxColorStyle::indexed, XlsxColorStyle::theme...
371
402
const XlsxColorStyle* realBackgroundColor = this->realBackgroundColor( themes );
372
if (realBackgroundColor) {
373
kDebug() << patternType << realBackgroundColor->value(themes).name()
374
<< realBackgroundColor->tint << realBackgroundColor->isValid(themes);
375
if (realBackgroundColor->isValid(themes)) {
376
cellStyle->addProperty("fo:background-color", realBackgroundColor->value(themes).name());
403
if ( realBackgroundColor )
405
// This is necessary because excel switches the indexes of 0 - 1 and 2 - 3 for theme colorindexes
406
// looks like it has a different internal indexing table
407
// i found the info here : http://blogs.msdn.com/b/excel/archive/2007/11/16/chart-pattern-fills.aspx
409
XlsxColorStyle changedColor( *realBackgroundColor );
410
if ( changedColor.theme == 0 )
411
changedColor.theme = 1;
412
else if ( changedColor.theme == 1 )
413
changedColor.theme = 0;
414
else if ( changedColor.theme == 2 )
415
changedColor.theme = 3;
416
else if ( changedColor.theme == 3 )
417
changedColor.theme = 2;
418
kDebug() << patternType << changedColor.value(themes).name()
419
<< changedColor.tint << changedColor.isValid(themes);
420
if (changedColor.isValid(themes)) {
421
cellStyle->addProperty("fo:background-color", changedColor.value(themes).name());
501
546
void XlsxFontStyle::setupCellTextStyle(
502
const QMap<QString, MSOOXML::DrawingMLTheme*> *themes,
547
const /*QMap<QString,*/ MSOOXML::DrawingMLTheme/**>*/ *themes,
503
548
KoGenStyle* cellStyle) const
505
550
if (!name.isEmpty()) {
509
554
//!@ todo reenable this cellStyle->addProperty("style:font-name", name, KoGenStyle::TextType);
510
555
cellStyle->addProperty("fo:font-family", name, KoGenStyle::TextType);
512
if (color.isValid(themes)) {
513
const QColor c(color.value(themes));
557
// This is necessary because excel switches the indexes of 0 - 1 and 2 - 3 for theme colorindexes
558
// looks like it has a different internal indexing table
559
// i found the info here : http://blogs.msdn.com/b/excel/archive/2007/11/16/chart-pattern-fills.aspx
561
XlsxColorStyle changedColor( color );
562
if ( changedColor.theme == 0 )
563
changedColor.theme = 1;
564
else if ( changedColor.theme == 1 )
565
changedColor.theme = 0;
566
else if ( changedColor.theme == 2 )
567
changedColor.theme = 3;
568
else if ( changedColor.theme == 3 )
569
changedColor.theme = 2;
570
else if (changedColor.isValid(themes)) {
571
const QColor c(changedColor.value(themes));
514
572
cellStyle->addProperty("fo:color", c.name(), KoGenStyle::TextType);
516
574
//! @todo implement more styling
650
708
cellStyle->addProperty("style:direction", "ttb");
651
709
else if (textRotation != 0) {
652
//@todo map other cases (to style:text-rotate-angle? that one only allows 0, 90, 270)
710
unsigned angle = textRotation;
711
if (angle > 90) angle = 360 - (angle - 90);
712
cellStyle->addProperty("style:rotation-angle", QString::number(angle));
666
726
case GeneralHorizontalAlignment: // ok?
667
727
if (verticalTtb) // Excel centers vertical text by default, so mimic that
668
728
cellStyle->addProperty("fo:text-align", "center", KoGenStyle::ParagraphType);
729
if (textRotation > 90 && textRotation < 180) // Excel right aligns rotated text for some angles
730
cellStyle->addProperty("fo:text-align", "end", KoGenStyle::ParagraphType);
670
732
case LeftHorizontalAlignment:
671
733
cellStyle->addProperty("fo:text-align", "start", KoGenStyle::ParagraphType);
687
750
case TopVerticalAlignment:
688
751
cellStyle->addProperty("style:vertical-align", "top");
690
case NoVerticalAlignment:
691
case JustifyVerticalAlignment: // ok?
753
case JustifyVerticalAlignment: // ok?
692
754
case DistributedVerticalAlignment:
693
755
cellStyle->addProperty("style:vertical-align", "top");
694
756
cellStyle->addProperty("koffice:vertical-distributed", "distributed");
759
case NoVerticalAlignment:
697
760
case BottomVerticalAlignment:
761
cellStyle->addProperty("style:vertical-align", "bottom");
705
770
//! See http://www.w3.org/TR/2001/REC-xsl-20011015/slice7.html#text-align
706
771
bool XlsxCellFormat::setupCellStyle(
707
772
const XlsxStyles *styles,
708
const QMap<QString, MSOOXML::DrawingMLTheme*> *themes,
773
const /*QMap<QString, */MSOOXML::DrawingMLTheme/**>*/ *themes,
709
774
KoGenStyle* cellStyle) const
711
776
kDebug() << "fontId:" << fontId << "fillId:" << fillId << "borderId:" << borderId;