diff --git a/RtfFile/Format/ConvertationManager.cpp b/RtfFile/Format/ConvertationManager.cpp index a6d7686054..1990875192 100644 --- a/RtfFile/Format/ConvertationManager.cpp +++ b/RtfFile/Format/ConvertationManager.cpp @@ -61,6 +61,8 @@ RtfConvertationManager::RtfConvertationManager( ) m_poRtfWriter = NULL; m_poRtfReader = NULL; + + m_nDefaultFontSize = 0; } _UINT32 RtfConvertationManager::ConvertRtfToOOX( std::wstring sSrcFileName, std::wstring sDstPath ) { @@ -91,17 +93,21 @@ _UINT32 RtfConvertationManager::ConvertRtfToOOX( std::wstring sSrcFileName, std: oWriter.m_sTempFolder = NSDirectory::CreateDirectoryWithUniqueName(NSDirectory::GetTempPath()); } - m_poRtfReader = &oReader; - m_poOOXWriter = &oWriter; - - if (false == oReader.Load( )) return AVS_FILEUTILS_ERROR_CONVERT; + m_poRtfReader = &oReader; + m_poOOXWriter = &oWriter; + if (false == oReader.Load()) + return AVS_FILEUTILS_ERROR_CONVERT; + if (!m_sDefaultFontName.empty()) + oDocument.m_oProperty.m_sDefFontName = m_sDefaultFontName; + if (m_nDefaultFontSize > 0) + oDocument.m_oProperty.m_nDefFontSize = m_nDefaultFontSize; oWriter.Save(); - NSDirectory::DeleteDirectory(oReader.m_sTempFolder); - NSDirectory::DeleteDirectory(oWriter.m_sTempFolder); + NSDirectory::DeleteDirectory(oReader.m_sTempFolder); + NSDirectory::DeleteDirectory(oWriter.m_sTempFolder); - return S_OK; + return S_OK; } _UINT32 RtfConvertationManager::ConvertOOXToRtf( std::wstring sDstFileName, std::wstring sSrcPath ) { diff --git a/RtfFile/Format/ConvertationManager.h b/RtfFile/Format/ConvertationManager.h index 33bd8a72d0..8ad0a30459 100644 --- a/RtfFile/Format/ConvertationManager.h +++ b/RtfFile/Format/ConvertationManager.h @@ -44,26 +44,25 @@ namespace OOX { namespace Vml { class CShapeType; } } class RtfConvertationManager { public: - std::wstring m_sTempFolder; + std::wstring m_sTempFolder; int m_nUserLCID; - + std::wstring m_sDefaultFontName; + int m_nDefaultFontSize; RtfConvertationManager(); - _UINT32 ConvertRtfToOOX( std::wstring sSrcFileName, std::wstring sDstPath); + _UINT32 ConvertRtfToOOX(std::wstring sSrcFileName, std::wstring sDstPath); - _UINT32 ConvertOOXToRtf( std::wstring sDstFileName, std::wstring sSrcPath); + _UINT32 ConvertOOXToRtf(std::wstring sDstFileName, std::wstring sSrcPath); - void OnCompleteItemRtf(); - void OnCompleteItemOOX(); + void OnCompleteItemRtf(); + void OnCompleteItemOOX(); private: - OOXWriter* m_poOOXWriter; - OOXReader* m_poOOXReader; - - RtfWriter* m_poRtfWriter; - RtfReader* m_poRtfReader; - - bool m_bParseFirstItem; + OOXWriter* m_poOOXWriter; + OOXReader* m_poOOXReader; + RtfWriter* m_poRtfWriter; + RtfReader* m_poRtfReader; + bool m_bParseFirstItem; }; diff --git a/RtfFile/Format/DestinationCommand.cpp b/RtfFile/Format/DestinationCommand.cpp index 68399b605d..097fd980e0 100644 --- a/RtfFile/Format/DestinationCommand.cpp +++ b/RtfFile/Format/DestinationCommand.cpp @@ -2957,18 +2957,18 @@ void RtfShapeReader::ShapePropertyReader::ShapePropertyValueReader::PopState( Rt int x = 0, y = 0; try { - if (PROP_DEF != m_oShape.m_nRelLeft) - x = XmlUtils::GetInteger(splitted[i].substr(0, pos)) - m_oShape.m_nRelLeft; - else - x = XmlUtils::GetInteger(splitted[i].substr(0, pos)); + if (PROP_DEF != m_oShape.m_nRelLeft) + x = XmlUtils::GetInteger(splitted[i].substr(0, pos)) - m_oShape.m_nRelLeft; + else + x = XmlUtils::GetInteger(splitted[i].substr(0, pos)); } catch(...){} try { - if (PROP_DEF != m_oShape.m_nRelTop) - y = XmlUtils::GetInteger(splitted[i].substr(pos + 1, splitted[i].length() - 1)) - m_oShape.m_nRelTop; - else - y = XmlUtils::GetInteger(splitted[i].substr(pos + 1, splitted[i].length() - 1)); + if (PROP_DEF != m_oShape.m_nRelTop) + y = XmlUtils::GetInteger(splitted[i].substr(pos + 1, splitted[i].length() - 1)) - m_oShape.m_nRelTop; + else + y = XmlUtils::GetInteger(splitted[i].substr(pos + 1, splitted[i].length() - 1)); } catch(...){} @@ -2992,10 +2992,10 @@ void RtfShapeReader::ShapePropertyReader::ShapePropertyValueReader::PopState( Rt m_oShape.m_aPSegmentInfo.push_back( val ); } } - else if (L"geoBottom" == m_sPropName) m_oShape.m_nGeoBottom = (PROP_DEF != m_oShape.m_nRelTop) ? nValue - m_oShape.m_nRelTop : nValue; - else if (L"geoLeft" == m_sPropName) m_oShape.m_nGeoLeft = (PROP_DEF != m_oShape.m_nRelLeft) ? nValue - m_oShape.m_nRelLeft : nValue; - else if (L"geoRight" == m_sPropName) m_oShape.m_nGeoRight = (PROP_DEF != m_oShape.m_nRelLeft) ? nValue - m_oShape.m_nRelLeft : nValue; - else if (L"geoTop" == m_sPropName) m_oShape.m_nGeoTop = (PROP_DEF != m_oShape.m_nRelTop) ? nValue - m_oShape.m_nRelTop : nValue; + else if (L"geoBottom" == m_sPropName) m_oShape.m_nGeoBottom = (PROP_DEF != m_oShape.m_nRelTop) ? nValue - m_oShape.m_nRelTop : nValue; + else if (L"geoLeft" == m_sPropName) m_oShape.m_nGeoLeft = (PROP_DEF != m_oShape.m_nRelLeft) ? nValue - m_oShape.m_nRelLeft : nValue; + else if (L"geoRight" == m_sPropName) m_oShape.m_nGeoRight = (PROP_DEF != m_oShape.m_nRelLeft) ? nValue - m_oShape.m_nRelLeft : nValue; + else if (L"geoTop" == m_sPropName) m_oShape.m_nGeoTop = (PROP_DEF != m_oShape.m_nRelTop) ? nValue - m_oShape.m_nRelTop : nValue; // else if ( L"dxWrapDistLeft" == m_sPropName ) m_oShape.m_nWrapDistLeft = RtfUtility::Emu2Twips( nValue ); else if ( L"dyWrapDistTop" == m_sPropName ) m_oShape.m_nWrapDistTop = RtfUtility::Emu2Twips( nValue ); diff --git a/RtfFile/Format/RtfProperty.cpp b/RtfFile/Format/RtfProperty.cpp index aca412d165..85eb810cea 100644 --- a/RtfFile/Format/RtfProperty.cpp +++ b/RtfFile/Format/RtfProperty.cpp @@ -143,12 +143,12 @@ std::wstring RtfFont::RenderToOOX(RenderParameter oRenderParameter) { if ( IsValid() == false) return L""; - std::wstring sResult; - - RtfDocument* poRtfDocument = static_cast(oRenderParameter.poDocument); - std::wstring sFontName = m_sName; + std::wstring sResult; - if( sFontName.empty() ) + RtfDocument* poRtfDocument = static_cast(oRenderParameter.poDocument); + std::wstring sFontName = m_sName; + + if( sFontName.empty() ) { if( PROP_DEF != poRtfDocument->m_oProperty.m_nDefFont ) { @@ -156,12 +156,14 @@ std::wstring RtfFont::RenderToOOX(RenderParameter oRenderParameter) poRtfDocument->m_oFontTable.GetFont( poRtfDocument->m_oProperty.m_nDefFont, oDefFont ); sFontName = oDefFont.m_sName; } - if( sFontName.empty()) - sFontName = L"Arial"; + if (sFontName.empty()) + { + sFontName = poRtfDocument->m_oProperty.m_sDefFontName; + } } if( RENDER_TO_OOX_PARAM_MINOR_FONT == oRenderParameter.nType ) { - std::wstring sTag; + std::wstring sTag; switch(m_eFontTheme) { case ft_flominor: @@ -1347,8 +1349,10 @@ void RtfCharProperty::SetDefaultRtf() m_poShading.SetDefaultRtf(); m_poBorder.SetDefaultRtf(); - if (false == m_bListLevel) - m_nFontSize = 24; + //if (false == m_bListLevel) + //{ + //m_nFontSize = DefaultStyle::FontSize; + //} } void RtfCharProperty::SetDefaultOOX() { @@ -1586,7 +1590,11 @@ std::wstring RtfCharProperty::RenderToOOX(RenderParameter oRenderParameter) bool bInsert = false; bool bDelete = false; - + + if (m_nFontSize == PROP_DEF) + { + m_nFontSize = poRtfDocument->m_oProperty.m_nDefFontSize; + } if( RENDER_TO_OOX_PARAM_MATH == oRenderParameter.nType) {//w:rPr в m:ctrlPr if (m_nRevised != PROP_DEF) diff --git a/RtfFile/Format/RtfSection.cpp b/RtfFile/Format/RtfSection.cpp index 50b69589a8..641b95b155 100644 --- a/RtfFile/Format/RtfSection.cpp +++ b/RtfFile/Format/RtfSection.cpp @@ -55,6 +55,9 @@ void RtfDocumentProperty::SetDefaultOOX() } void RtfDocumentProperty::SetDefault() { + m_sDefFontName = L"Times New Roman"; + m_nDefFontSize = 24; + m_eCodePage = cp_ansi; m_nTabWidth = 720; //todo -1 m_nDefFont = PROP_DEF; diff --git a/RtfFile/Format/RtfSection.h b/RtfFile/Format/RtfSection.h index f10b3aff99..5045e708f5 100644 --- a/RtfFile/Format/RtfSection.h +++ b/RtfFile/Format/RtfSection.h @@ -44,8 +44,10 @@ public: cp_pc, // pc IBM PC code page 437 cp_pca, // pca IBM PC code page 850, used by IBM Personal System/2 (not implemented in version 1 of Microsoft Word for OS/2) } m_eCodePage; + std::wstring m_sDefFontName; + int m_nDefFontSize; - int m_nAnsiCodePage; + int m_nAnsiCodePage; int m_nDefFont; int m_nDefMathFont; int m_nDefLang; diff --git a/X2tConverter/src/cextracttools.h b/X2tConverter/src/cextracttools.h index 4892e54f71..25c139a73c 100644 --- a/X2tConverter/src/cextracttools.h +++ b/X2tConverter/src/cextracttools.h @@ -493,6 +493,8 @@ namespace NExtractTools class InputParams { public: + std::wstring* m_sDefaultFontName; + int* m_nDefaultFontSize; std::wstring* m_sKey; std::wstring* m_sFileFrom; std::wstring* m_sFileTo; @@ -528,6 +530,8 @@ namespace NExtractTools public: InputParams() { + m_sDefaultFontName = NULL; + m_nDefaultFontSize = NULL; m_sKey = NULL; m_sFileFrom = NULL; m_sFileTo = NULL; @@ -561,6 +565,8 @@ namespace NExtractTools } ~InputParams() { + RELEASEOBJECT(m_sDefaultFontName); + RELEASEOBJECT(m_nDefaultFontSize); RELEASEOBJECT(m_sKey); RELEASEOBJECT(m_sFileFrom); RELEASEOBJECT(m_sFileTo); @@ -686,6 +692,16 @@ namespace NExtractTools RELEASEOBJECT(m_nFormatTo); m_nFormatTo = new int(XmlUtils::GetInteger(sValue)); } + else if (_T("m_sDefaultFontName") == sName) + { + RELEASEOBJECT(m_sDefaultFontName); + m_sDefaultFontName = new std::wstring(sValue); + } + else if (_T("m_nDefaultFontSize") == sName) + { + RELEASEOBJECT(m_nDefaultFontSize); + m_nDefaultFontSize = new int(XmlUtils::GetInteger(sValue)); + } else if (_T("m_nCsvTxtEncoding") == sName) { RELEASEOBJECT(m_nCsvTxtEncoding); diff --git a/X2tConverter/src/lib/rtf.h b/X2tConverter/src/lib/rtf.h index f9fffb71ef..c3423280f8 100644 --- a/X2tConverter/src/lib/rtf.h +++ b/X2tConverter/src/lib/rtf.h @@ -46,6 +46,11 @@ namespace NExtractTools rtfConvert.m_sTempFolder = convertParams.m_sTempDir; rtfConvert.m_nUserLCID = (NULL != params.m_nLcid) ? *params.m_nLcid : -1; + if (params.m_sDefaultFontName != NULL) + rtfConvert.m_sDefaultFontName = *params.m_sDefaultFontName; + if (params.m_nDefaultFontSize != NULL) + rtfConvert.m_nDefaultFontSize = *params.m_nDefaultFontSize; + return 0 == rtfConvert.ConvertRtfToOOX(sFrom, sTo) ? 0 : AVS_FILEUTILS_ERROR_CONVERT; } _UINT32 docx_dir2rtf(const std::wstring& sFrom, const std::wstring& sTo, InputParams& params, ConvertParams& convertParams) diff --git a/X2tConverter/test/qmake/main.cpp b/X2tConverter/test/qmake/main.cpp index 68e2f3a639..56e7c4bc93 100644 --- a/X2tConverter/test/qmake/main.cpp +++ b/X2tConverter/test/qmake/main.cpp @@ -88,6 +88,16 @@ int main(int argc, char** argv) oBuilder.WriteString(fonts_dir + L"/AllFonts.js"); oBuilder.WriteString(L""); + if (false) + { + oBuilder.WriteString(L""); + oBuilder.WriteEncodeXmlString(L"Arial"); + oBuilder.WriteString(L""); + oBuilder.WriteString(L""); + oBuilder.WriteEncodeXmlString(L"12"); + oBuilder.WriteString(L""); + } + // temp directory oBuilder.WriteString(L""); oBuilder.WriteEncodeXmlString(tmp_dir);