fix/bug73365

fix bug when after conversion text move to next column. Also detect and fix a new bug, when we have explicit break column but break is happening early
This commit is contained in:
Timofey Derevyankin
2025-08-21 14:28:47 +03:00
parent 98af93c631
commit b1c8969ede
4 changed files with 50 additions and 47 deletions

View File

@ -309,7 +309,7 @@ void DocxConverter::convert_document()
{
current_section_properties = &sections[sect];
for (size_t i = sections[sect].start_para; i < sections[sect].end_para; ++i)
for (size_t i = sections[sect].start_para; i < sections[sect].end_para; ++i)
{
convert(doc->m_arrItems[i]);
}
@ -875,6 +875,7 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
}
if(oox_paragraph->m_oParagraphProperty)
convert(oox_paragraph->m_oParagraphProperty->m_oRPr.GetPointer(), text_properties);
}
if (odt_context->in_drop_cap())
@ -947,7 +948,7 @@ void DocxConverter::convert(OOX::Logic::CParagraph *oox_paragraph)
}
//---------------------------------------------------------------------------------------------------------------------
for (size_t i = 0; i < oox_paragraph->m_arrItems.size(); ++i)
for (size_t i = 0; i < oox_paragraph->m_arrItems.size(); ++i)
{
//те элементы которые тока для Paragraph - здесь - остальные в общей куче
switch(oox_paragraph->m_arrItems[i]->getType())
@ -1046,12 +1047,18 @@ void DocxConverter::convert(OOX::Logic::CRun *oox_run)//wordprocessing 22.1.2.87
OOX::Logic::CBr* pBr= dynamic_cast<OOX::Logic::CBr*>(oox_run->m_arrItems[i]);
if (pBr)
{
int type = pBr->m_oType.GetValue();
bool need_restart_para = odt_context->text_context()->set_type_break(type, pBr->m_oClear.GetValue());
if( !odt_context->pendingBreakType ) // for bug when we have text and after conversion we have early break column (check bug 73365)
{
odt_context->pendingBreakType = true;
odt_context->m_pendingBreakType = pBr->m_oType.GetValue();
}
if (need_restart_para)
odt_context->add_paragraph_break(type);
// int type = pBr->m_oType.GetValue();
// bool need_restart_para = odt_context->text_context()->set_type_break(type, pBr->m_oClear.GetValue());
// if (need_restart_para)
// odt_context->add_paragraph_break(type);
}
}break;
case OOX::et_w_t:
@ -2241,8 +2248,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty* oox_section_pr, bool b
{
odt_context->add_section(continuous);
}
if (bSection && oox_section_pr->m_oCols.IsInit())
if ( oox_section_pr->m_oCols.IsInit() )
{
int num_columns = oox_section_pr->m_oCols->m_oNum.IsInit() ? oox_section_pr->m_oCols->m_oNum->GetValue() : 1;
@ -2254,10 +2260,21 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty* oox_section_pr, bool b
bool separator = oox_section_pr->m_oCols->m_oSep.IsInit() && oox_section_pr->m_oCols->m_oSep->ToBool();
odt_context->add_section_columns(num_columns,
oox_section_pr->m_oCols->m_arrColumns.size() > 0 ? -1 : default_space_pt , separator );
bool flag;
if( oox_section_pr->m_oCols->m_oEqualWidth.IsInit() )
{
flag = true;
}
else
{
flag = false;
}
if (num_columns > 1) //
odt_context->add_section_columns(num_columns,
oox_section_pr->m_oCols->m_arrColumns.size() > 0 ? -1 : default_space_pt ,
separator, flag );
if (num_columns > 1)
{
std::vector<std::pair<double,double>> width_space;

View File

@ -616,39 +616,6 @@ namespace odf_writer
if ((content_) && (content_->styles_.rdbuf()->in_avail() != 0))
{
std::wstring str_styles = content_->styles_.str();
if( str_styles.find(L"text:dont-balance-text-columns=\"true\"") == std::string::npos )
{
std::size_t style_pos = str_styles.find(L"style:section-properties");
if( style_pos != std::string::npos )
{
std::size_t end_pos = str_styles.find(L">", style_pos);
if( end_pos != std::string::npos )
{
std::wregex break_regex(L"fo:break-before\\s*=\\s*\"column\"");
bool have_fo_break_before_column = std::regex_search( str_styles, break_regex );
if( !have_fo_break_before_column )
{
str_styles.insert(end_pos,L" text:dont-balance-text-columns=\"true\" style:editable=\"false\"");
}
else
{
std::wregex pattern(L"fo:break-before\\s*=\\s*\"column\"");
str_styles.insert(end_pos,L" text:dont-balance-text-columns=\"false\" style:editable=\"false\"");
str_styles = std::regex_replace( str_styles, pattern , L"");
}
content_->styles_.str(L"");
content_->styles_.clear();
content_->styles_ << str_styles;
}
}
}
content_->styles_.flush();
CP_XML_STREAM() << content_->styles_.rdbuf();
content_->styles_.clear();

View File

@ -326,6 +326,13 @@ void odt_conversion_context::end_drawing_context()
}
void odt_conversion_context::start_paragraph(bool styled)
{
if (pendingBreakType) // for bug when we have text and after conversion we have early break column (check bug 73365)
{
add_paragraph_break(m_pendingBreakType);
m_pendingBreakType = -1;
pendingBreakType = false;
}
if (false == current_fields.empty() && current_fields.back().status == 1 && false == current_fields.back().in_span)
{
current_fields.back().status = 2;
@ -1106,7 +1113,7 @@ void odt_conversion_context::add_section(bool continuous)
sections_.push_back(state);
}
void odt_conversion_context::add_section_columns(int count, double space_pt, bool separator)
void odt_conversion_context::add_section_columns(int count, double space_pt, bool separator, bool flag)
{
if (sections_.empty() || count < 1) return;
@ -1114,6 +1121,15 @@ void odt_conversion_context::add_section_columns(int count, double space_pt, boo
if (!style_)return;
style_section_properties* section_properties = style_->content_.add_get_style_section_properties();
if( flag ) // for bug when we have implicit break column (check bug 73365)
{
section_properties->text_dont_balance_text_columns_ = flag;
}
else if( !flag )
{
section_properties->text_dont_balance_text_columns_ = flag;
}
create_element(L"style", L"columns", section_properties->style_columns_,this);

View File

@ -142,7 +142,7 @@ public:
void end_run ();
void add_section (bool continuous);
void add_section_columns (int count, double space_pt, bool separator );
void add_section_columns (int count, double space_pt, bool separator, bool flag );
void add_section_column (std::vector<std::pair<double,double>> width_space);
int get_current_section_columns ();
void flush_section ();
@ -202,6 +202,9 @@ public:
bool empty() {return current_root_elements_.empty();}
int m_pendingBreakType = -1;
bool pendingBreakType = false;
private:
void start_table_header_rows();
void end_table_header_rows ();