fix/bug77123

fix bug when the tabs were longer than available width
This commit is contained in:
Timofey Derevyankin
2025-10-27 16:27:48 +03:00
parent b4395efa91
commit 57221c0e32
6 changed files with 43 additions and 8 deletions

View File

@ -106,12 +106,13 @@ void tabs_context::reset()
}
tabs.clear();
}
void tabs_context::add(const odf_reader::office_element_ptr & element, double margin_left)
void tabs_context::add(const odf_reader::office_element_ptr & element, double margin_left, double margin_right)
{
odf_reader::style_tab_stop *tab_stop = dynamic_cast<odf_reader::style_tab_stop*>(element.get());
if (tab_stop)
{
tab_stop->margin_left = margin_left;
tab_stop->margin_right = margin_right;
auto type = tab_stop->style_type_ ? tab_stop->style_type_->get_type() : odf_types::style_type::Left;
@ -132,6 +133,7 @@ void tabs_context::add(const odf_reader::office_element_ptr & element, double ma
{
clear_tabs.erase(pFind);
}
tabs.push_back(element);
}
}
@ -152,6 +154,7 @@ void tabs_context::docx_convert(oox::docx_conversion_context & Context)
for (size_t i = 0; i < tabs.size(); i++)
{
odf_reader::style_tab_stop * tab_stop = dynamic_cast<odf_reader::style_tab_stop*>(tabs[i].get());
tab_stop->docx_convert(Context, false);
}
_pPr << L"</w:tabs>";

View File

@ -141,7 +141,7 @@ public:
void reset();
void add(const odf_reader::office_element_ptr & element, double margin_left);
void add(const odf_reader::office_element_ptr & element, double margin_left, double margin_right);
void docx_convert(oox::docx_conversion_context & Context);
};
class styles_context : boost::noncopyable

View File

@ -203,11 +203,17 @@ void calc_tab_stops(const style_instance * styleInstance, oox::tabs_context & co
styleInstance = styleInstance->parent();
}
double margin_left = 0;
double margin_right = 0;
for (size_t i = 0; i < parProps.size(); i++)
{
if (parProps[i]->content_.fo_margin_left_)
margin_left = 20.0 * parProps[i]->content_.fo_margin_left_->get_length().get_value_unit(odf_types::length::pt);
if( parProps[i]->content_.fo_margin_right_)
{
margin_right= 20.0 * parProps[i]->content_.fo_margin_right_->get_length().get_value_unit(odf_types::length::pt);
}
if ( parProps[i]->content_.style_tab_stops_ )
{
@ -215,7 +221,7 @@ void calc_tab_stops(const style_instance * styleInstance, oox::tabs_context & co
context.reset();
for (size_t j = 0; j < tab_stops->content_.size(); j++)
{
context.add(tab_stops->content_[j], margin_left);
context.add(tab_stops->content_[j], margin_left, margin_right);
}
}
}

View File

@ -111,6 +111,7 @@ public:
//-----------------------------
double margin_left;
double margin_right;
};

View File

@ -491,10 +491,10 @@ void paragraph_format_properties::docx_convert(oox::docx_conversion_context & Co
Context.get_tabs_context().docx_convert(Context);
//if (style_tab_stops_)
//{
// style_tab_stops_->docx_convert(Context);
//}
// if (style_tab_stops_)
// {
// style_tab_stops_->docx_convert(Context);
// }
}
void style_tab_stops::docx_convert(oox::docx_conversion_context & Context)
{
@ -537,8 +537,32 @@ void style_tab_stop::docx_convert(oox::docx_conversion_context & Context, bool c
}
}
const double PtPerCm = 28.346;
const double TwPerPt = 20.0;
double PageWidthTwips = 21 * PtPerCm * TwPerPt;
double LeftPageMarginTwips = 3 * PtPerCm * TwPerPt;
double RightPageMarginTwips = 1.5 * PtPerCm * TwPerPt;
double current_tab_width_twips = 0;
if( style_type_->get_type() == style_type::Left )
{
current_tab_width_twips = PageWidthTwips - LeftPageMarginTwips - RightPageMarginTwips - margin_right;
}
else
{
current_tab_width_twips = PageWidthTwips - LeftPageMarginTwips - RightPageMarginTwips - margin_left - margin_right;
}
if( tab_pos > current_tab_width_twips )
{
tab_pos = current_tab_width_twips;
tab_pos -= 150;
}
_pPr << L" w:val=\"" << val << "\"";
_pPr << L" w:pos=\"" << (int)tab_pos << "\"";
_pPr << L" w:pos=\"" << static_cast<int>(tab_pos) << "\"";
std::wstring leader;