From dce58b628f4d94cf80ee0693f5abecea5cd3fd15 Mon Sep 17 00:00:00 2001 From: ElenaSubbotina Date: Tue, 21 Nov 2017 18:10:05 +0300 Subject: [PATCH] fix bug #36322 --- .../DocDocxConverter/IVisitable.h | 2 + .../DocDocxConverter/PropertiesMapping.cpp | 89 ++++++++++--------- .../DocDocxConverter/ShadingDescriptor.h | 8 +- .../TableCellPropertiesMapping.cpp | 2 +- 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/ASCOfficeDocFile/DocDocxConverter/IVisitable.h b/ASCOfficeDocFile/DocDocxConverter/IVisitable.h index 8f31fea13c..da6bde0bcd 100644 --- a/ASCOfficeDocFile/DocDocxConverter/IVisitable.h +++ b/ASCOfficeDocFile/DocDocxConverter/IVisitable.h @@ -33,6 +33,8 @@ #include "IMapping.h" +#define GETBITS(from, numL, numH) ((from & (((1 << (numH - numL + 1)) - 1) << numL)) >> numL) + namespace DocFileFormat { class IVisitable diff --git a/ASCOfficeDocFile/DocDocxConverter/PropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/PropertiesMapping.cpp index df2bbf62d4..ebc64e69f9 100644 --- a/ASCOfficeDocFile/DocDocxConverter/PropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/PropertiesMapping.cpp @@ -462,57 +462,60 @@ namespace DocFileFormat void PropertiesMapping::appendShading( XMLTools::XMLElement* parent, const ShadingDescriptor& desc ) { + std::wstring pattern = getShadingPattern( desc ); if ( ( parent != NULL ) && ( desc.shadingSpecialValue == shadingSpecialValueNormal )) { XMLTools::XMLElement shd( L"w:shd" ); - //fill color - XMLTools::XMLAttribute fill( L"w:fill" ); - - if ( desc.shadingType == shadingTypeShd ) - { - if ( desc.cvBackAuto ) - { - fill.SetValue( L"auto" ); - } - else - { - fill.SetValue( RGBColor( (int)desc.cvBack, RedLast ).SixDigitHexCode); - } - } - else - { - fill.SetValue( FormatUtils::MapValueToWideString( desc.icoBack, &Global::ColorIdentifier[0][0], 17, 12 )); - } - - shd.AppendAttribute( fill ); - - //foreground color - XMLTools::XMLAttribute color( L"w:color" ); - - if ( desc.shadingType == shadingTypeShd ) - { - if ( desc.cvForeAuto ) - { - color.SetValue( L"auto" ); - } - else - { - color.SetValue( RGBColor( (int)desc.cvFore, RedLast ).SixDigitHexCode); - } - } - else - { - color.SetValue( FormatUtils::MapValueToWideString( desc.icoFore, &Global::ColorIdentifier[0][0], 17, 12 )); - } - - shd.AppendAttribute( color ); - //pattern XMLTools::XMLAttribute val( L"w:val" ); - val.SetValue( getShadingPattern( desc )); + val.SetValue( pattern); shd.AppendAttribute( val ); + if (pattern != L"nil") + { + //fill color + XMLTools::XMLAttribute fill( L"w:fill" ); + + if ( desc.shadingType == shadingTypeShd ) + { + if ( desc.cvBackAuto ) + { + fill.SetValue( L"auto" ); + } + else + { + fill.SetValue( RGBColor( (int)desc.cvBack, RedLast ).SixDigitHexCode); + } + } + else + { + fill.SetValue( FormatUtils::MapValueToWideString( desc.icoBack, &Global::ColorIdentifier[0][0], 17, 12 )); + } + + shd.AppendAttribute( fill ); + + //foreground color + XMLTools::XMLAttribute color( L"w:color" ); + + if ( desc.shadingType == shadingTypeShd ) + { + if ( desc.cvForeAuto ) + { + color.SetValue( L"auto" ); + } + else + { + color.SetValue( RGBColor( (int)desc.cvFore, RedLast ).SixDigitHexCode); + } + } + else + { + color.SetValue( FormatUtils::MapValueToWideString( desc.icoFore, &Global::ColorIdentifier[0][0], 17, 12 )); + } + + shd.AppendAttribute( color ); + } parent->RemoveChildByName( L"w:shd" ); parent->AppendChild( shd ); } diff --git a/ASCOfficeDocFile/DocDocxConverter/ShadingDescriptor.h b/ASCOfficeDocFile/DocDocxConverter/ShadingDescriptor.h index 76c3bba728..c4269e12c0 100644 --- a/ASCOfficeDocFile/DocDocxConverter/ShadingDescriptor.h +++ b/ASCOfficeDocFile/DocDocxConverter/ShadingDescriptor.h @@ -174,9 +174,9 @@ namespace DocFileFormat //it's a Word 97 SPRM short val = FormatUtils::BytesToInt16(bytes, 0, size); - icoFore = (val & 0x1F); - icoBack = ((val >> 5) & 0x1F); - ipat = (ShadingPattern) ((val >> 10) & 0x3F); + icoFore = GETBITS(val, 0, 4); + icoBack = GETBITS(val, 5, 9); + ipat = (ShadingPattern) GETBITS(val, 10, 15); shadingType = shadingTypeShd80; @@ -209,7 +209,7 @@ namespace DocFileFormat else if (0x0F == icoFore) { cvFore = RGB2 (0x80, 0x80, 0x80); } else if (0x10 == icoFore) { cvFore = RGB2 (0xC0, 0xC0, 0xC0); } - if (0x00 == icoBack) { cvBack = RGB2 (0x00, 0x00, 0x00); cvBackAuto = true; } + if (0x00 == icoBack) { cvBack = RGB2 (0xFF, 0xFF, 0xFF); cvBackAuto = true; } else if (0x01 == icoBack) { cvBack = RGB2 (0x00, 0x00, 0x00); } else if (0x02 == icoBack) { cvBack = RGB2 (0x00, 0x00, 0xFF); } else if (0x03 == icoBack) { cvBack = RGB2 (0x00, 0xFF, 0xFF); } diff --git a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp index c32801547d..90f1293d35 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp @@ -349,7 +349,7 @@ namespace DocFileFormat void TableCellPropertiesMapping::apppendCellShading (unsigned char* sprmArg, int size, int cellIndex) { - if (sprmArg) + if (sprmArg && cellIndex >= 0) { //shading descriptor can have 10 bytes (Word 2000) or 2 bytes (Word 97) int shdLength = 2;