diff --git a/DocxRenderer/src/logic/elements/ContText.cpp b/DocxRenderer/src/logic/elements/ContText.cpp index 7845c241aa..11bd4169dd 100644 --- a/DocxRenderer/src/logic/elements/ContText.cpp +++ b/DocxRenderer/src/logic/elements/ContText.cpp @@ -977,8 +977,10 @@ namespace NSDocxRenderer eHorizontalCrossingType eHType) { + double first_height = pFirstCont->m_dBotWithDescent - pFirstCont->m_dTopWithAscent; bool bIf1 = eVType == eVerticalCrossingType::vctCurrentAboveNext || - eVType == eVerticalCrossingType::vctCurrentInsideNext; + eVType == eVerticalCrossingType::vctCurrentInsideNext && + pSecondCont->m_dBot - pFirstCont->m_dBot > first_height * 0.2; bool bIf2 = eVType == eVerticalCrossingType::vctCurrentBelowNext; diff --git a/DocxRenderer/src/logic/elements/TextLine.cpp b/DocxRenderer/src/logic/elements/TextLine.cpp index 71d3f78691..4b85e0ff75 100644 --- a/DocxRenderer/src/logic/elements/TextLine.cpp +++ b/DocxRenderer/src/logic/elements/TextLine.cpp @@ -66,6 +66,8 @@ namespace NSDocxRenderer std::sort(m_arConts.begin(), m_arConts.end(), [] (const cont_ptr_t& a, const cont_ptr_t& b) { if (!a) return false; if (!b) return true; + if (fabs(a->m_dLeft - b->m_dLeft) < c_dTHE_SAME_STRING_X_PRECISION_MM) + return a->m_dRight < b->m_dRight; return a->m_dLeft < b->m_dLeft; }); @@ -245,12 +247,12 @@ namespace NSDocxRenderer else if (this_top < other_top && this_bot > other_bot) return eVerticalCrossingType::vctCurrentOutsideNext; - else if (this_top < other_top && this_bot < other_bot && - (this_bot >= other_top || fabs(this_bot - other_top) < c_dTHE_SAME_STRING_Y_PRECISION_MM)) + else if (this_top < other_top && this_bot < other_bot && this_bot > other_top && + this_bot - other_top > c_dLINE_DISTANCE_ERROR_MM) return eVerticalCrossingType::vctCurrentAboveNext; - else if (this_top > other_top && this_bot > other_bot && - (this_top <= other_bot || fabs(this_top - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM)) + else if (this_top > other_top && this_bot > other_bot && this_top < other_bot && + other_bot - this_top > c_dLINE_DISTANCE_ERROR_MM) return eVerticalCrossingType::vctCurrentBelowNext; else if (this_top == other_top && this_bot == other_bot && @@ -267,10 +269,10 @@ namespace NSDocxRenderer else if (fabs(this_bot - other_bot) < c_dTHE_SAME_STRING_Y_PRECISION_MM) return eVerticalCrossingType::vctBottomBorderMatch; - else if (this_bot < other_top) + else if (other_top - this_bot > -c_dLINE_DISTANCE_ERROR_MM) return eVerticalCrossingType::vctNoCrossingCurrentAboveNext; - else if (this_top > other_bot) + else if (this_top - other_bot > -c_dLINE_DISTANCE_ERROR_MM) return eVerticalCrossingType::vctNoCrossingCurrentBelowNext; else diff --git a/DocxRenderer/src/resources/Constants.h b/DocxRenderer/src/resources/Constants.h index f312637c27..9c06f2852b 100644 --- a/DocxRenderer/src/resources/Constants.h +++ b/DocxRenderer/src/resources/Constants.h @@ -24,7 +24,7 @@ constexpr double c_dPtToEMU = 12700.0; constexpr double c_dDegreeToAngle = 60000.0; const double c_dSTANDART_STRING_HEIGHT_MM = 4.2333333333333334; -const double c_dTHE_SAME_STRING_Y_PRECISION_MM = 0.03; +const double c_dTHE_SAME_STRING_Y_PRECISION_MM = 0.015; const double c_dTHE_SAME_STRING_X_PRECISION_MM = 0.03; const double c_dTHE_SAME_SPACING_ERROR = 0.1; const double c_dLINE_DISTANCE_ERROR_MM = 0.3;