Commit 8efed345 authored by ElenaSubbotina's avatar ElenaSubbotina

fix bug #35412

parent f5dcb1be
......@@ -47,23 +47,20 @@
int _tmain(int argc, _TCHAR* argv[])
{
if (argc < 3) return 0;
if (argc < 2) return 0;
std::wstring sXMLOptions = _T("<Options><TXTOptions><Encoding>1000</Encoding></TXTOptions></Options>");
std::wstring sXMLOptions = _T("<Options><TXTOptions><Encoding>50</Encoding></TXTOptions></Options>");
std::wstring srcFileName = argv[1];
std::wstring dstFileName = argv[2];
std::wstring outputDir = NSDirectory::GetFolderPath(dstFileName);
std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir);
int n1 = srcFileName.rfind(_T('.'));
std::wstring ext_1 = n1 >= 0 ? srcFileName.substr(n1+1, srcFileName.length() - n1) : _T("");
int n1 = srcFileName.rfind(L".");
int n2 = dstFileName.rfind(L".");
std::transform(ext_1.begin(), ext_1.end(), ext_1.begin(), ::tolower);
std::wstring ext_1 = n1>=0 ? srcFileName.substr(n1+1, srcFileName.length() - n1): L""; //ext_1.MakeLower();
std::wstring ext_2 = n2>=0 ? dstFileName.substr(n2+1, dstFileName.length() - n2): L""; //ext_2.MakeLower();
std::wstring dstFileName = argc > 2 ? argv[2] : srcFileName + L"_my." + (ext_1 == L"txt" ? L"docx" : L"txt");
std::transform(ext_1.begin(), ext_1.end(), ext_1.begin(), ::tolower);
std::wstring outputDir = NSDirectory::GetFolderPath(dstFileName);
std::wstring dstTempPath = NSDirectory::CreateDirectoryWithUniqueName(outputDir);
CTxtXmlFile txtFile;
......@@ -77,7 +74,7 @@ int _tmain(int argc, _TCHAR* argv[])
if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstFileName.c_str(), -1))
return S_FALSE;
}
if (ext_2 == L"txt")
else
{
// docx->txt
if (S_OK != oCOfficeUtils.ExtractToDirectory(srcFileName.c_str(), dstTempPath.c_str(), NULL, 0))
......
......@@ -85,7 +85,7 @@ namespace Docx2Txt
OOX::CDocument *pDocument, OOX::CNumbering* pNumbering, OOX::CStyles *pStyles);
size_t NoteCount;
std::list<std::wstring> Notes;
std::map<std::wstring, std::list<std::wstring>> Notes;
static std::wstring IntToLowerLetter (int number);
static std::wstring IntToUpperLetter (int number);
......@@ -198,10 +198,20 @@ namespace Docx2Txt
if(NoteCount != 0)
{
m_outputFile.m_listContent.push_back(_T("---------------------------"));
for(std::list<std::wstring>::const_iterator iter = Notes.begin(); iter != Notes.end(); iter++)
m_outputFile.m_listContent.push_back(L"");
m_outputFile.m_listContent.push_back(L"---------------------------");
for(std::map<std::wstring, std::list<std::wstring>>::const_iterator iter_map = Notes.begin(); iter_map != Notes.end(); iter_map++)
{
bool bFirst = true;
for(std::list<std::wstring>::const_iterator iter = iter_map->second.begin(); iter != iter_map->second.end(); iter++)
{
m_outputFile.m_listContent.push_back(*iter);
if (bFirst) m_outputFile.m_listContent.push_back(iter_map->first + L" " + *iter);
else m_outputFile.m_listContent.push_back(*iter);
bFirst = false;
}
}
}
}
......@@ -491,31 +501,52 @@ namespace Docx2Txt
if (run->m_arrItems[j]->getType() == OOX::et_w_footnoteReference || run->m_arrItems[j]->getType() == OOX::et_w_endnoteReference)
{// todooo Ref ????
std::list<std::wstring> notes_content;
OOX::Logic::CFootnoteReference* footnote_ref = dynamic_cast<OOX::Logic::CFootnoteReference*>(run->m_arrItems[j]);
OOX::Logic::CEndnoteReference* endnote_ref = dynamic_cast<OOX::Logic::CEndnoteReference*>(run->m_arrItems[j]);
NoteCount++;
std::wstring s = _T("[") + ToWString(NoteCount) + _T("]");
Notes.push_back(s);
if(run->m_arrItems[j]->getType() == OOX::et_w_footnoteReference)
if (footnote_ref)
{
smart_ptr<OOX::File> pFile = pDocument->Find(OOX::FileTypes::FootNote);
if (pFile.IsInit())
{
OOX::CFootnotes *pFootnotes = (OOX::CFootnotes*)pFile.operator->();
for (long r =0 ;r < pFootnotes->m_arrFootnote.size(); r++)
convert(pFootnotes->m_arrFootnote[r]->m_arrItems, Notes, Event, false, pDocument, pNumbering, pStyles);
for (size_t r = 0; r < pFootnotes->m_arrFootnote.size(); r++)
{
OOX::CFtnEdn* note = dynamic_cast<OOX::CFtnEdn*>(pFootnotes->m_arrFootnote[r]);
if (note && note->m_oId == footnote_ref->m_oId)
{
convert(pFootnotes->m_arrFootnote[r]->m_arrItems, notes_content, Event, false, pDocument, pNumbering, pStyles);
}
}
}
Notes.insert(std::make_pair(ToWString(NoteCount), notes_content));
}
else if(run->m_arrItems[j]->getType() == OOX::et_w_endnoteReference)
if (endnote_ref)
{
smart_ptr<OOX::File> pFile = pDocument->Find(OOX::FileTypes::EndNote);
if (pFile.IsInit())
{
OOX::CEndnotes *pEndnotes = (OOX::CEndnotes*)pFile.operator->();
for (long r =0 ;r < pEndnotes->m_arrEndnote.size(); r++)
convert(pEndnotes->m_arrEndnote[r]->m_arrItems, Notes, Event, false, pDocument, pNumbering, pStyles);
for (size_t r =0; r < pEndnotes->m_arrEndnote.size(); r++)
{
OOX::CFtnEdn* note = dynamic_cast<OOX::CFtnEdn*>(pEndnotes->m_arrEndnote[r]);
if (note && note->m_oId == endnote_ref->m_oId)
{
convert(pEndnotes->m_arrEndnote[r]->m_arrItems, notes_content, Event, false, pDocument, pNumbering, pStyles);
}
}
}
Notes.insert(std::make_pair(ToWString(NoteCount), notes_content));
}
wstr.replace(wstr.find(_T("_")), 1 , ToWString(NoteCount));
wstr += L"[" + ToWString(NoteCount) + L"]"; ;
}
line += wstr;
}
......
......@@ -104,13 +104,6 @@ static int ParseTxtOptions(const std::wstring & sXmlOptions)
HRESULT CTxtXmlFile::txt_LoadFromFile(const std::wstring & sSrcFileName, const std::wstring & sDstPath, const std::wstring & sXMLOptions)
{
//проверка на структуру xml - если что не так выкинет быстро
//HRESULT hr = xml_LoadFromFile(sSrcFileName, sDstPath, sXMLOptions);
//if(hr == S_OK)
// return S_OK;
//As Text
Writers::FileWriter *pDocxWriter = new Writers::FileWriter(sDstPath, L"", true, 1, false, NULL, L"");
if (pDocxWriter == NULL) return S_FALSE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment