Commit 6ed698c4 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatWriter - extending convert content (styles, elements, ...)

parent e1e58466
......@@ -83,6 +83,7 @@ void draw_shape::serialize_attlist(CP_ATTR_NODE)
void draw_rect_attlist::serialize(CP_ATTR_NODE)
{
CP_XML_ATTR_OPT(L"draw:filter-name", draw_filter_name_);
CP_XML_ATTR_OPT(L"draw:corner-radius", draw_corner_radius_);
}
const wchar_t * draw_rect::ns = L"draw";
......
......@@ -70,10 +70,10 @@ class draw_rect_attlist
{
public:
_CP_OPT(odf_types::length) draw_corner_radius_;
_CP_OPT(std::wstring) draw_filter_name_;
void serialize(CP_ATTR_NODE);
void serialize(CP_ATTR_NODE);
};
class draw_rect : public draw_shape
......
......@@ -1354,9 +1354,16 @@ void odf_drawing_context::set_horizontal_pos(double offset_pt)
impl_->anchor_settings_.style_horizontal_pos_svg_x_ = length(length(offset_pt,length::pt).get_value_unit(length::cm),length::cm);
impl_->x = offset_pt;
}
void odf_drawing_context::set_default_wrap_style()
{
if (impl_->is_header_ || impl_->is_footer_ )
{
impl_->anchor_settings_.style_wrap_ = style_wrap::RunThrough;
}
}
void odf_drawing_context::set_wrap_style(style_wrap::type type)
{
impl_->anchor_settings_.style_wrap_ = style_wrap(type);
}
void odf_drawing_context::set_overlap (bool val)
......@@ -1612,6 +1619,20 @@ void odf_drawing_context::set_line_head(int type, int len, int width)
impl_->current_graphic_properties->content().draw_marker_start_width_ = length(0.2,length::cm); break;
}
}
void odf_drawing_context::set_corner_radius (odf_types::length corner)
{
if (impl_->current_level_.empty())return;
draw_rect* draw = dynamic_cast<draw_rect*>(impl_->current_level_.back().get());
if (draw)
{
draw->draw_rect_attlist_.draw_corner_radius_ = corner;
}
}
std::wstring odf_drawing_context::add_marker_style(int type)
{
if (type == 2) return L"";
......
......@@ -39,6 +39,7 @@
#include "office_elements_create.h"
#include "length.h"
#include "anchortype.h"
#include "stylewrap.h"
#include "gradientstyle.h"
......@@ -86,6 +87,7 @@ public:
void set_horizontal_pos (int align);
void set_horizontal_pos (double offset_pt);
void set_default_wrap_style();
void set_wrap_style (odf_types::style_wrap::type style);
void set_overlap (bool val);
......@@ -108,6 +110,8 @@ public:
void set_group_scale (double cx, double cy);
void set_group_shift (double x, double y);
void set_corner_radius (odf_types::length corner);
void end_group();
void start_shape (int type);
......
......@@ -101,13 +101,6 @@ void odf_text_context::set_single_object(bool bSingle, style_paragraph_propertie
single_paragraph_ = bSingle;
paragraph_properties_ = para_props;
text_properties_ = text_props;
//if (paragraph_properties_)//??? а могут ли быть разрывы после-до диаграммы???
//{
// paragraph_properties_->content().fo_break_before_ = need_break_;
// need_break_ = boost::none;
//}
}
void odf_text_context::add_text_content(const std::wstring & text)
......@@ -605,7 +598,8 @@ bool odf_text_context::set_master_page_name (std::wstring & master_page_name)
style *style_ = dynamic_cast<style*>(current_level_.back().style_elm.get());
if (!style_) return false;
if (!style_)
return false;
style_->style_master_page_name_ = master_page_name;
return true;
......
......@@ -287,7 +287,7 @@ void odt_conversion_context::add_page_break()
office_element_ptr elm;
create_element(L"text", L"soft-page-break", elm, this);
if (current_root_elements_.size() > 0/* && text_context()->is_need_break()*/)
if (current_root_elements_.size() > 0)
{
text_p* para = NULL;
style * style_ = NULL;
......@@ -303,6 +303,7 @@ void odt_conversion_context::add_page_break()
{
//тут получается что разрыв будет прописан внутри элемента (не параграфа) - так что вручную свойство запишем
//в случае разрыва параграфов оно запишется при старте после-разрывного параграфа
text_context()->set_type_break(1, 0);
text_context()->save_property_break();
}
text_context()->start_element(elm);
......@@ -311,7 +312,7 @@ void odt_conversion_context::add_page_break()
if (para)
{
styles_context()->create_style(L"",odf_types::style_family::Paragraph, true, false, -1);
styles_context()->create_style(L"", odf_types::style_family::Paragraph, true, false, -1);
//styles_context()->last_state().apply_from(style_);
if (style_ )
{
......@@ -332,7 +333,7 @@ void odt_conversion_context::add_page_break()
void odt_conversion_context::start_hyperlink(std::wstring ref)
{
office_element_ptr hyperlink_elm;
create_element(L"text", L"a",hyperlink_elm,this);
create_element(L"text", L"a", hyperlink_elm, this);
text_a* hyperlink = dynamic_cast<text_a*>(hyperlink_elm.get());
if (!hyperlink)return;
......@@ -340,7 +341,7 @@ void odt_conversion_context::start_hyperlink(std::wstring ref)
////////////////////////////
hyperlink->common_xlink_attlist_.href_ = ref;
hyperlink->common_xlink_attlist_.type_= xlink_type::Simple;
hyperlink->common_xlink_attlist_.type_ = xlink_type::Simple;
//current_level_.back()->add_child_element(hyperlink_elm);
//current_level_.push_back(hyperlink_elm);
......
......@@ -51,7 +51,7 @@ namespace odf_writer {
using xml::xml_char_wc;
// style:tab-stop
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * style_tab_stop::ns = L"style";
const wchar_t * style_tab_stop::name = L"tab-stop";
......@@ -75,7 +75,6 @@ void style_tab_stop::serialize(std::wostream & strm)
}
}
}
// style:tab-stop
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * style_tab_stops::ns = L"style";
const wchar_t * style_tab_stops::name = L"tab-stops";
......@@ -97,7 +96,7 @@ void style_tab_stops::add_child_element( const office_element_ptr & child_elemen
{
style_tab_stops_.push_back(child_element);
}
// style:drop-cap
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * style_drop_cap::ns = L"style";
const wchar_t * style_drop_cap::name = L"drop-cap";
......@@ -116,7 +115,7 @@ void style_drop_cap::serialize(std::wostream & strm)
}
}
// style:background-image
//////////////////////////////////////////////////////////////////////////////////////////////////
const wchar_t * style_background_image::ns = L"style";
const wchar_t * style_background_image::name = L"background-image";
......@@ -304,7 +303,7 @@ void paragraph_format_properties::clear()
fo_padding_right_ = boost::none;
outline_level_ = boost::none;
style_page_number_ = boost::none;
style_snap_to_layout_grid_= boost::none;
style_snap_to_layout_grid_ = boost::none;
style_join_border_ = boost::none;
style_text_autospace_ = boost::none;
fo_keep_with_next_ = boost::none;
......@@ -314,14 +313,13 @@ void paragraph_format_properties::clear()
style_writing_mode_automatic_= boost::none;
style_line_break_ = boost::none;
style_background_transparency_= boost::none;
style_text_autospace_= boost::none;
style_text_autospace_ = boost::none;
text_line_number_ = boost::none;
style_line_break_ = boost::none;
text_number_lines_ = boost::none;
style_shadow_ = boost::none;
//todo borders !!!
//todooo borders
}
void paragraph_format_properties::apply_from(paragraph_format_properties & Other)
......
......@@ -76,7 +76,6 @@ namespace oox{
namespace odf_writer {
/// \class style_tab_stop
class style_tab_stop : public office_element_impl<style_tab_stop>
{
public:
......@@ -108,7 +107,6 @@ public:
CP_REGISTER_OFFICE_ELEMENT2(style_tab_stop)
/// \class style_tab_stops
class style_tab_stops : public office_element_impl<style_tab_stops>
{
public:
......@@ -131,7 +129,7 @@ public:
CP_REGISTER_OFFICE_ELEMENT2(style_tab_stops)
/// \class style_drop_cap
class style_drop_cap : public office_element_impl<style_drop_cap>
{
public:
......@@ -157,8 +155,6 @@ public:
CP_REGISTER_OFFICE_ELEMENT2(style_drop_cap)
/// \class style_background_image
/// style:background-image
class style_background_image : public office_element_impl<style_background_image>
{
public:
......@@ -186,7 +182,6 @@ public:
CP_REGISTER_OFFICE_ELEMENT2(style_background_image)
/// \class paragraph_format_properties
class paragraph_format_properties
{
public:
......@@ -265,7 +260,6 @@ public:
};
/// \class style_paragraph_properties
class style_paragraph_properties : public office_element_impl<style_paragraph_properties>
{
public:
......
......@@ -69,7 +69,6 @@ namespace cpdoccore {
namespace odf_writer {
// 15.4
class text_format_properties_content
{
public:
......@@ -79,10 +78,8 @@ public:
void set_r_style(const std::wstring & rStyle) { r_style_ = rStyle; }
private:
//static double process_font_size_impl(const _CP_OPT(font_size) & FontSize, const style_instance * currnetStyle, bool Complex = false, double Mul = 1.0);
//static int process_font_weight(const optional<font_weight>::Type & FontWeight);
//static int process_font_style(const optional<font_style>::Type & FontStyle);
void clear();
public:
_CP_OPT(std::wstring) r_style_;
......@@ -202,8 +199,6 @@ public:
class style_text_properties;
typedef shared_ptr<style_text_properties>::Type style_text_properties_ptr;
/// \class style_text_properties
/// style:text-properties
class style_text_properties : public office_element_impl<style_text_properties>
{
public:
......
......@@ -142,6 +142,16 @@ void OoxConverter::convert(SimpleTypes::Vml::CCssStyle *vml_style, bool group)
{
switch(vml_style->m_arrProperties[i]->get_Value().eMsoPosHorRel)
{
case SimpleTypes::Vml::cssmsoposhorrelRightMargin:
{
anchor_type_x = 2;
odf_context()->drawing_context()->set_horizontal_rel(5);
}break;
case SimpleTypes::Vml::cssmsoposhorrelLeftMargin:
{
anchor_type_x = 2;
odf_context()->drawing_context()->set_horizontal_rel(4);
}break;
case SimpleTypes::Vml::cssmsoposhorrelMargin:
{
anchor_type_x = 2;
......@@ -175,6 +185,13 @@ void OoxConverter::convert(SimpleTypes::Vml::CCssStyle *vml_style, bool group)
{
switch(vml_style->m_arrProperties[i]->get_Value().eMsoPosVerRel)
{
case SimpleTypes::Vml::cssmsoposverrelBottomMargin:
{
anchor_type_y = 2;
odf_context()->drawing_context()->set_vertical_pos(0);
odf_context()->drawing_context()->set_vertical_rel(3);
}break;
case SimpleTypes::Vml::cssmsoposverrelTopMargin:
case SimpleTypes::Vml::cssmsoposverrelMargin:
{
anchor_type_y = 2;
......@@ -673,6 +690,8 @@ void OoxConverter::convert(OOX::VmlWord::CWrap *vml_wrap)
{
if (vml_wrap == NULL) return;
odf_context()->drawing_context()->set_default_wrap_style();
if (vml_wrap->m_oType.IsInit())
{
switch(vml_wrap->m_oType->GetValue())
......@@ -709,6 +728,7 @@ void OoxConverter::convert(OOX::VmlWord::CWrap *vml_wrap)
}break;
}
}
bool anchor_page_x = false;
if (vml_wrap->m_oAnchorX.IsInit())
{
......@@ -747,6 +767,7 @@ void OoxConverter::convert(OOX::VmlWord::CWrap *vml_wrap)
odf_context()->drawing_context()->set_vertical_rel(2);//Line
}
}
}
void OoxConverter::convert(OOX::Vml::CVmlCommonElements *vml_common)
{
......
......@@ -408,8 +408,14 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
{
if (oox_paragraph == NULL) return;
bool bStyled = false;
if (current_section_properties)
{
if (odt_context->text_context()->get_KeepNextParagraph())
odt_context->end_paragraph();
odt_context->text_context()->set_KeepNextParagraph(false);
}
bool bStyled = false;
bool bStartNewParagraph = !odt_context->text_context()->get_KeepNextParagraph();
bool list_present = false;
......@@ -425,7 +431,7 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
std::wstring style_name = string2std_string(*oox_paragraph->m_oParagraphProperty->m_oPStyle->m_sVal);
odf_writer::odf_style_state_ptr style_state;
if (odt_context->styles_context()->find_odf_style_state(style_name,odf_types::style_family::Paragraph, style_state) && style_state)
if (odt_context->styles_context()->find_odf_style_state(style_name, odf_types::style_family::Paragraph, style_state) && style_state)
{
list_present = style_state->get_list_style_exist();
list_level = style_state->get_list_style_level();
......@@ -452,7 +458,10 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
if (oox_paragraph->m_oParagraphProperty || odt_context->is_empty_section() || current_section_properties)
{
bStyled = true;
bool bRunPara = oox_paragraph->m_oParagraphProperty ? (oox_paragraph->m_oParagraphProperty->m_oRPr.IsInit() ? true : false) : false;
odf_writer::style_paragraph_properties *paragraph_properties = NULL;
odf_writer::style_text_properties *text_properties = NULL;
if (odt_context->text_context()->get_KeepNextParagraph())
{
......@@ -461,17 +470,25 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
{
paragraph_properties = state->get_paragraph_properties();
if (bRunPara)
text_properties = state->get_text_properties();
if (oox_paragraph->m_oParagraphProperty && oox_paragraph->m_oParagraphProperty->m_oPStyle.IsInit() && oox_paragraph->m_oParagraphProperty->m_oPStyle->m_sVal.IsInit())
{
//перезатираем все свойства ... наложение не катит -- ваще то надо чистить после буквицы (Nadpis.docx) .. проверить надобность с остальными случами
paragraph_properties->content().clear();
if (text_properties)
text_properties->content().clear();
}
}
}
else
{
odt_context->styles_context()->create_style(L"",odf_types::style_family::Paragraph, true, false, -1);
odt_context->styles_context()->create_style(L"", odf_types::style_family::Paragraph, true, false, -1);
paragraph_properties = odt_context->styles_context()->last_state()->get_paragraph_properties();
if (bRunPara)
text_properties = odt_context->styles_context()->last_state()->get_text_properties();
if(list_present && list_style_id >= 0)
{
......@@ -481,6 +498,8 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
}
convert(oox_paragraph->m_oParagraphProperty, paragraph_properties);
if (text_properties && oox_paragraph->m_oParagraphProperty)
convert(oox_paragraph->m_oParagraphProperty->m_oRPr.GetPointer(), text_properties);
}
else
{
......@@ -495,6 +514,21 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
if ((list_present = odt_context->text_context()->get_list_item_state()) == false) odt_context->set_no_list();
if (oox_paragraph->m_arrItems.size() < 2 && odt_context->text_context()->get_KeepNextParagraph())
{//rapcomnat12.docx - стр 185
bool empty_para = true;
for (unsigned int nIndex = 0; empty_para && nIndex < oox_paragraph->m_arrItems.size(); nIndex++ )
{
switch(oox_paragraph->m_arrItems[nIndex]->getType())
{
case OOX::et_w_pPr: break;
default:
empty_para = false;
}
}
if (empty_para) return;
}
if (bStartNewParagraph)
{
odt_context->start_paragraph(bStyled);
......@@ -579,12 +613,20 @@ void DocxConverter::convert(OOX::Logic::CRun *oox_run)//wordprocessing 22.1.2.87
}break;
case OOX::et_w_lastRenderedPageBreak:
{
//odt_context->text_context()->add_page_break(); выше
//odt_context->add_page_break();
}break;
case OOX::et_w_br:
{
OOX::Logic::CBr* pBr= static_cast<OOX::Logic::CBr*>(oox_run->m_arrItems[i]);
if (pBr)odt_context->text_context()->set_type_break(pBr->m_oType.GetValue(), pBr->m_oClear.GetValue());
if (pBr)
{
int type = pBr->m_oType.GetValue();
if (type == 1)
odt_context->add_page_break();
else
odt_context->text_context()->set_type_break(type, pBr->m_oClear.GetValue());
}
}break;
case OOX::et_w_t:
{
......@@ -924,7 +966,7 @@ void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_pr, cp
odt_context->text_context()->set_type_break(1, 0); //page, clear_all
}
if (oox_paragraph_pr->m_oKeepNext.IsInit() && odt_context->table_context()->empty()/* && !oox_paragraph_pr->m_oFramePr.IsInit()*/)
if (oox_paragraph_pr->m_oKeepNext.IsInit() && odt_context->table_context()->empty() && !current_section_properties)
{
odt_context->text_context()->set_KeepNextParagraph(true);
}
......@@ -938,12 +980,23 @@ void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_pr, cp
paragraph_properties->content().style_page_number_ = current_section_properties->props->m_oPgNumType->m_oStart->GetValue();
}
convert(current_section_properties->props, current_section_properties->root);
}
//if (oox_paragraph_pr->m_oSectPr.IsInit())
//odf_writer::odf_style_state_ptr state = odt_context->styles_context()->last_state(odf_types::style_family::Paragraph);
//if (odt_context->is_paragraph_in_current_section_ && state)
//{
// convert(oox_paragraph_pr->m_oSectPr.GetPointer()); перенесено выше
// odf_writer::style *style_ = dynamic_cast<odf_writer::style*>(state->get_office_element().get());
// if (style_)
// {
// odt_context->is_paragraph_in_current_section_ = false;
// style_->style_master_page_name_ = odt_context->page_layout_context()->last_master() ?
// odt_context->page_layout_context()->last_master()->get_name() : L"";
// }
//}
}
if (oox_paragraph_pr->m_oTabs.IsInit())
{
paragraph_properties->add_child_element(odf_context()->start_tabs());
......@@ -2093,7 +2146,10 @@ void DocxConverter::convert(OOX::Logic::CPicture* oox_pic)
else if (oox_pic->m_oShapeRoundRect.IsInit())
{
odf_context()->drawing_context()->set_name(L"RoundRect");
odf_context()->drawing_context()->start_shape(SimpleTypes::shapetypeRoundRect);
odf_context()->drawing_context()->start_shape(SimpleTypes::shapetypeRect);
odf_types::length corner = odf_types::length(0.5, odf_types::length::cm);
odf_context()->drawing_context()->set_corner_radius(corner);
OoxConverter::convert(oox_pic->m_oShape.GetPointer());
OoxConverter::convert(oox_pic->m_oShapeRoundRect.GetPointer());
......
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