diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/ConvertationManager.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/ConvertationManager.cpp index 3a24d4edee..c65a0f5995 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/ConvertationManager.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/ConvertationManager.cpp @@ -71,19 +71,21 @@ HRESULT RtfConvertationManager::ConvertRtfToOOX( std::wstring sSrcFileName, std: m_poRtfReader = &oReader; m_poOOXWriter = &oWriter; - m_poRtfReader->m_convertationManager = this; + //m_poRtfReader->m_convertationManager = this; bool succes = oReader.Load( ); //сохранение будет поэлементое в обработчике OnCompleteItemRtf //надо только завершить - if( true == m_bParseFirstItem ) - { - m_bParseFirstItem = false; - oWriter.SaveByItemStart( ); - } - m_poOOXWriter->SaveByItem(); - oWriter.SaveByItemEnd( ); + //if( true == m_bParseFirstItem ) + //{ + // m_bParseFirstItem = false; + // oWriter.SaveByItemStart( ); + //} + //m_poOOXWriter->SaveByItem(); + //oWriter.SaveByItemEnd( ); + + oWriter.Save(); NSDirectory::DeleteDirectory(oReader.m_sTempFolder); NSDirectory::DeleteDirectory(oWriter.m_sTempFolder); diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp index 783f0f0baf..542138087e 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.cpp @@ -462,7 +462,7 @@ bool RtfNormalReader::ExecuteCommand( RtfDocument& oDocument, RtfReader& oReader { section.props->m_bFinalize = true; section.props->m_oProperty = oReader.m_oCurSectionProp; - } + } _section new_section; new_section.props = RtfSectionPtr( new RtfSection() ); @@ -510,8 +510,8 @@ bool RtfBorderCommand::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader else if( "brdrsh" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrsh; else if( "brdrdb" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdb; else if( "brdrdot" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdot; - else if( "brdrdash" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdash; - else if( "brdrhair" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrhair; + else if( "brdrdash" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdash; + else if( "brdrhair" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrhair; else if( "brdrdashsm" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdashsm; else if( "brdrdashd" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdashd; else if( "brdrdashdd" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdashdd; @@ -520,22 +520,24 @@ bool RtfBorderCommand::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader else if( "brdrtriple" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtriple; else if( "brdrtnthsg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthsg; else if( "brdrthtnsg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrthtnsg; - else if( "brdrtnthtnsg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthtnsg; + else if( "brdrtnthtnsg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthtnsg; else if( "brdrtnthmg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthmg; else if( "brdrthtnmg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrthtnmg; - else if( "brdrtnthtnmg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthtnmg; + else if( "brdrtnthtnmg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthtnmg; else if( "brdrtnthlg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthlg; else if( "brdrthtnlg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrthtnlg; - else if( "brdrtnthtnlg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthtnlg; - else if( "brdrwavy" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrwavy; + else if( "brdrtnthtnlg" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrtnthtnlg; + else if( "brdrwavy" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrwavy; else if( "brdrwavydb" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrwavydb; else if( "brdrdashdotstr" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrdashdotstr; else if( "brdremboss" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdremboss; else if( "brdrengrave" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrengrave; else if( "brdroutset" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdroutset; else if( "brdrinset" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrinset; - else if( "brdrnone" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrnone; - else if( "brdrw" == sCommand ) + else if( "brdrnone" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrnone; + else if( "brdrnil" == sCommand ) oOutput.m_eType = RtfBorder::bt_none; + else if( "brdrn" == sCommand ) oOutput.m_eType = RtfBorder::bt_brdrnone; + else if( "brdrw" == sCommand ) { if( true == hasParameter ) { @@ -722,6 +724,7 @@ bool RtfSectionCommand::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReade RtfParagraphReader oParagraphReader(sCommand, oReader); oAbstrReader.StartSubReader( oParagraphReader, oDocument, oReader ); + oParagraphReader.m_oParPropDest.m_bPar = true; oParagraphReader.m_oParPropDest.Finalize( oReader ); TextItemContainerPtr oNewFooterHeader = oParagraphReader.m_oParPropDest.m_oTextItems; diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.h b/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.h index 6647f80159..c62599f6cd 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.h +++ b/ASCOfficeRtfFile/RtfFormatLib/source/DestinationCommand.h @@ -1579,8 +1579,8 @@ private: RtfRowProperty oCurRowProperty; RtfReader* m_oReader; - bool m_bPar; // если последняя команда была par, то не надо добавлять параграф public: + bool m_bPar; // если последняя команда была par, то не надо добавлять параграф TextItemContainerPtr m_oTextItems; //для разбивки на TextItem RtfTab m_oCurTab; int nTargetItap; //уровень который считается не таблицей ( для того чтобы читать параграфы в таблицах ) @@ -2439,6 +2439,7 @@ public: } void ExitReader(RtfDocument& oDocument, RtfReader& oReader) { + oParagraphReaderDestination.m_bPar = true; oParagraphReaderDestination.Finalize( oReader ); _section section; diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/RtfProperty.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/RtfProperty.cpp index a9f718d33f..6da8f5050f 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/RtfProperty.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/RtfProperty.cpp @@ -1264,8 +1264,18 @@ std::wstring RtfStyle::RenderToOOXBegin(RenderParameter oRenderParameter) default: break; } - //sResult += L""; - sResult += L""; + if (m_sID.empty()) + { + m_sID = L"Style_" + std::to_wstring(m_nID); + } + sResult += L""; sResult += L""; if( PROP_DEF != m_nBasedOn ) @@ -1277,6 +1287,7 @@ std::wstring RtfStyle::RenderToOOXBegin(RenderParameter oRenderParameter) //sResult += L"m_sName ) + L"\"/>"; } } + //if( PROP_DEF != m_nNext ) // sResult += L"", );//Todo //if( PROP_DEF != m_nLink ) @@ -2290,11 +2301,11 @@ std::wstring RtfParagraphProperty::RenderToOOX(RenderParameter oRenderParameter) switch ( m_eTextFollow ) { - case tf_frmtxlrtb: sResult += L""; break; - case tf_frmtxtbrl: sResult += L""; break; - case tf_frmtxbtlr: sResult += L""; break; - case tf_frmtxlrtbv: sResult += L"";break; - case tf_frmtxtbrlv: sResult += L"";break; + case tf_frmtxlrtb: sResult += L""; break; + case tf_frmtxtbrl: sResult += L""; break; + case tf_frmtxbtlr: sResult += L""; break; + case tf_frmtxlrtbv: sResult += L"";break; + case tf_frmtxtbrlv: sResult += L"";break; default: break; } diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.cpp index a4b752f974..7a40841c6a 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.cpp @@ -36,6 +36,49 @@ #include "../../../UnicodeConverter/UnicodeConverter.h" #include "../../../ASCOfficePPTXFile/Editor/Drawing/Shapes/BaseShape/PPTShape/PptShape.h" +#include "../../../DesktopEditor/raster/BgraFrame.h" +#include "../../../DesktopEditor/raster/Metafile/MetaFile.h" + +bool RtfShape::GetPictureResolution(RenderParameter oRenderParameter, int & Width, int &Height) +{ + if (!m_oPicture) return false; + + //if (!oRenderParameter.appFonts) + //{ + // oRenderParameter.appFonts = new CApplicationFonts(); + // oRenderParameter.appFonts->Initialize(); + //} + + std::wstring fileName = m_oPicture->m_sPicFilename; + + if (fileName.empty()) return false; + + CApplicationFonts appFonts; + appFonts.Initialize(); + + CBgraFrame image; + MetaFile::CMetaFile meta_file(/*oRenderParameter.*/&appFonts); + + if ( meta_file.LoadFromFile(fileName.c_str())) + { + double dX = 0, dY = 0, dW = 0, dH = 0; + meta_file.GetBounds(&dX, &dY, &dW, &dH); + + Width = dW; + Height = dH; + } + else if ( image.OpenFile(fileName, 0 )) + { + Width = image.get_Width(); + Height = image.get_Height(); + + return true; + } + + + return false; +} + void RtfShape::SetDefault() { @@ -928,25 +971,47 @@ std::wstring RtfShape::RenderToOOXBegin(RenderParameter oRenderParameter) //sStyle += L"right:" + std::to_wstring() + L";" , m_nRelRight); sStyle += L"width:" + std::to_wstring(nWidth) + L";height:" + std::to_wstring(nHeight) + L";"; } - else if( 0 != m_oPicture && PROP_DEF != m_oPicture->m_nWidthGoal && PROP_DEF != m_oPicture->m_nHeightGoal - && PROP_DEF != (int)m_oPicture->m_dScaleX && PROP_DEF != (int)m_oPicture->m_dScaleY ) + else if( 0 != m_oPicture) { - float nWidth = (int)(m_oPicture->m_nWidthGoal * m_oPicture->m_dScaleX / 100.); - if( PROP_DEF != m_oPicture->m_nCropL ) - nWidth -= m_oPicture->m_nCropL; - if( PROP_DEF != m_oPicture->m_nCropR ) - nWidth -= m_oPicture->m_nCropR; + if (PROP_DEF != m_oPicture->m_nWidthGoal && PROP_DEF != m_oPicture->m_nHeightGoal + && PROP_DEF != (int)m_oPicture->m_dScaleX && PROP_DEF != (int)m_oPicture->m_dScaleY )//scale default = 100. + { + float nWidth = m_oPicture->m_nWidthGoal * m_oPicture->m_dScaleX / 100.f; + if( PROP_DEF != m_oPicture->m_nCropL ) + nWidth -= m_oPicture->m_nCropL; + if( PROP_DEF != m_oPicture->m_nCropR ) + nWidth -= m_oPicture->m_nCropR; - float nHeight = (int)(m_oPicture->m_nHeightGoal * m_oPicture->m_dScaleY / 100.); - if( PROP_DEF != m_oPicture->m_nCropT ) - nHeight -= m_oPicture->m_nCropT; - if( PROP_DEF != m_oPicture->m_nCropB ) - nHeight -= m_oPicture->m_nCropB; + float nHeight = m_oPicture->m_nHeightGoal * m_oPicture->m_dScaleY / 100.f; + if( PROP_DEF != m_oPicture->m_nCropT ) + nHeight -= m_oPicture->m_nCropT; + if( PROP_DEF != m_oPicture->m_nCropB ) + nHeight -= m_oPicture->m_nCropB; - if (oRenderParameter.nType == RENDER_TO_OOX_PARAM_SHAPE_WSHAPE2) - sStyle += L"width:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nWidth), L"%.2f") + L";height:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nHeight), L"%.2f") + L";"; + if (oRenderParameter.nType == RENDER_TO_OOX_PARAM_SHAPE_WSHAPE2) + sStyle += L"width:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nWidth), L"%.2f") + L";height:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nHeight), L"%.2f") + L";"; + else + sStyle += L"width:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nWidth), L"%.2f") + L"pt;height:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nHeight), L"%.2f") + L"pt;"; + } else - sStyle += L"width:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nWidth), L"%.2f") + L"pt;height:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(nHeight), L"%.2f") + L"pt;"; + { + int fileWidth = 0, fileHeight = 0; + + if (PROP_DEF == m_oPicture->m_nWidth || PROP_DEF == m_oPicture->m_nHeight) + { + if (GetPictureResolution(oRenderParameter, fileWidth, fileHeight) || fileWidth < 1 || fileHeight < 1) + { + if (PROP_DEF == m_oPicture->m_nWidth) + m_oPicture->m_nWidth = fileWidth *20 / 4 * 3; // px->twip + if (PROP_DEF == m_oPicture->m_nHeight) + m_oPicture->m_nHeight = fileHeight *20 / 4 * 3; + } + } + if (PROP_DEF != m_oPicture->m_nWidth && PROP_DEF != m_oPicture->m_nHeight) + { + sStyle += L"width:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(m_oPicture->m_nWidth), L"%.2f") + L"pt;height:" + XmlUtils::DoubleToString(RtfUtility::Twip2pt(m_oPicture->m_nHeight), L"%.2f") + L"pt;"; + } + } } switch( m_nPositionH ) diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.h b/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.h index a2c04659bc..e634578004 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.h +++ b/ASCOfficeRtfFile/RtfFormatLib/source/RtfShape.h @@ -291,5 +291,7 @@ public: std::wstring GroupRenderToRtf(RenderParameter oRenderParameter); std::wstring GroupRenderToOOX(RenderParameter oRenderParameter); + + bool GetPictureResolution(RenderParameter oRenderParameter, int & Width, int &Height); }; diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.cpp index 2a60a7aab7..b8bab8029f 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.cpp @@ -219,6 +219,96 @@ bool OOXDocumentWriter::SaveByItemStart( std::wstring sFolder ) m_oFileWriter->Write((BYTE*)sXmlUTF.c_str(), sXmlUTF.length()); return true; } +bool OOXDocumentWriter::SaveBySection() +{ + if( m_oDocument.GetCount() < 1) + return false; + + RenderParameter oNewParam; + + oNewParam.poDocument = &m_oDocument; + oNewParam.poWriter = &m_oWriter; + oNewParam.poRels = &m_oWriter.m_oDocRels; + oNewParam.nType = RENDER_TO_OOX_PARAM_UNKNOWN; + + std::wstring sXml, sXmlSectProp; + + bool bParaPrevEmpty = false, bParaCurrEmpty = false; + + for (int i = 0; i < m_oDocument[0].props->GetCount(); i++) + { + if (i == m_oDocument[0].props->GetCount() - 1 && m_oDocument.GetCount() > 1) + { + _section section; + if (m_oDocument.GetItem(section, 0)) + { + sXmlSectProp = section.props->RenderToOOX(oNewParam); + } + } + RtfParagraph *para = dynamic_cast(m_oDocument[0].props->operator[](i).get()); + bParaCurrEmpty = (para) ? (para->GetCount() < 1) : true; + + sXml = m_oDocument[0].props->operator[](i)->RenderToOOX(oNewParam); + + if (!sXml.empty() || !sXmlSectProp.empty()) + { + if (sXml.empty()) + { + sXml = L"" + sXmlSectProp + L""; + } + else + { + if (!sXmlSectProp.empty()) + { + if (bParaPrevEmpty && bParaCurrEmpty) + { + sXml += L"" + sXmlSectProp + L""; + } + else + { + int nFind = -1, nFindPict = -1, pos = sXml.size(); + + do + { + nFindPict = sXml.rfind(L"", pos); + nFind = sXml.rfind(L"", pos); + pos = nFindPict - 1; + }while(nFindPict > 0 && nFind > nFindPict); + + if( -1 != nFind) + { + sXml.insert( nFind, sXmlSectProp ); + } + else + { + int Find = sXml.rfind( L"" ); + if( -1 != nFind ) + sXml.insert( nFind + 5, L"" + sXmlSectProp + L"" ); + } + } + } + } + + std::string sXmlUTF = NSFile::CUtf8Converter::GetUtf8StringFromUnicode(sXml); + if (m_oFileWriter) + { + m_oFileWriter->Write((BYTE*)sXmlUTF.c_str(), sXmlUTF.length()); + } + } + bParaPrevEmpty = bParaCurrEmpty; + } + + if (m_oDocument.GetCount() > 1 ) + { + m_oDocument.RemoveItem( 0 ); //удаляем секцию кроме последней + } + else + { + m_oDocument[0].props->m_aArray.clear(); + } + + return true; +} bool OOXDocumentWriter::SaveByItem() { if( true == m_bFirst ) diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.h b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.h index 6d6341c571..8b0042400a 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.h +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXDocumentWriter.h @@ -57,9 +57,15 @@ public: std::wstring CreateXmlEnd( ); bool SaveByItemStart( std::wstring sFolder ); - bool SaveByItem (); - bool SaveByItemEnd (); + bool SaveByItem(); + bool SaveByItemEnd(); + bool SaveBySection(); + + int GetCountSections() + { + return m_oDocument.GetCount(); + } int GetCount() { int nCount = 0; diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.cpp index 9dab429496..e981bf2df1 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.cpp @@ -100,12 +100,15 @@ OOXWriter::~OOXWriter() } bool OOXWriter::Save() { - int nItemsCount = ((OOXDocumentWriter*)m_poDocumentWriter)->GetCount(); + int nItemsCount = ((OOXDocumentWriter*)m_poDocumentWriter)->GetCountSections(); + SaveByItemStart(); + for( int i = 0; i < nItemsCount; i++ ) { - SaveByItem(); + SaveBySection(); } + return SaveByItemEnd(); } bool OOXWriter::SaveByItemStart() @@ -116,6 +119,10 @@ bool OOXWriter::SaveByItem() { return ((OOXDocumentWriter*)m_poDocumentWriter)->SaveByItem(); } +bool OOXWriter::SaveBySection() +{ + return ((OOXDocumentWriter*)m_poDocumentWriter)->SaveBySection(); +} bool OOXWriter::SaveByItemEnd() { OOX::CContentTypes oContentTypes; diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.h b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.h index 71a0083f94..901eceebf8 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.h +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Writer/OOXWriter.h @@ -75,6 +75,8 @@ public: bool SaveByItem(); bool SaveByItemEnd(); + bool SaveBySection(); + private: RtfDocument& m_oDocument; };