Commit 9913a25a authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

.....

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@56930 954022d7-b5bf-4e40-9824-e11837661b57
parent cc381506
......@@ -238,10 +238,6 @@
RelativePath=".\src\common\readdocelement.cpp"
>
</File>
<File
RelativePath=".\include\cpdoccore\common\readstring.h"
>
</File>
</Files>
<Globals>
</Globals>
......
#ifndef _CPDOCCORE_COMMON_READSTRING_H_
#define _CPDOCCORE_COMMON_READSTRING_H_
#pragma once
#include <cpdoccore/CPOptional.h>
#include <lexical_cast.h>
#include "logging.h"
namespace cpdoccore {
namespace common {
template <class T, class StringT>
typename optional<T>::Type read_string( const StringT & Value )
{
try
{
return optional<T>::Type ( ::boost::lexical_cast<T>( Value ) );
}
catch(...)
{
_CP_LOG(warning) << L"[warning] : could't convert \'" << Value << L"\' to type \'" << typeid(T).name() << L"\'\n";
throw;
return optional<T>::Type();
}
}
typename optional<T>::Type read_string( const StringT & Value );
}
}
#endif // #ifndef _CPDOCCORE_COMMON_READSTRING_H_
......@@ -5,7 +5,9 @@
#include <vector>
#include <cpdoccore/CPSharedPtr.h>
#include <cpdoccore/CPOptional.h>
#include <cpdoccore/common/readstring.h>
#include <logging.h>
#include <boost_string.h>
#include <cpdoccore/xml/xmlchar.h>
......@@ -92,7 +94,8 @@ namespace cpdoccore
{
try
{
return common::read_string<V>( *val );
return optional<V>::Type ( ::boost::lexical_cast<V>( *val ) );
//return common::read_string<V>( *val );
}
catch(...)
{
......@@ -205,8 +208,14 @@ namespace cpdoccore
template <class StringT, class T>
static bool _cp_apply_attribute(xml::attributes_wc_ptr attr, const StringT & QualifiedName, T & Val, const T & Default)
{
_CP_OPT(T) tmp = attr->get_val<T>(QualifiedName);
Val = tmp.get_value_or(Default);
_CP_OPT(T) tmp;
try
{
tmp = attr->get_val<T>(QualifiedName);
Val = tmp.get_value_or(Default);
}catch(...)
{
}
return (!!tmp);
}
......
......@@ -39,6 +39,24 @@ docx_conversion_context::docx_conversion_context(package::docx_document * Output
process_note_(noNote)
{}
std::wstring styles_map::get(const std::wstring & Name, odf::style_family::type Type)
{
const std::wstring n = name(Name, Type);
if (map_.count(n))
{
return map_[n];
}
else
{
const std::wstring id = std::wstring(L"style") + boost::lexical_cast<std::wstring>(count_++);
map_[n] = id;
return id;
}
}
std::wstring styles_map::name(const std::wstring & Name, odf::style_family::type Type)
{
return Name + L":" + boost::lexical_cast<std::wstring>(odf::style_family(Type));
}
void docx_conversion_context::add_element_to_run()
{
if (!current_run_)
......
......@@ -64,20 +64,7 @@ class styles_map
{
public:
styles_map() : count_(0) {}
std::wstring get(const std::wstring & Name, odf::style_family::type Type)
{
const std::wstring n = name(Name, Type);
if (map_.count(n))
{
return map_[n];
}
else
{
const std::wstring id = std::wstring(L"style") + boost::lexical_cast<std::wstring>(count_++);
map_[n] = id;
return id;
}
}
std::wstring get(const std::wstring & Name, odf::style_family::type Type);
bool check(const std::wstring & Name, odf::style_family::type Type)
{
......@@ -86,12 +73,8 @@ public:
}
private:
std::wstring name(const std::wstring & Name, odf::style_family::type Type)
{
return Name + L":" + boost::lexical_cast<std::wstring>(odf::style_family(Type));
}
std::wstring name(const std::wstring & Name, odf::style_family::type Type);
private:
size_t count_;
boost::unordered_map<std::wstring, std::wstring> map_;
......
......@@ -94,7 +94,7 @@ length length::parse(const std::wstring & Str)
u = length::emu;
else
{
BOOST_THROW_EXCEPTION( errors::invalid_attribute() );
// BOOST_THROW_EXCEPTION( errors::invalid_attribute() );
}
return length(v, u);
......
......@@ -66,7 +66,8 @@ void office_body::docx_convert(oox::docx_conversion_context & Context)
Context.set_master_page_name(masterPages[0]->style_master_page_attlist_.style_name_.get_value_or(style_ref(L"Standard")).style_name() );
}
Context.set_page_properties(Context.root()->odf_context().pageLayoutContainer().page_layout_first()->name());
const page_layout_instance * layout = Context.root()->odf_context().pageLayoutContainer().page_layout_first();
if (layout) Context.set_page_properties(layout->name());
//backcolor (for all pages)
if (page_layout_instance * firtsPageLayout = Context.root()->odf_context().pageLayoutContainer().page_layout_by_name(Context.get_page_properties()))
{
......
......@@ -287,7 +287,7 @@ const wchar_t * span::name = L"span";
void span::add_attributes( const xml::attributes_wc_ptr & Attributes )
{
CP_APPLY_ATTR(L"text:style-name", text_style_name_, style_ref(L""));
CP_APPLY_ATTR(L"text:style-name", text_style_name_, style_ref(L""));
const ::std::wstring classNames = Attributes->get_val< ::std::wstring >(L"text:class-names").get_value_or(L"");
::std::vector< ::std::wstring > classNamesArray;
......
......@@ -11,6 +11,7 @@
#include "office_elements.h"
#include "office_elements_create.h"
#include "anchortype.h"
namespace cpdoccore {
namespace odf
......@@ -29,7 +30,23 @@ public:
void set_drawings_rect(double x_pt, double y_pt, double width_pt, double height_pt);
void clear();
void set_styles_context(odf_style_context* styles_context);// embedded
void set_margin_left (double valPt);
void set_margin_right (double valPt);
void set_margin_top (double valPt);
void set_margin_bottom (double valPt);
void set_anchor (anchor_type::type type);
void set_vertical_rel(int from);
void set_vertical_pos(int align);
void set_vertical_pos(double offset_pt);
void set_horizontal_rel(int from);
void set_horizontal_pos(int align);
void set_horizontal_pos(double offset_pt);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
office_element_ptr & get_current_style_element() ;
office_element_ptr & get_current_element();
......
......@@ -30,7 +30,17 @@ odf_style_state & odf_style_context::last_state()
else
throw;
}
odf_style_state * odf_style_context::last_state(style_family family)
{
for (long i = style_state_list_.size()-1; i>=0; i--)
{
if (style_state_list_[i].get_family() == family)
{
return &style_state_list_[i];
}
}
return NULL;
}
void odf_style_context::create_style(std::wstring oox_name,const style_family family, bool automatic,bool root,int oox_id)
{
std::wstring odf_name = oox_name;
......@@ -77,14 +87,6 @@ void odf_style_context::create_default_style(const style_family family)
last_state().set_automatic(false);
last_state().set_root(true);
last_state().set_default(true);
////////////////////////////////////////////
odf::default_style* style = dynamic_cast<odf::default_style*>(elm.get());
if (style == NULL)return;
odf::style_table_cell_properties * cell_properties = style->style_content_.get_style_table_cell_properties();
odf::style_text_properties * text_properties = style->style_content_.get_style_text_properties();
odf::style_paragraph_properties * paragraph_properties = style->style_content_.get_style_paragraph_properties();
}
void odf_style_context::reset_defaults()
{
......
......@@ -54,6 +54,7 @@ public:
bool find_odf_style_state(int oox_id_style, const style_family family, odf_style_state *& state, bool root = false);
odf_style_state & last_state();
odf_style_state * last_state(style_family family);
odf_number_styles_context & numbers_styles() {return number_styles_context_;}
......
......@@ -57,6 +57,13 @@ std::wstring & odf_style_state::get_name()
return style_->style_name_;
}
style_family & odf_style_state::get_family()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return style_family(style_family::None);
return style_family_;
}
void odf_style_state::set_parent_style_name(std::wstring & name)
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
......@@ -94,72 +101,99 @@ void odf_style_state::set_conditional(bool val)
style_text_properties * odf_style_state::get_text_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_) return style_->style_content_.get_style_text_properties();
return style_->style_content_.get_style_text_properties();
default_style* style_d_ = dynamic_cast<default_style*>(odf_style_.get());
if (style_d_)return style_d_->style_content_.get_style_text_properties();
return NULL;
}
style_paragraph_properties * odf_style_state::get_paragraph_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
return style_->style_content_.get_style_paragraph_properties();
if (style_) return style_->style_content_.get_style_paragraph_properties();
default_style* style_d = dynamic_cast<default_style*>(odf_style_.get());
if (style_d) return style_d->style_content_.get_style_paragraph_properties();
return NULL;
}
style_graphic_properties * odf_style_state::get_graphic_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_)return style_->style_content_.get_style_graphic_properties();
default_style* default_style_ = dynamic_cast<default_style*>(odf_style_.get());
if (default_style_)return default_style_->style_content_.get_style_graphic_properties();
return style_->style_content_.get_style_graphic_properties();
return NULL;
}
style_table_properties * odf_style_state::get_table_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_) return style_->style_content_.get_style_table_properties();
default_style* default_style_ = dynamic_cast<default_style*>(odf_style_.get());
if (default_style_) return default_style_->style_content_.get_style_table_properties();
return style_->style_content_.get_style_table_properties();
return NULL;
}
style_section_properties * odf_style_state::get_section_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_) return style_->style_content_.get_style_section_properties();
return style_->style_content_.get_style_section_properties();
default_style* default_style_ = dynamic_cast<default_style*>(odf_style_.get());
if (default_style_) return default_style_->style_content_.get_style_section_properties();
return NULL;
}
style_table_cell_properties * odf_style_state::get_table_cell_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_) return style_->style_content_.get_style_table_cell_properties();
default_style* default_style_ = dynamic_cast<default_style*>(odf_style_.get());
if (default_style_) return default_style_->style_content_.get_style_table_cell_properties();
return style_->style_content_.get_style_table_cell_properties();
return NULL;
}
style_table_row_properties * odf_style_state::get_table_row_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_) return style_->style_content_.get_style_table_row_properties();
default_style* default_style_ = dynamic_cast<default_style*>(odf_style_.get());
if (default_style_) return default_style_->style_content_.get_style_table_row_properties();
return style_->style_content_.get_style_table_row_properties();
return NULL;
}
style_table_column_properties * odf_style_state::get_table_column_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_) return style_->style_content_.get_style_table_column_properties();
default_style* default_style_ = dynamic_cast<default_style*>(odf_style_.get());
if (default_style_) return default_style_->style_content_.get_style_table_column_properties();
return style_->style_content_.get_style_table_column_properties();
return NULL;
}
style_chart_properties * odf_style_state::get_chart_properties()
{
style* style_ = dynamic_cast<style*>(odf_style_.get());
if (!style_)return NULL;
if (style_) return style_->style_content_.get_style_chart_properties();
default_style* default_style_ = dynamic_cast<default_style*>(odf_style_.get());
if (default_style_) return default_style_->style_content_.get_style_chart_properties();
return style_->style_content_.get_style_chart_properties();
return NULL;
}
//style_drawing_page_properties * odf_style_state::get_drawing_page_properties()
//{
......
......@@ -42,7 +42,8 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
void set_name(std::wstring & name);
std::wstring & get_name();
style_family & get_family();
void set_number_format(int id) {num_fmt_id_ = id;}
int get_number_format() {return num_fmt_id_;}
......
......@@ -10,6 +10,7 @@
#include "styles.h"
#include "style_text_properties.h"
#include "style_paragraph_properties.h"
#include "text_elements.h"
#include "paragraph_elements.h"
......@@ -192,6 +193,8 @@ void odf_text_context::add_textline_break()
}
void odf_text_context::add_text_style(office_element_ptr & style_elm, std::wstring style_name)
{
if (style_name.size() < 1 || !style_elm)return;
if (text_elements_list_.size() < 1 )return;
if (text_span* span = dynamic_cast<text_span*>(text_elements_list_.back().elm.get()))
{
......@@ -210,27 +213,52 @@ void odf_text_context::add_text_style(office_element_ptr & style_elm, std::wstri
}
}
void odf_text_context::add_page_break()
void odf_text_context::add_tab()
{
office_element_ptr elm;
create_element(L"text", L"soft-page-break", elm, odf_context_);
bool in_span = false;
if (text_span* span = dynamic_cast<text_span*>(current_level_.back().get()))
{
in_span = true;
end_span(); // todoo -
}
create_element(L"text", L"tab", elm, odf_context_);
if (current_level_.size()>0)
current_level_.back()->add_child_element(elm);
}
void odf_text_context::add_page_break()
{
// office_element_ptr elm;
//create_element(L"text", L"soft-page-break", elm, odf_context_);
//end paragraph + style add after-break = page
//start paragraph - continues style
if (in_span)
{
start_span(false);
}
//bool in_span = false;
//if (text_span* span = dynamic_cast<text_span*>(current_level_.back().get()))
//{
// in_span = true;
// end_span(); // todoo -
//}
//bool in_paragraph = false;
//if (text_p* p = dynamic_cast<text_p*>(current_level_.back().get()))
//{
// in_paragraph = true;
////fo:break-before
if (paragraph_properties_) paragraph_properties_->content().fo_break_before_ = fo_break(fo_break::Page);
//if (current_level_.size()>0)
// current_level_.back()->add_child_element(elm);
// end_paragraph(); // todoo -
//}
////end paragraph + style add after-break = page
////start paragraph - continues style
//if (in_paragraph)
//{
//// start_paragraph(false);
//
// //if (current_level_.size()>0)
// // current_level_.back()->add_child_element(elm);
//}
//if (in_span)
//{
// start_span(false);
//}
}
void odf_text_context::set_parent_paragraph_style(std::wstring & style_name)
{
......
......@@ -56,6 +56,7 @@ public:
void add_textline_break();
void add_page_break();
void add_tab();
std::vector<office_element_ptr> current_level_;//
......
......@@ -33,7 +33,7 @@ class graphic_format_properties
{
public:
graphic_format_properties(); //for defaults set
//void apply_from(const graphic_format_properties & Other);
void apply_from(const graphic_format_properties & Other);
void serialize(std::wostream & strm, const wchar_t * ns, const wchar_t * name );
......
......@@ -181,6 +181,7 @@ void paragraph_format_properties::serialize(std::wostream & _Wostream ,const wch
CP_XML_ATTR_OPT(L"style:writing-mode", style_writing_mode_);
CP_XML_ATTR_OPT(L"style:writing-mode-automatic", style_writing_mode_automatic_);
CP_XML_ATTR_OPT(L"style:snap-to-layout-grid", style_snap_to_layout_grid_);
CP_XML_ATTR_OPT(L"style:contextual-spacing", style_contextual_spacing_);
//_CP_OPT(std::wstring) style_page_number_str_;
//CP_XML_ATTR_OPT(L"style:page-number", style_page_number_str_);
......
......@@ -335,6 +335,8 @@ public:
//
_CP_OPT(Bool) style_join_border_;
_CP_OPT(Bool) style_contextual_spacing_;
};
/// \class style_paragraph_properties
......
#pragma once
#include <boost_filesystem_version.h>
#include <boost/lexical_cast.hpp>
#include <cpdoccore/CPOptional.h>
#include <atlcoll.h>
static std::wstring string2std_string(CString val)
......
......@@ -12,6 +12,8 @@ namespace OOX
{
class CDocx;
class CTheme;
class CDocDefaults;
class CStyle;
namespace Logic
{
......@@ -75,8 +77,8 @@ namespace Oox2Odf
odf::odt_conversion_context *odt_context;
OOX::Logic::CDrawing *docx_current_drawing; // .. ,
void convert_document();
void convert_styles();
void convert(OOX::WritingElement *oox_unknown);
......@@ -84,6 +86,8 @@ namespace Oox2Odf
void convert(OOX::Logic::CRun *oox_run);
void convert(OOX::Logic::CParagraphProperty *oox_paragraph_prop, odf::style_paragraph_properties *paragraph_properties);
void convert(OOX::Logic::CRunProperty *oox_run_prop, odf::style_text_properties *text_properties);
void convert(OOX::Logic::CPBdr *oox_border, odf::style_paragraph_properties *paragraph_properties);
void convert(ComplexTypes::Word::CShading *oox_shading, odf::style_text_properties *text_properties );
void convert(OOX::Logic::CText *oox_text);
void convert(OOX::Logic::CAlternateContent *oox_alt_content);
void convert(OOX::Logic::CDrawing *oox_drawing);
......@@ -94,15 +98,17 @@ namespace Oox2Odf
void convert(OOX::Logic::CShape *oox_shape);
void convert(OOX::Drawing::CChart *oox_chart);
void convert(OOX::Drawing::CPicture *oox_chart);
void convert(ComplexTypes::Word::CColor *color, _CP_OPT(odf::color) & odf_color);
void convert(SimpleTypes::CUniversalMeasure *oox_size, _CP_OPT(odf::length) & odf_size);
void convert(ComplexTypes::Word::CJc *oox_jc, _CP_OPT(odf::text_align) & align);
void convert(OOX::Logic::CPBdr *oox_border, odf::style_paragraph_properties * paragraph_properties);
void convert(ComplexTypes::Word::CColor *color, _CP_OPT(odf::color) & odf_color);
void convert(SimpleTypes::CUniversalMeasure *oox_size, _CP_OPT(odf::length) & odf_size);
void convert(SimpleTypes::CUniversalMeasure *oox_size, _CP_OPT(odf::length_or_percent) & odf_size);
void convert(ComplexTypes::Word::CJc *oox_jc, _CP_OPT(odf::text_align) & align);
void convert(ComplexTypes::Word::CBorder *borderProp, std::wstring & odf_border_prop);
void convert(ComplexTypes::Word::CShading *oox_shading, odf::style_text_properties * text_properties );
void convert(SimpleTypes::CHexColor<> *color, SimpleTypes::CThemeColor<> *theme_color,
SimpleTypes::CUcharHexNumber<>* theme_tint,
SimpleTypes::CUcharHexNumber<>* theme_shade, _CP_OPT(odf::color) & odf_color);
void convert(OOX::CDocDefaults *def_style);
void convert(OOX::CStyle *style);
};
}
\ 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