Commit 1045a0d6 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

начата конвертация docx->doct

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@56748 954022d7-b5bf-4e40-9824-e11837661b57
parent bd02a66d
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/random_generator.hpp> #include <boost/uuid/random_generator.hpp>
#include <boost/algorithm/string.hpp>
#include "source\Oox2OdfConverter\Converter.h" #include "source\Oox2OdfConverter\Converter.h"
...@@ -137,7 +138,9 @@ HRESULT COfficeOdfFileW::SaveToFileImpl(const std::wstring & srcPath, ...@@ -137,7 +138,9 @@ HRESULT COfficeOdfFileW::SaveToFileImpl(const std::wstring & srcPath,
try try
{ {
Oox2Odf::Converter converter(srcTempPath); std::wstring type = DetectTypeDocument(srcTempPath);
Oox2Odf::Converter converter(srcTempPath, type);
converter.convert(); converter.convert();
converter.write(dstTempPath); converter.write(dstTempPath);
...@@ -151,3 +154,51 @@ HRESULT COfficeOdfFileW::SaveToFileImpl(const std::wstring & srcPath, ...@@ -151,3 +154,51 @@ HRESULT COfficeOdfFileW::SaveToFileImpl(const std::wstring & srcPath,
return S_OK; return S_OK;
} }
namespace fs = boost::filesystem;
std::wstring COfficeOdfFileW::DetectTypeDocument(const std::wstring & Path)
{
fs::wpath full_path(/* fs::initial_path<fs::wpath>()*/ Path);
//full_path = fs::system_complete( fs::wpath( Path ) );
unsigned long file_count = 0;
unsigned long dir_count = 0;
unsigned long other_count = 0;
unsigned long err_count = 0;
if (!fs::exists( full_path ) )return L"";
if (!fs::is_directory( full_path ) )return L"";
fs::wdirectory_iterator end_iter;
for ( fs::wdirectory_iterator dir_itr( full_path ); dir_itr != end_iter; ++dir_itr )
{
try
{
if ( fs::is_directory( dir_itr->status() ) )
{
++dir_count;
std::wstring tmp = dir_itr->path().filename();
boost::algorithm::to_lower(tmp);
if (tmp == L"word") return L"text";
if (tmp == L"xl") return L"spreadsheet";
}
else if ( fs::is_regular_file( dir_itr->status() ) )
{
++file_count;
}
else
{
++other_count;
}
}
catch ( const std::exception & ex )
{
++err_count;
}
}
return L"";
}
\ No newline at end of file
...@@ -90,5 +90,7 @@ private: ...@@ -90,5 +90,7 @@ private:
HRESULT SaveToFileImpl(const std::wstring & srcPath, const std::wstring & srcTempPath, HRESULT SaveToFileImpl(const std::wstring & srcPath, const std::wstring & srcTempPath,
const std::wstring & dstTempPath, const std::wstring & dstFileName); const std::wstring & dstTempPath, const std::wstring & dstFileName);
std::wstring DetectTypeDocument(const std::wstring & Path);
}; };
...@@ -983,6 +983,14 @@ ...@@ -983,6 +983,14 @@
RelativePath=".\OdfFormat\office_spreadsheet.h" RelativePath=".\OdfFormat\office_spreadsheet.h"
> >
</File> </File>
<File
RelativePath=".\OdfFormat\office_text.cpp"
>
</File>
<File
RelativePath=".\OdfFormat\office_text.h"
>
</File>
<File <File
RelativePath=".\OdfFormat\paragraph_elements.cpp" RelativePath=".\OdfFormat\paragraph_elements.cpp"
> >
...@@ -1207,6 +1215,14 @@ ...@@ -1207,6 +1215,14 @@
<Filter <Filter
Name="odf text" Name="odf text"
> >
<File
RelativePath=".\OdfFormat\odt_conversion_context.cpp"
>
</File>
<File
RelativePath=".\OdfFormat\odt_conversion_context.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="odf presentation" Name="odf presentation"
......
...@@ -124,6 +124,11 @@ void odf_conversion_context::start_spreadsheet() ...@@ -124,6 +124,11 @@ void odf_conversion_context::start_spreadsheet()
create_object(); create_object();
create_element(L"office", L"spreadsheet", objects_.back().content, this,true); create_element(L"office", L"spreadsheet", objects_.back().content, this,true);
} }
void odf_conversion_context::start_text()
{
create_object();
create_element(L"office", L"text", objects_.back().content, this,true);
}
void odf_conversion_context::create_object() void odf_conversion_context::create_object()
{ {
_object obj; _object obj;
...@@ -143,6 +148,10 @@ void odf_conversion_context::end_chart() ...@@ -143,6 +148,10 @@ void odf_conversion_context::end_chart()
end_object(); end_object();
chart_context_.set_styles_context(styles_context()); chart_context_.set_styles_context(styles_context());
} }
void odf_conversion_context::end_text()
{
end_object();
}
void odf_conversion_context::end_spreadsheet() void odf_conversion_context::end_spreadsheet()
{ {
end_object(); end_object();
......
...@@ -61,6 +61,9 @@ public: ...@@ -61,6 +61,9 @@ public:
void start_spreadsheet(); void start_spreadsheet();
void end_spreadsheet(); void end_spreadsheet();
void start_text();
void end_text();
void create_object(); void create_object();
void end_object(); void end_object();
......
...@@ -178,7 +178,7 @@ void odf_text_context::start_span(bool styled) ...@@ -178,7 +178,7 @@ void odf_text_context::start_span(bool styled)
void odf_text_context::end_span() void odf_text_context::end_span()
{ {
if (single_paragraph_)return; if (styles_context_ == NULL || single_paragraph_)return;
current_level_.pop_back(); current_level_.pop_back();
} }
......
#include "precompiled_cpodf.h"
#include "office_text.h"
#include <boost/foreach.hpp>
#include <cpdoccore/xml/xmlchar.h>
#include <cpdoccore/xml/serialize.h>
#include <cpdoccore/xml/attributes.h>
#include <cpdoccore/xml/simple_xml_writer.h>
namespace cpdoccore {
namespace odf {
using xml::xml_char_wc;
// office:text
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * office_text::ns = L"office";
const wchar_t * office_text::name = L"text";
namespace {
bool is_text_content(const std::wstring & ns, const std::wstring & name)
{
if (ns == L"text")
{
return (
name == L"h" ||
name == L"p" ||
name == L"list" ||
name == L"numbered-paragraph" ||
name == L"section" ||
name == L"table-of-content" ||
name == L"illustration-index" ||
name == L"table-index" ||
name == L"object-index" ||
name == L"user-index" ||
name == L"alphabetical-index" ||
name == L"bibliography" ||
// change-marks
name == L"change" ||
name == L"change-start" ||
name == L"change-end"
);
}
else if (ns == L"table")
{
return name == L"table";
}
else if (ns == L"draw" || ns == L"dr3d")
{
return true; // all shapes //
}
return false;
}
}
void office_text::create_child_element( const ::std::wstring & Ns, const ::std::wstring & Name)
{
if (is_text_content(Ns, Name))
{
CP_CREATE_ELEMENT(content_);
}
else
CP_NOT_APPLICABLE_ELM();
}
void office_text::add_child_element(office_element_ptr & child_element)
{
content_.push_back(child_element);
}
void office_text::serialize(std::wostream & _Wostream)
{
CP_XML_WRITER(_Wostream)
{
CP_XML_NODE_SIMPLE()
{
BOOST_FOREACH(office_element_ptr & elm, content_)
{
elm->serialize(CP_XML_STREAM());
}
}
}
}
}
}
#pragma once
#include <iosfwd>
#include <cpdoccore/CPOptional.h>
#include <cpdoccore/xml/xmlelement.h>
#include <cpdoccore/xml/nodetype.h>
#include "office_elements.h"
#include "office_elements_create.h"
namespace cpdoccore {
namespace odf {
/// \class office_text
/// \brief office:text
class office_text : public office_element_impl<office_text>
{
public:
static const wchar_t * ns;
static const wchar_t * name;
static const xml::NodeType xml_type = xml::typeElement;
static const ElementType type = typeOfficeText;
CPDOCCORE_DEFINE_VISITABLE();
virtual void create_child_element(const ::std::wstring & Ns, const ::std::wstring & Name);
virtual void add_child_element( office_element_ptr & child_element);
virtual void serialize(std::wostream & _Wostream);
// virtual void add_attributes( const xml::attributes_wc_ptr & Attributes );
// virtual void add_child_element( xml::sax * Reader, const ::std::wstring & Ns, const ::std::wstring & Name);
// virtual void add_text(const std::wstring & Text);
private:
bool text_global_;
// TODO: office-text-content-prelude:
// TODO: office-forms
// TODO: text-tracked-changes
// TODO: text-decls
// TODO: table-decls
office_element_ptr_array content_;
// TODO: text-page-sequence
// TODO: office-text-content-epilogue:
// TODO: table-functions
};
CP_REGISTER_OFFICE_ELEMENT2(office_text);
}
}
...@@ -23,10 +23,8 @@ namespace Oox2Odf ...@@ -23,10 +23,8 @@ namespace Oox2Odf
{ {
return (Val * 360000 * 2.54) / 72; return (Val * 360000 * 2.54) / 72;
} }
Converter::Converter(const std::wstring & path) Converter::Converter(const std::wstring & path, std::wstring type)
{ {
std::wstring type = L"spreadsheet";
if (type == L"text") impl_ = new DocxConverter(path); if (type == L"text") impl_ = new DocxConverter(path);
if (type == L"spreadsheet") impl_ = new XlsxConverter(path); if (type == L"spreadsheet") impl_ = new XlsxConverter(path);
} }
......
...@@ -28,6 +28,8 @@ namespace OOX ...@@ -28,6 +28,8 @@ namespace OOX
namespace Drawing namespace Drawing
{ {
class CInline;
class CAnchor;
class CNonVisualDrawingProps; class CNonVisualDrawingProps;
class CShapeProperties; class CShapeProperties;
class CGroupShapeProperties; class CGroupShapeProperties;
...@@ -319,7 +321,7 @@ public: ...@@ -319,7 +321,7 @@ public:
{ {
public: public:
Converter(const std::wstring & path); Converter(const std::wstring & path, std::wstring type);
virtual ~Converter(); virtual ~Converter();
public: public:
......
...@@ -9,7 +9,18 @@ ...@@ -9,7 +9,18 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include "odf_conversion_context.h" #include "odf_conversion_context.h"
//#include "odt_conversion_context.h" #include "odt_conversion_context.h"
#include "odf_text_context.h"
#include "odf_drawing_context.h"
#include "styles.h"
#include "style_table_properties.h"
#include "style_text_properties.h"
#include "style_paragraph_properties.h"
#include "style_graphic_properties.h"
using namespace cpdoccore; using namespace cpdoccore;
...@@ -31,22 +42,185 @@ void DocxConverter::write(const std::wstring & path) ...@@ -31,22 +42,185 @@ void DocxConverter::write(const std::wstring & path)
} }
odf::odf_conversion_context* DocxConverter::odf_context() odf::odf_conversion_context* DocxConverter::odf_context()
{ {
return NULL;//odt_context; return odt_context;
} }
OOX::CTheme* DocxConverter::oox_theme() OOX::CTheme* DocxConverter::oox_theme()
{ {
return NULL; return NULL;
} }
CString DocxConverter::find_link_by_id (CString sId, int type)
{
CString ref;
//if (type==1)
//{
// if (docx_current_drawing)
// {
// smart_ptr<OOX::File> oFile = docx_current_drawing->Find(sId);
// if (oFile.IsInit() && OOX::FileTypes::Image == oFile->type())
// {
// OOX::Image* pImage = (OOX::Image*)oFile.operator->();
// ref = pImage->filename().GetPath();
// }
// }
// if (ref.GetLength() < 1 && oox_current_chart)
// {
// smart_ptr<OOX::File> oFile = oox_current_chart->Find(sId);
// if (oFile.IsInit() && OOX::FileTypes::Image == oFile->type())
// {
// OOX::Image* pImage = (OOX::Image*)oFile.operator->();
// ref = pImage->filename().GetPath();
// }
// }
//}
return ref;
}
void DocxConverter::convertDocument() void DocxConverter::convertDocument()
{ {
if (!docx_document)return; if (!docx_document)return;
const OOX::CDocument* document = docx_document->GetDocument(); odt_context = new odf::odt_conversion_context(output_document);
if (!odt_context)return;
odt_context->start_document();
//convert_styles();
convert_document();
// docx
delete docx_document; docx_document = NULL;
odt_context->end_document();
}
void DocxConverter::convert_document()
{
const OOX::CDocument* document = docx_document->GetDocument();
if (!document)return; if (!document)return;
//odf_context_ = new odf::odf_conversion_context(output_document); for ( int nIndex = 0; nIndex < document->m_arrItems.GetSize(); nIndex++ )
{
convert(document->m_arrItems[nIndex]);
}
}
void DocxConverter::convert(OOX::WritingElement *oox_unknown)
{
if (oox_unknown == NULL)return;
switch(oox_unknown->getType())
{
case OOX::et_w_r:
{
OOX::Logic::CRun* pRun= static_cast<OOX::Logic::CRun*>(oox_unknown);
convert(pRun);
}break;
case OOX::et_w_p:
{
OOX::Logic::CParagraph* pP= static_cast<OOX::Logic::CParagraph*>(oox_unknown);
convert(pP);
}break;
case OOX::et_w_pPr:
{
OOX::Logic::CParagraphProperty* pPProp= static_cast<OOX::Logic::CParagraphProperty*>(oox_unknown);
convert(pPProp);
}break;
case OOX::et_w_rPr:
{
OOX::Logic::CRunProperty* pRProp= static_cast<OOX::Logic::CRunProperty*>(oox_unknown);
convert(pRProp);
}break;
case OOX::et_w_t:
{
OOX::Logic::CText* pText= static_cast<OOX::Logic::CText*>(oox_unknown);
convert(pText);
}break;
case OOX::et_mc_alternateContent:
{
OOX::Logic::CAlternateContent* pAltCont= static_cast<OOX::Logic::CAlternateContent*>(oox_unknown);
convert(pAltCont);
}break;
case OOX::et_w_drawing:
{
OOX::Logic::CDrawing* pDrawing= static_cast<OOX::Logic::CDrawing*>(oox_unknown);
convert(pDrawing);
}
default:
{
OoxConverter::convert(oox_unknown);
}
}
}
void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
{
if (oox_paragraph == NULL) return;
odt_context->start_paragraph();
for ( int nIndex = 0; nIndex < oox_paragraph->m_arrItems.GetSize(); nIndex++ )
{
convert(oox_paragraph->m_arrItems[nIndex]);
}
odt_context->end_paragraph();
}
void DocxConverter::convert(OOX::Logic::CRun *oox_run)
{
if (oox_run == NULL) return;
odt_context->start_run();
for(int i = 0; i < oox_run->m_arrItems.GetSize(); ++i)
{
convert(oox_run->m_arrItems[i]);
}
odt_context->end_run();
}
void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_prop)
{
if (oox_paragraph_prop == NULL) return;
}
void DocxConverter::convert(OOX::Logic::CRunProperty *oox_run_prop)
{
if (oox_run_prop == NULL) return;
}
void DocxConverter::convert(OOX::Logic::CText *oox_text)
{
if (oox_text == NULL) return;
odt_context->add_text_content(string2std_string(oox_text->m_sText));
}
void DocxConverter::convert(OOX::Logic::CAlternateContent *oox_alt_content)
{
if (oox_alt_content == NULL)return;
for(int i = 0; i < oox_alt_content->m_arrChoiceItems.GetSize(); ++i)
{
convert(oox_alt_content->m_arrChoiceItems[i]);
}
for(int i = 0; i < oox_alt_content->m_arrFallbackItems.GetSize(); ++i)
{
convert(oox_alt_content->m_arrFallbackItems[i]);
}
}
void DocxConverter::convert(OOX::Logic::CDrawing *oox_drawing)
{
if (oox_drawing == NULL) return;
convert(oox_drawing->m_oAnchor.GetPointer());
convert(oox_drawing->m_oInline.GetPointer());
}
void DocxConverter::convert(OOX::Drawing::CAnchor *oox_anchor)
{
if (oox_anchor == NULL)return;
}
void DocxConverter::convert(OOX::Drawing::CInline *oox_inline)
{
if (oox_inline == NULL)return;
} }
} }
\ No newline at end of file
...@@ -5,7 +5,20 @@ ...@@ -5,7 +5,20 @@
namespace OOX namespace OOX
{ {
class CDocx; class CDocx;
class CTheme;
namespace Logic
{
class CDrawing;
class CParagraph;
class CParagraphProperty;
class CRun;
class CRunProperty;
class CText;
class CAlternateContent;
}
} }
namespace cpdoccore namespace cpdoccore
{ {
namespace odf namespace odf
...@@ -16,6 +29,7 @@ namespace cpdoccore ...@@ -16,6 +29,7 @@ namespace cpdoccore
} }
class ods_conversion_context; class ods_conversion_context;
class odf_conversion_context; class odf_conversion_context;
class odt_conversion_context;
} }
} }
using namespace cpdoccore; using namespace cpdoccore;
...@@ -32,12 +46,29 @@ namespace Oox2Odf ...@@ -32,12 +46,29 @@ namespace Oox2Odf
virtual odf::odf_conversion_context *odf_context(); virtual odf::odf_conversion_context *odf_context();
virtual OOX::CTheme *oox_theme(); virtual OOX::CTheme *oox_theme();
virtual CString find_link_by_id (CString sId, int t) {return L"";} virtual CString find_link_by_id (CString sId, int t);
private: private:
OOX::CDocx *docx_document; OOX::CDocx *docx_document;
cpdoccore::odf::package::odf_document *output_document; cpdoccore::odf::package::odf_document *output_document;
/////////////////////////////// odf::odt_conversion_context *odt_context;
OOX::Logic::CDrawing *docx_current_drawing; // .. ,
void convert_document();
void convert(OOX::WritingElement *oox_unknown);
void convert(OOX::Logic::CParagraph *oox_paragraph);
void convert(OOX::Logic::CRun *oox_run);
void convert(OOX::Logic::CParagraphProperty *oox_paragraph_prop);
void convert(OOX::Logic::CRunProperty *oox_run_prop);
void convert(OOX::Logic::CText *oox_text);
void convert(OOX::Logic::CAlternateContent *oox_alt_content);
void convert(OOX::Logic::CDrawing *oox_drawing);
void convert(OOX::Drawing::CAnchor *oox_anchor);
void convert(OOX::Drawing::CInline *oox_inline);
}; };
} }
\ No newline at end of file
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