From 57221c0e32592f2c95cc58b9754a9dad26af1b06 Mon Sep 17 00:00:00 2001 From: Timofey Derevyankin Date: Mon, 27 Oct 2025 16:27:48 +0300 Subject: [PATCH] fix/bug77123 fix bug when the tabs were longer than available width --- .../Converter/oox_conversion_context.cpp | 5 ++- .../Reader/Converter/oox_conversion_context.h | 2 +- OdfFile/Reader/Format/calcs_styles.cpp | 8 ++++- .../Format/style_paragraph_properties.h | 1 + .../style_paragraph_properties_docx.cpp | 34 ++++++++++++++++--- PdfFile/SrcWriter/Utils.h | 1 + 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/OdfFile/Reader/Converter/oox_conversion_context.cpp b/OdfFile/Reader/Converter/oox_conversion_context.cpp index 462e289fd3..a74d5cc0e9 100644 --- a/OdfFile/Reader/Converter/oox_conversion_context.cpp +++ b/OdfFile/Reader/Converter/oox_conversion_context.cpp @@ -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(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(tabs[i].get()); + tab_stop->docx_convert(Context, false); } _pPr << L""; diff --git a/OdfFile/Reader/Converter/oox_conversion_context.h b/OdfFile/Reader/Converter/oox_conversion_context.h index 43feb78d14..aa79261a2d 100644 --- a/OdfFile/Reader/Converter/oox_conversion_context.h +++ b/OdfFile/Reader/Converter/oox_conversion_context.h @@ -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 diff --git a/OdfFile/Reader/Format/calcs_styles.cpp b/OdfFile/Reader/Format/calcs_styles.cpp index d44b341d93..cf46f27f41 100644 --- a/OdfFile/Reader/Format/calcs_styles.cpp +++ b/OdfFile/Reader/Format/calcs_styles.cpp @@ -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); } } } diff --git a/OdfFile/Reader/Format/style_paragraph_properties.h b/OdfFile/Reader/Format/style_paragraph_properties.h index d5cb210944..7edaaa4036 100644 --- a/OdfFile/Reader/Format/style_paragraph_properties.h +++ b/OdfFile/Reader/Format/style_paragraph_properties.h @@ -111,6 +111,7 @@ public: //----------------------------- double margin_left; + double margin_right; }; diff --git a/OdfFile/Reader/Format/style_paragraph_properties_docx.cpp b/OdfFile/Reader/Format/style_paragraph_properties_docx.cpp index 370b815d02..e36c057cb4 100644 --- a/OdfFile/Reader/Format/style_paragraph_properties_docx.cpp +++ b/OdfFile/Reader/Format/style_paragraph_properties_docx.cpp @@ -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(tab_pos) << "\""; std::wstring leader; diff --git a/PdfFile/SrcWriter/Utils.h b/PdfFile/SrcWriter/Utils.h index d737624c3d..8375787182 100644 --- a/PdfFile/SrcWriter/Utils.h +++ b/PdfFile/SrcWriter/Utils.h @@ -33,6 +33,7 @@ #define _PDF_WRITER_SRC_UTILS_H #include "Types.h" +#include #define NEEDS_ESCAPE(c) (c < 0x21 || \ c > 0x7e || \