Fix text line shape between lines of paragraph

This commit is contained in:
Alexey Nagaev
2026-01-29 16:50:48 +03:00
parent 97cbd8dcc7
commit 325c2d3000
2 changed files with 35 additions and 2 deletions

View File

@ -1342,6 +1342,21 @@ namespace NSDocxRenderer
return IsHorizontalLineTrough(dummy_cont);
}
bool CPage::IsTextLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept
{
double left = std::min(pFirst->m_dLeft, pSecond->m_dLeft);
double right = std::max(pFirst->m_dRight, pSecond->m_dRight);
double top = std::min(pFirst->m_dBotWithMaxDescent, pSecond->m_dBotWithMaxDescent);
double bot = std::max(pFirst->m_dTopWithMaxAscent, pSecond->m_dTopWithMaxAscent);
auto dummy_cont = std::make_shared<CContText>();
dummy_cont->m_dLeft = left - c_dGRAPHICS_ERROR_MM;
dummy_cont->m_dRight = right + c_dGRAPHICS_ERROR_MM;
dummy_cont->m_dTop = top - c_dGRAPHICS_ERROR_MM;
dummy_cont->m_dBot = bot + c_dGRAPHICS_ERROR_MM;
return IsTextLineTrough(dummy_cont);
}
bool CPage::IsVerticalLineTrough(base_item_ptr_t pFirst) const noexcept
{
@ -1369,6 +1384,20 @@ namespace NSDocxRenderer
return false;
}
bool CPage::IsTextLineTrough(base_item_ptr_t pFirst) const noexcept
{
const auto width = pFirst->m_dRight - pFirst->m_dLeft;
const auto center = pFirst->m_dLeft + width / 2;
for (const auto& text_line : m_arShapes)
if (text_line && text_line->m_eType == CShape::eShapeType::stTextBox && text_line->m_dBot > pFirst->m_dTop &&
text_line->m_dBot < pFirst->m_dBot &&
text_line->m_dLeft <= center &&
text_line->m_dRight >= center)
return true;
return false;
}
void CPage::SplitLines()
{
@ -1438,7 +1467,7 @@ namespace NSDocxRenderer
for (const auto& line : m_arTextLines)
{
if (fabs(line->m_dBotWithMaxDescent - curr_bot) < 4 * c_dTHE_SAME_STRING_Y_PRECISION_MM)
if (fabs(line->m_dBot - curr_bot) < 4 * c_dTHE_SAME_STRING_Y_PRECISION_MM)
{
bot_aligned_text_lines.back().push_back(line);
}
@ -1446,7 +1475,7 @@ namespace NSDocxRenderer
{
bot_aligned_text_lines.push_back({});
bot_aligned_text_lines.back().push_back(line);
curr_bot = line->m_dBotWithMaxDescent;
curr_bot = line->m_dBot;
}
}
@ -1933,6 +1962,8 @@ namespace NSDocxRenderer
{
if (IsHorizontalLineBetween(text_lines[index], text_lines[index + 1]))
ar_delims[index] = true;
if (IsTextLineBetween(text_lines[index], text_lines[index + 1]))
ar_delims[index] = true;
}
// на основе ar_delims разбиваем на параграфы

View File

@ -194,9 +194,11 @@ namespace NSDocxRenderer
bool IsVerticalLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept;
bool IsHorizontalLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept;
bool IsTextLineBetween(text_line_ptr_t pFirst, text_line_ptr_t pSecond) const noexcept;
bool IsVerticalLineTrough(base_item_ptr_t pFirst) const noexcept;
bool IsHorizontalLineTrough(base_item_ptr_t pFirst) const noexcept;
bool IsTextLineTrough(base_item_ptr_t pFirst) const noexcept;
void ToXml(NSStringUtils::CStringBuilder& oWriter) const noexcept;
void WriteSectionToFile(bool bLastPage, NSStringUtils::CStringBuilder& oWriter) const noexcept;