diff --git a/OOXML/Binary/Document/BinReader/Readers.cpp b/OOXML/Binary/Document/BinReader/Readers.cpp index b647412ef3d..e1210e711da 100644 --- a/OOXML/Binary/Document/BinReader/Readers.cpp +++ b/OOXML/Binary/Document/BinReader/Readers.cpp @@ -260,15 +260,21 @@ docRGB Binary_CommonReader2::ReadColor() oRGB.B = m_oBufferedStream.GetUChar(); return oRGB; } -void Binary_CommonReader2::ReadHexColor(SimpleTypes::CHexColor *pColor) +void Binary_CommonReader2::ReadHexColor(SimpleTypes::CHexColor *pColor, long length) { if (!pColor) { - m_oBufferedStream.Skip(3); + m_oBufferedStream.Skip(length); return; } - pColor->SetValue(SimpleTypes::hexcolorRGB); + + if (length == 4) + { + pColor->SetValue(SimpleTypes::hexcolorARGB); + + pColor->Set_A(m_oBufferedStream.GetUChar()); + } pColor->Set_R(m_oBufferedStream.GetUChar()); pColor->Set_G(m_oBufferedStream.GetUChar()); @@ -341,7 +347,7 @@ int Binary_CommonReader2::ReadShdComplexType(BYTE type, long length, void* poRes case c_oSerShdType::Color: { pShd->m_oColor.Init(); - ReadHexColor(pShd->m_oColor.GetPointer()); + ReadHexColor(pShd->m_oColor.GetPointer(), length); }break; case c_oSerShdType::ColorTheme: { @@ -352,7 +358,7 @@ int Binary_CommonReader2::ReadShdComplexType(BYTE type, long length, void* poRes case c_oSerShdType::Fill: { pShd->m_oFill.Init(); - ReadHexColor(pShd->m_oFill.GetPointer()); + ReadHexColor(pShd->m_oFill.GetPointer(), length); }break; case c_oSerShdType::FillTheme: { @@ -1339,7 +1345,8 @@ int Binary_pPrReader::ReadBorder(BYTE type, long length, void* poResult) { pBorder->m_oColor.Init(); pBorder->m_oColor->SetValue(SimpleTypes::hexcolorRGB); - oBinary_CommonReader2.ReadHexColor(pBorder->m_oColor.GetPointer()); + + oBinary_CommonReader2.ReadHexColor(pBorder->m_oColor.GetPointer(), length); } else if ( c_oSerBorderType::Space == type ) { diff --git a/OOXML/Binary/Document/BinReader/Readers.h b/OOXML/Binary/Document/BinReader/Readers.h index a396a049311..1f48e6d4ac6 100644 --- a/OOXML/Binary/Document/BinReader/Readers.h +++ b/OOXML/Binary/Document/BinReader/Readers.h @@ -57,7 +57,7 @@ class Binary_CommonReader2 : public Binary_CommonReader public: Binary_CommonReader2(NSBinPptxRW::CBinaryFileReader& poBufferedStream); docRGB ReadColor(); - void ReadHexColor(SimpleTypes::CHexColor *pColor); + void ReadHexColor(SimpleTypes::CHexColor *pColor, long length); void ReadThemeColor(int length, CThemeColor& oCThemeColor); int ReadThemeColorContent(BYTE type, long length, void* poResult); template int ReadTrackRevision(long length, T* poResult); diff --git a/OOXML/Binary/Document/BinWriter/BinWriters.cpp b/OOXML/Binary/Document/BinWriter/BinWriters.cpp index bbba33bc4cc..3a2210edf89 100644 --- a/OOXML/Binary/Document/BinWriter/BinWriters.cpp +++ b/OOXML/Binary/Document/BinWriter/BinWriters.cpp @@ -153,11 +153,12 @@ void BinaryCommonWriter::WriteBorder(const BYTE & type, const ComplexTypes::Word } void BinaryCommonWriter::WriteBorder(const ComplexTypes::Word::CBorder& border) {//todooo сделать все типы бордера - if (border.m_oVal.IsInit()) - { - if (border.m_oColor.IsInit()) - WriteColor(c_oSerBorderType::Color, border.m_oColor.get()); + if (border.m_oColor.IsInit()) + WriteColor(c_oSerBorderType::Color, border.m_oColor.get()); + + if (border.m_oVal.IsInit()) + { WriteThemeColor(c_oSerBorderType::ColorTheme, border.m_oColor, border.m_oThemeColor, border.m_oThemeTint, border.m_oThemeShade); if (border.m_oSpace.IsInit()) @@ -295,6 +296,15 @@ void BinaryCommonWriter::WriteColor(BYTE type, const SimpleTypes::CHexColor& col m_oStream.WriteBYTE(color.Get_G()); m_oStream.WriteBYTE(color.Get_B()); } + else if (SimpleTypes::hexcolorARGB == color.GetValue()) + { + m_oStream.WriteBYTE(type); + m_oStream.WriteBYTE(c_oSerPropLenType::Long); + m_oStream.WriteBYTE(color.Get_A()); + m_oStream.WriteBYTE(color.Get_R()); + m_oStream.WriteBYTE(color.Get_G()); + m_oStream.WriteBYTE(color.Get_B()); + } } void BinaryCommonWriter::WriteThemeColor(BYTE type, const nullable& oHexColor, const nullable& oThemeColor, const nullable& oThemeTint, const nullable& oThemeShade) diff --git a/OOXML/Common/ComplexTypes.cpp b/OOXML/Common/ComplexTypes.cpp index e31d7ad1b15..a909bb481bf 100644 --- a/OOXML/Common/ComplexTypes.cpp +++ b/OOXML/Common/ComplexTypes.cpp @@ -115,6 +115,10 @@ namespace Word oReader.ReadTillEnd(); } std::wstring CBorder::ToString() const + { + return ToString(true); + } + std::wstring CBorder::ToString(bool noAlpha) const { std::wstring sResult; @@ -127,7 +131,7 @@ namespace Word if ( m_oColor.IsInit() ) { sResult += L"w:color=\""; - sResult += m_oColor->ToStringNoAlpha(); + sResult += noAlpha ? m_oColor->ToStringNoAlpha() : m_oColor->ToString(); sResult += L"\" "; } if (m_oThemeColor.IsInit()) @@ -437,6 +441,10 @@ namespace Word oReader.ReadTillEnd(); } std::wstring CShading::ToString() const + { + return ToString(true); + } + std::wstring CShading::ToString(bool noAlpha) const { std::wstring sResult; @@ -446,13 +454,13 @@ namespace Word sResult += m_oVal->ToString(); sResult += L"\" "; } - if ( m_oColor.IsInit() ) + if (m_oColor.IsInit()) { sResult += L"w:color=\""; - sResult += m_oColor->ToStringNoAlpha(); + sResult += noAlpha ? m_oColor->ToStringNoAlpha() : m_oColor->ToString(); sResult += L"\" "; } - if ( m_oThemeColor.IsInit() ) + if (m_oThemeColor.IsInit()) { sResult += L"w:themeColor=\""; sResult += m_oThemeColor->ToString(); @@ -496,7 +504,6 @@ namespace Word } return sResult; } - void CShading::ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { WritingElement_ReadAttributes_Start( oReader ) diff --git a/OOXML/Common/ComplexTypes.h b/OOXML/Common/ComplexTypes.h index b8e3b5dd2f2..ea14aa1fc37 100644 --- a/OOXML/Common/ComplexTypes.h +++ b/OOXML/Common/ComplexTypes.h @@ -140,7 +140,8 @@ namespace ComplexTypes virtual void FromXML(XmlUtils::CXmlNode& oNode); virtual void FromXML(XmlUtils::CXmlLiteReader& oReader); virtual std::wstring ToString() const; - + + std::wstring ToString(bool noAlpha) const; private: void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); @@ -245,6 +246,8 @@ namespace ComplexTypes virtual void FromXML(XmlUtils::CXmlNode& oNode); virtual void FromXML(XmlUtils::CXmlLiteReader& oReader); virtual std::wstring ToString() const; + + std::wstring ToString(bool noAlpha) const; private: void ReadAttributes(XmlUtils::CXmlLiteReader& oReader); diff --git a/OOXML/Common/SimpleTypes_Word.cpp b/OOXML/Common/SimpleTypes_Word.cpp index 2233a9926f6..2b546cd0bf1 100644 --- a/OOXML/Common/SimpleTypes_Word.cpp +++ b/OOXML/Common/SimpleTypes_Word.cpp @@ -1757,9 +1757,11 @@ namespace SimpleTypes /// - CHexColor::CHexColor(unsigned char r, unsigned char g, unsigned char b) + CHexColor::CHexColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { this->m_eValue = hexcolorRGB; + + m_unA = a; m_unR = r; m_unG = g; m_unB = b; @@ -1779,9 +1781,19 @@ namespace SimpleTypes if ( m_sValue.length() < 6 ) return; - m_unR = HexToInt( (int)m_sValue[1] ) + (unsigned char)(HexToInt( (int)m_sValue[0] ) << 4); - m_unG = HexToInt( (int)m_sValue[3] ) + (unsigned char)(HexToInt( (int)m_sValue[2] ) << 4); - m_unB = HexToInt( (int)m_sValue[5] ) + (unsigned char)(HexToInt( (int)m_sValue[4] ) << 4); + if (m_sValue.length() > 6) + { + m_unA = HexToInt((int)m_sValue[1]) + (unsigned char)(HexToInt((int)m_sValue[0]) << 4); + m_unR = HexToInt((int)m_sValue[3]) + (unsigned char)(HexToInt((int)m_sValue[2]) << 4); + m_unG = HexToInt((int)m_sValue[5]) + (unsigned char)(HexToInt((int)m_sValue[4]) << 4); + m_unB = HexToInt((int)m_sValue[7]) + (unsigned char)(HexToInt((int)m_sValue[6]) << 4); + } + else + { + m_unR = HexToInt((int)m_sValue[1]) + (unsigned char)(HexToInt((int)m_sValue[0]) << 4); + m_unG = HexToInt((int)m_sValue[3]) + (unsigned char)(HexToInt((int)m_sValue[2]) << 4); + m_unB = HexToInt((int)m_sValue[5]) + (unsigned char)(HexToInt((int)m_sValue[4]) << 4); + } } void CHexColor::Parse3() @@ -1823,8 +1835,8 @@ namespace SimpleTypes } else if (8 <= sValue.length()) { - this->m_eValue = hexcolorRGB; - m_sValue = sValue.substr(2, 6); + this->m_eValue = hexcolorARGB; + m_sValue = sValue.substr(0, 8); Parse(); } else if ( 6 <= sValue.length() ) @@ -1842,52 +1854,20 @@ namespace SimpleTypes else this->m_eValue = EHexColor::hexcolorAuto;//eDefValue; } - return this->m_eValue; } - /* - template<> - EHexColor CHexColor::FromString(const std::wstring &sValue) + std::wstring CHexColor::ToString () const { - if ( _T("auto") == sValue || _T("none") == sValue ) - this->m_eValue = hexcolorAuto; - else + switch(this->m_eValue) { - //В документации не написано, что цвет может приходить строкой, но в реальных докуентах встречается и word это разруливает. - //CHighlightColor oHighlightColor(sValue); - CPresetColorVal<> oPresetColorVal; - if(oPresetColorVal.FromStringIgnoreCase(sValue)) - { - this->m_eValue = hexcolorRGB; - m_unR = oPresetColorVal.Get_R(); - m_unG = oPresetColorVal.Get_G(); - m_unB = oPresetColorVal.Get_B(); - } - else if ( 6 <= sValue.length() ) - { - this->m_eValue = hexcolorRGB; - m_sValue = sValue.substr( 0, 6 ); - Parse(); - } - else if ( 3 == sValue.length() )// a la #339 (Compo 3AP.docx) - { - this->m_eValue = hexcolorRGB; - m_sValue = sValue; - Parse3(); - } - else this->m_eValue = EHexColor::hexcolorAuto;//eDefValue; + case hexcolorARGB: + { + std::wstringstream sstream; + sstream << boost::wformat(L"%02x%02x%02x%02x") % m_unA % m_unR % m_unG % m_unB; + return sstream.str(); } - - return this->m_eValue; - } - */ - - std::wstring CHexColor::ToString () const - { - switch(this->m_eValue) - { case hexcolorRGB : { std::wstringstream sstream; @@ -1901,42 +1881,43 @@ namespace SimpleTypes } } - std::wstring CHexColor::ToStringNoAlpha () const + std::wstring CHexColor::ToStringNoAlpha () const { - switch(this->m_eValue) - { - case hexcolorRGB : + switch (this->m_eValue) { - std::wstringstream sstream; - sstream << boost::wformat( L"%02x%02x%02x" ) % m_unR % m_unG % m_unB; + case hexcolorARGB: + case hexcolorRGB: + { + std::wstringstream sstream; + sstream << boost::wformat(L"%02x%02x%02x") % m_unR % m_unG % m_unB; - return sstream.str(); + return sstream.str(); + } + case hexcolorAuto: + default: + return (L"auto"); } - case hexcolorAuto : - default : - return (L"auto"); } } - + void CHexColor::Set_A(unsigned char A) + { + m_unA = A; + } void CHexColor::Set_R(unsigned char R) { m_unR = R; } - void CHexColor::Set_G(unsigned char G) { m_unG = G; } - void CHexColor::Set_B(unsigned char B) { m_unB = B; } - unsigned char CHexColor::Get_R() const { return m_unR; } - unsigned char CHexColor::Get_G() const { return m_unG; @@ -1949,7 +1930,7 @@ namespace SimpleTypes unsigned char CHexColor::Get_A() const { - return 255; + return m_unA; } //-------------------------------------------------------------------------------- diff --git a/OOXML/Common/SimpleTypes_Word.h b/OOXML/Common/SimpleTypes_Word.h index e882f736108..cc5ce6b646f 100644 --- a/OOXML/Common/SimpleTypes_Word.h +++ b/OOXML/Common/SimpleTypes_Word.h @@ -847,7 +847,9 @@ namespace SimpleTypes enum EHexColor { hexcolorAuto = 0, - hexcolorRGB = 1 + hexcolorRGB = 1, + hexcolorARGB = 2 + }; //-------------------------------------------------------------------------------- @@ -877,10 +879,11 @@ namespace SimpleTypes DEFINE_SIMPLE_TYPE_START(CHexColor, EHexColor, hexcolorAuto) public: - CHexColor(unsigned char r, unsigned char g, unsigned char b); + CHexColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255); - std::wstring ToStringNoAlpha () const; + std::wstring ToStringNoAlpha () const; + void Set_A(unsigned char R); void Set_R(unsigned char R); void Set_G(unsigned char G); void Set_B(unsigned char B); @@ -896,6 +899,7 @@ namespace SimpleTypes std::wstring m_sValue; + unsigned char m_unA = 255; unsigned char m_unR = 0; unsigned char m_unG = 0; unsigned char m_unB = 0; diff --git a/OOXML/DocxFormat/Logic/Sdt.cpp b/OOXML/DocxFormat/Logic/Sdt.cpp index fdc8a97069a..75371299219 100644 --- a/OOXML/DocxFormat/Logic/Sdt.cpp +++ b/OOXML/DocxFormat/Logic/Sdt.cpp @@ -1635,8 +1635,8 @@ namespace OOX WritingElement_WriteNode_2(m_oFormPr); WritingElement_WriteNode_2(m_oTextFormPr); WritingElement_WriteNode_2(m_oComplexFormPr); - WritingElement_WriteNode_1(L"toXML(); - //----------------------------------------------------------------------------------------------- + +#define WritingElement_WriteNode_3( sStartNodeString, oValue ) \ + if ( oValue.IsInit() )\ + {\ + sResult += sStartNodeString;\ + sResult += oValue->ToString(false);\ + sResult += _T("/>");\ +} +//----------------------------------------------------------------------------------------------- #define WritingElement_ReadAttributes_ReadSingle2(Reader, AttrName, Value) \ if ( Reader.GetAttributesCount() > 0 ){\ if ( Reader.MoveToFirstAttribute() ){\