Skip to content

Commit

Permalink
fix additional sdtPr
Browse files Browse the repository at this point in the history
  • Loading branch information
ElenaSubbotina committed Feb 12, 2025
1 parent 8098fec commit f145378
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 84 deletions.
19 changes: 13 additions & 6 deletions OOXML/Binary/Document/BinReader/Readers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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:
{
Expand All @@ -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:
{
Expand Down Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion OOXML/Binary/Document/BinReader/Readers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T> int ReadTrackRevision(long length, T* poResult);
Expand Down
18 changes: 14 additions & 4 deletions OOXML/Binary/Document/BinWriter/BinWriters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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<SimpleTypes::CHexColor>& oHexColor, const nullable<SimpleTypes::CThemeColor>& oThemeColor,
const nullable<SimpleTypes::CUcharHexNumber>& oThemeTint, const nullable<SimpleTypes::CUcharHexNumber>& oThemeShade)
Expand Down
17 changes: 12 additions & 5 deletions OOXML/Common/ComplexTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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())
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -496,7 +504,6 @@ namespace Word
}
return sResult;
}

void CShading::ReadAttributes(XmlUtils::CXmlLiteReader& oReader)
{
WritingElement_ReadAttributes_Start( oReader )
Expand Down
5 changes: 4 additions & 1 deletion OOXML/Common/ComplexTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
103 changes: 42 additions & 61 deletions OOXML/Common/SimpleTypes_Word.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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() )
Expand All @@ -1842,52 +1854,20 @@ namespace SimpleTypes
else this->m_eValue = EHexColor::hexcolorAuto;//eDefValue;

}

return this->m_eValue;
}

/*
template<>
EHexColor CHexColor<EHexColor::hexcolorRGB>::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<highlightcolorNone> 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;
Expand All @@ -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;
Expand All @@ -1949,7 +1930,7 @@ namespace SimpleTypes

unsigned char CHexColor::Get_A() const
{
return 255;
return m_unA;
}

//--------------------------------------------------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions OOXML/Common/SimpleTypes_Word.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,9 @@ namespace SimpleTypes
enum EHexColor
{
hexcolorAuto = 0,
hexcolorRGB = 1
hexcolorRGB = 1,
hexcolorARGB = 2

};

//--------------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions OOXML/DocxFormat/Logic/Sdt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"<w:border ", m_oBorder);
WritingElement_WriteNode_1(L"<w:shd ", m_oShd);
WritingElement_WriteNode_3(L"<w:border ", m_oBorder);
WritingElement_WriteNode_3(L"<w:shd ", m_oShd);

return sResult;
}
Expand Down
Loading

0 comments on commit f145378

Please sign in to comment.