Commit e646e21e authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatWriter - refactoring sections

parent eb968120
......@@ -49,8 +49,9 @@ namespace odf_reader {
namespace {
std::wstring process_border(border_style & borderStyle,
const _CP_OPT(border_widths) & borderLineWidths,
const _CP_OPT(length) & borderPadding, const std::wstring & Shadow = L"")
const _CP_OPT(border_widths)& borderLineWidths,
const _CP_OPT(length) & borderPadding,
const std::wstring & Shadow = L"")
{
std::wstring w_sz;
std::wstring w_color;
......@@ -66,20 +67,20 @@ std::wstring process_border(border_style & borderStyle,
double width = borderStyle.get_length().get_value_unit(length::pt);
//borderLineWidths ? borderLineWidths->get_summ_unit(length::pt) : borderStyle.get_length().get_value_unit(length::pt);
int szInt = (int)(0.5 + 8.0 * width);
if (szInt <= 0)
szInt = 1;
if (szInt <= 0) szInt = 1;
w_sz = boost::lexical_cast<std::wstring>( szInt );
w_color = boost::lexical_cast<std::wstring>( borderStyle.get_color().get_hex_value() );
if (borderPadding)
w_space = boost::lexical_cast<std::wstring>((int)(borderPadding->get_value_unit(length::pt) + 0.5) );
w_space = boost::lexical_cast<std::wstring>((int)(borderPadding->get_value_unit(length::pt)) );
switch(borderStyle.get_style())
{
case border_style::none: w_val = L"none"; break;
case border_style::solid:
case border_style::single:
w_val = L"single"; break;
case border_style::single: w_val = L"single"; break;
case border_style::double_: w_val = L"double"; break;
case border_style::dotted: w_val = L"dotted"; break;
case border_style::dashed: w_val = L"dashed"; break;
......
This diff is collapsed.
......@@ -1082,10 +1082,17 @@ void odf_drawing_context::set_solid_fill(std::wstring hexColor)
switch(impl_->current_drawing_part_)
{
case Area:
impl_->current_graphic_properties->content().common_draw_fill_attlist_.draw_fill_ = draw_fill::solid;
impl_->current_graphic_properties->content().common_draw_fill_attlist_.draw_fill_color_ = hexColor;
impl_->current_graphic_properties->content().common_background_color_attlist_.fo_background_color_ = color(hexColor);
//последнее нужно - что если будут вводить текст - под текстом будет цвет фона (или он поменяется в полях текста)
if ((impl_->is_footer_ || impl_->is_header_) &&
(impl_->current_graphic_properties->content().common_draw_fill_attlist_.draw_fill_) &&
(impl_->current_graphic_properties->content().common_draw_fill_attlist_.draw_fill_->get_type() == draw_fill::bitmap))
{
}
else
impl_->current_graphic_properties->content().common_draw_fill_attlist_.draw_fill_ = draw_fill::solid;
break;
case Line:
impl_->current_graphic_properties->content().svg_stroke_color_ = hexColor;
......@@ -1855,9 +1862,9 @@ void odf_drawing_context::start_image(std::wstring odf_path)
draw_image* image = dynamic_cast<draw_image*>(image_elm.get());
if (image == NULL)return;
image->common_xlink_attlist_.type_= xlink_type::Simple;
image->common_xlink_attlist_.type_ = xlink_type::Simple;
image->common_xlink_attlist_.show_ = xlink_show::Embed;
image->common_xlink_attlist_.actuate_= xlink_actuate::OnLoad;
image->common_xlink_attlist_.actuate_ = xlink_actuate::OnLoad;
if (!odf_path.empty()) image->common_xlink_attlist_.href_= odf_path; //may be later set
......
......@@ -71,21 +71,20 @@ odf_page_layout_context::~odf_page_layout_context()
odf_layout_state * odf_page_layout_context::last_layout()
{
if (layout_state_list_.size() >0)
if (!layout_state_list_.empty())
return &layout_state_list_.back();
else
return NULL;
}
odf_master_state * odf_page_layout_context::last_master()
{
if (master_state_list_.size() >0)
if (!master_state_list_.empty())
return &master_state_list_.back();
else
return NULL;
}
void odf_page_layout_context::start_master_page(std::wstring page_name)
void odf_page_layout_context::add_master_page(std::wstring page_name)
{
office_element_ptr elm;
create_element(L"style", L"master-page", elm, odf_context_);
......@@ -94,7 +93,9 @@ void odf_page_layout_context::start_master_page(std::wstring page_name)
master_state_list_.push_back( odf_master_state(elm) );
///////////////////////////////////////
if (page_name.length() <1)page_name =L"MasterPage" + boost::lexical_cast<std::wstring>(master_state_list_.size());
if (page_name.empty())
page_name = L"MasterPage" + boost::lexical_cast<std::wstring>(master_state_list_.size());
master_state_list_.back().set_name(page_name);
/////////////////////////
......@@ -102,68 +103,6 @@ void odf_page_layout_context::start_master_page(std::wstring page_name)
create_layout_page();
master_state_list_.back().set_layout_name(layout_state_list_.back().get_name());
}
void odf_page_layout_context::end_master_page()
{
if (master_state_list_.size() < 1)return;
bool header=false, f_header = false, l_header = false;
bool footer=false, f_footer = false, l_footer = false;
for (long i = 0; i < master_state_list_.back().elements_.size(); i++)
{
if (!master_state_list_.back().elements_[i].elm)continue;
if (master_state_list_.back().elements_[i].elm->get_type() == typeStyleHeader)header = true;
if (master_state_list_.back().elements_[i].elm->get_type() == typeStyleFooter)footer = true;
if (master_state_list_.back().elements_[i].elm->get_type() == typeStyleHeaderFirst)f_header = true;
if (master_state_list_.back().elements_[i].elm->get_type() == typeStyleFooterFirst)f_footer = true;
if (master_state_list_.back().elements_[i].elm->get_type() == typeStyleHeaderLeft)l_header = true;
if (master_state_list_.back().elements_[i].elm->get_type() == typeStyleFooterLeft)l_footer = true;
}
if (f_header && !f_footer && footer)
{
add_footer(2);
office_element_ptr blank_p_elm;
create_element(L"text", L"p", blank_p_elm, odf_context_);
master_state_list_.back().elements_.back().elm->add_child_element(blank_p_elm);
f_footer = true;
}
if (!f_header && f_footer && header)
{
add_header(2);
office_element_ptr blank_p_elm;
create_element(L"text", L"p", blank_p_elm, odf_context_);
master_state_list_.back().elements_.back().elm->add_child_element(blank_p_elm);
f_header = true;
}
//Так как лажовый Libra и Apach Оо не воспринимают бланковые колонтитулы только первых страниц - городим велосипед на остальные страницы
if (!header && (f_header || l_header))
{
add_header(0);
office_element_ptr blank_p_elm;
create_element(L"text", L"p", blank_p_elm, odf_context_);
master_state_list_.back().elements_.back().elm->add_child_element(blank_p_elm);
header = true;
}
if (!footer && (f_footer || l_footer))
{
add_footer(0);
office_element_ptr blank_p_elm;
create_element(L"text", L"p", blank_p_elm, odf_context_);
master_state_list_.back().elements_.back().elm->add_child_element(blank_p_elm);
footer = true;
}
}
void odf_page_layout_context::process_master_styles(office_element_ptr root )
{
......@@ -320,7 +259,8 @@ bool odf_page_layout_context::add_footer(int type)
if (type == 1)
{
if (even_and_left_headers_)create_element(L"style", L"footer-left", elm, odf_context_);
if (even_and_left_headers_)
create_element(L"style", L"footer-left", elm, odf_context_);
}
else if (type == 2)
create_element(L"style", L"footer-first", elm, odf_context_);
......@@ -330,7 +270,7 @@ bool odf_page_layout_context::add_footer(int type)
if (!elm) return false;
if (master_state_list_.empty())
start_master_page(L"");
add_master_page(L"");
master_state_list_.back().add_footer(elm);
/////////////////////////////////////////////////////////////////////
......@@ -377,17 +317,18 @@ bool odf_page_layout_context::add_header(int type)
if (type == 1)
{
if (even_and_left_headers_)create_element(L"style", L"header-left", elm, odf_context_);
if (even_and_left_headers_)
create_element(L"style", L"header-left", elm, odf_context_);
}
else if (type == 2)
create_element(L"style", L"header-first", elm, odf_context_);
else
create_element(L"style", L"header", elm, odf_context_);
if (!elm)return false;
if (!elm) return false;
if (master_state_list_.empty())
start_master_page(L"");
add_master_page(L"");
master_state_list_.back().add_header(elm);
////////////////////////////////////////////////////////////////////////
......@@ -594,15 +535,6 @@ void odf_page_layout_context::set_pages_mirrored(bool val)
}
}
void odf_page_layout_context::set_even_and_left_headers(bool val)
{
even_and_left_headers_ = val;
}
void odf_page_layout_context::set_title_page_enable(bool val)
{
}
style_page_layout_properties * odf_page_layout_context::get_properties()
{
if (layout_state_list_.size() < 1) return NULL;
......
......@@ -60,9 +60,8 @@ public:
void set_styles_context (odf_style_context * Context);
void start_master_page(std::wstring oox_name);
void add_master_page(std::wstring oox_name);
void create_layout_page();
void end_master_page();
void set_current_master_page_base();
......@@ -91,7 +90,6 @@ public:
void set_title_page_enable (bool val);
void set_pages_mirrored (bool val);
void set_even_and_left_headers (bool val);
bool add_footer(int type);
void set_footer_size(_CP_OPT(odf_types::length) length_);
......@@ -104,9 +102,9 @@ public:
void set_page_number_format (_CP_OPT(int) & type, _CP_OPT(int) & start);
double current_page_width_;
bool even_and_left_headers_;
private:
bool even_and_left_headers_;
style_page_layout_properties *get_properties();
style_header_footer_properties *get_header_properties();
......
......@@ -135,7 +135,7 @@ void ods_conversion_context::start_sheet()
drawing_context()->set_styles_context(styles_context());
page_layout_context()->set_styles_context(styles_context());
page_layout_context()->start_master_page(L"");
page_layout_context()->add_master_page(L"");
current_table().set_table_master_page(page_layout_context()->last_master() ?
page_layout_context()->last_master()->get_name() : L"");
......@@ -173,8 +173,6 @@ void ods_conversion_context::end_sheet()
table_context_.end_table();
styles_context()->reset_defaults();
page_layout_context()->end_master_page();
}
void ods_conversion_context::start_row(int _start_row, int repeated, int level, bool _default)
......
......@@ -241,7 +241,7 @@ void odt_conversion_context::end_drawings()
anchor_type::type anchor = drawing_context()->get_anchor();
bool bSet = false;
if ( anchor == anchor_type::Page || anchor == anchor_type::Paragraph)
if (( anchor == anchor_type::Page || anchor == anchor_type::Paragraph) || (is_header_ || is_footer_))
{
for (long i = text_context()->current_level_.size()-1; i>=0; i--)
{
......@@ -423,10 +423,16 @@ void odt_conversion_context::set_master_page_name(std::wstring master_name)
return;
}
style *style_ = dynamic_cast<style*>(current_root_elements_.back().style_elm.get());
if (!style_)
{
//генерация
}
if (style_)
{
is_paragraph_in_current_section_ = false;
style *style_ = dynamic_cast<style*>(current_root_elements_[0].style_elm.get());
if (style_)style_->style_master_page_name_ = master_name;
style_->style_master_page_name_ = master_name;
}
}
int odt_conversion_context::get_current_section_columns()
{
......@@ -1005,6 +1011,26 @@ void odt_conversion_context::end_header_footer()
is_footer_ = false;
}
void odt_conversion_context::add_empty_header(int type)
{
if (start_header(type))
{
start_paragraph(false);
end_paragraph();
}
end_header_footer();
}
void odt_conversion_context::add_empty_footer(int type)
{
if (start_footer(type))
{
start_paragraph(false);
end_paragraph();
}
end_header_footer();
}
void odt_conversion_context::set_background(_CP_OPT(color) & color, int type)
{
if (!color) return;
......
......@@ -147,6 +147,9 @@ public:
bool start_footer(int type);
void end_header_footer();
void add_empty_header(int type);
void add_empty_footer(int type);
void set_background(_CP_OPT(color) & color, int type);
bool is_paragraph_in_current_section_;
......
......@@ -140,6 +140,18 @@ namespace Oox2Odf
void convert(OOX::WritingElement *oox_unknown);
private:
struct _section
{
_section() : start_para(0), end_para(-1), props(NULL), root(false) {}
_section(OOX::Logic::CSectionProperty *s, int start = 0, int end = -1, bool r = false) : props(s), start_para(start), end_para(end), root(r) {}
OOX::Logic::CSectionProperty *props;
int start_para;
int end_para;
bool root;
} *current_section_properties;
OOX::CDocx *docx_document;
cpdoccore::odf_writer::package::odf_document *output_document;
......
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