Commit 871046d8 authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

добавлена возможность создания embedded объектов.

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@56034 954022d7-b5bf-4e40-9824-e11837661b57
parent bdbf679c
......@@ -18,7 +18,7 @@ namespace odf {
using boost::filesystem::wpath;
mediaitems::item::item( std::wstring const & _oox_ref,
_mediaitems::item::item( std::wstring const & _oox_ref,
Type _type,
std::wstring const & _odf_ref
)
......@@ -32,7 +32,7 @@ mediaitems::item::item( std::wstring const & _oox_ref,
namespace fs = boost::filesystem;
void mediaitems::add_or_find(const std::wstring & oox_ref, Type type, std::wstring & odf_ref)
void _mediaitems::add_or_find(const std::wstring & oox_ref, Type type, std::wstring & odf_ref)
{
std::wstring output_sub_path;//
std::wstring output_fileName;
......@@ -81,7 +81,7 @@ void mediaitems::add_or_find(const std::wstring & oox_ref, Type type, std::wstr
}
odf_ref = output_path;
}
void mediaitems::dump_rels(rels & Rels)
void _mediaitems::dump_rels(rels & Rels)
{
size_t i = 0;
BOOST_FOREACH(item & elm, items_)
......
......@@ -8,13 +8,13 @@ namespace odf {
class rels;
class mediaitems
class _mediaitems
{
public:
enum Type { typeUnknown = 0, typeImage, typeAudio, typeVideo};
//oleObject ???
mediaitems()
_mediaitems()
{
count_image =0;
count_media =0;
......
......@@ -15,29 +15,29 @@ namespace media {
using boost::filesystem::wpath;
std::wstring get_rel_type(mediaitems::Type type)
std::wstring get_rel_type(_mediaitems::Type type)
{
switch (type)
{
case mediaitems::typeImage:
case _mediaitems::typeImage:
return L"";
default:
return L"";
}
}
std::wstring get_default_file_name(mediaitems::Type type)
std::wstring get_default_file_name(_mediaitems::Type type)
{
switch (type)
{
case mediaitems::typeImage:
case _mediaitems::typeImage:
return L"image";
default:
return L"media";
}
}
std::wstring create_file_name(const std::wstring & uri, mediaitems::Type type, size_t Num)
std::wstring create_file_name(const std::wstring & uri, _mediaitems::Type type, size_t Num)
{
#ifdef BOOST_FILESYSTEM_LEGACY
return get_default_file_name(type) + boost::lexical_cast<std::wstring>(Num) + wpath(uri).extension();
......
......@@ -9,8 +9,8 @@ namespace odf {
namespace utils {
namespace media {
std::wstring create_file_name(const std::wstring & uri, mediaitems::Type type, size_t Num);
std::wstring get_rel_type(mediaitems::Type type);
std::wstring create_file_name(const std::wstring & uri, _mediaitems::Type type, size_t Num);
std::wstring get_rel_type(_mediaitems::Type type);
}
}
......
......@@ -152,7 +152,7 @@ namespace odf
}
///////////////////////////
media::media(mediaitems & _Mediaitems) : mediaitems_(_Mediaitems)
media::media(_mediaitems & mediaitems) : mediaitems_(mediaitems)
{
}
......@@ -163,9 +163,9 @@ namespace odf
fs::wpath path = fs::wpath(RootPath) / L"media";
fs::create_directory(path);
BOOST_FOREACH( mediaitems::item & item, mediaitems_.items() )
BOOST_FOREACH( _mediaitems::item & item, mediaitems_.items() )
{
if (item.type == mediaitems::typeAudio || item.type == mediaitems::typeVideo)
if (item.type == _mediaitems::typeAudio || item.type == _mediaitems::typeVideo)
{
fs::wpath file_name = fs::wpath(item.oox_ref);
fs::wpath file_name_out = fs::wpath(RootPath) / item.odf_ref;
......@@ -177,7 +177,7 @@ namespace odf
}
pictures::pictures(mediaitems & _Mediaitems) : mediaitems_(_Mediaitems)
pictures::pictures(_mediaitems & mediaitems) : mediaitems_(mediaitems)
{
}
......@@ -188,9 +188,9 @@ namespace odf
fs::wpath path = fs::wpath(RootPath) / L"Pictures";
fs::create_directory(path);
BOOST_FOREACH( mediaitems::item & item, mediaitems_.items() )
BOOST_FOREACH( _mediaitems::item & item, mediaitems_.items() )
{
if (item.type == mediaitems::typeImage && item.oox_ref.length()>0)
if (item.type == _mediaitems::typeImage && item.oox_ref.length()>0)
{
fs::wpath file_name = fs::wpath(item.oox_ref);
fs::wpath file_name_out = fs::wpath(RootPath) / item.odf_ref;
......@@ -212,13 +212,13 @@ namespace odf
content_.set_content(_content);
meta_ = element_ptr(new meta_file());
}
void object_files::set_media(mediaitems & _Mediaitems)
void object_files::set_media(_mediaitems & mediaitems)
{
media_ = element_ptr( new media(_Mediaitems) );
media_ = element_ptr( new media(mediaitems) );
}
void object_files::set_pictures(mediaitems & _Mediaitems)
void object_files::set_pictures(_mediaitems & mediaitems)
{
pictures_ = element_ptr( new pictures(_Mediaitems) );
pictures_ = element_ptr( new pictures(mediaitems) );
}
void object_files::set_styles(content_simple_ptr & _content)
{
......@@ -235,7 +235,7 @@ namespace odf
if (pictures_) pictures_->write(RootPath);
}
void odf_document::add_object(element_ptr _object,bool root)
void odf_document::add_object(element_ptr _object, bool root)
{
if (root)base_ = _object;
else objects_.push_back(_object);
......
......@@ -10,7 +10,7 @@ namespace cpdoccore
namespace odf
{
class mediaitems;//picture & media
class _mediaitems;//picture & media
class rels;
......@@ -134,21 +134,21 @@ namespace odf
class media : public element
{
public:
media(mediaitems & _Mediaitems);
media(_mediaitems & mediaitems);
virtual void write(const std::wstring & RootPath);
private:
mediaitems & mediaitems_;
_mediaitems & mediaitems_;
};
class pictures : public element
{
public:
pictures(mediaitems & _Mediaitems);
pictures(_mediaitems & mediaitems);
virtual void write(const std::wstring & RootPath);
private:
mediaitems & mediaitems_;
_mediaitems & mediaitems_;
};
class object_files : public element
......@@ -160,8 +160,8 @@ namespace odf
void set_styles (content_simple_ptr & _Styles);
void set_media(mediaitems & _Mediaitems);
void set_pictures(mediaitems & _Mediaitems);
void set_media (_mediaitems & mediaitems);
void set_pictures (_mediaitems & mediaitems);
virtual void write(const std::wstring & RootPath);
......
......@@ -13,27 +13,33 @@ namespace odf {
//////////////////////////////////////////////////////////////////////////////////////////////////
odf_conversion_context::odf_conversion_context(package::odf_document * outputDocument) : style_context_(*this)
odf_conversion_context::odf_conversion_context(package::odf_document * outputDocument)
{
output_document_ = outputDocument;
current_object_ =0;
}
odf_conversion_context::~odf_conversion_context()
odf_style_context* odf_conversion_context::styles_context()
{
return objects_[current_object_].style_context.get();
}
odf_number_styles_context* odf_conversion_context::numbers_styles_context()
{
if (objects_[current_object_].style_context)
return &(objects_[current_object_].style_context->numbers_styles());
else return NULL;
}
office_element_ptr & odf_conversion_context::getCurrentElement()
_mediaitems* odf_conversion_context::mediaitems()
{
if (content_.size()>0)
{
return content_.back();
}
else
{
CP_ASSERT(false);
throw std::runtime_error("internal error");
}
return &objects_[current_object_].mediaitems;
}
odf_conversion_context::~odf_conversion_context()
{
}
//void odf_conversion_context::start_font_face()
......@@ -43,72 +49,90 @@ office_element_ptr & odf_conversion_context::getCurrentElement()
void odf_conversion_context::end_document()
{
///////////////////çàâåðøàþùàÿ îáðàáîòêà
process_styles();
//////////////////////////////////////////////////////////////////////
package::content_content_ptr content_root_ = package::content_content::create();
BOOST_FOREACH(const office_element_ptr & elm, content_)
{
elm->serialize(content_root_->content());
}
BOOST_FOREACH(const office_element_ptr & elm, content_styles_)
rels rels_;
for (long i=0; i< objects_.size(); i++)
{
elm->serialize(content_root_->styles());
}
//////////////////////////////////////////////////////////////////////////////////////////
package::content_simple_ptr content_style_ = package::content_simple::create();
BOOST_FOREACH(const office_element_ptr & elm, styles_)
{// ìàñòåð-ïåéäæû, çàäàííûå çàëèâêè (ãðàäèåíòû, áèòìàïû), äåôîëòíûå ñòèëè, êîëîíòèòóëû, ðàçìåòêè, çàìåòêè,...
elm->serialize(content_style_->content());
}
////////////////////////////////////////////////////////////////////////////////////////////////////
package::object_files *object_files = new package::object_files();
if (object_files)
{
object_files->set_content(content_root_);
object_files->set_styles(content_style_);
object_files->set_media(mediaitems_);
object_files->set_pictures(mediaitems_);
output_document_->add_object(package::element_ptr(object_files ),true);
_object & object = objects_[i];
bool isRoot = (i==0? true : false);
if (object.content == NULL)continue;
process_styles(object);
package::content_content_ptr content_root_ = package::content_content::create();
object.content->serialize(content_root_->content());
BOOST_FOREACH(const office_element_ptr & elm, object.content_styles)
{
elm->serialize(content_root_->styles());
}
package::content_simple_ptr content_style_ = package::content_simple::create();
BOOST_FOREACH(const office_element_ptr & elm, object.styles)
{// ìàñòåð-ïåéäæû, çàäàííûå çàëèâêè (ãðàäèåíòû, áèòìàïû), äåôîëòíûå ñòèëè, êîëîíòèòóëû, ðàçìåòêè, çàìåòêè,...
elm->serialize(content_style_->content());
}
////////////////////////////
package::object_files *object_files = new package::object_files();
if (object_files)
{
object_files->set_content (content_root_);
object_files->set_styles (content_style_);
object_files->set_media (object.mediaitems);
object_files->set_pictures (object.mediaitems);
output_document_->add_object(package::element_ptr(object_files ),isRoot);
}
object.mediaitems.dump_rels(rels_);
}
mediaitems_.dump_rels(rels_);
std::vector<package::content_content_ptr> objects_; //styles â îáúåêòàõ ïî÷òè ïóñòûå .. - ññûëêè íà êàðòèíêè ... è òîëüêî
//ñîáñòâåííî ñòèëè çàïèñûâàþòñÿ â ñàì êîíòåíò
output_document_->set_rels(rels_);
}
void odf_conversion_context::start_chart()
{
create_object();
create_element(L"office", L"chart", objects_.back().content, this,true);
}
void odf_conversion_context::start_spreadsheet()
{
create_object();
create_element(L"office", L"spreadsheet", objects_.back().content, this,true);
}
void odf_conversion_context::create_object()
{
_object obj;
obj.style_context = boost::make_shared<odf_style_context>();
obj.style_context->set_odf_context(this);
objects_.push_back(obj);
void odf_conversion_context::add_rel(relationship const & r)
current_object_ = objects_.size()-1;
}
void odf_conversion_context::end_object()
{
rels_.add(r);
current_object_ = 0;
}
void odf_conversion_context::process_styles()
void odf_conversion_context::process_styles(_object & object)
{
create_element(L"office", L"font-face-decls", styles_, this,true);
create_element(L"office", L"font-face-decls", object.styles, this,true);
create_element(L"office", L"styles", styles_, this,true);//îáùèå ñòèëè
style_context_.process_office(styles_.back());
create_element(L"office", L"styles", object.styles, this,true);//îáùèå ñòèëè
object.style_context->process_office(object.styles.back());
create_element(L"office", L"automatic-styles", styles_, this,true);
style_context_.process_automatic_styles(styles_.back());
create_element(L"office", L"automatic-styles", object.styles, this,true);
object.style_context->process_automatic_styles(object.styles.back());
create_element(L"office", L"master-styles", styles_, this,true);
style_context_.process_master(styles_.back());
create_element(L"office", L"master-styles", object.styles, this,true);
object.style_context->process_master(object.styles.back());
///////////////////////////////
create_element(L"office", L"font-face-decls", content_styles_, this,true);
create_element(L"office", L"automatic-styles", content_styles_, this,true);
style_context_.process_automatic(content_styles_.back());
create_element(L"office", L"font-face-decls", object.content_styles, this,true);
create_element(L"office", L"automatic-styles", object.content_styles, this,true);
object.style_context->process_automatic(object.content_styles.back());
}
}
}
......@@ -15,38 +15,43 @@ typedef shared_ptr<office_element>::Type office_element_ptr;
class odf_conversion_context : boost::noncopyable
{
struct _object
{
office_element_ptr content;
std::vector<office_element_ptr> content_styles;
std::vector<office_element_ptr> styles;
odf_style_context_ptr style_context;
_mediaitems mediaitems;
};
public:
odf_conversion_context(package::odf_document * outputDocument);
virtual ~odf_conversion_context();
virtual void start_document() = 0 ;
void end_document();
virtual odf_drawing_context & drawing_context() = 0;
virtual odf_text_context * text_context() = 0;
office_element_ptr & getCurrentElement();
std::vector<office_element_ptr> content_;
std::vector<office_element_ptr> content_styles_;
std::vector<office_element_ptr> styles_;
virtual void start_document() = 0 ;
void end_document();
void add_rel(relationship const & r);
package::odf_document * output_document_;
odf_style_context & styles_context(){return style_context_;}
odf_number_styles_context & numbers_styles_context() {return style_context_.numbers_styles();}
std::vector<_object> objects_;//"0" = root
virtual odf_drawing_context * drawing_context() = 0;
virtual odf_text_context * text_context() = 0;
private:
rels rels_;
void process_styles();
odf_style_context * styles_context();
odf_number_styles_context * numbers_styles_context();
_mediaitems * mediaitems();
public:
void start_chart();
void start_spreadsheet();
void create_object();
void end_object();
odf_style_context style_context_;
private:
void process_styles(_object & object);
int current_object_;
//page_layout_container & pageLayoutContainer() { return page_layout_container_; }
//fonts_container & fontContainer() { return fonts_container_; }
......@@ -57,7 +62,6 @@ public:
//styles_lite_container & drawStyles() { return draw_style_container_; }
//styles_lite_container & Templates() { return template_container_; }
mediaitems mediaitems_;
//styles_container major_style_container_;
//page_layout_container page_layout_container_;
......
......@@ -97,7 +97,7 @@ public:
Impl(odf_conversion_context *odf_context) :odf_context_(odf_context)
{
current_drawing_state_.clear();
styles_context_ = &odf_context_->styles_context();
styles_context_ = odf_context_->styles_context();
current_graphic_properties = NULL;
}
......@@ -1318,7 +1318,7 @@ void odf_drawing_context::set_bitmap_link(std::wstring link)
{
std::wstring odf_ref_name ;
impl_->odf_context_->mediaitems_.add_or_find(link,mediaitems::typeImage,odf_ref_name);
impl_->odf_context_->mediaitems()->add_or_find(link,_mediaitems::typeImage,odf_ref_name);
draw_fill_image * fill_image = dynamic_cast<draw_fill_image *>(impl_->styles_context_->last_state().get_office_element().get());
if (!fill_image) return;
......
......@@ -196,10 +196,13 @@ static const def_language_code LanguageCodeTable[] =
{L"Zulu", L"", L"", 0x0435}
};
odf_number_styles_context::odf_number_styles_context(odf_conversion_context & Context): context_(Context)
odf_number_styles_context::odf_number_styles_context()
{
}
void odf_number_styles_context::set_odf_context(odf_conversion_context * Context)
{
odf_context_ = Context;
}
void odf_number_styles_context::create(int oox_num_fmt, std::wstring formatCode)
{
if (oox_num_fmt <164)return create_default(oox_num_fmt,formatCode);
......@@ -358,7 +361,7 @@ void odf_number_styles_context::create_style(number_format_state & state)
void odf_number_styles_context::create_number_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"number-style", root_elm, &context_);
create_element(L"number", L"number-style", root_elm, odf_context_);
if (state.format_code.size()>0)
{
......@@ -372,7 +375,7 @@ void odf_number_styles_context::create_numbers(number_format_state & state, offi
{
optional< int>::Type min_digit, min_decimal;
create_element(L"number", L"number", elm, &context_);
create_element(L"number", L"number", elm, odf_context_);
styles_elments.push_back(elm);
number_number* number_number_ = dynamic_cast<number_number*>(elm.get());
......@@ -415,14 +418,14 @@ void odf_number_styles_context::create_numbers(number_format_state & state, offi
}
void odf_number_styles_context::create_percentage_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"percentage-style", root_elm, &context_);
create_element(L"number", L"percentage-style", root_elm, odf_context_);
office_element_ptr elm;
create_numbers(state, elm);
root_elm->add_child_element(elm);
create_element(L"number", L"text", elm, &context_);
create_element(L"number", L"text", elm, odf_context_);
number_text* number_text_ = dynamic_cast<number_text*>(elm.get());
if (number_text_)number_text_->add_text(L"%");
......@@ -432,14 +435,14 @@ void odf_number_styles_context::create_percentage_style(number_format_state & st
void odf_number_styles_context::create_currency_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"currency-style", root_elm, &context_);
create_element(L"number", L"currency-style", root_elm, odf_context_);
{
int res1= state.format_code[0].rfind(L"]");
int res2= state.format_code[0].rfind(L"#");
int res3= state.format_code[0].rfind(L"0");
office_element_ptr elm_symbol;
create_element(L"number", L"currency-symbol", elm_symbol, &context_);
create_element(L"number", L"currency-symbol", elm_symbol, odf_context_);
styles_elments.push_back(elm_symbol);
number_currency_symbol* number_currency_symbol_ = dynamic_cast<number_currency_symbol*>(elm_symbol.get());
......@@ -472,7 +475,7 @@ void odf_number_styles_context::create_currency_style(number_format_state & stat
create_numbers(state, elm_number);
//////////////////////////////////////////
office_element_ptr elm_text;
create_element(L"number", L"text", elm_text, &context_);
create_element(L"number", L"text", elm_text, odf_context_);
number_text* number_text_ = dynamic_cast<number_text*>(elm_text.get());
if (number_text_)number_text_->add_text(L" ");
styles_elments.push_back(elm_text);
......@@ -494,7 +497,7 @@ void odf_number_styles_context::create_currency_style(number_format_state & stat
void odf_number_styles_context::create_date_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"date-style", root_elm, &context_);
create_element(L"number", L"date-style", root_elm, odf_context_);
//state.language_code == L"F800" System long date format
......@@ -514,7 +517,7 @@ void odf_number_styles_context::create_date_style(number_format_state & state, o
sz = s.length();
if ((res=s.find(L"m")) >=0)
{
create_element(L"number", L"month", elm, &context_);
create_element(L"number", L"month", elm, odf_context_);
number_month* number_month_ = dynamic_cast<number_month*>(elm.get());
if (number_month_ && sz > 2)number_month_->number_textual_ = true;
......@@ -525,7 +528,7 @@ void odf_number_styles_context::create_date_style(number_format_state & state, o
{
if (sz < 3)
{
create_element(L"number", L"day", elm, &context_);
create_element(L"number", L"day", elm, odf_context_);
number_day* number_day_ = dynamic_cast<number_day*>(elm.get());
if (number_day_)
{
......@@ -535,7 +538,7 @@ void odf_number_styles_context::create_date_style(number_format_state & state, o
}
else
{
create_element(L"number", L"day-of-week", elm, &context_);
create_element(L"number", L"day-of-week", elm, odf_context_);
number_day_of_week* number_day_of_week_ = dynamic_cast<number_day_of_week*>(elm.get());
if (number_day_of_week_)
{
......@@ -546,7 +549,7 @@ void odf_number_styles_context::create_date_style(number_format_state & state, o
}
else if ((res=s.find(L"y")) >=0)
{
create_element(L"number", L"year", elm, &context_);
create_element(L"number", L"year", elm, odf_context_);
number_year* number_year_ = dynamic_cast<number_year*>(elm.get());
if (number_year_)
{
......@@ -561,7 +564,7 @@ void odf_number_styles_context::create_date_style(number_format_state & state, o
// ""
boost::algorithm::replace_all(s, L"\\", L"");
}
create_element(L"number", L"text", elm, &context_);
create_element(L"number", L"text", elm, odf_context_);
number_text* number_text_ = dynamic_cast<number_text*>(elm.get());
if (number_text_)number_text_->add_text(s);
}
......@@ -576,7 +579,7 @@ void odf_number_styles_context::create_date_style(number_format_state & state, o
void odf_number_styles_context::create_time_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"time-style", root_elm, &context_);
create_element(L"number", L"time-style", root_elm, odf_context_);
// state.language_code == L"F400")//System time format
std::wstring s = state.format_code[0];
......@@ -596,7 +599,7 @@ void odf_number_styles_context::create_time_style(number_format_state & state, o
sz = s.length();
if ((res=s.find(L"h")) >=0)
{
create_element(L"number", L"hours", elm, &context_);
create_element(L"number", L"hours", elm, odf_context_);
number_hours* number_hours_ = dynamic_cast<number_hours*>(elm.get());
if (number_hours_)
{
......@@ -606,11 +609,11 @@ void odf_number_styles_context::create_time_style(number_format_state & state, o
}
else if ((res=s.find(L"am")) >=0/* || (res=s.find(L"pm")) >=0*/) // ..
{
create_element(L"number", L"am-pm", elm, &context_);
create_element(L"number", L"am-pm", elm, odf_context_);
}
else if ((res=s.find(L"m")) >=0 && (res=s.find(L"am")) <0 && (res=s.find(L"pm")) <0 )
{
create_element(L"number", L"minutes", elm, &context_);
create_element(L"number", L"minutes", elm, odf_context_);
number_minutes* number_minutes_ = dynamic_cast<number_minutes*>(elm.get());
if (number_minutes_)
{
......@@ -620,7 +623,7 @@ void odf_number_styles_context::create_time_style(number_format_state & state, o
}
else if ((res=s.find(L"s")) >=0)
{
create_element(L"number", L"seconds", elm, &context_);
create_element(L"number", L"seconds", elm, odf_context_);
number_seconds* number_seconds_ = dynamic_cast<number_seconds*>(elm.get());
if (number_seconds_)
{
......@@ -637,7 +640,7 @@ void odf_number_styles_context::create_time_style(number_format_state & state, o
// ""
boost::algorithm::replace_all(s, L"\\", L"");
}
create_element(L"number", L"text", elm, &context_);
create_element(L"number", L"text", elm, odf_context_);
number_text* number_text_ = dynamic_cast<number_text*>(elm.get());
if (number_text_)number_text_->add_text(s);
}
......@@ -651,12 +654,12 @@ void odf_number_styles_context::create_time_style(number_format_state & state, o
void odf_number_styles_context::create_boolean_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"boolean-style", root_elm, &context_);
create_element(L"number", L"boolean-style", root_elm, odf_context_);
}
void odf_number_styles_context::create_text_style(number_format_state & state, office_element_ptr & root_elm)
{
create_element(L"number", L"text-style", root_elm, &context_);
create_element(L"number", L"text-style", root_elm, odf_context_);
}
void odf_number_styles_context::detect_format(number_format_state & state)
......
......@@ -34,7 +34,8 @@ struct number_format_state
class odf_number_styles_context
{
public:
odf_number_styles_context(odf_conversion_context & Context);
odf_number_styles_context();
void set_odf_context(odf_conversion_context * Context);
number_format_state & add_or_find(int oox_num_fmt, std::wstring formatCode = L"");
void process_styles(office_element_ptr root );
......@@ -50,7 +51,7 @@ private:
void detect_format(number_format_state & state);
////////////////
odf_conversion_context & context_;
odf_conversion_context *odf_context_;
std::vector<office_element_ptr> styles_elments;
//////////////////
......
......@@ -13,10 +13,16 @@
namespace cpdoccore {
namespace odf {
odf_style_context::odf_style_context(odf_conversion_context & Context): context_(Context), number_styles_context_(Context)
odf_style_context::odf_style_context()
{
}
void odf_style_context::set_odf_context(odf_conversion_context * Context)
{
odf_context_ = Context;
number_styles_context_.set_odf_context(Context);
}
odf_style_state & odf_style_context::last_state()
{
if (style_state_list_.size() >0)
......@@ -31,7 +37,7 @@ void odf_style_context::create_style(std::wstring oox_name,const style_family fa
if (odf_name.length() <1)odf_name = find_free_name(family);
office_element_ptr elm;
create_element(L"style", L"style", elm, &context_);
create_element(L"style", L"style", elm, odf_context_);
style_state_list_.push_back( odf_style_state(/*context_, */elm, family) );
......@@ -55,7 +61,7 @@ void odf_style_context::add_style(office_element_ptr elm, bool automatic, bool r
void odf_style_context::create_default(const style_family family)
{
office_element_ptr elm;
create_element(L"style", L"default-style", elm, &context_);
create_element(L"style", L"default-style", elm, odf_context_);
style_state_list_.push_back( odf_style_state(elm, family) );
......
......@@ -16,11 +16,14 @@ class odf_conversion_context;
class office_element;
typedef shared_ptr<office_element>::Type office_element_ptr;
class odf_style_context;
typedef shared_ptr<odf_style_context>::Type odf_style_context_ptr;
/// \class ods_table_context
class odf_style_context
{
public:
odf_style_context(odf_conversion_context & Context);
odf_style_context();
void set_odf_context(odf_conversion_context * Context);
void create_style(std::wstring name, const style_family style_family, bool automatic = false, bool root = false, int oox_id = -1);
void create_default(const style_family style_family);
......@@ -54,7 +57,7 @@ public:
private:
odf_number_styles_context number_styles_context_;
odf_conversion_context & context_;
odf_conversion_context * odf_context_;
std::vector<odf_style_state> style_state_list_;
......
......@@ -83,9 +83,8 @@ ods_conversion_context::ods_conversion_context(package::odf_document * outputDoc
void ods_conversion_context::start_document()
{
create_element(L"office", L"spreadsheet", content_, this,true);
current_spreadsheet_ = dynamic_cast<office_spreadsheet*>(content_.back().get());
start_spreadsheet();
current_spreadsheet_ = dynamic_cast<office_spreadsheet*>(objects_.back().content.get());
}
......@@ -116,19 +115,19 @@ void ods_conversion_context::set_sheet_dimension(std::wstring & ref)
void ods_conversion_context::end_sheet()
{
if (current_table().drawing_context().is_exist_content())
if (current_table().drawing_context()->is_exist_content())
{
office_element_ptr shapes_root_elm;
create_element(L"table", L"shapes",shapes_root_elm,this);
current_table().drawing_context().finalize(shapes_root_elm);
current_table().drawing_context()->finalize(shapes_root_elm);
current_table().add_child_element(shapes_root_elm);
}
table_context_.end_table();
styles_context().reset_defaults();
styles_context()->reset_defaults();
}
void ods_conversion_context::start_row(int _start_row, int repeated, int level, bool _default)
......@@ -156,12 +155,12 @@ void ods_conversion_context::start_row(int _start_row, int repeated, int level,
office_element_ptr style_elm;
if ( _default)
{
style_elm = styles_context().find_odf_style_default(style_family::TableRow);
style_elm = styles_context()->find_odf_style_default(style_family::TableRow);
}
else
{
styles_context().create_style(L"",style_family::TableRow, true, false, -1);
style_elm = styles_context().last_state().get_office_element();
styles_context()->create_style(L"",style_family::TableRow, true, false, -1);
style_elm = styles_context()->last_state().get_office_element();
style* _style = dynamic_cast<style*>(style_elm.get());
if (!_style)return;
......@@ -179,7 +178,7 @@ void ods_conversion_context::start_row(int _start_row, int repeated, int level,
if ( _default)
{
//std::wstring style_cell_name= styles_context().find_odf_style_name_default(odf::style_family::TableCell);
//std::wstring style_cell_name= styles_context()->find_odf_style_name_default(odf::style_family::TableCell);
//current_table().set_row_default_cell_style(style_cell_name);
}
}
......@@ -284,7 +283,7 @@ void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
if ( xfd_style >=0)
{
odf_style_state *style_state=NULL;
styles_context().find_odf_style_state(xfd_style, style_family::TableCell,style_state);
styles_context()->find_odf_style_state(xfd_style, style_family::TableCell,style_state);
if (style_state)
{
style_elm = style_state->get_office_element();
......@@ -292,7 +291,7 @@ void ods_conversion_context::start_cell(std::wstring & ref, int xfd_style)
int number_format = style_state->get_number_format();//oox
if (number_format >0)
format_value_type = numbers_styles_context().add_or_find(number_format).ods_type;
format_value_type = numbers_styles_context()->add_or_find(number_format).ods_type;
}
else
{//error
......@@ -362,14 +361,14 @@ void ods_conversion_context::add_column(int start_column, int repeated, int leve
office_element_ptr style_elm;
if ( _default)
{
style_elm = styles_context().find_odf_style_default(style_family::TableColumn);
style_elm = styles_context()->find_odf_style_default(style_family::TableColumn);
}
else
{
// .. - , .
// 2 ( , )
styles_context().create_style(L"",style_family::TableColumn, true, false, -1);
style_elm = styles_context().last_state().get_office_element();
styles_context()->create_style(L"",style_family::TableColumn, true, false, -1);
style_elm = styles_context()->last_state().get_office_element();
style* _style = dynamic_cast<style*>(style_elm.get());
if (!_style)return;
......@@ -387,13 +386,13 @@ void ods_conversion_context::add_column(int start_column, int repeated, int leve
if (_default)
{
std::wstring style_cell_name= styles_context().find_odf_style_name_default(odf::style_family::TableCell);
std::wstring style_cell_name= styles_context()->find_odf_style_name_default(odf::style_family::TableCell);
current_table().set_column_default_cell_style(style_cell_name);
}
}
void ods_conversion_context::start_text_context()
{
current_text_context_ = new odf_text_context(&styles_context(),this);
current_text_context_ = new odf_text_context(styles_context(),this);
}
void ods_conversion_context::end_text_context()
......@@ -449,9 +448,9 @@ void ods_conversion_context::start_image(std::wstring & image_file_name)
{
std::wstring odf_ref_name ;
mediaitems_.add_or_find(image_file_name,mediaitems::typeImage,odf_ref_name);
mediaitems()->add_or_find(image_file_name,_mediaitems::typeImage,odf_ref_name);
current_table().drawing_context().start_image(odf_ref_name);
current_table().drawing_context()->start_image(odf_ref_name);
}
}
}
......@@ -39,23 +39,23 @@ public:
void add_merge_cells(std::wstring & ref);
void add_hyperlink(std::wstring & ref, std::wstring & link, std::wstring & display);
void start_comment(int col, int row, std::wstring & author);
void set_comment_rect(double l, double t, double w, double h);
void end_comment();
void start_comment (int col, int row, std::wstring & author);
void set_comment_rect (double l, double t, double w, double h);
void end_comment ();
///////////////////////////////////////////////////////
ods_table_state & current_table() { return table_context_.state();}
/////////////////////////////////////////////////////
void start_text_context();
void end_text_context();
virtual odf_drawing_context& drawing_context(){return current_table().drawing_context();}
virtual odf_text_context* text_context(){return current_text_context_;}
virtual odf_drawing_context * drawing_context() {return current_table().drawing_context();}
virtual odf_text_context * text_context() {return current_text_context_;}
void start_drawing(){drawing_context().start_drawing();}
void end_drawing(){drawing_context().end_drawing();}
void start_drawing() {drawing_context()->start_drawing();}
void end_drawing() {drawing_context()->end_drawing();}
void start_image(std::wstring & image_file_name);
void end_image(){drawing_context().end_image();}
void end_image(){drawing_context()->end_image();}
private:
ods_table_context table_context_;
......
......@@ -27,7 +27,7 @@ void ods_table_context::start_table(office_element_ptr & elm, std::wstring & nam
std::wstring style_name_new = L"ta" + boost::lexical_cast<std::wstring>(table_state_list_.size());
office_element_ptr & style = context_.styles_context().add_or_find(style_name_new, style_family::Table, true);
office_element_ptr & style = context_.styles_context()->add_or_find(style_name_new, style_family::Table, true);
style->create_child_element(L"style", L"table-properties");
......
......@@ -141,7 +141,7 @@ public:
void convert_position(oox_table_position & oox_pos, double & x, double & y);
odf_drawing_context& drawing_context(){return drawing_context_;}
odf_drawing_context * drawing_context(){return &drawing_context_;}
//
// xlsx_table_metrics & get_table_metrics() { return xlsx_table_metrics_; }
......
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