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

outline

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@57062 954022d7-b5bf-4e40-9824-e11837661b57
parent ed5b4dac
......@@ -7,12 +7,25 @@
#include "logging.h"
#include "styles.h"
#include "style_paragraph_properties.h"
#include <boost/foreach.hpp>
#include <iostream>
namespace cpdoccore {
namespace odf {
void calc_paragraph_properties_content(std::vector<style_paragraph_properties*> & parProps, paragraph_format_properties * result)
{
if (result == NULL)return;
BOOST_REVERSE_FOREACH(style_paragraph_properties* v, parProps)
{
if (v)
result->apply_from(v->content());
}
}
odf_style_context::odf_style_context()
{
}
......@@ -211,6 +224,24 @@ bool odf_style_context::find_odf_style_state(int oox_id_style, const style_famil
}
return false;
}
bool odf_style_context::find_odf_style(std::wstring style_name, style_family::type family, style *& style_)
{
for (int i=0;i<style_state_list_.size(); i++)
{
if (style_state_list_[i].odf_style_)
{
if (style_state_list_[i].style_family_.get_type() == family && style_state_list_[i].get_name() == style_name)
{
style_ = dynamic_cast<style*>(style_state_list_[i].odf_style_.get());
return true;
}
}
}
return false;
}
office_element_ptr odf_style_context::find_odf_style_default(const style_family family)
{
for (int i=0;i<current_default_styles_.size(); i++)
......@@ -305,6 +336,24 @@ office_element_ptr & odf_style_context::add_or_find(std::wstring name, const sty
return last_state().get_office_element();
}
void odf_style_context::calc_paragraph_properties(std::wstring style_name, style_family::type family, paragraph_format_properties * result)
{
std::vector<style_paragraph_properties*> parProps;
while (style_name.length()>0)
{
style *style_ = NULL;
if (!find_odf_style(style_name, family, style_) || !style_)break;
if (style_paragraph_properties * parProp = style_->style_content_.get_style_paragraph_properties())
parProps.push_back(parProp);
style_name = style_->style_parent_style_name_ ? *style_->style_parent_style_name_ : L"";
}
calc_paragraph_properties_content(parProps, result);
}
}
}
\ No newline at end of file
#pragma once
#include <string>
#include "odf_style_state.h"
#include "odf_number_styles_context.h"
......@@ -8,17 +9,17 @@
namespace cpdoccore {
namespace odf {
//class ods_conversion_context;
//class odt_conversion_context;
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 style;
class paragraph_format_properties;
class odf_style_context
{
public:
......@@ -42,16 +43,18 @@ public:
void reset_defaults();
void add_default(odf_style_state & state) {current_default_styles_.push_back(state);}
std::wstring find_odf_style_name (int oox_id_style, const style_family family, bool root = false);
office_element_ptr find_odf_style (int oox_id_style, const style_family family, bool root = false);
std::wstring find_odf_style_name (int oox_id_style, const style_family family, bool root = false);
office_element_ptr find_odf_style (int oox_id_style, const style_family family, bool root = false);
std::wstring find_odf_style_name_default(const style_family family);
office_element_ptr find_odf_style_default (const style_family family);
std::wstring find_odf_style_name_default (const style_family family);
office_element_ptr find_odf_style_default (const style_family family);
std::wstring find_conditional_style_name(int oox_id_style, const style_family family);
std::wstring find_conditional_style_name (int oox_id_style, const style_family family);
office_element_ptr find_conditional_style (int oox_id_style, const style_family family);
bool find_odf_style_state(int oox_id_style, const style_family family, odf_style_state *& state, bool root = false);
bool find_odf_style(std::wstring style_name, style_family::type family, style *& style_);
odf_style_state & last_state();
odf_style_state * last_state(style_family family);
......@@ -60,6 +63,9 @@ public:
std::wstring find_free_name(const style_family family);
//////////////////////////////////////////////////////////////////////
void calc_paragraph_properties(std::wstring style_name, style_family::type family, paragraph_format_properties * result);
private:
odf_number_styles_context number_styles_context_;
odf_conversion_context * odf_context_;
......
......@@ -40,14 +40,16 @@ public:
void add_child(office_element_ptr & child);
/////////////////////////////////////////////////////////////////////////////////////////
void set_name(std::wstring & name);
std::wstring & get_name();
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_;}
void set_parent_style_name(std::wstring & name) ;
void set_data_style_name(std::wstring & name);
void set_display_name(std::wstring & name);
......
......@@ -29,6 +29,8 @@ odf_text_context::odf_text_context(odf_conversion_context *odf_context)
text_properties_ = NULL;
last_paragraph_ = NULL;
current_outline_ = 0;
}
odf_text_context::~odf_text_context()
{
......@@ -64,7 +66,18 @@ void odf_text_context::add_text_content(const std::wstring & text)
void odf_text_context::start_paragraph(bool styled)
{
office_element_ptr paragr_elm;
create_element(L"text", L"p",paragr_elm,odf_context_);
if (current_outline_ > 0)
{
create_element(L"text", L"h",paragr_elm,odf_context_);
text_h* h = dynamic_cast<text_h*>(paragr_elm.get());
if (h)h->text_outline_level_ = current_outline_ + 1;
}
else
{
create_element(L"text", L"p",paragr_elm,odf_context_);
}
current_outline_ = 0;
start_paragraph(paragr_elm, styled);
......@@ -84,23 +97,31 @@ void odf_text_context::start_paragraph(office_element_ptr & elm, bool styled)
office_element_ptr style_elm;
if (styled)
{
{
style_name = styles_context_->last_state().get_name();
style_elm = styles_context_->last_state().get_office_element();
text_p* p = dynamic_cast<text_p*>(elm.get());
if (p)p->paragraph_.paragraph_attrs_.text_style_name_ = style_ref(style_name);
if (parent_paragraph_style_.length() >0)
text_h* h = dynamic_cast<text_h*>(elm.get());
if (h)h->paragraph_.paragraph_attrs_.text_style_name_ = style_ref(style_name);
style *style_ = dynamic_cast<style*>(style_elm.get());
if (style_)
{
style *style_ = dynamic_cast<style*>(style_elm.get());
if (style_)style_->style_parent_style_name_ = parent_paragraph_style_;
if (parent_paragraph_style_.length() >0)style_->style_parent_style_name_ = parent_paragraph_style_;
paragraph_properties_ = style_->style_content_.get_style_paragraph_properties();//
}
}
else if (parent_paragraph_style_.length() >0)
{
text_p* p = dynamic_cast<text_p*>(elm.get());
if (p)p->paragraph_.paragraph_attrs_.text_style_name_ = style_ref(parent_paragraph_style_);
text_h* h = dynamic_cast<text_h*>(elm.get());
if (h)p->paragraph_.paragraph_attrs_.text_style_name_ = style_ref(parent_paragraph_style_);
}
odf_text_state state={elm, style_name, style_elm,level};
......@@ -191,11 +212,18 @@ void odf_text_context::add_textline_break()
if (current_level_.size()>0)
current_level_.back()->add_child_element(elm);
}
void odf_text_context::set_outline_level(int level)
{
current_outline_ = level;
}
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()))
{
span->text_style_name_ = style_ref(style_name);
......@@ -212,6 +240,13 @@ void odf_text_context::add_text_style(office_element_ptr & style_elm, std::wstri
text_elements_list_.back().style_name = style_name;
}
if (text_h* h = dynamic_cast<text_h*>(text_elements_list_.back().elm.get()))
{
h->paragraph_.paragraph_attrs_.text_style_name_ = style_ref(style_name);
text_elements_list_.back().style_elm = style_elm;
text_elements_list_.back().style_name = style_name;
}
}
void odf_text_context::add_tab()
{
......
......@@ -58,6 +58,8 @@ public:
void add_page_break();
void add_tab();
int current_outline_;
std::vector<office_element_ptr> current_level_;//
std::vector<odf_text_state> text_elements_list_;//, , ...
......@@ -67,6 +69,8 @@ public:
style_text_properties *get_text_properties(){return text_properties_;}
style_paragraph_properties *get_paragraph_properties(){return paragraph_properties_;}
void set_outline_level(int level);
private:
bool single_paragraph_;
style_paragraph_properties *paragraph_properties_;//- , ,
......
......@@ -212,7 +212,7 @@ void style_paragraph_properties::serialize(std::wostream & strm)
{
style_paragraph_properties_content_.serialize(strm,ns,name);
}
void paragraph_format_properties::apply_from(const paragraph_format_properties & Other)
void paragraph_format_properties::apply_from(paragraph_format_properties & Other)
{
apply_line_width(fo_line_height_, Other.fo_line_height_);
_CP_APPLY_PROP(style_line_height_at_least_, Other.style_line_height_at_least_);
......@@ -283,6 +283,8 @@ void paragraph_format_properties::apply_from(const paragraph_format_properties &
_CP_APPLY_PROP(style_page_number_, Other.style_page_number_);
_CP_APPLY_PROP(style_background_transparency_, Other.style_background_transparency_);
_CP_APPLY_PROP(style_join_border_, Other.style_join_border_);
_CP_APPLY_PROP(outline_level_, Other.outline_level_);
}
......
......@@ -166,7 +166,7 @@ public:
void serialize(std::wostream & strm, const wchar_t * ns, const wchar_t * name );
void apply_from(const paragraph_format_properties & Other);
void apply_from( paragraph_format_properties & Other);
public:
// 15.5.1 fo:line-height
......@@ -337,6 +337,13 @@ public:
_CP_OPT(Bool) style_join_border_;
_CP_OPT(Bool) style_contextual_spacing_;
//-----------------------------------------------------------------------------
//not writing elements - used in other place
//-----------------------------------------------------------------------------
_CP_OPT(unsigned int) outline_level_;
};
/// \class style_paragraph_properties
......
......@@ -207,7 +207,16 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
if (oox_paragraph == NULL) return;
bool styled = false;
odt_context->start_paragraph();
if (oox_paragraph->m_oParagraphProperty)
{
styled = true;
odt_context->styles_context()->create_style(L"",odf::style_family::Paragraph, true, false, -1);
odf::style_paragraph_properties * paragraph_properties = odt_context->styles_context()->last_state().get_paragraph_properties();
convert(oox_paragraph->m_oParagraphProperty, paragraph_properties);
}
odt_context->start_paragraph(styled);
for ( int nIndex = 0; nIndex < oox_paragraph->m_arrItems.GetSize(); nIndex++ )
{
......@@ -216,17 +225,7 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
{
case OOX::et_w_pPr:
{
styled = true;
OOX::Logic::CParagraphProperty* pPProp= static_cast<OOX::Logic::CParagraphProperty*>(oox_paragraph->m_arrItems[nIndex]);
odt_context->styles_context()->create_style(L"",odf::style_family::Paragraph, true, false, -1);
odf::style_paragraph_properties * paragraph_properties = odt_context->styles_context()->last_state().get_paragraph_properties();
//odf::style_text_properties * text_properties = odt_context->styles_context()->last_state().get_text_properties();
convert(pPProp, paragraph_properties/*, text_properties*/);
odt_context->text_context()->add_text_style(odt_context->styles_context()->last_state().get_office_element(),odt_context->styles_context()->last_state().get_name());
odt_context->text_context()->set_single_object(false, paragraph_properties,NULL);// - .. -
// ..
}break;
default:
convert(oox_paragraph->m_arrItems[nIndex]);
......@@ -360,7 +359,17 @@ void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_pr, cp
if (oox_paragraph_pr->m_oPStyle.IsInit() && oox_paragraph_pr->m_oPStyle->m_sVal.IsInit())
{
odt_context->styles_context()->last_state().set_parent_style_name(string2std_string(*oox_paragraph_pr->m_oPStyle->m_sVal));
std::wstring style_name = string2std_string(*oox_paragraph_pr->m_oPStyle->m_sVal);
odt_context->styles_context()->last_state().set_parent_style_name(style_name);
/////////////////////////find parent properties
cpdoccore::odf::style_paragraph_properties parent_paragraph_properties;
odt_context->styles_context()->calc_paragraph_properties(style_name,odf::style_family::Paragraph, &parent_paragraph_properties.content());
if (parent_paragraph_properties.content().outline_level_)
{
odt_context->text_context()->set_outline_level(*parent_paragraph_properties.content().outline_level_);
}
}
if (oox_paragraph_pr->m_oSpacing.IsInit())
......@@ -446,7 +455,7 @@ void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_pr, cp
convert(oox_paragraph_pr->m_oPBdr.GetPointer(), paragraph_properties);
if (oox_paragraph_pr->m_oRPr.IsInit())// !!!
if (oox_paragraph_pr->m_oRPr.IsInit())
{
odf::style_text_properties * text_properties = odf_context()->text_context()->get_text_properties();
if (text_properties)
......@@ -480,6 +489,12 @@ void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_pr, cp
}
//m_oSectPr
if (oox_paragraph_pr->m_oOutlineLvl.IsInit() && oox_paragraph_pr->m_oOutlineLvl->m_oVal.IsInit())
{
int level = oox_paragraph_pr->m_oOutlineLvl->m_oVal->GetValue();
paragraph_properties->content().outline_level_ = level;
odt_context->text_context()->set_outline_level ( level);
}
}
void DocxConverter::convert(OOX::Logic::CPBdr *oox_border, odf::style_paragraph_properties * paragraph_properties)
{
......@@ -1216,9 +1231,13 @@ void DocxConverter::convert(OOX::CStyle *oox_style)
if (oox_style->m_oRunPr.IsInit())
{
odf::style_text_properties * text_properties = odt_context->styles_context()->last_state().get_text_properties();
convert(oox_style->m_oRunPr.GetPointer(), text_properties);
}
if (oox_style->m_oParPr.IsInit())
{
odf::style_paragraph_properties * paragraph_properties = odt_context->styles_context()->last_state().get_paragraph_properties();
convert(oox_style->m_oParPr.GetPointer(), paragraph_properties);
}
if (oox_style->m_oBasedOn.IsInit() && oox_style->m_oBasedOn->m_sVal.IsInit())
odt_context->styles_context()->last_state().set_parent_style_name(string2std_string(*oox_style->m_oBasedOn->m_sVal));
......
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