From c64a33f42df920c62bc813224f2858df9748c365 Mon Sep 17 00:00:00 2001 From: ElenaSubbotina Date: Tue, 3 Apr 2018 15:28:08 +0300 Subject: [PATCH] DocFormatReader - add older version format --- .../CharacterPropertiesMapping.cpp | 669 +++++++++--------- .../CharacterPropertyExceptions.h | 217 ++++-- .../DocDocxConverter/CommentsMapping.h | 2 +- .../DocDocxConverter/DateAndTime.h | 47 +- .../DocDocxConverter/DocumentMapping.cpp | 19 +- .../DocDocxConverter/DocumentMapping.h | 2 +- .../DocDocxConverter/DocumentProperties.cpp | 78 +- .../DocDocxConverter/DocumentProperties.h | 3 +- .../DocDocxConverter/EndnotesMapping.h | 2 +- .../DocDocxConverter/FileInformationBlock.h | 42 +- .../DocDocxConverter/FooterMapping.cpp | 2 +- .../DocDocxConverter/FootnotesMapping.h | 2 +- .../FormattedDiskPagePAPX.cpp | 2 - .../DocDocxConverter/HeaderAndFooterTable.cpp | 167 ++--- .../DocDocxConverter/HeaderAndFooterTable.h | 17 +- .../DocDocxConverter/HeaderMapping.cpp | 2 +- .../DocDocxConverter/ListData.cpp | 62 +- ASCOfficeDocFile/DocDocxConverter/ListData.h | 7 +- .../DocDocxConverter/ListLevel.cpp | 4 + .../DocDocxConverter/MainDocumentMapping.cpp | 4 +- .../DocDocxConverter/OleObject.cpp | 2 +- .../ParagraphPropertiesMapping.cpp | 2 +- .../ParagraphPropertyExceptions.cpp | 182 ++++- ASCOfficeDocFile/DocDocxConverter/Plex.h | 4 +- .../DocDocxConverter/PropertyExceptions.cpp | 12 +- .../DocDocxConverter/RevisionData.cpp | 7 +- .../DocDocxConverter/SectionDescriptor.h | 33 +- .../SectionPropertiesMapping.cpp | 37 +- .../SectionPropertyExceptions.h | 4 + .../DocDocxConverter/SettingsMapping.cpp | 2 +- .../SinglePropertyModifier.cpp | 5 +- .../DocDocxConverter/SinglePropertyModifier.h | 6 + .../DocDocxConverter/StringTable.h | 21 +- .../DocDocxConverter/StyleSheet.cpp | 48 +- .../TableCellPropertiesMapping.cpp | 3 +- ASCOfficeDocFile/DocDocxConverter/TableInfo.h | 6 - .../DocDocxConverter/TableMapping.cpp | 2 +- .../TablePropertiesMapping.cpp | 24 +- .../DocDocxConverter/TextboxMapping.cpp | 2 +- .../DocDocxConverter/WordDocument.cpp | 12 +- 40 files changed, 1095 insertions(+), 669 deletions(-) diff --git a/ASCOfficeDocFile/DocDocxConverter/CharacterPropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/CharacterPropertiesMapping.cpp index 554130f928..f1870acec5 100644 --- a/ASCOfficeDocFile/DocDocxConverter/CharacterPropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/CharacterPropertiesMapping.cpp @@ -129,357 +129,360 @@ namespace DocFileFormat parent->AppendChild( *webHidden ); RELEASEOBJECT( webHidden ); } - std::list::iterator end = sprms->end(); - for (std::list::iterator iter = sprms->begin(); iter != end; ++iter) + if ((sprms) && (!sprms->empty())) { - int nProperty = 0; //for unknown test - - switch ( (int)( iter->OpCode ) ) + std::list::iterator end = sprms->end(); + for (std::list::iterator iter = sprms->begin(); iter != end; ++iter) { - case sprmOldCIstd : - case sprmCIstd : // style id + int nProperty = 0; //for unknown test + + switch ( (int)( iter->OpCode ) ) { - if (_isRunStyleNeeded && !_webHidden) + case sprmOldCIstd : + case sprmCIstd : // style id { - _currentIstd = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); - if (_currentIstd < _doc->Styles->Styles->size()) + if (_isRunStyleNeeded && !_webHidden) { - appendValueElement( parent, L"rStyle", StyleSheetMapping::MakeStyleId( _doc->Styles->Styles->at( _currentIstd ) ), true ); + _currentIstd = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); + if (_currentIstd < _doc->Styles->Styles->size()) + { + appendValueElement( parent, L"rStyle", StyleSheetMapping::MakeStyleId( _doc->Styles->Styles->at( _currentIstd ) ), true ); + } + } + }break; + + case sprmCFBiDi : + appendFlagElement( parent, *iter, L"rtl", true ); + _isRTL = true; + break; + + case sprmOldCFBold : + case sprmCFBold : + appendFlagElement( parent, *iter, L"b", true ); + break; + + case sprmCFBoldBi : + appendFlagElement( parent, *iter, L"bCs", true ); + break; + + case sprmOldCFCaps : + case sprmCFCaps : + appendFlagElement( parent, *iter, L"caps", true ); + break; + + case sprmCFComplexScripts : + appendFlagElement( parent, *iter, L"cs", true ); + break; + + case sprmCFDStrike : + appendFlagElement( parent, *iter, L"dstrike", true ); + break; + + case sprmCFEmboss : + appendFlagElement( parent, *iter, L"emboss", true ); + break; + + case sprmCFImprint : + appendFlagElement( parent, *iter, L"imprint", true ); + break; + + case sprmOldCFItalic : + case sprmCFItalic : + appendFlagElement( parent, *iter, L"i", true ); + break; + + case sprmCFItalicBi: + appendFlagElement( parent, *iter, L"iCs", true ); + break; + + case 0x0875: + appendFlagElement( parent, *iter, L"noProof", true ); + break; + + case sprmOldCFOutline: + case sprmCFOutline: + appendFlagElement( parent, *iter, L"outline", true ); + break; + + case sprmOldCFShadow: + case sprmCFShadow: + appendFlagElement( parent, *iter, L"shadow", true ); + break; + + case sprmOldCFSmallCaps: + case sprmCFSmallCaps: + appendFlagElement( parent, *iter, L"smallCaps", true ); + break; + + case sprmCFSpecVanish: + appendFlagElement( parent, *iter, L"specVanish", true ); + break; + + case sprmOldCFStrike: + case sprmCFStrike: + appendFlagElement( parent, *iter, L"strike", true ); + break; + + case sprmOldCFVanish: + case sprmCFVanish: + appendFlagElement( parent, *iter, L"vanish", true ); + break; + + case 0x0811: + appendFlagElement( parent, *iter, L"webHidden", true ); + break; + + case sprmOldCIss: + case sprmCIss: + if (iter->argumentsSize > 0 && iter->Arguments[0] < 3) //Metaevan.doc + appendValueElement( parent, L"vertAlign", FormatUtils::MapValueToWideString( iter->Arguments[0], &SuperscriptIndex[0][0], 3, 12 ), true ); + break; + + case sprmCRgLid0_80: + case sprmCRgLid0: + { //latin + LanguageId langid( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); + + LanguageIdMapping* langIDMapping = new LanguageIdMapping( lang, Default ); + + langid.Convert( langIDMapping ); + + RELEASEOBJECT( langIDMapping ); + }break; + + case sprmOldCLid: + case sprmCRgLid1_80: + case sprmCRgLid1: + { //east asia + LanguageId langid( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); + + LanguageIdMapping* langIDMapping = new LanguageIdMapping( lang, EastAsian ); + + langid.Convert( langIDMapping ); + + RELEASEOBJECT( langIDMapping ); + }break; + + case sprmCLidBi: + { + LanguageId langid( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); + + LanguageIdMapping* langIDMapping = new LanguageIdMapping( lang, Complex ); + + langid.Convert( langIDMapping ); + + RELEASEOBJECT( langIDMapping ); + }break; + + case sprmCBrc80: + case sprmCBrc: + { //borders + XMLTools::XMLElement bdr( L"w:bdr" ); + BorderCode bc( iter->Arguments, iter->argumentsSize ); + appendBorderAttributes( &bc, &bdr ); + parent->AppendChild( bdr ); + }break; + + case sprmCShd80: + case sprmCShd: + { //shading + ShadingDescriptor desc( iter->Arguments, iter->argumentsSize ); + + appendShading( parent, desc ); + }break; + + case sprmOldCIco: + case sprmCIco: + case sprmCIcoBi: + {//color + colorVal->SetValue( FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::ColorIdentifier[0][0], 17, 12 )); + }break; + + case sprmCCv: + { + std::wstringstream sstream; + + sstream << boost::wformat(L"%02x%02x%02x") % iter->Arguments[0] % /*G*/iter->Arguments[1] % /*B*/iter->Arguments[2]; + colorVal->SetValue(sstream.str()); + }break; + + case sprmCOldHighlight: + { + appendValueElement( parent, L"highlight", FormatUtils::MapValueToWideString( iter->Arguments[1], &Global::ColorNameIdentifier[0][0], 17, 12 ), true ); + }break; + case sprmCHighlight: + { + appendValueElement( parent, L"highlight", FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::ColorNameIdentifier[0][0], 17, 12 ), true ); + }break; + + case sprmOldCDxaSpace: + case sprmCDxaSpace: + { + appendValueElement( parent, L"spacing", FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); + }break; + + case sprmCFtcBi : + {//default from FontTable + size_t nIndex = FormatUtils::BytesToUInt16 (iter->Arguments, 0, iter->argumentsSize); + if( nIndex < _doc->FontTable->Data.size() ) + { + FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); + if (ffn) + m_sDefaultFont = ffn->xszFtn; + } + }break; + + case sprmCHpsBi : + { + appendValueElement( parent, L"szCs", + FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); + } + break; + // Font Size in points (2~3276) default 20-half-points + case sprmOldCHps : + { + appendValueElement (parent, L"sz", + FormatUtils::IntToWideString (FormatUtils::BytesToUChar (iter->Arguments, 0, iter->argumentsSize) ), + true ); + }break; + case sprmCHps : + { + appendValueElement (parent, L"sz", + FormatUtils::IntToWideString (FormatUtils::BytesToUInt16 (iter->Arguments, 0, iter->argumentsSize) ), true ); + }break; + + case sprmCMajority : + { //for complex props + }break; + + case sprmOldCHpsPos: + { // The vertical position, in half-points, of text relative to the normal position. (MUST be between -3168 and 3168) + short nVertPos = FormatUtils::BytesToUChar(iter->Arguments, 0, iter->argumentsSize); + appendValueElement (parent, L"position", nVertPos, true); + }break; + case sprmCHpsPos: + { // The vertical position, in half-points, of text relative to the normal position. (MUST be between -3168 and 3168) + short nVertPos = FormatUtils::BytesToInt16(iter->Arguments, 0, iter->argumentsSize); + appendValueElement (parent, L"position", nVertPos, true); + }break; + + case sprmOldCHpsKern: + case sprmCHpsKern: + { + appendValueElement( parent, L"kern", FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); + }break; + + case sprmOldCFtc: + case sprmCRgFtc0: + { // font family + size_t nIndex = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); + + if( nIndex < _doc->FontTable->Data.size() ) + { + XMLTools::XMLAttribute* ascii = new XMLTools::XMLAttribute( L"w:ascii" ); + FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); + m_sAsciiFont = ffn->xszFtn; + ascii->SetValue( FormatUtils::XmlEncode(m_sAsciiFont, true)); + rFonts->AppendAttribute( *ascii ); + RELEASEOBJECT( ascii ); + } + }break; + + case sprmCRgFtc1: + { + size_t nIndex = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); + + if( nIndex >= 0 && nIndex < _doc->FontTable->Data.size() ) + { + XMLTools::XMLAttribute* eastAsia = new XMLTools::XMLAttribute( L"w:eastAsia" ); + FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); + m_sEastAsiaFont = ffn->xszFtn; + eastAsia->SetValue( FormatUtils::XmlEncode(m_sEastAsiaFont)); + rFonts->AppendAttribute( *eastAsia ); + RELEASEOBJECT( eastAsia ); } } - }break; + break; - case sprmCFBiDi : - appendFlagElement( parent, *iter, L"rtl", true ); - _isRTL = true; - break; - - case sprmOldCFBold : - case sprmCFBold : - appendFlagElement( parent, *iter, L"b", true ); - break; - - case sprmCFBoldBi : - appendFlagElement( parent, *iter, L"bCs", true ); - break; - - case sprmOldCFCaps : - case sprmCFCaps : - appendFlagElement( parent, *iter, L"caps", true ); - break; - - case sprmCFComplexScripts : - appendFlagElement( parent, *iter, L"cs", true ); - break; - - case sprmCFDStrike : - appendFlagElement( parent, *iter, L"dstrike", true ); - break; - - case sprmCFEmboss : - appendFlagElement( parent, *iter, L"emboss", true ); - break; - - case sprmCFImprint : - appendFlagElement( parent, *iter, L"imprint", true ); - break; - - case sprmOldCFItalic : - case sprmCFItalic : - appendFlagElement( parent, *iter, L"i", true ); - break; - - case sprmCFItalicBi: - appendFlagElement( parent, *iter, L"iCs", true ); - break; - - case 0x0875: - appendFlagElement( parent, *iter, L"noProof", true ); - break; - - case sprmOldCFOutline: - case sprmCFOutline: - appendFlagElement( parent, *iter, L"outline", true ); - break; - - case sprmOldCFShadow: - case sprmCFShadow: - appendFlagElement( parent, *iter, L"shadow", true ); - break; - - case sprmOldCFSmallCaps: - case sprmCFSmallCaps: - appendFlagElement( parent, *iter, L"smallCaps", true ); - break; - - case sprmCFSpecVanish: - appendFlagElement( parent, *iter, L"specVanish", true ); - break; - - case sprmOldCFStrike: - case sprmCFStrike: - appendFlagElement( parent, *iter, L"strike", true ); - break; - - case sprmOldCFVanish: - case sprmCFVanish: - appendFlagElement( parent, *iter, L"vanish", true ); - break; - - case 0x0811: - appendFlagElement( parent, *iter, L"webHidden", true ); - break; - - case sprmOldCIss: - case sprmCIss: - if (iter->argumentsSize > 0 && iter->Arguments[0] < 3) //Metaevan.doc - appendValueElement( parent, L"vertAlign", FormatUtils::MapValueToWideString( iter->Arguments[0], &SuperscriptIndex[0][0], 3, 12 ), true ); - break; - - case sprmCRgLid0_80: - case sprmCRgLid0: - { //latin - LanguageId langid( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - - LanguageIdMapping* langIDMapping = new LanguageIdMapping( lang, Default ); - - langid.Convert( langIDMapping ); - - RELEASEOBJECT( langIDMapping ); - }break; - - case sprmOldCLid: - case sprmCRgLid1_80: - case sprmCRgLid1: - { //east asia - LanguageId langid( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - - LanguageIdMapping* langIDMapping = new LanguageIdMapping( lang, EastAsian ); - - langid.Convert( langIDMapping ); - - RELEASEOBJECT( langIDMapping ); - }break; - - case sprmCLidBi: - { - LanguageId langid( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ); - - LanguageIdMapping* langIDMapping = new LanguageIdMapping( lang, Complex ); - - langid.Convert( langIDMapping ); - - RELEASEOBJECT( langIDMapping ); - }break; - - case sprmCBrc80: - case sprmCBrc: - { //borders - XMLTools::XMLElement bdr( L"w:bdr" ); - BorderCode bc( iter->Arguments, iter->argumentsSize ); - appendBorderAttributes( &bc, &bdr ); - parent->AppendChild( bdr ); - }break; - - case sprmCShd80: - case sprmCShd: - { //shading - ShadingDescriptor desc( iter->Arguments, iter->argumentsSize ); - - appendShading( parent, desc ); - }break; - - case sprmOldCIco: - case sprmCIco: - case sprmCIcoBi: - {//color - colorVal->SetValue( FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::ColorIdentifier[0][0], 17, 12 )); - }break; - - case sprmCCv: - { - std::wstringstream sstream; - - sstream << boost::wformat(L"%02x%02x%02x") % iter->Arguments[0] % /*G*/iter->Arguments[1] % /*B*/iter->Arguments[2]; - colorVal->SetValue(sstream.str()); - }break; - - case sprmCOldHighlight: - { - appendValueElement( parent, L"highlight", FormatUtils::MapValueToWideString( iter->Arguments[1], &Global::ColorIdentifier[0][0], 17, 12 ), true ); - }break; - case sprmCHighlight: - { - appendValueElement( parent, L"highlight", FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::ColorIdentifier[0][0], 17, 12 ), true ); - }break; - - case sprmOldCDxaSpace: - case sprmCDxaSpace: - { - appendValueElement( parent, L"spacing", FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); - }break; - - case sprmCFtcBi : - {//default from FontTable - size_t nIndex = FormatUtils::BytesToUInt16 (iter->Arguments, 0, iter->argumentsSize); - if( nIndex < _doc->FontTable->Data.size() ) + case sprmCRgFtc2: { - FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); - if (ffn) - m_sDefaultFont = ffn->xszFtn; - } - }break; + size_t nIndex = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); - case sprmCHpsBi : - { - appendValueElement( parent, L"szCs", - FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); - } - break; -// Font Size in points (2~3276) default 20-half-points - case sprmOldCHps : - { - appendValueElement (parent, L"sz", - FormatUtils::IntToWideString (FormatUtils::BytesToUChar (iter->Arguments, 0, iter->argumentsSize) ), - true ); - }break; - case sprmCHps : - { - appendValueElement (parent, L"sz", - FormatUtils::IntToWideString (FormatUtils::BytesToUInt16 (iter->Arguments, 0, iter->argumentsSize) ), true ); - }break; - - case sprmCMajority : - { //for complex props - }break; - - case sprmOldCHpsPos: - { // The vertical position, in half-points, of text relative to the normal position. (MUST be between -3168 and 3168) - short nVertPos = FormatUtils::BytesToUChar(iter->Arguments, 0, iter->argumentsSize); - appendValueElement (parent, L"position", nVertPos, true); - }break; - case sprmCHpsPos: - { // The vertical position, in half-points, of text relative to the normal position. (MUST be between -3168 and 3168) - short nVertPos = FormatUtils::BytesToInt16(iter->Arguments, 0, iter->argumentsSize); - appendValueElement (parent, L"position", nVertPos, true); - }break; - - case sprmOldCHpsKern: - case sprmCHpsKern: - { - appendValueElement( parent, L"kern", FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); - }break; - - case sprmOldCFtc: - case sprmCRgFtc0: - { // font family - size_t nIndex = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); - - if( nIndex < _doc->FontTable->Data.size() ) - { - XMLTools::XMLAttribute* ascii = new XMLTools::XMLAttribute( L"w:ascii" ); - FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); - m_sAsciiFont = ffn->xszFtn; - ascii->SetValue( FormatUtils::XmlEncode(m_sAsciiFont, true)); - rFonts->AppendAttribute( *ascii ); - RELEASEOBJECT( ascii ); - } - }break; - - case sprmCRgFtc1: - { - size_t nIndex = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); - - if( nIndex >= 0 && nIndex < _doc->FontTable->Data.size() ) - { - XMLTools::XMLAttribute* eastAsia = new XMLTools::XMLAttribute( L"w:eastAsia" ); - FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); - m_sEastAsiaFont = ffn->xszFtn; - eastAsia->SetValue( FormatUtils::XmlEncode(m_sEastAsiaFont)); - rFonts->AppendAttribute( *eastAsia ); - RELEASEOBJECT( eastAsia ); - } - } - break; - - case sprmCRgFtc2: - { - size_t nIndex = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); - - if( nIndex>=0 && nIndex < _doc->FontTable->Data.size() ) - { - XMLTools::XMLAttribute* ansi = new XMLTools::XMLAttribute( L"w:hAnsi" ); - FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); - m_shAnsiFont = ffn->xszFtn; - ansi->SetValue( FormatUtils::XmlEncode(m_shAnsiFont)); - rFonts->AppendAttribute( *ansi ); - RELEASEOBJECT( ansi ); - } - }break; - - case sprmOldCKul: - case sprmCKul: - { //Underlining - appendValueElement( parent, L"u", FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::UnderlineCode[0][0], 56, 16 ), true ); - } - break; - - case sprmCCharScale: - { //char width - appendValueElement( parent, L"w", FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); - }break; - - case sprmCSfxText: - { //animation - appendValueElement( parent, L"effect", FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::TextAnimation[0][0], 7, 16 ), true ); - }break; - - case sprmCIdctHint: - { - switch(iter->Arguments[0]) - { - case 0: break; // default - case 1: break; // eastAsia - case 2: break; // cs - case 0xFF: break; //No ST_Hint equivalent - } - - }break; - - case sprmCPbiIBullet: - { - int nIndex = FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize ); - if (nIndex >=0) - { - std::map::iterator it = _doc->PictureBulletsCPsMap.find(nIndex); - if (it != _doc->PictureBulletsCPsMap.end()) + if( nIndex>=0 && nIndex < _doc->FontTable->Data.size() ) { - //добавить + XMLTools::XMLAttribute* ansi = new XMLTools::XMLAttribute( L"w:hAnsi" ); + FontFamilyName* ffn = static_cast( _doc->FontTable->operator [] ( nIndex ) ); + m_shAnsiFont = ffn->xszFtn; + ansi->SetValue( FormatUtils::XmlEncode(m_shAnsiFont)); + rFonts->AppendAttribute( *ansi ); + RELEASEOBJECT( ansi ); } + }break; + + case sprmOldCKul: + case sprmCKul: + { //Underlining + appendValueElement( parent, L"u", FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::UnderlineCode[0][0], 56, 16 ), true ); } - }break; + break; - case sprmCPbiGrf: - { - //used picture bullet - int val = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); + case sprmCCharScale: + { //char width + appendValueElement( parent, L"w", FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ), true ); + }break; + + case sprmCSfxText: + { //animation + appendValueElement( parent, L"effect", FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::TextAnimation[0][0], 7, 16 ), true ); + }break; - }break; + case sprmCIdctHint: + { + switch(iter->Arguments[0]) + { + case 0: break; // default + case 1: break; // eastAsia + case 2: break; // cs + case 0xFF: break; //No ST_Hint equivalent + } - case sprmCRsidProp: - case sprmCRsidText: - break; + }break; - default: - if (iter->argumentsSize == 2) - { - nProperty = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); - }else - if (iter->argumentsSize == 1) - { - nProperty = FormatUtils::BytesToUChar( iter->Arguments, 0, iter->argumentsSize ); + case sprmCPbiIBullet: + { + int nIndex = FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize ); + if (nIndex >=0) + { + std::map::iterator it = _doc->PictureBulletsCPsMap.find(nIndex); + if (it != _doc->PictureBulletsCPsMap.end()) + { + //добавить + } + } + }break; + + case sprmCPbiGrf: + { + //used picture bullet + int val = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); + + }break; + + case sprmCRsidProp: + case sprmCRsidText: + break; + + default: + if (iter->argumentsSize == 2) + { + nProperty = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ); + }else + if (iter->argumentsSize == 1) + { + nProperty = FormatUtils::BytesToUChar( iter->Arguments, 0, iter->argumentsSize ); + } + break; } - break; } } diff --git a/ASCOfficeDocFile/DocDocxConverter/CharacterPropertyExceptions.h b/ASCOfficeDocFile/DocDocxConverter/CharacterPropertyExceptions.h index 674607f0fd..f10811cabc 100644 --- a/ASCOfficeDocFile/DocDocxConverter/CharacterPropertyExceptions.h +++ b/ASCOfficeDocFile/DocDocxConverter/CharacterPropertyExceptions.h @@ -48,93 +48,174 @@ namespace DocFileFormat CharacterPropertyExceptions( unsigned char* bytes, int size, int nWordVersion) : PropertyExceptions( bytes, size, nWordVersion ) { - if (nWordVersion == 2 && size > 0) + if (nWordVersion > 1) { RELEASEOBJECT( grpprl ); grpprl = new std::list(); MemoryStream oStream(bytes, size); int pos = 0; - - if (pos + 2 > size) return; - unsigned short fChar = oStream.ReadUInt16(); pos += 2; - unsigned char val; - val = GETBIT(fChar, 0); grpprl->push_back(SinglePropertyModifier(sprmOldCFBold, 1, &val)); - val = GETBIT(fChar, 1); grpprl->push_back(SinglePropertyModifier(sprmOldCFItalic, 1, &val)); - val = GETBIT(fChar, 2); grpprl->push_back(SinglePropertyModifier(sprmOldCFStrike, 1, &val)); - val = GETBIT(fChar, 3); grpprl->push_back(SinglePropertyModifier(sprmOldCFOutline, 1, &val)); - val = GETBIT(fChar, 4); grpprl->push_back(SinglePropertyModifier(sprmOldCFFldVanish, 1, &val)); - val = GETBIT(fChar, 5); grpprl->push_back(SinglePropertyModifier(sprmOldCFSmallCaps, 1, &val)); - val = GETBIT(fChar, 6); grpprl->push_back(SinglePropertyModifier(sprmOldCFCaps, 1, &val)); - val = GETBIT(fChar, 7); grpprl->push_back(SinglePropertyModifier(sprmOldCFVanish, 1, &val)); - val = GETBIT(fChar, 8); grpprl->push_back(SinglePropertyModifier(sprmOldCFRMark, 1, &val)); - val = GETBIT(fChar, 9); grpprl->push_back(SinglePropertyModifier(sprmOldCFSpec, 1, &val)); + if (nWordVersion == 3) + { + if (pos + 2 > size) return; + unsigned short fChar = oStream.ReadUInt16(); pos += 2; - bool fsIco = GETBIT(fChar, 10); - bool fsFtc = GETBIT(fChar, 11); - bool fsHps = GETBIT(fChar, 12); - bool fsKul = GETBIT(fChar, 13); - bool fsPos = GETBIT(fChar, 14); - bool fsSpace = GETBIT(fChar, 15); + unsigned char val; + val = GETBIT(fChar, 0); grpprl->push_back(SinglePropertyModifier(sprmOldCFBold, 1, &val)); + val = GETBIT(fChar, 1); grpprl->push_back(SinglePropertyModifier(sprmOldCFItalic, 1, &val)); + val = GETBIT(fChar, 2); grpprl->push_back(SinglePropertyModifier(sprmOldCFStrike, 1, &val)); + val = GETBIT(fChar, 3); grpprl->push_back(SinglePropertyModifier(sprmOldCFOutline, 1, &val)); + val = GETBIT(fChar, 4); grpprl->push_back(SinglePropertyModifier(sprmOldCFFldVanish, 1, &val)); + val = GETBIT(fChar, 5); grpprl->push_back(SinglePropertyModifier(sprmOldCFSmallCaps, 1, &val)); + val = GETBIT(fChar, 6); grpprl->push_back(SinglePropertyModifier(sprmOldCFCaps, 1, &val)); + val = GETBIT(fChar, 7); grpprl->push_back(SinglePropertyModifier(sprmOldCFVanish, 1, &val)); + val = GETBIT(fChar, 8); grpprl->push_back(SinglePropertyModifier(sprmOldCFRMark, 1, &val)); + val = GETBIT(fChar, 9); grpprl->push_back(SinglePropertyModifier(sprmOldCFSpec, 1, &val)); - if (pos + 2 > size) return; - int fff = oStream.ReadUInt16(); pos += 2;//????? + bool fsIco = GETBIT(fChar, 10); + bool fsFtc = GETBIT(fChar, 11); + bool fsHps = GETBIT(fChar, 12); + bool fsKul = GETBIT(fChar, 13); + bool fsPos = GETBIT(fChar, 14); + bool fsSpace = GETBIT(fChar, 15); - if (pos + 2 > size) return; - unsigned short ftc = oStream.ReadUInt16(); pos += 2; // Font Code - grpprl->push_back(SinglePropertyModifier(sprmOldCFtc, 2, (unsigned char*)&ftc)); + if (pos + 2 > size) return; + int fff = oStream.ReadUInt16(); pos += 2;//????? - if (pos + 1 > size) return; - unsigned char hps = oStream.ReadByte(); pos += 1; // Font size in half points + if (pos + 2 > size) return; + unsigned short ftc = oStream.ReadUInt16(); pos += 2; // Font Code + grpprl->push_back(SinglePropertyModifier(sprmOldCFtc, 2, (unsigned char*)&ftc)); + + if (pos + 1 > size) return; + unsigned char hps = oStream.ReadByte(); pos += 1; // Font size in half points - if (hps > 0) - { - grpprl->push_back(SinglePropertyModifier(sprmOldCHps, 1, &hps)); - } - - if (pos + 1 > size) return; - unsigned char hpsPos = oStream.ReadByte(); pos += 1; // Sub/Superscript ( signed number, 0 = normal ) - grpprl->push_back(SinglePropertyModifier(sprmOldCHpsPos, 1, &hpsPos)); - - if (pos + 2 > size) return; - unsigned short fText = oStream.ReadUInt16(); pos += 2; + if (hps > 0) + { + grpprl->push_back(SinglePropertyModifier(sprmOldCHps, 1, &hps)); + } + + if (pos + 1 > size) return; + unsigned char hpsPos = oStream.ReadByte(); pos += 1; // Sub/Superscript ( signed number, 0 = normal ) + grpprl->push_back(SinglePropertyModifier(sprmOldCHpsPos, 1, &hpsPos)); + + if (pos + 2 > size) return; + unsigned short fText = oStream.ReadUInt16(); pos += 2; - unsigned short qpsSpace = GETBITS(fText, 0, 5); - unsigned char wSpare2 = GETBITS(fText, 6, 7); - unsigned char ico = GETBITS(fText, 8, 11); - unsigned char kul = GETBITS(fText, 12, 14); - bool fSysVanish = GETBIT(fChar, 15); + unsigned short qpsSpace = GETBITS(fText, 0, 5); + unsigned char wSpare2 = GETBITS(fText, 6, 7); + unsigned char ico = GETBITS(fText, 8, 11); + unsigned char kul = GETBITS(fText, 12, 14); + bool fSysVanish = GETBIT(fChar, 15); - //if (fsKul) - { grpprl->push_back(SinglePropertyModifier(sprmOldCKul, 1, &kul)); - } - //if (fsIco) - { grpprl->push_back(SinglePropertyModifier(sprmOldCIco, 1, &ico)); - } - if (pos + 2 > size) return; - unsigned int xxx = oStream.ReadUInt16(); pos += 2;// ??? - - if (pos + 2 > size) return; - unsigned int yyy = oStream.ReadUInt16(); pos += 2;// ??? - if (pos + 2 > size) return; - unsigned int fcPic = oStream.ReadUInt16(); pos += 2; - grpprl->push_back(SinglePropertyModifier(sprmOldCPicLocation, 4, (BYTE*)&fcPic)); - - if (pos + 2 > size) return; - unsigned short zzz = oStream.ReadUInt16(); pos += 2;// ??? type + //sizeof(CHP) == 12 == 0xC + if (pos + 4 > size) return; + unsigned int fcPic = oStream.ReadUInt16(); pos += 4; //pos = 8 + grpprl->push_back(SinglePropertyModifier(sprmOldCPicLocation, 4, (BYTE*)&fcPic)); - //if (pos + 2 > size) return; - //unsigned short dx = oStream.ReadUInt16(); pos += 2;// ??? - // - //if (pos + 2 > size) return; - //unsigned short dy = oStream.ReadUInt16(); pos += 2;// ??? + if (pos + 1 > size) return; + unsigned char fnPic = oStream.ReadByte(); pos += 1; - //short scale_complex[6] = {dx, dy, 0, 0, 0, 0}; - //grpprl->push_back(SinglePropertyModifier(sprmOldPicScale, 12, (BYTE*)scale_complex)); + if (pos + 2 > size) return; + unsigned short hpsLargeChp = oStream.ReadUInt16(); pos += 2;// ??? type + } + else if (nWordVersion == 2) + { + if (pos + 2 > size) return; + unsigned short fChar = oStream.ReadUInt16(); pos += 2; + + unsigned char val; + val = GETBIT(fChar, 0); grpprl->push_back(SinglePropertyModifier(sprmOldCFBold, 1, &val)); + val = GETBIT(fChar, 1); grpprl->push_back(SinglePropertyModifier(sprmOldCFItalic, 1, &val)); + val = GETBIT(fChar, 2); grpprl->push_back(SinglePropertyModifier(sprmOldCIbstRMark, 1, &val)); + val = GETBIT(fChar, 3); grpprl->push_back(SinglePropertyModifier(sprmOldCFOutline, 1, &val)); + val = GETBIT(fChar, 4); grpprl->push_back(SinglePropertyModifier(sprmOldCFFldVanish, 1, &val)); + val = GETBIT(fChar, 5); grpprl->push_back(SinglePropertyModifier(sprmOldCFSmallCaps, 1, &val)); + val = GETBIT(fChar, 6); grpprl->push_back(SinglePropertyModifier(sprmOldCFCaps, 1, &val)); + val = GETBIT(fChar, 7); grpprl->push_back(SinglePropertyModifier(sprmOldCFVanish, 1, &val)); + val = GETBIT(fChar, 8); grpprl->push_back(SinglePropertyModifier(sprmOldCFRMark, 1, &val)); + val = GETBIT(fChar, 9); grpprl->push_back(SinglePropertyModifier(sprmOldCFSpec, 1, &val)); + val = GETBIT(fChar, 10); grpprl->push_back(SinglePropertyModifier(sprmOldCFStrike, 1, &val)); + val = GETBIT(fChar, 11); grpprl->push_back(SinglePropertyModifier(sprmOldCFObj, 1, &val)); + val = GETBIT(fChar, 12); grpprl->push_back(SinglePropertyModifier(sprmCFBoldBi, 1, &val)); + val = GETBIT(fChar, 13); grpprl->push_back(SinglePropertyModifier(sprmCFItalicBi, 1, &val)); + val = GETBIT(fChar, 14); grpprl->push_back(SinglePropertyModifier(sprmCFBiDi, 1, &val)); + val = GETBIT(fChar, 15); grpprl->push_back(SinglePropertyModifier(sprmCFDiacColor, 1, &val)); + + if (pos + 2 > size) return; + unsigned short fChar2 = oStream.ReadUInt16(); pos += 2; + bool fsIco = GETBIT(fChar2, 0); + bool fsFtc = GETBIT(fChar2, 1); + bool fsHps = GETBIT(fChar2, 2); + bool fsKul = GETBIT(fChar2, 3); + bool fsPos = GETBIT(fChar2, 4); + bool fsSpace = GETBIT(fChar2, 5); + bool fsLid = GETBIT(fChar2, 6); + bool fsIcoBi = GETBIT(fChar2, 7); + bool fsFtcBi = GETBIT(fChar2, 8); + bool fsHpsBi = GETBIT(fChar2, 9); + bool fsLidBi = GETBIT(fChar2, 10); + + if (pos + 2 > size) return; + unsigned short ftc = oStream.ReadUInt16(); pos += 2; // Font Code + grpprl->push_back(SinglePropertyModifier(sprmOldCFtc, 2, (unsigned char*)&ftc)); + + if (pos + 1 > size) return; + unsigned char hps = oStream.ReadByte(); pos += 1; // Font size in half points + + if (hps > 0) + { + grpprl->push_back(SinglePropertyModifier(sprmOldCHps, 1, &hps)); + } + + if (pos + 1 > size) return; + unsigned char hpsPos = oStream.ReadByte(); pos += 1; // Sub/Superscript ( signed number, 0 = normal ) + grpprl->push_back(SinglePropertyModifier(sprmOldCHpsPos, 1, &hpsPos)); + + if (pos + 2 > size) return; + unsigned short fText = oStream.ReadUInt16(); pos += 2; + + unsigned short qpsSpace = GETBITS(fText, 0, 5); + unsigned char wSpare2 = GETBITS(fText, 6, 7); + unsigned char ico = GETBITS(fText, 8, 11); + unsigned char kul = GETBITS(fText, 12, 14); + bool fSysVanish = GETBIT(fChar, 15); + + grpprl->push_back(SinglePropertyModifier(sprmOldCKul, 1, &kul)); + grpprl->push_back(SinglePropertyModifier(sprmOldCIco, 1, &ico)); + + //if (pos + 1 > size) return; + //unsigned char icoBi = oStream.ReadUInt16(); pos += 1;//wSpare3 + + if (pos + 2 > size) return; + unsigned short lid = oStream.ReadUInt16(); pos += 2; + grpprl->push_back(SinglePropertyModifier(sprmOldCLid, 2, (BYTE*)&lid)); + + if (pos + 2 > size) return; + unsigned short ftcBi = oStream.ReadUInt16(); pos += 2; + grpprl->push_back(SinglePropertyModifier(sprmCFtcBi, 4, (BYTE*)&ftcBi)); + + //if (pos + 2 > size) return; + //unsigned short hpsBi = oStream.ReadUInt16(); pos += 2; + //grpprl->push_back(SinglePropertyModifier(sprmCHpsBi, 4, (BYTE*)&hpsBi)); + + //if (pos + 2 > size) return; + //unsigned short lidBi = oStream.ReadUInt16(); pos += 2; + //grpprl->push_back(SinglePropertyModifier(sprmCLidBi, 2, (BYTE*)&lidBi)); + + if (pos + 4 > size) return; + unsigned int fcPic = oStream.ReadUInt16(); pos += 4; //pos = 8 + grpprl->push_back(SinglePropertyModifier(sprmOldCPicLocation, 4, (BYTE*)&fcPic)); + + if (pos + 1 > size) return; + unsigned char fnPic = oStream.ReadByte(); pos += 1; + + if (pos + 2 > size) return; + unsigned short hpsLargeChp = oStream.ReadUInt16(); pos += 2;// ??? type + } } } }; diff --git a/ASCOfficeDocFile/DocDocxConverter/CommentsMapping.h b/ASCOfficeDocFile/DocDocxConverter/CommentsMapping.h index 423045c0f8..2dd979bd35 100644 --- a/ASCOfficeDocFile/DocDocxConverter/CommentsMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/CommentsMapping.h @@ -107,7 +107,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph(cp); + cp = writeParagraph(cp, 0x7fffffff); } } diff --git a/ASCOfficeDocFile/DocDocxConverter/DateAndTime.h b/ASCOfficeDocFile/DocDocxConverter/DateAndTime.h index 8d41364b23..6817a9575f 100644 --- a/ASCOfficeDocFile/DocDocxConverter/DateAndTime.h +++ b/ASCOfficeDocFile/DocDocxConverter/DateAndTime.h @@ -59,29 +59,30 @@ namespace DocFileFormat short wdy; public: - /// Creates a new DateAndTime with default values - DateAndTime() - { - setDefaultValues(); - } - - /// Parses the unsigned char sto retrieve a DateAndTime - DateAndTime( unsigned char* bytes, int size ) - { - if ( size == 4 ) - { - this->mint = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 0, 6 ); - this->hr = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 6, 5 ); - this->dom = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 11, 5 ); - this->mon = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 16, 4 ); - this->yr = (short)( 1900 + FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 20, 9 ) ); - this->wdy = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 29, 3 ); - } - else - { - //throw new ByteParseException("Cannot parse the struct DTTM, the length of the struct doesn't match"); - } - } + DateAndTime() + { + setDefaultValues(); + } + DateAndTime( unsigned int val ) + { + DateAndTime((unsigned char*)&val, 4); + } + DateAndTime( unsigned char* bytes, int size ) + { + if ( size == 4 ) + { + this->mint = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 0, 6 ); + this->hr = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 6, 5 ); + this->dom = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 11, 5 ); + this->mon = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 16, 4 ); + this->yr = (short)( 1900 + FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 20, 9 ) ); + this->wdy = (short)FormatUtils::GetIntFromBits( FormatUtils::BytesToInt32( bytes, 0, size ), 29, 3 ); + } + else + { + //throw new ByteParseException("Cannot parse the struct DTTM, the length of the struct doesn't match"); + } + } #if defined(_WIN32) || defined(_WIN64) SYSTEMTIME ToSYSTEMTIME() { diff --git a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp index 8a3ceb18a7..38e8ca4e59 100755 --- a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp @@ -145,7 +145,7 @@ namespace DocFileFormat // Writes a Paragraph that starts at the given cp and // ends at the next paragraph end mark or section end mark - int DocumentMapping::writeParagraph(int cp) + int DocumentMapping::writeParagraph(int cp, int cpEnd) { //search the paragraph end int cpParaEnd = cp; @@ -175,7 +175,7 @@ namespace DocFileFormat { cpParaEnd++; - return writeParagraph(cp, cpParaEnd, false); + return writeParagraph(cp, min(cpEnd, cpParaEnd), false); } } @@ -191,8 +191,8 @@ namespace DocFileFormat int fc = m_document->FindFileCharPos(cp); int fcEnd = m_document->FindFileCharPos(cpEnd); - if (fc < 0 || fcEnd < 0) - return 0; + if (fc < 0 || fcEnd < 0 || fc == fcEnd) + return -1; ParagraphPropertyExceptions* papx = findValidPapx(fc); @@ -1596,7 +1596,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph( cp ); + cp = writeParagraph( cp, 0x7fffffff ); } } @@ -1745,13 +1745,8 @@ namespace DocFileFormat // Checks if the CHPX is special bool DocumentMapping::isSpecial(CharacterPropertyExceptions* chpx) { - /* - for (list::iterator iter = chpx->grpprl->begin(); iter != chpx->grpprl->end(); ++iter) - { - short value = FormatUtils::BytesToInt16 (iter->Arguments, 0, iter->argumentsSize); - int c = 0; - } - */ + if (!chpx) return false; + if (!chpx->grpprl) return false; for (std::list::iterator iter = chpx->grpprl->begin(); iter != chpx->grpprl->end(); ++iter) { diff --git a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.h b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.h index d6aaf447e9..be404510fd 100644 --- a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.h @@ -87,7 +87,7 @@ namespace DocFileFormat bool isSectionEnd ( int cp ); // Writes a Paragraph that starts at the given cp and // ends at the next paragraph end mark or section end mark - int writeParagraph( int cp ); + int writeParagraph( int cp, int cpEnd ); // Writes a Paragraph that starts at the given cpStart and // ends at the given cpEnd int writeParagraph( int initialCp, int cpEnd, bool sectionEnd, bool lastBad = false ); diff --git a/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.cpp b/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.cpp index 214f887dc9..6a68da0f2d 100644 --- a/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.cpp @@ -52,18 +52,85 @@ namespace DocFileFormat //setDefaultCompatibilityOptions( fib->m_FibBase.nFib ); - unsigned int size = fib->m_FibWord97.lcbDop; - unsigned char* bytes = tStream.ReadBytes( size, true ); + unsigned int size = fib->m_FibWord97.lcbDop; + unsigned char* bytes = NULL; try { - if ( size > 0 ) + if (fib->m_nWordVersion == 2) + { + unsigned char* Temp = tStream.ReadBytes(size, true); + tStream.Seek(fib->m_FibWord97.fcDop, 0); + delete []Temp; + + unsigned char flags1 = tStream.ReadByte(); + + fFacingPages = GETBIT(flags1, 0); + fWindowControl = GETBIT(flags1, 1); + Fpc = GETBITS(flags1, 5, 6); + bool fWide = GETBIT(flags1, 7); + + grpfIhdt = tStream.ReadByte(); + + unsigned short flags2 = tStream.ReadUInt16(); + rncFtn = GETBIT(flags2, 0); + nFtn = GETBITS(flags2, 1, 15); + + unsigned char irmBar = tStream.ReadByte(); + + unsigned char flags3 = tStream.ReadByte(); + unsigned char irmProps = GETBITS(flags3, 0, 6); + fRevMarking = GETBIT(flags3, 7); + + unsigned short flags4 = tStream.ReadUInt16(); + fBackup = GETBIT(flags4, 0); + fExactWords = GETBIT(flags4, 1); + fPagHidden = GETBIT(flags4, 2); + fPagResults = GETBIT(flags4, 3); + fLockAtn = GETBIT(flags4, 4); + fMirrorMargins = GETBIT(flags4, 5); + bool fKeepFileFormat = GETBIT(flags4, 6); + fDflttrueType = GETBIT(flags4, 7); + + fPagSuppressTopSpacing = GETBIT(flags4, 8); + fMaybeRTLTables = GETBIT(flags4, 9); + + bool fSpares = tStream.ReadUInt16(); + dxaTab = tStream.ReadUInt16(); + + wSpare = tStream.ReadUInt16();//ftcDefaultBi + dxaHotZ = tStream.ReadUInt16(); + + wSpare2 = tStream.ReadUInt16(); + wSpare3 = tStream.ReadUInt16(); + + dttmCreated = DateAndTime( tStream.ReadUInt32() ); + dttmRevised = DateAndTime( tStream.ReadUInt32() ); + dttmLastPrint = DateAndTime( tStream.ReadUInt32() ); + + nRevision = tStream.ReadUInt16(); + tmEdited = tStream.ReadUInt32(); + + cWords = tStream.ReadUInt32(); + cCh = tStream.ReadUInt32(); + cPg = tStream.ReadUInt16(); + + unsigned short rgwSpareDocSum[2]; + rgwSpareDocSum[0] = tStream.ReadUInt16(); + rgwSpareDocSum[1] = tStream.ReadUInt16(); + + } + else if ( size > 0 ) { - fFacingPages = FormatUtils::GetBitFromBytes( bytes, 2, 0 ); + bytes = tStream.ReadBytes( size, true ); + + fFacingPages = FormatUtils::GetBitFromBytes( bytes, 2, 0 ); fWindowControl = FormatUtils::GetBitFromBytes( bytes, 2, 1 ); fPMHMainDoc = FormatUtils::GetBitFromBytes( bytes, 2, 2 ); grfSuppression = (short)FormatUtils::GetUIntFromBytesBits( bytes, 2, 3, 2 ); - Fpc = (short)(short)FormatUtils::GetUIntFromBytesBits( bytes, 2, 5, 2 ); + Fpc = (short)FormatUtils::GetUIntFromBytesBits( bytes, 2, 5, 2 ); + + grpfIhdt = FormatUtils::BytesToUChar( bytes, 1, size ); rncFtn = (short)FormatUtils::GetUIntFromBytesBits( ( bytes + 2 ), 2, 0, 2 ); nFtn = (short)FormatUtils::GetUIntFromBytesBits( ( bytes + 2 ), 2, 2, 14 ); @@ -545,6 +612,7 @@ namespace DocFileFormat fSwapBordersFacingPgs = false; dxaTab = 0; wSpare = 0; + wSpare3 = 0; dxaHotZ = 0; cConsecHypLim = 0; wSpare2 = 0; diff --git a/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.h b/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.h index 453d1f6070..3217901452 100644 --- a/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.h +++ b/ASCOfficeDocFile/DocDocxConverter/DocumentProperties.h @@ -177,7 +177,8 @@ namespace DocFileFormat unsigned short cConsecHypLim; // Reserved unsigned short wSpare2; - // Date and time document was created + unsigned short wSpare3; + // Date and time document was created DateAndTime dttmCreated; // Date and time document was last revised DateAndTime dttmRevised; diff --git a/ASCOfficeDocFile/DocDocxConverter/EndnotesMapping.h b/ASCOfficeDocFile/DocDocxConverter/EndnotesMapping.h index 9fc3582b23..6c73e67716 100644 --- a/ASCOfficeDocFile/DocDocxConverter/EndnotesMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/EndnotesMapping.h @@ -91,7 +91,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph( cp ); + cp = writeParagraph( cp, 0x7fffffff ); } } diff --git a/ASCOfficeDocFile/DocDocxConverter/FileInformationBlock.h b/ASCOfficeDocFile/DocDocxConverter/FileInformationBlock.h index 2b6532bfc5..cd37a57054 100644 --- a/ASCOfficeDocFile/DocDocxConverter/FileInformationBlock.h +++ b/ASCOfficeDocFile/DocDocxConverter/FileInformationBlock.h @@ -772,8 +772,8 @@ namespace DocFileFormat m_FibWord97.fcPlcfSed = reader.ReadInt32(); //0x7c m_FibWord97.lcbPlcfSed = reader.ReadInt16(); - m_FibWord97.fcPlcPad = reader.ReadInt32();//fcPlcfpgd - m_FibWord97.lcbPlcPad = reader.ReadInt16();//cbPlcfpgd + m_FibWord97.fcPlcPad = reader.ReadInt32(); + m_FibWord97.lcbPlcPad = reader.ReadInt16(); m_FibWord97.fcPlcfPhe = reader.ReadInt32();// 0x88 m_FibWord97.lcbPlcfPhe = reader.ReadInt16(); @@ -832,37 +832,43 @@ namespace DocFileFormat m_FibWord97.fcSttbfMcr = reader.ReadInt32();// 0xf4 m_FibWord97.lcbSttbfMcr = reader.ReadInt16(); - m_FibWord2.fcPrEnv = reader.ReadInt32(); // 0xfa - m_FibWord2.lcbPrEnv = reader.ReadInt16(); //316 + m_FibWord97.fcPrDrvr = reader.ReadInt32();// + m_FibWord97.lcbPrDrvr = reader.ReadInt16(); - m_FibWord97.fcWss = reader.ReadInt32();// 0x100 + m_FibWord97.fcPrEnvPort = reader.ReadInt32();// + m_FibWord97.lcbPrEnvPort = reader.ReadInt16(); + + m_FibWord97.fcPrEnvLand = reader.ReadInt32();// + m_FibWord97.lcbPrEnvLand = reader.ReadInt16(); + + m_FibWord97.fcWss = reader.ReadInt32();// 268 m_FibWord97.lcbWss = reader.ReadInt16(); - m_FibWord97.fcDop = reader.ReadInt32();// 0x106 + m_FibWord97.fcDop = reader.ReadInt32(); m_FibWord97.lcbDop = reader.ReadInt16(); m_FibWord97.fcSttbfAssoc = reader.ReadInt32(); - m_FibWord97.lcbSttbfAssoc = reader.ReadInt16(); + m_FibWord97.lcbSttbfAssoc = reader.ReadInt16();; - m_FibWord97.fcClx = reader.ReadInt32(); // 0x112 + m_FibWord97.fcClx = reader.ReadInt32(); m_FibWord97.lcbClx = reader.ReadInt16(); - m_FibWord97.fcPlcfPgdFtn = reader.ReadInt32(); + m_FibWord97.fcPlcfPgdFtn = reader.ReadInt32(); //292 m_FibWord97.lcbPlcfPgdFtn = reader.ReadInt16(); m_FibWord97.fcAutosaveSource = reader.ReadInt32(); m_FibWord97.lcbAutosaveSource = reader.ReadInt16(); - m_FibWord2.fcSpare5 = reader.ReadInt32(); - m_FibWord2.lcbSpare5 = reader.ReadInt16(); - m_FibWord2.fcSpare6 = reader.ReadInt32(); - m_FibWord2.lcbSpare6 = reader.ReadInt16(); - m_FibWord2.wSpare4 = reader.ReadInt16(); + m_FibWord2.fcSpare5 = reader.ReadInt32(); + m_FibWord2.lcbSpare5 = reader.ReadInt16(); + m_FibWord2.fcSpare6 = reader.ReadInt32(); + m_FibWord2.lcbSpare6 = reader.ReadInt16(); + m_FibWord2.wSpare4 = reader.ReadInt16(); - m_FibWord2.pnChpFirst = reader.ReadInt16(); - m_FibWord2.pnPapFirst = reader.ReadInt16(); - m_FibWord2.cpnBteChp = reader.ReadInt16(); - m_FibWord2.cpnBtePap = reader.ReadInt16(); + m_FibWord2.pnChpFirst = reader.ReadInt16(); + m_FibWord2.pnPapFirst = reader.ReadInt16(); + m_FibWord2.cpnBteChp = reader.ReadInt16(); + m_FibWord2.cpnBtePap = reader.ReadInt16(); } } if (m_FibBase.nFib > Fib1995 || m_FibBase.nFib == 0) diff --git a/ASCOfficeDocFile/DocDocxConverter/FooterMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/FooterMapping.cpp index c568f31f08..65d419de33 100644 --- a/ASCOfficeDocFile/DocDocxConverter/FooterMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/FooterMapping.cpp @@ -89,7 +89,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph( cp ); + cp = writeParagraph( cp, 0x7fffffff ); } } diff --git a/ASCOfficeDocFile/DocDocxConverter/FootnotesMapping.h b/ASCOfficeDocFile/DocDocxConverter/FootnotesMapping.h index 3a88ef5a06..17e2c94dcc 100644 --- a/ASCOfficeDocFile/DocDocxConverter/FootnotesMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/FootnotesMapping.h @@ -93,7 +93,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph( cp ); + cp = writeParagraph( cp, 0x7fffffff ); } while (cp <= cpStart) //conv_fQioC665ib4ngHkDGY4__docx.doc cp++; diff --git a/ASCOfficeDocFile/DocDocxConverter/FormattedDiskPagePAPX.cpp b/ASCOfficeDocFile/DocDocxConverter/FormattedDiskPagePAPX.cpp index 1c9f1b6fdb..6b2ba264e7 100644 --- a/ASCOfficeDocFile/DocDocxConverter/FormattedDiskPagePAPX.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/FormattedDiskPagePAPX.cpp @@ -113,8 +113,6 @@ namespace DocFileFormat //fill the rgbx array bx.phe = ParagraphHeight( phe, 6, false ); - - j += 1; } else { diff --git a/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.cpp b/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.cpp index e3ecaaf284..5fce5a7bf5 100644 --- a/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.cpp @@ -38,110 +38,83 @@ namespace DocFileFormat { HeaderAndFooterTable::HeaderAndFooterTable (FileInformationBlock* fib, POLE::Stream* pTableStream) { + m_nCurrentIndex = 0; + VirtualStreamReader tableReader (pTableStream, fib->m_FibWord97.fcPlcfHdd, fib->m_nWordVersion); if (fib->m_FibWord97.fcPlcfHdd > tableReader.GetSize()) return; unsigned int tableSize = fib->m_FibWord97.lcbPlcfHdd / 4;//in bytes - if ( ( tableSize > 0 ) && ( fib->m_RgLw97.ccpHdr > 0 ) ) + if ( tableSize < 1 || fib->m_RgLw97.ccpHdr <1 ) + return; + + int* table = new int[tableSize]; + + for (unsigned int i = 0; i < tableSize; ++i) { - int* table = new int[tableSize]; - - for (unsigned int i = 0; i < tableSize; ++i) - { - table[i] = tableReader.ReadInt32(); - } - - int initialPos = fib->m_RgLw97.ccpText + fib->m_RgLw97.ccpFtn; - - - //the first 6 _entries are about footnote and endnote formatting - //so skip these _entries - int pos = (fib->m_FibBase.fComplex || !fib->m_nWordVersion) ? 6 : 0; - - int count = ( tableSize - pos - 2) / 6; - - for (int i = 0; i < count; ++i) - { - //Even Header - if ( table[pos] == table[pos + 1] ) - { - m_arEvenHeaders.push_back( NULL ); - } - else - { - m_arEvenHeaders.push_back( new CharacterRange( ( initialPos + table[pos] ), ( table[pos + 1] - table[pos] ) ) ); - } - - pos++; - - //Odd Header - if ( table[pos] == table[pos + 1] ) - { - m_arOddHeaders.push_back( NULL ); - } - else - { - m_arOddHeaders.push_back( new CharacterRange( ( initialPos + table[pos] ), ( table[pos + 1] - table[pos] ) ) ); - } - - pos++; - - //Even Footer - if ( table[pos] == table[pos + 1] ) - { - m_arEvenFooters.push_back( NULL ); - } - else - { - m_arEvenFooters.push_back( new CharacterRange( ( initialPos + table[pos] ), ( table[pos + 1] - table[pos] ) ) ); - } - - pos++; - - //Odd Footer - if ( table[pos] == table[pos + 1] ) - { - m_arOddFooters.push_back( NULL ); - } - else - { - m_arOddFooters.push_back( new CharacterRange( ( initialPos + table[pos] ), ( table[pos + 1] - table[pos] ) ) ); - } - - pos++; - - //First Page Header - if ( table[pos] == table[pos + 1] ) - { - m_arFirstHeaders.push_back (NULL); - } - else - { - m_arFirstHeaders.push_back (new CharacterRange( ( initialPos + table[pos] ), ( table[pos + 1] - table[pos] ) )); - } - - pos++; - - if (pos >= tableSize) - break; - - //First Page Footers - if ( table[pos] == table[pos + 1] ) - { - m_arFirstFooters.push_back( NULL ); - } - else - { - m_arFirstFooters.push_back( new CharacterRange( ( initialPos + table[pos] ), ( table[pos + 1] - table[pos] ) ) ); - } - - pos++; - } - - RELEASEARRAYOBJECTS(table); + table[i] = tableReader.ReadInt32(); } + + int initialPos = fib->m_RgLw97.ccpText + fib->m_RgLw97.ccpFtn; + + int count = 0; + int pos = (fib->m_FibBase.fComplex || fib->m_nWordVersion == 0) ? 6 : 0; + //the first 6 _entries are about footnote and endnote formatting -Word97 so skip these + + std::vector*> arHeadersFooters; + + if (fib->m_nWordVersion == 2) + { + count = ( tableSize - 1); + } + else + { + count = ( tableSize - pos - 1) / 6; + + arHeadersFooters.push_back(&m_arEvenHeaders); + arHeadersFooters.push_back(&m_arOddHeaders); + arHeadersFooters.push_back(&m_arEvenFooters); + arHeadersFooters.push_back(&m_arOddFooters); + arHeadersFooters.push_back(&m_arFirstHeaders); + arHeadersFooters.push_back(&m_arFirstFooters); + } + + for (int i = 0; i < count; ++i) + { + //Even Header + if (fib->m_nWordVersion == 2) + { + if ( table[pos] == table[pos + 1] ) + { + m_arCommonHeadersFooters.push_back( NULL ); + } + else + { + m_arCommonHeadersFooters.push_back( new CharacterRange( initialPos + table[pos], table[pos + 1] - table[pos]) ); + } + pos++; + } + else + { + for (size_t j = 0; j < 6; j++) + { + if ( table[pos] == table[pos + 1] ) + { + arHeadersFooters[j]->push_back( NULL ); + } + else + { + arHeadersFooters[j]->push_back( new CharacterRange( initialPos + table[pos], table[pos + 1] - table[pos]) ); + } + pos++; + + if (pos >= tableSize) break; + } + } + if (pos >= tableSize) break; + } + RELEASEARRAYOBJECTS(table); } HeaderAndFooterTable::~HeaderAndFooterTable() @@ -152,5 +125,7 @@ namespace DocFileFormat for_each (m_arFirstHeaders.begin(), m_arFirstHeaders.end(), DeleteDynamicObject()); for_each (m_arOddFooters.begin(), m_arOddFooters.end(), DeleteDynamicObject()); for_each (m_arOddHeaders.begin(), m_arOddHeaders.end(), DeleteDynamicObject()); + + for_each (m_arCommonHeadersFooters.begin(), m_arCommonHeadersFooters.end(), DeleteDynamicObject()); } } \ No newline at end of file diff --git a/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.h b/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.h index 8065c9f1fe..81501f457e 100644 --- a/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.h +++ b/ASCOfficeDocFile/DocDocxConverter/HeaderAndFooterTable.h @@ -34,10 +34,12 @@ #include "CharacterRange.h" #include "FileInformationBlock.h" -#define GET_CHARS_RANGE(NAME) inline CharacterRange* Get##NAME(int nIndex) {\ +#define GET_CHARS_RANGE(NAME) inline CharacterRange* Get##NAME(int nIndex)\ +{\ if (m_ar##NAME.empty()) return NULL; \ if (nIndex < (int)m_ar##NAME.size()) return m_ar##NAME[nIndex];\ - return NULL; } \ + return NULL; \ +}\ namespace DocFileFormat { @@ -54,8 +56,17 @@ namespace DocFileFormat GET_CHARS_RANGE (EvenFooters); GET_CHARS_RANGE (OddFooters); + inline CharacterRange* GetNextHeaderFooter() + { + if (m_nCurrentIndex < m_arCommonHeadersFooters.size()) + return m_arCommonHeadersFooters[m_nCurrentIndex++]; + + return NULL; + } private: - + size_t m_nCurrentIndex; + std::vector m_arCommonHeadersFooters; + std::vector m_arFirstHeaders; std::vector m_arEvenHeaders; std::vector m_arOddHeaders; diff --git a/ASCOfficeDocFile/DocDocxConverter/HeaderMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/HeaderMapping.cpp index a7a147f070..77ca9dd0e0 100644 --- a/ASCOfficeDocFile/DocDocxConverter/HeaderMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/HeaderMapping.cpp @@ -84,7 +84,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph( cp ); + cp = writeParagraph( cp, 0x7fffffff ); } } diff --git a/ASCOfficeDocFile/DocDocxConverter/ListData.cpp b/ASCOfficeDocFile/DocDocxConverter/ListData.cpp index 32a798ee69..4e3dd29861 100644 --- a/ASCOfficeDocFile/DocDocxConverter/ListData.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/ListData.cpp @@ -152,37 +152,53 @@ namespace DocFileFormat } OutlineListDescriptor::OutlineListDescriptor( unsigned char * data, int length ) { - int pos = 0; + if (length < 212) + { + //int sz = FormatUtils::BytesToUChar(data, 0, length); + int pos = 0; - for (int i = 0 ; i < 9; i++) - { - lvl[i].Parse(data + pos, length - pos); - pos += 16; + for (int i = 0 ; i < 9; i++) + { + lvl[i].Parse(data + pos, 1); + pos += 1; + } } + else + { + int pos = 0; - fRestartHdr = FormatUtils::BytesToUChar(data, pos, length); pos += 2; - fSpareOlst2 = FormatUtils::BytesToUChar(data, pos, length); pos += 2; - fSpareOlst3 = FormatUtils::BytesToUChar(data, pos, length); pos += 2; - fSpareOlst4 = FormatUtils::BytesToUChar(data, pos, length); pos += 2; - - short strLen = length - pos; - - while (strLen > 0) - { - if (data[strLen + 20 - 1] != 0) - break; - strLen--; + for (int i = 0 ; i < 9; i++) + { + lvl[i].Parse(data + pos, length - pos); + pos += 16; + } + + fRestartHdr = FormatUtils::BytesToUChar(data, pos, length); pos += 2; + fSpareOlst2 = FormatUtils::BytesToUChar(data, pos, length); pos += 2; + fSpareOlst3 = FormatUtils::BytesToUChar(data, pos, length); pos += 2; + fSpareOlst4 = FormatUtils::BytesToUChar(data, pos, length); pos += 2; + + short strLen = length - pos; + + while (strLen > 0) + { + if (data[strLen + 20 - 1] != 0) + break; + strLen--; + } + if (strLen > 0) + { + FormatUtils::GetSTLCollectionFromBytes( &(xst), data + 20, ( strLen ), ENCODING_WINDOWS_1250); + } } - if (strLen > 0) - { - FormatUtils::GetSTLCollectionFromBytes( &(xst), data + 20, ( strLen ), ENCODING_WINDOWS_1250); - } } ByteStructure* OutlineListDescriptor::ConstructObject(VirtualStreamReader* reader, int length) { - unsigned char *data = reader->ReadBytes(212, true); - OutlineListDescriptor *newObject = new OutlineListDescriptor(data, 212); + int sz = GetSize(reader->nWordVersion); + + unsigned char *data = reader->ReadBytes(sz, true); + OutlineListDescriptor *newObject = new OutlineListDescriptor(data, sz); delete []data; diff --git a/ASCOfficeDocFile/DocDocxConverter/ListData.h b/ASCOfficeDocFile/DocDocxConverter/ListData.h index f6ea0cb129..a9b6062150 100644 --- a/ASCOfficeDocFile/DocDocxConverter/ListData.h +++ b/ASCOfficeDocFile/DocDocxConverter/ListData.h @@ -143,8 +143,13 @@ namespace DocFileFormat std::wstring xst; //64 chars ansi - public: static const int STRUCTURE_SIZE = 212; + static const int STRUCTURE_SIZE_OLD = 10; + public: + static const int GetSize(int nWordVersion) + { + return (nWordVersion == 2) ? STRUCTURE_SIZE_OLD : STRUCTURE_SIZE; + } virtual ByteStructure* ConstructObject( VirtualStreamReader* reader, int length ); virtual ~OutlineListDescriptor(); diff --git a/ASCOfficeDocFile/DocDocxConverter/ListLevel.cpp b/ASCOfficeDocFile/DocDocxConverter/ListLevel.cpp index bc7f1c3643..d028374533 100644 --- a/ASCOfficeDocFile/DocDocxConverter/ListLevel.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/ListLevel.cpp @@ -116,6 +116,10 @@ namespace DocFileFormat void NumberingLevelDescriptor::Parse(unsigned char * data, int length ) { + if (length < 16) + { + return; + } bEnabled = true; nfc = FormatUtils::BytesToUChar(data, 0, length); diff --git a/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp index b5f9a397b9..5d73b97d0c 100644 --- a/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/MainDocumentMapping.cpp @@ -110,7 +110,7 @@ namespace DocFileFormat int countText = m_document->FIB->m_RgLw97.ccpText; int countTextRel = m_document->FIB->m_RgLw97.ccpText - 1; - while (cp < countText) + while (cp < countText && cp >= 0) { fc = m_document->FindFileCharPos(cp); @@ -135,7 +135,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph(cp); + cp = writeParagraph(cp, countTextRel); } } else diff --git a/ASCOfficeDocFile/DocDocxConverter/OleObject.cpp b/ASCOfficeDocFile/DocDocxConverter/OleObject.cpp index 19a3e41ba7..77da9f744f 100644 --- a/ASCOfficeDocFile/DocDocxConverter/OleObject.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/OleObject.cpp @@ -272,7 +272,7 @@ bool OleObject::processCompObjStream( const std::wstring& compStream ) POLE::Stream* pCompStream = new POLE::Stream(oleStorage, compStream); - if ( pCompStream ) + if ( (pCompStream) && (!pCompStream->fail()) ) { VirtualStreamReader reader( pCompStream, 0, false); processCompObjStream(reader); diff --git a/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertiesMapping.cpp index 438c1bd688..afd2b37d84 100644 --- a/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertiesMapping.cpp @@ -492,7 +492,7 @@ namespace DocFileFormat pos++; - for( int i=0; i < itbdDelMax; i++ ) + for( int i = 0; i < itbdDelMax; i++ ) { XMLTools::XMLElement tab( L"w:tab" ); diff --git a/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertyExceptions.cpp b/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertyExceptions.cpp index 4141b43e9d..6a51545402 100644 --- a/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertyExceptions.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/ParagraphPropertyExceptions.cpp @@ -39,12 +39,186 @@ namespace DocFileFormat { if (size < 1) return; - if (nWordVersion == 2) - { + if (nWordVersion > 1) + { istd = bytes[0]; - - ReadExceptions(( bytes + 7 ), ( size - 7 ), nWordVersion); + + ReadExceptions(bytes + 7, size - 7, nWordVersion); + + // RELEASEOBJECT( grpprl ); + // grpprl = new std::list(); + // + // MemoryStream oStream(bytes, size); + // int pos = 1; + // if (pos + 1 > size) return; + // unsigned char jc = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPJc, 1, (BYTE*)&jc)); + // if (pos + 1 > size) return; + // unsigned char fSideBySide = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPFSideBySide, 1, (BYTE*)&fSideBySide)); + + // if (pos + 1 > size) return; + // unsigned char fKeep = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPFKeep, 1, (BYTE*)&fKeep)); + + // if (pos + 1 > size) return; + // unsigned char fKeepFollow = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPFKeepFollow, 1, (BYTE*)&fKeepFollow)); + + // if (pos + 1 > size) return; + // unsigned char fPageBreakBefore = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPPageBreakBefore, 1, (BYTE*)&fPageBreakBefore)); + // + // if (pos + 1 > size) return; + // unsigned char flag = oStream.ReadByte(); pos += 1; + // unsigned char pcVert = GETBITS(flag, 4, 5); + // unsigned char pcHorz = GETBITS(flag, 6, 7); + // //grpprl->push_back(SinglePropertyModifier(sprmOldPPageBreakBefore, 1, &fPageBreakBefore)); + // //grpprl->push_back(SinglePropertyModifier(sprmOldPPageBreakBefore, 1, &fPageBreakBefore)); + + // if (pos + 1 > size) return; + // unsigned char brcp = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcp, 1, (BYTE*)&brcp)); + // + // if (pos + 1 > size) return; + // unsigned char brcl = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcl, 1, (BYTE*)&brcl)); + + // if (pos + 1 > size) return; + // unsigned char nfcSeqNumb = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPPageBreakBefore, 1, (BYTE*)&nfcSeqNumb)); + // + // if (pos + 1 > size) return; + // unsigned char nnSeqNumb = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPNLvlAnm, 1, (BYTE*)&nnSeqNumb)); + // + // if (pos + 2 > size) return; + // unsigned short dxaRight = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDxaRight, 2, (BYTE*)&dxaRight)); + // + // if (pos + 2 > size) return; + // unsigned short dxaLeft = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDxaLeft, 2, (BYTE*)&dxaLeft)); + // + // if (pos + 2 > size) return; + // unsigned short dxaLeft1 = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDxaLeft1, 2, (BYTE*)&dxaLeft1)); + // + // if (pos + 2 > size) return; + // unsigned short dyaLine = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDyaLine, 2, (BYTE*)&dyaLine)); + // + // if (pos + 2 > size) return; + // unsigned short dyaBefore = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDyaBefore, 2, (BYTE*)&dyaBefore)); + // + // if (pos + 2 > size) return; + // unsigned short dyaAfter = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDyaAfter, 2, (BYTE*)&dyaAfter)); + ////phe - 6 + // if (pos + 6 > size) return; + // + // //oStream.ReadUInt16(); + // //oStream.ReadUInt16(); + // //oStream.ReadUInt16(); + + // if (pos + 1 > size) return; + // unsigned char fInTable = oStream.ReadUInt16(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPFInTable, 1, (BYTE*)&fInTable)); + // + // if (pos + 1 > size) return; + // unsigned char fTtp = oStream.ReadUInt16(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPTtp, 1, (BYTE*)&fTtp)); + // + // if (pos + 2 > size) return; + // unsigned short ptap = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPPageBreakBefore, 2, (BYTE*)&ptap)); + + // if (pos + 2 > size) return; + // unsigned short dxaAbs = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDxaAbs, 2, (BYTE*)&dxaAbs)); + // + // if (pos + 2 > size) return; + // unsigned short dyaAbs = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDyaAbs, 2, (BYTE*)&dyaAbs)); + + // if (pos + 2 > size) return; + // unsigned short dxaWidth = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPDxaWidth, 2, (BYTE*)&dxaWidth)); + // + // if (pos + 2 > size) return; + // unsigned short brcTop = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcTop10, 2, (BYTE*)&brcTop)); + // + // if (pos + 2 > size) return; + // unsigned short brcLeft = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcLeft10, 2, (BYTE*)&brcLeft)); + // + // if (pos + 2 > size) return; + // unsigned short brcBottom = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcBottom10, 2, (BYTE*)&brcBottom)); + // + // if (pos + 2 > size) return; + // unsigned short brcRight = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcRight10, 2, (BYTE*)&brcRight)); + + // if (pos + 2 > size) return; + // unsigned short brcBetween = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcBetween10, 2, (BYTE*)&brcBetween)); + // + // if (pos + 2 > size) return; + // unsigned short brcBar = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPBrcBar10, 2, (BYTE*)&brcBar)); + // + // if (pos + 2 > size) return; + // unsigned short dxaFromText = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPPageBreakBefore, 2, (BYTE*)&dxaFromText)); + // + // if (pos + 2 > size) return; + // unsigned short dyaFromText = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPFromText10, 2, (BYTE*)&dyaFromText)); + // + // if (pos + 1 > size) return; + // unsigned char wr = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmOldPWr, 1, &wr)); + // + // if (pos + 1 > size) return; + // unsigned char zz = oStream.ReadByte(); pos += 1; + // + // if (pos + 1 > size) return; + // unsigned char fTransparent = oStream.ReadByte(); pos += 1; + // + // if (pos + 1 > size) return; + // unsigned char fBiDi = oStream.ReadByte(); pos += 1; + // grpprl->push_back(SinglePropertyModifier(sprmPFBiDi, 1, &fBiDi)); + // + // if (pos + 1 > size) return; + // unsigned char bSpare = oStream.ReadByte(); pos += 1; + // + // if (pos + 2 > size) return; + // unsigned short dyaHeight = oStream.ReadUInt16(); pos += 2; + // unsigned char fMinHeight = GETBIT(dyaHeight, 15); + // dyaHeight = GETBITS(dyaHeight, 0, 14); + // grpprl->push_back(SinglePropertyModifier(sprmOldTDyaRowHeight, 2, (BYTE*)&dyaHeight)); + // //grpprl->push_back(SinglePropertyModifier(sprmOldTDyaRowHeight, 1, &fMinHeight)); + // + // if (pos + 2 > size) return; + // unsigned short shd = oStream.ReadUInt16(); pos += 2; + // grpprl->push_back(SinglePropertyModifier(sprmOldPShd, 2, (BYTE*)&shd)); + + // if (pos + 2 > size) return; + // unsigned short itbdMac = oStream.ReadUInt16(); pos += 2; + // if (itbdMac > 0) + // { + // short *tabs = new short[itbdMac + 1]; + // for (unsigned short i = 0; i < itbdMac; i++) + // { + // tabs[i + 1] = oStream.ReadUInt16(); pos += 2; + // } + // grpprl->push_back(SinglePropertyModifier(sprmPChgTabs, 2 * (itbdMac + 1), (BYTE*)tabs)); + // delete []tabs; + // } } else { diff --git a/ASCOfficeDocFile/DocDocxConverter/Plex.h b/ASCOfficeDocFile/DocDocxConverter/Plex.h index b48b5c8da9..eb3fdad98d 100644 --- a/ASCOfficeDocFile/DocDocxConverter/Plex.h +++ b/ASCOfficeDocFile/DocDocxConverter/Plex.h @@ -43,14 +43,14 @@ namespace DocFileFormat friend class TextboxMapping; protected: - static const int CP_LENGTH = 4; + int CP_LENGTH; std::vector CharacterPositions; std::vector Elements; bool m_bIsValid; public: Plex(int structureLength, POLE::Stream* stream, unsigned int fc, unsigned int lcb, int nWordVersion) - : m_bIsValid(false) + : m_bIsValid(false), CP_LENGTH(/*nWordVersion == 2 ? 2 :*/ 4) { if ((lcb > 0) && (NULL != stream)) { diff --git a/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp b/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp index 52851c53fb..7da9e6385b 100644 --- a/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp @@ -53,7 +53,7 @@ namespace DocFileFormat PropertyExceptions::PropertyExceptions( unsigned char* bytes, int size, int nWordVersion ) : grpprl(NULL) { - if (nWordVersion == 2) + if (nWordVersion >= 2)//word 2.0 or 1.0 return; ReadExceptions(bytes, size, nWordVersion); @@ -80,12 +80,16 @@ namespace DocFileFormat unsigned short code = (nWordVersion > 0) ? FormatUtils::BytesToUChar ( bytes, sprmStart, size ) : FormatUtils::BytesToUInt16 ( bytes, sprmStart, size ) ; - if (nWordVersion > 0 && code == 0) + OperationCode opCode = (OperationCode)(nWordVersion == 2 ? OpCode93To95[code] : code); + + if (nWordVersion > 0 && opCode == 0) { sprmStart++; continue; - } - OperationCode opCode = (OperationCode)code; + } + + //if (nWordVersion == 2) + // bytes[sprmStart]= (unsigned char)opCode; short opSize = -1; if (nWordVersion > 0) diff --git a/ASCOfficeDocFile/DocDocxConverter/RevisionData.cpp b/ASCOfficeDocFile/DocDocxConverter/RevisionData.cpp index 718cb87911..707fcf3ee7 100644 --- a/ASCOfficeDocFile/DocDocxConverter/RevisionData.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/RevisionData.cpp @@ -48,8 +48,13 @@ namespace DocFileFormat RevisionData::RevisionData( CharacterPropertyExceptions* chpx ) : Dttm(), Isbt(0), Type(NoRevision), Changes(NULL), RsidDel(0), RsidProp(0), Rsid(0) { + if (!chpx) return; + if (!chpx->grpprl) + return; + bool collectRevisionData = true; - this->Changes = new std::list(); + + Changes = new std::list(); for ( std::list::iterator iter = chpx->grpprl->begin(); iter != chpx->grpprl->end(); iter++ ) { diff --git a/ASCOfficeDocFile/DocDocxConverter/SectionDescriptor.h b/ASCOfficeDocFile/DocDocxConverter/SectionDescriptor.h index a78766577d..21bcc6a234 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SectionDescriptor.h +++ b/ASCOfficeDocFile/DocDocxConverter/SectionDescriptor.h @@ -41,19 +41,22 @@ namespace DocFileFormat friend class WordDocument; private: - static const int SED_LENGTH = 12; short fn; short fnMpr; int fcMpr; /// A signed integer that specifies the position in the WordDocument Stream where a Sepx structure is located. int fcSepx; + static const int STRUCTURE_SIZE = 12; + static const int STRUCTURE_SIZE_OLD = 6; public: - static const int STRUCTURE_SIZE = 12; - - SectionDescriptor() - { - } + static const int GetSize(int nWordVersion) + { + return (nWordVersion == 2) ? STRUCTURE_SIZE_OLD : STRUCTURE_SIZE; + } + SectionDescriptor() : fn(0), fnMpr(0), fcMpr(0), fcSepx(0) + { + } virtual ~SectionDescriptor() { @@ -63,10 +66,20 @@ namespace DocFileFormat { SectionDescriptor *newObject = new SectionDescriptor(); - newObject->fn = reader->ReadInt16(); - newObject->fcSepx = reader->ReadInt32(); - newObject->fnMpr = reader->ReadInt16(); - newObject->fcMpr = reader->ReadInt32(); + if (reader->nWordVersion == 2) + { + newObject->fn = reader->ReadInt16(); + newObject->fcSepx = reader->ReadInt32(); + //newObject->fnMpr = reader->ReadInt16(); + //newObject->fcMpr = reader->ReadInt16(); + } + else + { + newObject->fn = reader->ReadInt16(); + newObject->fcSepx = reader->ReadInt32(); + newObject->fnMpr = reader->ReadInt16(); + newObject->fcMpr = reader->ReadInt32(); + } return static_cast( newObject ); } diff --git a/ASCOfficeDocFile/DocDocxConverter/SectionPropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/SectionPropertiesMapping.cpp index a0a7c324b1..02f669e0e3 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SectionPropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/SectionPropertiesMapping.cpp @@ -98,11 +98,11 @@ namespace DocFileFormat XMLTools::XMLElement endnotePr (L"w:endnotePr"); XMLTools::XMLElement pgNumType (L"w:pgNumType"); - HeaderAndFooterTable* pTable = _ctx->_doc->headerAndFooterTable; + HeaderAndFooterTable* pTable = _ctx->_doc->headerAndFooterTable; if (pTable) { - unsigned char fHF = 255; //all headers & footers + unsigned char fHF = _ctx->_doc->nWordVersion == 0 ? 255 : 0; //all headers & footers for (std::list::iterator iter = sepx->grpprl->begin(); iter != sepx->grpprl->end(); ++iter) { switch (iter->OpCode) @@ -132,17 +132,29 @@ namespace DocFileFormat }break; } } - // Header + if (_ctx->_doc->nWordVersion == 2) + { + if (GETBIT(fHF, 0)) WriteSectionStory (pTable->GetNextHeaderFooter(), std::wstring(L"headerReference"), std::wstring(L"even")); + if (GETBIT(fHF, 1)) WriteSectionStory (pTable->GetNextHeaderFooter(), std::wstring(L"headerReference"), std::wstring(L"default")); + if (GETBIT(fHF, 2)) WriteSectionStory (pTable->GetNextHeaderFooter(), std::wstring(L"footerReference"), std::wstring(L"even")); + if (GETBIT(fHF, 3)) WriteSectionStory (pTable->GetNextHeaderFooter(), std::wstring(L"footerReference"), std::wstring(L"default")); + if (GETBIT(fHF, 4)) WriteSectionStory (pTable->GetNextHeaderFooter(), std::wstring(L"headerReference"), std::wstring(L"first")); + if (GETBIT(fHF, 5)) WriteSectionStory (pTable->GetNextHeaderFooter(), std::wstring(L"footerReference"), std::wstring(L"first")); + } + else + { + // Header - if (FormatUtils::GetBitFromInt(fHF, 0)) WriteSectionStory (pTable->GetEvenHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"even")); - if (FormatUtils::GetBitFromInt(fHF, 1)) WriteSectionStory (pTable->GetOddHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"default")); - if (FormatUtils::GetBitFromInt(fHF, 4)) WriteSectionStory (pTable->GetFirstHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"first")); + if (FormatUtils::GetBitFromInt(fHF, 0)) WriteSectionStory (pTable->GetEvenHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"even")); + if (FormatUtils::GetBitFromInt(fHF, 1)) WriteSectionStory (pTable->GetOddHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"default")); + if (FormatUtils::GetBitFromInt(fHF, 4)) WriteSectionStory (pTable->GetFirstHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"first")); - // Footer + // Footer - if (FormatUtils::GetBitFromInt(fHF, 2)) WriteSectionStory (pTable->GetEvenFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"even")); - if (FormatUtils::GetBitFromInt(fHF, 3)) WriteSectionStory (pTable->GetOddFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"default")); - if (FormatUtils::GetBitFromInt(fHF, 5)) WriteSectionStory (pTable->GetFirstFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"first")); + if (FormatUtils::GetBitFromInt(fHF, 2)) WriteSectionStory (pTable->GetEvenFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"even")); + if (FormatUtils::GetBitFromInt(fHF, 3)) WriteSectionStory (pTable->GetOddFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"default")); + if (FormatUtils::GetBitFromInt(fHF, 5)) WriteSectionStory (pTable->GetFirstFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"first")); + } } //MUST be ignored if the section does not have page number restart enabled.([MS-DOC] — v20101113. стр 152) @@ -216,7 +228,10 @@ namespace DocFileFormat case sprmOldSBOrientation: case sprmSBOrientation: //orientation - appendValueAttribute( &pgSz, L"w:orient", FormatUtils::MapValueToWideString( iter->Arguments[0], &PageOrientationMap[0][0], 3, 10 ) ); + if (_ctx->_doc->nWordVersion == 2) + appendValueAttribute( &pgSz, L"w:orient", FormatUtils::MapValueToWideString( iter->Arguments[0] + 1, &PageOrientationMap[0][0], 3, 10 ) ); + else + appendValueAttribute( &pgSz, L"w:orient", FormatUtils::MapValueToWideString( iter->Arguments[0], &PageOrientationMap[0][0], 3, 10 ) ); break; //paper source diff --git a/ASCOfficeDocFile/DocDocxConverter/SectionPropertyExceptions.h b/ASCOfficeDocFile/DocDocxConverter/SectionPropertyExceptions.h index d97a4ccd7c..ebb3c1781e 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SectionPropertyExceptions.h +++ b/ASCOfficeDocFile/DocDocxConverter/SectionPropertyExceptions.h @@ -42,6 +42,10 @@ namespace DocFileFormat SectionPropertyExceptions( unsigned char* bytes, int size, int nWordVersion ): PropertyExceptions( bytes, size, nWordVersion ), isBidi(false) { + if (nWordVersion >= 2) + { + ReadExceptions(bytes, size, nWordVersion); + } for ( std::list::iterator iter = grpprl->begin(); iter != grpprl->end(); iter++ ) { SinglePropertyModifier sprm( *iter ); diff --git a/ASCOfficeDocFile/DocDocxConverter/SettingsMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/SettingsMapping.cpp index bdb43be57a..b383d32a10 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SettingsMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/SettingsMapping.cpp @@ -56,7 +56,7 @@ namespace DocFileFormat //zoom m_oXmlWriter.WriteNodeBegin ( L"w:zoom", TRUE ); - m_oXmlWriter.WriteAttribute ( L"w:percent", FormatUtils::IntToWideString( dop->wScaleSaved ) ); + m_oXmlWriter.WriteAttribute ( L"w:percent", FormatUtils::IntToWideString( dop->wScaleSaved > 0 ? dop->wScaleSaved : 100 ) ); if ( dop->zkSaved != 0 ) { diff --git a/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp b/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp index 3af306d58a..3cc926bb49 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp @@ -53,7 +53,10 @@ namespace DocFileFormat { opCodeSize = 1; //first 1 byte are the operation code ... - OpCode = (OperationCode)FormatUtils::BytesToUChar( bytes, 0, size ); + unsigned char code = FormatUtils::BytesToUChar( bytes, 0, size ); + + OpCode = (OperationCode)(nWordVersion == 2 ? OpCode93To95[code] : code); + if (OpCode == 0 && size == 4) { //так записывается rgb цвет ( diff --git a/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.h b/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.h index 3d65483938..1dd0a8cf90 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.h +++ b/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.h @@ -45,6 +45,12 @@ namespace DocFileFormat TAP = 5 } SprmType; + static const int OpCode93To95[] = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 65, 66, 67, 0, 82, 83, 0, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 0, 0x085C, 0x085D, 0x4A5E, 0x485F, 0x4A60, 0x4A61, 0x085A, 0, 0, 0, 0, 0, 0, 0, 119, 120, 121, 122, 123, 124, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x322A, 0, 0x3228, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 182, 183, 184, 0x560B, 0, 0, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 208, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + class SinglePropertyModifier { public: diff --git a/ASCOfficeDocFile/DocDocxConverter/StringTable.h b/ASCOfficeDocFile/DocDocxConverter/StringTable.h index 3d3ad8f5a7..7a7515859f 100644 --- a/ASCOfficeDocFile/DocDocxConverter/StringTable.h +++ b/ASCOfficeDocFile/DocDocxConverter/StringTable.h @@ -125,21 +125,14 @@ namespace DocFileFormat long cDataStart = reader->GetPosition(); unsigned short cb = 0, elem_sz = 0; - if (reader->nWordVersion == 2) - { - cb = reader->ReadByte(); - elem_sz = reader->ReadByte(); + //if (reader->nWordVersion == 2) + //{ + // unsigned char * bytes = reader->ReadBytes(lcb, true); + // reader->Seek( (int)fc, 0/*STREAM_SEEK_SET*/ ); + // delete []bytes; + //} - if (elem_sz > 0) - { - count_elements = cb; - } - else - { - this->cbData = cb; - } - } - else if (reader->nWordVersion == 1) + if (reader->nWordVersion > 0) { cb = reader->ReadUInt16(); this->cbData = cb; // all size diff --git a/ASCOfficeDocFile/DocDocxConverter/StyleSheet.cpp b/ASCOfficeDocFile/DocDocxConverter/StyleSheet.cpp index 6c9d534ffb..d4125b08fb 100644 --- a/ASCOfficeDocFile/DocDocxConverter/StyleSheet.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/StyleSheet.cpp @@ -112,24 +112,58 @@ namespace DocFileFormat StyleSheetDescription* std = new StyleSheetDescription(); - if (sz_name != 0 && sz_name < 0xff) + if (sz_name != 0 && sz_name < 0xde) { + //user style unsigned char *bytes = tableReader.ReadBytes( sz_name, true ); FormatUtils::GetSTLCollectionFromBytes( &std->xstzName, bytes, sz_name, ENCODING_WINDOWS_1250 ); RELEASEARRAYOBJECTS( bytes ); } + // ms style + else if (sz_name == 0) + { + //defpr + } else { - if (Styles->empty()) - { - std->sti = Normal; - std->xstzName = L"Normal"; - } + int ind = 255 - sz_name; + std::wstring names [] = {L"Normal", L"Heading1", L"Heading2", L"Heading3", L"Heading4", L"Heading5", L"Heading6", L"Heading7", + L"Heading8", L"Heading9", L"FootnoteText", L"FootnoteReference", L"Header", L"Footer", L"IndexHeading", L"LineNumber"}; + _StyleIdentifier sti[] = {Normal, Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, Heading7, Heading8, Heading9, + FootnoteText, FootnoteReference, Header, Footer, IndexHeading, LineNumber}; + + std->sti = sti[ind]; + std->xstzName = names[ind]; } +// 0 Normal standard PAP(standard PAP has all fields cleared to 0), standard CHP ( chp.hps = 20, all other fields set to 0). +// +// 255 Normal indent pap.dxaLeft = 720. +///* Heading levels */ +// 254 heading 1 pap.dyaBefore = 240 (12 points), chp.fBold = negation of Normal style's chp.fBold, chp.kul = 1 (single underline), chp.hps = 24, chp.ftc = 2 . +// 253 heading 2 pap.dyaBefore = 120 (6 points), chp.fBold = negation of Normal style's chp.fBold, chp.hps = 24, chp.ftc = 2 +// 252 heading 3 pap.dxaLeft = 360, chp.fBold = negation of Normal style's chp.fBold, chp.hps = 24; +// 251 heading 4 pap.dxaLeft = 360, chp.kul = 1 (single underline), chp.hps = 24; +// 250 heading 5 pap.dxaLeft = 720, chp.fBold = negation of Normal style's chp.fBold, chp.hps = 20; +// 249 heading 6 pap.dxaLeft = 720, chp.kul = 1 (single underline), chp.hps = 20; +// 248 heading 7 pap.dxaLeft = 720, chp.fItalic = negation of Normal style's chp.fItalic, chp.hps = 20; +// 247 heading 8 pap.dxaLeft = 720, chp.fItalic = negation of Normal style's chp.fItalic, chp.hps = 20; +// 246 heading 9 pap.dxaLeft = 720, chp.fItalic = negation of Normal style's chp.fItalic, chp.hps = 20; +// 245 footnote text chp.hps = 20 +// 244 footnote reference chp.hps = 16; hpsPos = 6 +// 243 header When running a U.S. system file: +// pap.itbdMac = 2, pap.rgdxaTab[0] = 3 * 1440, pap.rgtbd[0].jc = 1, pap.rgtbd[0].tlc = 0, pap.rgdxaTab[1] = 6* 1440, pap.rgtbd[1].jc = 1, pap.rgtbd[1].tlc = 0; +// When running an International metric system: +// pap.itbdMac = 2, pap.rgdxaTab[0] =3969, pap.rgtbd[0].jc = 1, pap.rgtbd[0].tlc = 0, pap.rgdxaTab[1] = 8504, pap.rgtbd[1].jc = 1, pap.rgtbd[1].tlc = 0; +// 242 footer When running a U.S. system file: +// pap.itbdMac = 2, pap.rgdxaTab[0] = 3 * 1440, pap.rgtbd[0].jc = 1, pap.rgtbd[0].tlc = 0, pap.rgdxaTab[1] = 6* 1440, pap.rgtbd[1].jc = 1, pap.rgtbd[1].tlc = 0; +// When running an International metric system: +// pap.itbdMac = 2, pap.rgdxaTab[0] =3969, pap.rgtbd[0].jc = 1, pap.rgtbd[0].tlc = 0, pap.rgdxaTab[1] = 8504, pap.rgtbd[1].jc = 1, pap.rgtbd[1].tlc = 0; +// 241 index heading same as properties for Normal style (stc == 0) +// 240 line number same as properties for Normal style (stc == 0) Styles->push_back(std); - sz += sz_name != 0xff ? sz_name : 0; + sz += sz_name < 0xde ? sz_name : 0; } unsigned short sz_chpxs = tableReader.ReadUInt16(); i = 0; diff --git a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp index 2e3a0c11f2..b9abf48b5b 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp @@ -280,7 +280,8 @@ namespace DocFileFormat XMLTools::XMLAttribute tcWVal ( L"w:w", FormatUtils::IntToWideString( _width > 1 ? _width : nComputedCellWidth) ); - XMLTools::XMLAttribute tcWType ( L"w:type", _width > 1 ? FormatUtils::MapValueToWideString( _ftsWidth, &Global::CellWidthTypeMap[0][0], 4, 5 ) : L"dxa" ); + XMLTools::XMLAttribute tcWType ( L"w:type", _width > 1 ? FormatUtils::MapValueToWideString( _ftsWidth, &Global::CellWidthTypeMap[0][0], 4, 5 ) : + (nComputedCellWidth > 0 ? L"dxa" : L"auto")); tcW.AppendAttribute( tcWType ); tcW.AppendAttribute( tcWVal ); diff --git a/ASCOfficeDocFile/DocDocxConverter/TableInfo.h b/ASCOfficeDocFile/DocDocxConverter/TableInfo.h index 2b347a8e79..4b46273391 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableInfo.h +++ b/ASCOfficeDocFile/DocDocxConverter/TableInfo.h @@ -57,12 +57,6 @@ namespace DocFileFormat case sprmPFInTable: { fInTable = ( iter->Arguments[0] == 1 ) ? (true) : (false); - - if (nWordVersion > 0) - { - iTap = 1; - fInnerTableCell = fInnerTtp = true; - } }break; //case sprmOldPFTtp: diff --git a/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp index 73f152d192..9ab306615a 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp @@ -293,7 +293,7 @@ namespace DocFileFormat documentMapping = static_cast(mapping); } - documentMapping->writeParagraph( cpStart ); + documentMapping->writeParagraph( cpStart, 0x7fffffff ); } } diff --git a/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp index 67744263cd..ab0c7e2f67 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp @@ -75,6 +75,8 @@ namespace DocFileFormat BYTE itcFirst = 0; BYTE itcLim = 0; + bool bTableW = false; + for ( std::list::iterator iter = tapx->grpprl->begin(); iter != tapx->grpprl->end(); iter++ ) { switch( iter->OpCode ) @@ -105,8 +107,8 @@ namespace DocFileFormat break; case sprmTTableWidth: - { //preferred table width - + { + //preferred table width unsigned char fts = iter->Arguments[0]; short width = FormatUtils::BytesToInt16( iter->Arguments, 1, iter->argumentsSize ); @@ -119,6 +121,8 @@ namespace DocFileFormat tblW.AppendAttribute( w ); _tblPr->AppendChild( tblW ); + + bTableW = true; } break; case sprmTMerge: @@ -386,8 +390,20 @@ namespace DocFileFormat break; } } + if (false == bTableW) + { + XMLTools::XMLElement tblW( L"w:tblW"); - //indent + XMLTools::XMLAttribute w( L"w:w", L"0"); + XMLTools::XMLAttribute type( L"w:type", L"auto" ); + + tblW.AppendAttribute( type ); + tblW.AppendAttribute( w ); + + _tblPr->AppendChild( tblW ); + } + + //indent if ( tblIndent != 0 ) { XMLTools::XMLElement tblInd( L"w:tblInd"); @@ -401,7 +417,7 @@ namespace DocFileFormat _tblPr->AppendChild( tblInd ); } - //append floating props + //append floating props if ( tblpPr.GetAttributeCount() > 0 ) { _tblPr->AppendChild( tblpPr ); diff --git a/ASCOfficeDocFile/DocDocxConverter/TextboxMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TextboxMapping.cpp index 23baaeb4a0..9692c5200c 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TextboxMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TextboxMapping.cpp @@ -173,7 +173,7 @@ namespace DocFileFormat else { //this PAPX is for a normal paragraph - cp = writeParagraph( cp ); + cp = writeParagraph( cp, 0x7fffffff ); } } _isTextBoxContent = false; diff --git a/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp b/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp index a7011fbc3f..65b5c5d8f8 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/WordDocument.cpp @@ -322,9 +322,9 @@ namespace DocFileFormat FootnoteReferenceCharactersPlex = new Plex(FootnoteDescriptor::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcffndRef, FIB->m_FibWord97.lcbPlcffndRef, nWordVersion); } - if (FIB->m_FibWord97.lcbPlcPad > 0) + if (nWordVersion > 0 && FIB->m_FibWord97.lcbPlcPad > 0) { - OutlineListDescriptorPlex = new Plex(OutlineListDescriptor::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcPad, FIB->m_FibWord97.lcbPlcPad, nWordVersion); + OutlineListDescriptorPlex = new Plex(OutlineListDescriptor::GetSize(nWordVersion), TableStream, FIB->m_FibWord97.fcPlcPad, FIB->m_FibWord97.lcbPlcPad, nWordVersion); } if (FIB->m_RgLw97.ccpEdn > 0) @@ -335,7 +335,7 @@ namespace DocFileFormat if (FIB->m_RgLw97.ccpHdr > 0) { - HeaderStoriesPlex = new Plex( EmptyStructure::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcfHdd, FIB->m_FibWord97.lcbPlcfHdd, nWordVersion); + HeaderStoriesPlex = new Plex( EmptyStructure::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcfHdd, FIB->m_FibWord97.lcbPlcfHdd, nWordVersion); } if (FIB->m_RgLw97.ccpAtn > 0) @@ -348,7 +348,7 @@ namespace DocFileFormat TextboxIndividualPlex = new Plex (FTXBXS::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcftxbxTxt, FIB->m_FibWord97.lcbPlcftxbxTxt, nWordVersion); - SectionPlex = new Plex (SectionDescriptor::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcfSed, FIB->m_FibWord97.lcbPlcfSed, nWordVersion); + SectionPlex = new Plex (SectionDescriptor::GetSize(nWordVersion), TableStream, FIB->m_FibWord97.fcPlcfSed, FIB->m_FibWord97.lcbPlcfSed, nWordVersion); BookmarkStartPlex = new Plex (BookmarkFirst::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcfBkf, FIB->m_FibWord97.lcbPlcfBkf, nWordVersion); BookmarkEndPlex = new Plex (EmptyStructure::STRUCTURE_SIZE, TableStream, FIB->m_FibWord97.fcPlcfBkl, FIB->m_FibWord97.lcbPlcfBkl, nWordVersion); @@ -550,8 +550,8 @@ namespace DocFileFormat VirtualStreamReader wordReader( WordDocumentStream, sed->fcSepx, nWordVersion); //!!!TODO: cbSepx is the size in bytes of the rest properties part!!! - short cbSepx = wordReader.ReadInt16(); - unsigned char* bytes = wordReader.ReadBytes( ( cbSepx /*- 2*/ ), true ); + short cbSepx = nWordVersion == 2 ? wordReader.ReadByte() : wordReader.ReadInt16(); + unsigned char* bytes = wordReader.ReadBytes( ( cbSepx /*- 2*/ ), true ); AllSepx->insert( std::pair( cp, new SectionPropertyExceptions( bytes, ( cbSepx /*- 2*/ ), nWordVersion ) ) );