|
@ -151,12 +151,12 @@ void Styles::addFormat(Format *format, bool force) |
|
|
//Font
|
|
|
//Font
|
|
|
if (!format->fontIndexValid()) { |
|
|
if (!format->fontIndexValid()) { |
|
|
if (!m_fontsHash.contains(format->fontKey())) { |
|
|
if (!m_fontsHash.contains(format->fontKey())) { |
|
|
QSharedPointer<XlsxFormatFontData> font = QSharedPointer<XlsxFormatFontData>(new XlsxFormatFontData(format->d->fontData)); |
|
|
format->setFontIndex(m_fontsList.size()); //Assign proper index
|
|
|
font->setIndex(m_fontsList.size()); //Assign proper index
|
|
|
m_fontsList.append(format); |
|
|
m_fontsList.append(font); |
|
|
m_fontsHash[format->fontKey()] = format; |
|
|
m_fontsHash[font->key()] = font; |
|
|
} else { |
|
|
|
|
|
format->setFontIndex(m_fontsHash[format->fontKey()]->fontIndex()); |
|
|
} |
|
|
} |
|
|
format->setFontIndex(m_fontsHash[format->fontKey()]->index()); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Fill
|
|
|
//Fill
|
|
@ -287,81 +287,77 @@ void Styles::writeFonts(XmlStreamWriter &writer) |
|
|
writer.writeStartElement(QStringLiteral("fonts")); |
|
|
writer.writeStartElement(QStringLiteral("fonts")); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_fontsList.count())); |
|
|
writer.writeAttribute(QStringLiteral("count"), QString::number(m_fontsList.count())); |
|
|
for (int i=0; i<m_fontsList.size(); ++i) { |
|
|
for (int i=0; i<m_fontsList.size(); ++i) { |
|
|
QSharedPointer<XlsxFormatFontData> font = m_fontsList[i]; |
|
|
Format *format = m_fontsList[i]; |
|
|
|
|
|
|
|
|
writer.writeStartElement(QStringLiteral("font")); |
|
|
writer.writeStartElement(QStringLiteral("font")); |
|
|
if (font->bold) |
|
|
|
|
|
|
|
|
if (format->fontBold()) |
|
|
writer.writeEmptyElement(QStringLiteral("b")); |
|
|
writer.writeEmptyElement(QStringLiteral("b")); |
|
|
if (font->italic) |
|
|
if (format->fontItalic()) |
|
|
writer.writeEmptyElement(QStringLiteral("i")); |
|
|
writer.writeEmptyElement(QStringLiteral("i")); |
|
|
if (font->strikeOut) |
|
|
if (format->fontStrikeOut()) |
|
|
writer.writeEmptyElement(QStringLiteral("strike")); |
|
|
writer.writeEmptyElement(QStringLiteral("strike")); |
|
|
if (font->outline) |
|
|
if (format->fontOutline()) |
|
|
writer.writeEmptyElement(QStringLiteral("outline")); |
|
|
writer.writeEmptyElement(QStringLiteral("outline")); |
|
|
if (font->shadow) |
|
|
if (format->boolProperty(FormatPrivate::P_Font_Shadow)) |
|
|
writer.writeEmptyElement(QStringLiteral("shadow")); |
|
|
writer.writeEmptyElement(QStringLiteral("shadow")); |
|
|
if (font->underline != Format::FontUnderlineNone) { |
|
|
if (format->hasProperty(FormatPrivate::P_Font_Underline)) { |
|
|
writer.writeEmptyElement(QStringLiteral("u")); |
|
|
Format::FontUnderline u = format->fontUnderline(); |
|
|
if (font->underline == Format::FontUnderlineDouble) |
|
|
if (u != Format::FontUnderlineNone) { |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("double")); |
|
|
writer.writeEmptyElement(QStringLiteral("u")); |
|
|
else if (font->underline == Format::FontUnderlineSingleAccounting) |
|
|
if (u== Format::FontUnderlineDouble) |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("singleAccounting")); |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("double")); |
|
|
else if (font->underline == Format::FontUnderlineDoubleAccounting) |
|
|
else if (u == Format::FontUnderlineSingleAccounting) |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("doubleAccounting")); |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("singleAccounting")); |
|
|
|
|
|
else if (u == Format::FontUnderlineDoubleAccounting) |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("doubleAccounting")); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if (font->scirpt != Format::FontScriptNormal) { |
|
|
if (format->hasProperty(FormatPrivate::P_Font_Script)) { |
|
|
writer.writeEmptyElement(QStringLiteral("vertAligh")); |
|
|
Format::FontScript s = format->fontScript(); |
|
|
if (font->scirpt == Format::FontScriptSuper) |
|
|
if (s != Format::FontScriptNormal) { |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("superscript")); |
|
|
writer.writeEmptyElement(QStringLiteral("vertAlign")); |
|
|
else |
|
|
if (s == Format::FontScriptSuper) |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("subscript")); |
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("superscript")); |
|
|
|
|
|
else |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("subscript")); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
writer.writeEmptyElement(QStringLiteral("sz")); |
|
|
if (format->hasProperty(FormatPrivate::P_Font_Size)) { |
|
|
writer.writeAttribute(QStringLiteral("val"), QString::number(font->size)); |
|
|
writer.writeEmptyElement(QStringLiteral("sz")); |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("val"), QString::number(format->fontSize())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (font->color.isValid()) { |
|
|
if (format->fontColor().isValid()) { |
|
|
writer.writeEmptyElement(QStringLiteral("color")); |
|
|
writer.writeEmptyElement(QStringLiteral("color")); |
|
|
QString color = font->color.name(); |
|
|
QString color = format->fontColor().name(); |
|
|
writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.mid(1));//remove #
|
|
|
writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.mid(1));//remove #
|
|
|
} else if (!font->themeColor.isEmpty()) { |
|
|
} else if (format->hasProperty(FormatPrivate::P_Font_ThemeColor)) { |
|
|
writer.writeEmptyElement(QStringLiteral("color")); |
|
|
writer.writeEmptyElement(QStringLiteral("color")); |
|
|
QStringList themes = font->themeColor.split(QLatin1Char(':')); |
|
|
QStringList themes = format->stringProperty(FormatPrivate::P_Font_ThemeColor).split(QLatin1Char(':')); |
|
|
writer.writeAttribute(QStringLiteral("theme"), themes[0]); |
|
|
writer.writeAttribute(QStringLiteral("theme"), themes[0]); |
|
|
if (!themes[1].isEmpty()) |
|
|
if (!themes[1].isEmpty()) |
|
|
writer.writeAttribute(QStringLiteral("tint"), themes[1]); |
|
|
writer.writeAttribute(QStringLiteral("tint"), themes[1]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
writer.writeEmptyElement(QStringLiteral("name")); |
|
|
if (!format->fontName().isEmpty()) { |
|
|
writer.writeAttribute(QStringLiteral("val"), font->name); |
|
|
writer.writeEmptyElement(QStringLiteral("name")); |
|
|
writer.writeEmptyElement(QStringLiteral("family")); |
|
|
writer.writeAttribute(QStringLiteral("val"), format->fontName()); |
|
|
writer.writeAttribute(QStringLiteral("val"), QString::number(font->family)); |
|
|
} |
|
|
if (font->name == QLatin1String("Calibri")) { |
|
|
if (format->hasProperty(FormatPrivate::P_Font_Family)) { |
|
|
|
|
|
writer.writeEmptyElement(QStringLiteral("family")); |
|
|
|
|
|
writer.writeAttribute(QStringLiteral("val"), QString::number(format->intProperty(FormatPrivate::P_Font_Family))); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (format->hasProperty(FormatPrivate::P_Font_Scheme)) { |
|
|
writer.writeEmptyElement(QStringLiteral("scheme")); |
|
|
writer.writeEmptyElement(QStringLiteral("scheme")); |
|
|
writer.writeAttribute(QStringLiteral("val"), font->scheme); |
|
|
writer.writeAttribute(QStringLiteral("val"), format->stringProperty(FormatPrivate::P_Font_Scheme)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// if (!format->isDxfFormat()) {
|
|
|
// if (!format->isDxfFormat()) {
|
|
|
// writer.writeEmptyElement(QStringLiteral("sz"));
|
|
|
// writer.writeEmptyElement(QStringLiteral("sz"));
|
|
|
// writer.writeAttribute(QStringLiteral("val"), QString::number(format->fontSize()));
|
|
|
// writer.writeAttribute(QStringLiteral("val"), QString::number(format->fontSize()));
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
|
|
|
// //font color
|
|
|
|
|
|
// if (format->theme()) {
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("color"));
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("theme"), QString::number(format->theme()));
|
|
|
|
|
|
// } else if (format->colorIndexed()) {
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("color"));
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("indexed"), QString::number(format->colorIndexed()));
|
|
|
|
|
|
// } else if (format->fontColor().isValid()) {
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("color"));
|
|
|
|
|
|
// QString color = format->fontColor().name();
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("rgb"), QStringLiteral("FF")+color.mid(1));//remove #
|
|
|
|
|
|
// } else if (!format->isDxfFormat()) {
|
|
|
|
|
|
// writer.writeEmptyElement(QStringLiteral("color"));
|
|
|
|
|
|
// writer.writeAttribute(QStringLiteral("theme"), QStringLiteral("1"));
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// if (!format->isDxfFormat()) {
|
|
|
// if (!format->isDxfFormat()) {
|
|
|
// writer.writeEmptyElement(QStringLiteral("name"));
|
|
|
// writer.writeEmptyElement(QStringLiteral("name"));
|
|
|
// writer.writeAttribute(QStringLiteral("val"), format->fontName());
|
|
|
// writer.writeAttribute(QStringLiteral("val"), format->fontName());
|
|
@ -602,72 +598,78 @@ bool Styles::readNumFmts(XmlStreamReader &reader) |
|
|
bool Styles::readFonts(XmlStreamReader &reader) |
|
|
bool Styles::readFonts(XmlStreamReader &reader) |
|
|
{ |
|
|
{ |
|
|
Q_ASSERT(reader.name() == QLatin1String("fonts")); |
|
|
Q_ASSERT(reader.name() == QLatin1String("fonts")); |
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
QXmlStreamAttributes attrs = reader.attributes(); |
|
|
int count = attributes.value(QLatin1String("count")).toString().toInt(); |
|
|
int count = attrs.value(QLatin1String("count")).toString().toInt(); |
|
|
for (int i=0; i<count; ++i) { |
|
|
for (int i=0; i<count; ++i) { |
|
|
reader.readNextStartElement(); |
|
|
reader.readNextStartElement(); |
|
|
if (reader.name() != QLatin1String("font")) |
|
|
if (reader.name() != QLatin1String("font")) |
|
|
return false; |
|
|
return false; |
|
|
QSharedPointer<XlsxFormatFontData> font(new XlsxFormatFontData); |
|
|
Format *format = createFormat(); |
|
|
while((reader.readNextStartElement(),true)) { //read until font endelement.
|
|
|
while((reader.readNextStartElement(),true)) { //read until font endelement.
|
|
|
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|
|
if (reader.tokenType() == QXmlStreamReader::StartElement) { |
|
|
if (reader.name() == QLatin1String("b")) { |
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
font->bold = true; |
|
|
if (reader.name() == QLatin1String("name")) { |
|
|
|
|
|
format->setFontName(attributes.value(QLatin1String("val")).toString()); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("charset")) { |
|
|
|
|
|
format->setProperty(FormatPrivate::P_Font_Charset, attributes.value(QLatin1String("val")).toString().toInt()); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("family")) { |
|
|
|
|
|
format->setProperty(FormatPrivate::P_Font_Family, attributes.value(QLatin1String("val")).toString().toInt()); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("b")) { |
|
|
|
|
|
format->setFontBold(true); |
|
|
} else if (reader.name() == QLatin1String("i")) { |
|
|
} else if (reader.name() == QLatin1String("i")) { |
|
|
font->italic = true; |
|
|
format->setFontItalic(true); |
|
|
} else if (reader.name() == QLatin1String("strike")) { |
|
|
} else if (reader.name() == QLatin1String("strike")) { |
|
|
font->strikeOut = true; |
|
|
format->setFontStrikeOut(true); |
|
|
} else if (reader.name() == QLatin1String("outline")) { |
|
|
} else if (reader.name() == QLatin1String("outline")) { |
|
|
font->outline = true; |
|
|
format->setFontOutline(true); |
|
|
} else if (reader.name() == QLatin1String("shadow")) { |
|
|
} else if (reader.name() == QLatin1String("shadow")) { |
|
|
font->shadow = true; |
|
|
format->setProperty(FormatPrivate::P_Font_Shadow, true); |
|
|
} else if (reader.name() == QLatin1String("u")) { |
|
|
} else if (reader.name() == QLatin1String("condense")) { |
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
format->setProperty(FormatPrivate::P_Font_Condense, attributes.value(QLatin1String("val")).toString().toInt()); |
|
|
QString value = attributes.value(QLatin1String("val")).toString(); |
|
|
} else if (reader.name() == QLatin1String("extend")) { |
|
|
if (value == QLatin1String("double")) |
|
|
format->setProperty(FormatPrivate::P_Font_Extend, attributes.value(QLatin1String("val")).toString().toInt()); |
|
|
font->underline = Format::FontUnderlineDouble; |
|
|
|
|
|
else if (value == QLatin1String("doubleAccounting")) |
|
|
|
|
|
font->underline = Format::FontUnderlineDoubleAccounting; |
|
|
|
|
|
else if (value == QLatin1String("singleAccounting")) |
|
|
|
|
|
font->underline = Format::FontUnderlineSingleAccounting; |
|
|
|
|
|
else |
|
|
|
|
|
font->underline = Format::FontUnderlineSingle; |
|
|
|
|
|
} else if (reader.name() == QLatin1String("vertAligh")) { |
|
|
|
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
|
|
|
QString value = attributes.value(QLatin1String("val")).toString(); |
|
|
|
|
|
if (value == QLatin1String("superscript")) |
|
|
|
|
|
font->scirpt = Format::FontScriptSuper; |
|
|
|
|
|
else |
|
|
|
|
|
font->scirpt = Format::FontScriptSub; |
|
|
|
|
|
} else if (reader.name() == QLatin1String("sz")) { |
|
|
|
|
|
font->size = reader.attributes().value(QLatin1String("val")).toString().toInt(); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("color")) { |
|
|
} else if (reader.name() == QLatin1String("color")) { |
|
|
QXmlStreamAttributes attributes = reader.attributes(); |
|
|
|
|
|
if (attributes.hasAttribute(QLatin1String("rgb"))) { |
|
|
if (attributes.hasAttribute(QLatin1String("rgb"))) { |
|
|
QString colorString = attributes.value(QLatin1String("rgb")).toString(); |
|
|
QString colorString = attributes.value(QLatin1String("rgb")).toString(); |
|
|
font->color = fromARGBString(colorString); |
|
|
format->setFontColor(fromARGBString(colorString)); |
|
|
} else if (attributes.hasAttribute(QLatin1String("indexed"))) { |
|
|
} else if (attributes.hasAttribute(QLatin1String("indexed"))) { |
|
|
font->color = getColorByIndex(attributes.value(QLatin1String("indexed")).toString().toInt()); |
|
|
QColor color = getColorByIndex(attributes.value(QLatin1String("indexed")).toString().toInt()); |
|
|
|
|
|
format->setFontColor(color); |
|
|
} else if (attributes.hasAttribute(QLatin1String("theme"))) { |
|
|
} else if (attributes.hasAttribute(QLatin1String("theme"))) { |
|
|
QString theme = attributes.value(QLatin1String("theme")).toString(); |
|
|
QString theme = attributes.value(QLatin1String("theme")).toString(); |
|
|
QString tint = attributes.value(QLatin1String("tint")).toString(); |
|
|
QString tint = attributes.value(QLatin1String("tint")).toString(); |
|
|
font->themeColor = theme + QLatin1Char(':') + tint; |
|
|
format->setProperty(FormatPrivate::P_Font_ThemeColor, QString(theme + QLatin1Char(':') + tint)); |
|
|
} |
|
|
} |
|
|
} else if (reader.name() == QLatin1String("name")) { |
|
|
} else if (reader.name() == QLatin1String("sz")) { |
|
|
font->name = reader.attributes().value(QLatin1String("val")).toString(); |
|
|
int sz = attributes.value(QLatin1String("val")).toString().toInt(); |
|
|
} else if (reader.name() == QLatin1String("family")) { |
|
|
format->setFontSize(sz); |
|
|
font->family = reader.attributes().value(QLatin1String("val")).toString().toInt(); |
|
|
} else if (reader.name() == QLatin1String("u")) { |
|
|
|
|
|
QString value = attributes.value(QLatin1String("val")).toString(); |
|
|
|
|
|
if (value == QLatin1String("double")) |
|
|
|
|
|
format->setFontUnderline(Format::FontUnderlineDouble); |
|
|
|
|
|
else if (value == QLatin1String("doubleAccounting")) |
|
|
|
|
|
format->setFontUnderline(Format::FontUnderlineDoubleAccounting); |
|
|
|
|
|
else if (value == QLatin1String("singleAccounting")) |
|
|
|
|
|
format->setFontUnderline(Format::FontUnderlineSingleAccounting); |
|
|
|
|
|
else |
|
|
|
|
|
format->setFontUnderline(Format::FontUnderlineSingle); |
|
|
|
|
|
} else if (reader.name() == QLatin1String("vertAlign")) { |
|
|
|
|
|
QString value = attributes.value(QLatin1String("val")).toString(); |
|
|
|
|
|
if (value == QLatin1String("superscript")) |
|
|
|
|
|
format->setFontScript(Format::FontScriptSuper); |
|
|
|
|
|
else if (value == QLatin1String("subscript")) |
|
|
|
|
|
format->setFontScript(Format::FontScriptSub); |
|
|
} else if (reader.name() == QLatin1String("scheme")) { |
|
|
} else if (reader.name() == QLatin1String("scheme")) { |
|
|
font->scheme = reader.attributes().value(QLatin1String("val")).toString(); |
|
|
format->setProperty(FormatPrivate::P_Font_Scheme, attributes.value(QLatin1String("val")).toString()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("font")) |
|
|
if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("font")) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
m_fontsList.append(font); |
|
|
m_fontsList.append(format); |
|
|
m_fontsHash.insert(font->key(), font); |
|
|
m_fontsHash.insert(format->fontKey(), format); |
|
|
font->setIndex(m_fontsList.size()-1);//first call key(), then setIndex()
|
|
|
format->setFontIndex(m_fontsList.size()-1); |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -907,7 +909,11 @@ bool Styles::readCellXfs(XmlStreamReader &reader) |
|
|
if (fontIndex >= m_fontsList.size()) { |
|
|
if (fontIndex >= m_fontsList.size()) { |
|
|
qDebug("Error read styles.xml, cellXfs fontId"); |
|
|
qDebug("Error read styles.xml, cellXfs fontId"); |
|
|
} else { |
|
|
} else { |
|
|
format->d->fontData = *m_fontsList[fontIndex]; |
|
|
Format *fontFormat = m_fontsList[fontIndex]; |
|
|
|
|
|
for (int i=FormatPrivate::P_Font_STARTID; i<FormatPrivate::P_Font_ENDID; ++i) { |
|
|
|
|
|
if (fontFormat->hasProperty(i)) |
|
|
|
|
|
format->setProperty(i, fontFormat->property(i)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|