Commit 369596b8 authored by ElenaSubbotina's avatar ElenaSubbotina

OdfFormatWriter - fix dropCap, sections

parent 15af8f56
......@@ -67,7 +67,7 @@
Name="VCLinkerTool"
AdditionalDependencies="Urlmon.lib"
LinkIncremental="1"
IgnoreDefaultLibraryNames="LIBCMTD.lib"
IgnoreDefaultLibraryNames=""
IgnoreEmbeddedIDL="true"
GenerateDebugInformation="true"
SubSystem="1"
......
......@@ -59,7 +59,7 @@ HRESULT convert_single(std::wstring srcFileName)
switch(fileChecker.nFileType)
{
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX:
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM: dstPath += L"-my.odt"; type = L"document"; break;
case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM: dstPath += L"-my.odt"; type = L"text"; break;
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX:
case AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSM: dstPath += L"-my.ods"; type = L"spreadsheet"; break;
......
......@@ -118,7 +118,7 @@ void odt_conversion_context::start_document()
void odt_conversion_context::end_document()
{
//add sections to root
for (size_t i = 0; i< sections_.size(); i++)
for (size_t i = 0; i < sections_.size(); i++)
{
root_document_->add_child_element(sections_[i].elm);
}
......@@ -183,7 +183,8 @@ odf_text_context* odt_conversion_context::text_context()
}
void odt_conversion_context::start_text_context()
{
odf_text_context_ptr new_text_context_ = boost::shared_ptr<odf_text_context>(new odf_text_context(this, odf_conversion_context::styles_context()));
odf_text_context_ptr new_text_context_ = boost::shared_ptr<odf_text_context>(new odf_text_context(this, /*odf_conversion_context::*/styles_context()));
//объекты с текстом в колонтитулах
if (!new_text_context_)return;
text_context_.push_back(new_text_context_);
......@@ -199,15 +200,16 @@ void odt_conversion_context::add_text_content(const std::wstring & text)
{
if (drop_cap_state_.enabled)
{
int count = text.size();
int count = text.length();
drop_cap_state_.characters += count;
if (drop_cap_state_.inline_style == false)
{
style_text_properties * props = text_context()->get_text_properties();
if (props)
{
if (drop_cap_state_.inline_style == false)
{
std::wstring f_name = props->content_.fo_font_family_.get_value_or(L"Arial");
double f_size = props->content_.fo_font_size_.get_value_or(font_size(length(12,length::pt))).get_length().get_value_unit(length::pt);
double f_size = props->content_.fo_font_size_.get_value_or(font_size(length(12, length::pt))).get_length().get_value_unit(length::pt);
drop_cap_state_.characters_size_pt += utils::calculate_size_font_symbols(text, f_name, f_size, applicationFonts_);
}
......@@ -479,6 +481,14 @@ int odt_conversion_context::get_current_section_columns()
}
void odt_conversion_context::add_section(bool continuous)
{
//--dump first elements to root------------------------------------------------
for (size_t i = 0; i< current_root_elements_.size(); i++)
{
root_document_->add_child_element(current_root_elements_[i].elm);
}
current_root_elements_.clear();
//----------------------------------------------------------------------------
odt_section_state state;
state.empty = true;
......@@ -662,9 +672,9 @@ void odt_conversion_context::set_no_list()
}
void odt_conversion_context::flush_section()
{
if (sections_.size() > 0 && sections_.back().empty)
if (!sections_.empty() && sections_.back().empty)
{
for (size_t i=0; i< current_root_elements_.size(); i++)
for (size_t i = 0; i < current_root_elements_.size(); i++)
{
if ((sections_.back().continuous && i < 2) || !sections_.back().continuous)
// при вставлении параграфа возможен искусственный разрыв в параграфах - см add_page_break
......@@ -697,7 +707,7 @@ void odt_conversion_context::start_run(bool styled)
if (is_hyperlink_ && text_context_.size() > 0) return;
if (current_field_.started== false && current_field_.type >1 && current_field_.enabled ==true && !current_field_.in_span)
if (current_field_.started == false && current_field_.type > 1 && current_field_.enabled == true && !current_field_.in_span)
{
text_context()->start_field(current_field_.type);
current_field_.started = true;
......@@ -705,7 +715,14 @@ void odt_conversion_context::start_run(bool styled)
text_context()->start_span(styled);
if (current_field_.started== false && current_field_.type >1 && current_field_.enabled ==true && current_field_.in_span)//поле стартуется в span - нужно для сохранения стиля
if (drop_cap_state_.enabled)
{
style_text_properties *props = text_context()->get_text_properties();
if (props)
props->apply_from(dynamic_cast<style_text_properties*>(drop_cap_state_.text_properties.get()));
}
if (current_field_.started == false && current_field_.type > 1 && current_field_.enabled == true && current_field_.in_span)//поле стартуется в span - нужно для сохранения стиля
{
text_context()->start_field(current_field_.type);
current_field_.started = true;
......@@ -945,7 +962,14 @@ void odt_conversion_context::end_change (int id, int type)
// return (text_changes_state_.current_types.back() == 2);
//}
//--------------------------------------------------------------------------------------------------------
style_text_properties* odt_conversion_context::get_drop_cap_properties()
{
if (!drop_cap_state_.text_properties)
{
create_element(L"style", L"text-properties", drop_cap_state_.text_properties, this);
}
return dynamic_cast<style_text_properties *>(drop_cap_state_.text_properties.get());
}
void odt_conversion_context::start_drop_cap(style_paragraph_properties *paragraph_properties)
{
if (drop_cap_state_.enabled)
......@@ -967,6 +991,8 @@ void odt_conversion_context::set_drop_cap_lines(int lines)
style_drop_cap *drop_cap = dynamic_cast<style_drop_cap*>(drop_cap_state_.paragraph_properties->content_.style_drop_cap_.get());
if (drop_cap)drop_cap->style_lines_ = lines;
drop_cap_state_.lines = lines;
}
void odt_conversion_context::set_drop_cap_margin(bool val)
{
......@@ -977,7 +1003,7 @@ void odt_conversion_context::end_drop_cap()
{
if (!drop_cap_state_.enabled) return;
if (drop_cap_state_.characters >0 && drop_cap_state_.paragraph_properties)
if (drop_cap_state_.characters > 0 && drop_cap_state_.paragraph_properties)
{
style_drop_cap *drop_cap = dynamic_cast<style_drop_cap*>(drop_cap_state_.paragraph_properties->content_.style_drop_cap_.get());
if (drop_cap)
......
......@@ -113,6 +113,8 @@ public:
void set_drop_cap_lines (int lines);
void set_drop_cap_margin(bool val);
void end_drop_cap ();
bool in_drop_cap () {return drop_cap_state_.enabled;}
style_text_properties* get_drop_cap_properties();
bool start_comment (int oox_comment_id);
void end_comment (int oox_comment_id);
......@@ -203,14 +205,25 @@ private:
struct _drop_cap_state
{
void clear(){enabled = false; paragraph_properties = NULL; characters = 0; inline_style = true; characters_size_pt =0;}
bool enabled;
style_paragraph_properties *paragraph_properties;
int characters;
bool inline_style;
double characters_size_pt;
void clear()
{
enabled = false;
paragraph_properties = NULL;
characters = 0;
inline_style = true;
characters_size_pt = 0;
lines = 0;
text_properties = office_element_ptr();
}
bool enabled = false;
style_paragraph_properties *paragraph_properties = NULL;
office_element_ptr text_properties;
int lines = 0;
int characters = 0;
bool inline_style = false;
double characters_size_pt = 0;
}drop_cap_state_;
};
......
......@@ -269,8 +269,15 @@ void style_paragraph_properties::apply_from(style_paragraph_properties * Other)
content_.apply_from(Other->content_);
}
void paragraph_format_properties::clear()
void paragraph_format_properties::clear(bool bEraseDropCap)
{
if (bEraseDropCap)
{
style_drop_cap_ = office_element_ptr();
fo_text_indent_ = boost::none;
}
style_tab_stops_ = office_element_ptr();
style_background_image_ = office_element_ptr();
fo_line_height_ = boost::none;
style_line_height_at_least_ = boost::none;
style_line_spacing_ = boost::none;
......@@ -287,7 +294,6 @@ void paragraph_format_properties::clear()
style_register_true_ = boost::none;
fo_margin_left_ = boost::none;
fo_margin_right_ = boost::none;
//fo_text_indent_ = boost::none;//заточено под буквицу
style_auto_text_indent_ = boost::none;
fo_margin_top_ = boost::none;
fo_margin_bottom_ = boost::none;
......@@ -318,7 +324,11 @@ void paragraph_format_properties::clear()
text_number_lines_ = boost::none;
style_shadow_ = boost::none;
//todooo borders
common_border_attlist_.fo_border_ = boost::none;
common_border_attlist_.fo_border_top_ = boost::none;
common_border_attlist_.fo_border_bottom_= boost::none;
common_border_attlist_.fo_border_left_ = boost::none;
common_border_attlist_.fo_border_right_ = boost::none;
}
void paragraph_format_properties::apply_from(paragraph_format_properties & Other)
......
......@@ -192,9 +192,8 @@ public:
void apply_from( paragraph_format_properties & Other);
void clear();
void clear(bool bEraseDropCap = true);
public:
_CP_OPT(odf_types::length) style_line_height_at_least_;
_CP_OPT(odf_types::length_or_percent) style_line_spacing_;
_CP_OPT(odf_types::Bool) style_font_independent_line_spacing_;
......
......@@ -58,6 +58,37 @@ using namespace cpdoccore;
namespace Oox2Odf
{
bool compare (OOX::Logic::CSectionProperty* props1, OOX::Logic::CSectionProperty* props2)
{
size_t cols_1 = 1, cols_2 = 1;
if (props1 && props1->m_oCols.IsInit())
{
cols_1 = props1->m_oCols->m_oNum.IsInit() ? props1->m_oCols->m_oNum->GetValue() : 1;
if (!props1->m_oCols->m_arrColumns.empty())
cols_1 = min(cols_1, props1->m_oCols->m_arrColumns.size());
}
if (props2)
{
if (props2->m_oCols.IsInit())
{
cols_2 = props2->m_oCols->m_oNum.IsInit() ? props2->m_oCols->m_oNum->GetValue() : 1;
if (!props2->m_oCols->m_arrColumns.empty())
cols_2 = min(cols_2, props2->m_oCols->m_arrColumns.size());
}
else
{
if (props2->m_oType.IsInit() && props2->m_oType->m_oVal.IsInit())
{
if (props2->m_oType->m_oVal->GetValue() == SimpleTypes::sectionmarkContinious)
cols_2 = cols_1;
}
}
}
return cols_1 == cols_2;
}
DocxConverter::DocxConverter(const std::wstring & path, const ProgressCallback* CallBack)
{
const OOX::CPath oox_path(std::wstring(path.c_str()));
......@@ -181,16 +212,18 @@ void DocxConverter::convert_document()
std::vector<_section> sections;
//----------------------------------------------------------------------------------------------------------
std::vector<OOX::WritingElement*>::const_iterator last_section_start = document->m_arrItems.begin();
//считаем количесво секций и запоминаем их свойства ..
for (std::vector<OOX::WritingElement*>::const_iterator it = document->m_arrItems.begin(); it != document->m_arrItems.end(); ++it)
size_t last_section_start = 0;
OOX::Logic::CSectionProperty* prev = NULL;
for (size_t i = 0; i < document->m_arrItems.size(); ++i)
{
if ((*it) == NULL) continue;
if ((document->m_arrItems[i]) == NULL) continue;
if ((*it)->getType() == OOX::et_w_p)
if (document->m_arrItems[i]->getType() == OOX::et_w_p)
{
OOX::Logic::CParagraph * para = dynamic_cast<OOX::Logic::CParagraph *>(*it);
OOX::Logic::CParagraph * para = dynamic_cast<OOX::Logic::CParagraph *>(document->m_arrItems[i]);
if ((para) && (para->m_oParagraphProperty))
{
......@@ -200,11 +233,13 @@ void DocxConverter::convert_document()
section.props = para->m_oParagraphProperty->m_oSectPr.GetPointer();
section.start_para = last_section_start;
section.end_para = it; section.end_para++;
section.end_para = i + 1;
section.bContinue = compare (prev, section.props);
sections.push_back(section);
last_section_start = it; last_section_start++;
last_section_start = i + 1;
prev = section.props;
}
}
}
......@@ -213,7 +248,9 @@ void DocxConverter::convert_document()
section.props = document->m_oSectPr.GetPointer();
section.start_para = last_section_start;
section.end_para = document->m_arrItems.end();
section.end_para = document->m_arrItems.size();
section.bContinue = compare (prev, section.props);
sections.push_back(section);
//----------------------------------------------------------------------------------------------------------
......@@ -224,9 +261,9 @@ void DocxConverter::convert_document()
{
current_section_properties = &sections[sect];
for (std::vector<OOX::WritingElement*>::const_iterator it = sections[sect].start_para; it != sections[sect].end_para; ++it)
for (size_t i = sections[sect].start_para; i < sections[sect].end_para; ++i)
{
convert(*it);
convert(document->m_arrItems[i]);
}
}
}
......@@ -487,15 +524,24 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
if (bRunPara)
text_properties = state->get_text_properties();
if (odt_context->in_drop_cap()) //после буквицы (Nadpis.docx) - нужно накатить свойства параграфа нормального
{
//очистить все кроме drop_cap
paragraph_properties->content_.clear(false);
}
else
{
// ????
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();
paragraph_properties->content_.clear(true);
if (text_properties)
text_properties->content_.clear();
}
}
}
}
else
{
odt_context->styles_context()->create_style(L"", odf_types::style_family::Paragraph, true, false, -1);
......@@ -510,11 +556,26 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
odt_context->styles_context()->last_state()->set_list_style_name(list_style_name);
}
}
if (odt_context->in_drop_cap())
{
odt_context->end_drop_cap();
}
convert(oox_paragraph->m_oParagraphProperty, paragraph_properties);
if (text_properties && oox_paragraph->m_oParagraphProperty)
{
if (odt_context->in_drop_cap())
{
convert(oox_paragraph->m_oParagraphProperty->m_oRPr.GetPointer(), odt_context->get_drop_cap_properties());
//вообще то свойства правильные параграфа идут в следующем после буквицы параграфе
}
else
{
convert(oox_paragraph->m_oParagraphProperty->m_oRPr.GetPointer(), text_properties);
}
}
}
else
{
odt_context->text_context()->set_KeepNextParagraph(false); //НУЖНО ПРИВЯЗАТЬ к УРОВНЮ на котором хранить m_bKeepNextParagraph !!! todooo
......@@ -572,8 +633,6 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
}
//---------------------------------------------------------------------------------------------------------------------
if (odt_context->text_context()->get_KeepNextParagraph()) odt_context->end_drop_cap();
if (!odt_context->text_context()->get_KeepNextParagraph()) odt_context->end_paragraph();
if(list_present && !odt_context->text_context()->get_KeepNextParagraph())
......@@ -1055,7 +1114,7 @@ void DocxConverter::convert(OOX::Logic::CParagraphProperty *oox_paragraph_pr, cp
{
if (current_section_properties)
{
convert(current_section_properties->props, current_section_properties->root);
convert(current_section_properties->props, !current_section_properties->bContinue);
}
return;
}
......@@ -1232,7 +1291,7 @@ 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);
convert(current_section_properties->props, !current_section_properties->bContinue);
//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)
......@@ -1328,7 +1387,7 @@ void DocxConverter::apply_HF_from(OOX::Logic::CSectionProperty *props, OOX::Logi
}
}
}
void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool root)
void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool bSection)
{
if (oox_section_pr == NULL) return;
current_section_properties = NULL;
......@@ -1353,18 +1412,18 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool r
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (!last_section_properties && (root || continuous == false || oox_section_pr->m_oTitlePg.IsInit()))
if (!last_section_properties && (!bSection || continuous == false || oox_section_pr->m_oTitlePg.IsInit()))
{
last_section_properties = oox_section_pr;
}
else if (root || continuous == false)
else if (!bSection || continuous == false)
{
apply_HF_from(last_section_properties, oox_section_pr);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (root || continuous == false)
if (!bSection || continuous == false)
{
odt_context->page_layout_context()->add_master_page(root ? L"Standard" : L"");
odt_context->page_layout_context()->add_master_page(bSection ? L"" : L"Standard");
}
bool present_header = false;
......@@ -1499,7 +1558,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool r
//nullable<SimpleTypes::CDecimalNumber<> > m_oChapStyle;
}
if (continuous == false || root || oox_section_pr->m_oTitlePg.IsInit())
if (continuous == false || oox_section_pr->m_oTitlePg.IsInit())
{
OOX::Logic::CSectionProperty* s = last_section_properties;
......@@ -1590,24 +1649,18 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool r
//nullable<ComplexTypes::Word::CRel > m_oPrinterSettings;
//nullable<OOX::Logic::CSectPrChange > m_oSectPrChange;
//--------------------------------------------------------------------------------------------------------------------------------------------
if (bSection)
{
odt_context->add_section(continuous);
}
int num_columns = 1;
if (oox_section_pr->m_oCols.IsInit())
if (bSection && oox_section_pr->m_oCols.IsInit())
{
num_columns = oox_section_pr->m_oCols->m_oNum.IsInit() ? oox_section_pr->m_oCols->m_oNum->GetValue() : 1;
int num_columns = oox_section_pr->m_oCols->m_oNum.IsInit() ? oox_section_pr->m_oCols->m_oNum->GetValue() : 1;
if (num_columns > 1 && oox_section_pr->m_oCols->m_arrColumns.size() > 0)
num_columns = /*(std::max)*/( /*num_columns,*/ (int)oox_section_pr->m_oCols->m_arrColumns.size()) ;
}
if (/*num_columns != odt_context->get_current_section_columns() || */num_columns >= 1) //колонки
{
if (!root || num_columns > 1)
odt_context->add_section(continuous);
if (oox_section_pr->m_oCols.IsInit())
{
double default_space_pt = -1;
if (oox_section_pr->m_oCols->m_oSpace.IsInit()) default_space_pt = oox_section_pr->m_oCols->m_oSpace->ToPoints();
......@@ -1637,7 +1690,6 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool r
//}
odt_context->add_section_column(width_space);
}
}
}
void DocxConverter::convert(OOX::Logic::CBackground *oox_background, int type)
{
......@@ -3612,7 +3664,7 @@ void DocxConverter::convert(OOX::Logic::CTbl *oox_table)
if (in_frame)
{
if (current_section_properties)
convert(current_section_properties->props, current_section_properties->root);
convert(current_section_properties->props, !current_section_properties->bContinue);
odt_context->start_paragraph();
......
......@@ -159,10 +159,10 @@ namespace Oox2Odf
struct _section
{
OOX::Logic::CSectionProperty *props;
std::vector<OOX::WritingElement*>::const_iterator start_para;
std::vector<OOX::WritingElement*>::const_iterator end_para;
size_t start_para;
size_t end_para;
bool root;
bool bContinue = false;
} *current_section_properties;
OOX::CDocx *docx_document;
cpdoccore::odf_writer::package::odf_document *output_document;
......@@ -184,7 +184,7 @@ namespace Oox2Odf
void convert(OOX::Logic::CBackground *oox_background, int type);
void convert(OOX::Logic::CSdt *oox_sdt);
void convert(OOX::Logic::CSectionProperty *oox_section_pr, bool root = false);
void convert(OOX::Logic::CSectionProperty *oox_section_pr, bool bSection);
void convert(OOX::Logic::CParagraph *oox_paragraph);
void convert(OOX::Logic::CRun *oox_run);
void convert(OOX::Logic::CParagraphProperty *oox_para_prop, odf_writer::style_paragraph_properties *paragraph_properties);
......
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