diff --git a/RtfFile/Format/ConvertationManager.cpp b/RtfFile/Format/ConvertationManager.cpp index a6d7686054..2810287ac1 100644 --- a/RtfFile/Format/ConvertationManager.cpp +++ b/RtfFile/Format/ConvertationManager.cpp @@ -95,7 +95,10 @@ _UINT32 RtfConvertationManager::ConvertRtfToOOX( std::wstring sSrcFileName, std: 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 != NULL) + oDocument.m_oProperty.m_nDefFontSize = m_nDefaultFontSize; oWriter.Save(); NSDirectory::DeleteDirectory(oReader.m_sTempFolder); diff --git a/RtfFile/Format/ConvertationManager.h b/RtfFile/Format/ConvertationManager.h index 33bd8a72d0..643cdf3cc8 100644 --- a/RtfFile/Format/ConvertationManager.h +++ b/RtfFile/Format/ConvertationManager.h @@ -46,7 +46,8 @@ class RtfConvertationManager public: std::wstring m_sTempFolder; int m_nUserLCID; - + std::wstring m_sDefaultFontName; + int m_nDefaultFontSize; RtfConvertationManager(); _UINT32 ConvertRtfToOOX( std::wstring sSrcFileName, std::wstring sDstPath); diff --git a/RtfFile/Format/RtfProperty.cpp b/RtfFile/Format/RtfProperty.cpp index aca412d165..a47fb65acc 100644 --- a/RtfFile/Format/RtfProperty.cpp +++ b/RtfFile/Format/RtfProperty.cpp @@ -156,9 +156,15 @@ std::wstring RtfFont::RenderToOOX(RenderParameter oRenderParameter) poRtfDocument->m_oFontTable.GetFont( poRtfDocument->m_oProperty.m_nDefFont, oDefFont ); sFontName = oDefFont.m_sName; } + if (!poRtfDocument->m_oProperty.m_sDefFontName.empty() && sFontName.empty()) + { + sFontName = poRtfDocument->m_oProperty.m_sDefFontName; + } if( sFontName.empty()) - sFontName = L"Arial"; - } + { + sFontName = DefaultStyle::FontName; + } + } if( RENDER_TO_OOX_PARAM_MINOR_FONT == oRenderParameter.nType ) { std::wstring sTag; @@ -1347,8 +1353,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 +1594,18 @@ std::wstring RtfCharProperty::RenderToOOX(RenderParameter oRenderParameter) bool bInsert = false; bool bDelete = false; - + + if (m_nFontSize == PROP_DEF) + { + if (poRtfDocument->m_oProperty.m_nDefFontSize != PROP_DEF) + { + m_nFontSize = poRtfDocument->m_oProperty.m_nDefFontSize; + } + else + { + m_nFontSize = DefaultStyle::FontSize; + } + } if( RENDER_TO_OOX_PARAM_MATH == oRenderParameter.nType) {//w:rPr в m:ctrlPr if (m_nRevised != PROP_DEF) diff --git a/RtfFile/Format/RtfProperty.h b/RtfFile/Format/RtfProperty.h index e8aa7f2fba..293657f929 100644 --- a/RtfFile/Format/RtfProperty.h +++ b/RtfFile/Format/RtfProperty.h @@ -1299,6 +1299,11 @@ public: std::wstring RenderToOOX(RenderParameter oRenderParameter); }; +namespace DefaultStyle +{ +const std::wstring FontName = L"Times New Roman"; +const int FontSize = 24; +} //typedef boost::shared_ptr RtfTableStylePropertyPtr; typedef boost::shared_ptr RtfCharStylePtr; typedef boost::shared_ptr RtfParagraphStylePtr; diff --git a/RtfFile/Format/RtfSection.cpp b/RtfFile/Format/RtfSection.cpp index 50b69589a8..0c20fc6a44 100644 --- a/RtfFile/Format/RtfSection.cpp +++ b/RtfFile/Format/RtfSection.cpp @@ -55,6 +55,8 @@ void RtfDocumentProperty::SetDefaultOOX() } void RtfDocumentProperty::SetDefault() { + m_sDefFontName = L""; + m_nDefFontSize = PROP_DEF; 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..6f8d487b96 100644 --- a/RtfFile/Format/RtfSection.h +++ b/RtfFile/Format/RtfSection.h @@ -44,6 +44,8 @@ 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_nDefFont; diff --git a/X2tConverter/src/cextracttools.h b/X2tConverter/src/cextracttools.h index 4892e54f71..30ca89f251 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("DefaultFontName") == sName) + { + RELEASEOBJECT(m_sDefaultFontName); + m_sDefaultFontName = new std::wstring(sValue); + } + else if (_T("DefaultFontSize") == 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..1fc143f419 100644 --- a/X2tConverter/src/lib/rtf.h +++ b/X2tConverter/src/lib/rtf.h @@ -45,7 +45,16 @@ 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; + } + else + { + rtfConvert.m_nDefaultFontSize = NULL; + } 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 c1ff84e987..2e1c4e24de 100644 --- a/X2tConverter/test/qmake/main.cpp +++ b/X2tConverter/test/qmake/main.cpp @@ -38,14 +38,16 @@ int main(int argc, char** argv) std::wstring curr_dir = NSFile::GetProcessDirectory(); std::wstring wsep = FILE_SEPARATOR_STR; - std::wstring filename_in = curr_dir + wsep + L"123.docx"; - std::wstring filename_out = curr_dir + wsep + L"123.pdf"; + // std::wstring filename_in = curr_dir + wsep + L"Diva readme.rtf"; + std::wstring filename_in = curr_dir + wsep + L"CONTRACT.rtf"; + std::wstring filename_out = curr_dir + wsep + L"123.docx"; std::wstring fonts_dir = curr_dir + wsep + L"fonts"; std::wstring xml = curr_dir + wsep + L"params.xml"; std::wstring tmp_dir = NSDirectory::CreateDirectoryWithUniqueName(curr_dir); CheckFonts(fonts_dir); + std::wstring fontname = L"Times New Roman"; // GENERATE XML NSStringUtils::CStringBuilder oBuilder; @@ -88,7 +90,13 @@ int main(int argc, char** argv) oBuilder.WriteString(fonts_dir + L"/AllFonts.js"); oBuilder.WriteString(L""); - // temp directory + oBuilder.WriteString(L""); + oBuilder.WriteEncodeXmlString(fontname); + oBuilder.WriteString(L""); + oBuilder.WriteString(L""); + oBuilder.WriteEncodeXmlString(L"24"); + oBuilder.WriteString(L""); + // temp directory oBuilder.WriteString(L""); oBuilder.WriteEncodeXmlString(tmp_dir); oBuilder.WriteString(L"");