commit df26844463af7c872d92f04a65832f0d022c46c7
Author: Thibaut Cuvelier <tcuvel...@lyx.org>
Date:   Mon Mar 24 03:01:39 2025 +0100

    MathStream: extract a technical condition to a helper function.
    
    This change makes the code slightly easier to read, as 
`operator<<(MathMLStream & ms, docstring const & s)` already has a huge 
complexity.
---
 src/mathed/MathStream.cpp | 28 ++++++++++++++++++----------
 src/mathed/MathStream.h   |  3 +++
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index 9899ec81ec..5b1d4f7816 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -659,6 +659,22 @@ MathMLStream & operator<<(MathMLStream & ms, MathData 
const & ar)
 }
 
 
+bool MathMLStream::needsFontMapping() const {
+       // Condition written for *not* needing mapping, because it's easier
+       // (every field has a default value). The function returns the
+       // opposite because it's easier to understand.
+       return !(
+               (current_font_.family() == 
MathFontInfo::MathFontFamily::MATH_INHERIT_FAMILY ||
+                                       current_font_.family() == 
MathFontInfo::MathFontFamily::MATH_NORMAL_FAMILY) &&
+               (current_font_.series() == 
MathFontInfo::MathFontSeries::MATH_INHERIT_SERIES ||
+                                       current_font_.series() == 
MathFontInfo::MathFontSeries::MATH_MEDIUM_SERIES) &&
+               (current_font_.shape() == 
MathFontInfo::MathFontShape::MATH_INHERIT_SHAPE ||
+                                       (in_mtext_ && current_font_.shape() == 
MathFontInfo::MathFontShape::MATH_UP_SHAPE) ||
+                                       (!in_mtext_ && current_font_.shape() == 
MathFontInfo::MathFontShape::MATH_ITALIC_SHAPE))
+       );
+}
+
+
 MathMLStream & operator<<(MathMLStream & ms, docstring const & s)
 {
        ms.beforeText();
@@ -670,16 +686,8 @@ MathMLStream & operator<<(MathMLStream & ms, docstring 
const & s)
                if (ms.version() == MathMLVersion::mathmlCore) {
                        // New case: MathML uses Unicode characters to indicate 
fonts.
                        // If possible, avoid doing the mapping: it involves 
looking up a hash
-                       // table and doing a lot of conditions *per character*
-                       bool needs_no_mapping =
-                               (ms.current_font_.family() == 
MathFontInfo::MathFontFamily::MATH_INHERIT_FAMILY ||
-                                       ms.current_font_.family() == 
MathFontInfo::MathFontFamily::MATH_NORMAL_FAMILY) &&
-                               (ms.current_font_.series() == 
MathFontInfo::MathFontSeries::MATH_INHERIT_SERIES ||
-                                       ms.current_font_.series() == 
MathFontInfo::MathFontSeries::MATH_MEDIUM_SERIES) &&
-                               (ms.current_font_.shape() == 
MathFontInfo::MathFontShape::MATH_INHERIT_SHAPE ||
-                                       (ms.in_mtext_ && 
ms.current_font_.shape() == MathFontInfo::MathFontShape::MATH_UP_SHAPE) ||
-                                       (!ms.in_mtext_ && 
ms.current_font_.shape() == MathFontInfo::MathFontShape::MATH_ITALIC_SHAPE));
-                       if (needs_no_mapping) {
+                       // table and doing a lot of conditions *per character*.
+                       if (!ms.needsFontMapping()) {
                                ms.os_ << s;
                        } else {
                                // Perform the conversion character per 
character (which might
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index 28471ce715..b2f538ad6e 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -515,6 +515,9 @@ private:
        void beforeText();
        /// Check whether there is a <mtext> to close here
        void beforeTag();
+       /// Determines whether characters should be mapped for font variations.
+       /// (True if characters must respect font, in particular.)
+       bool needsFontMapping() const;
        ///
        odocstream & os_;
        ///
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to