commit 6a82d71c94847d28c5167a0cd184c6ccbb2647a0
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Tue Jul 22 19:58:04 2025 +0200

    Handle text justification
    
    INSETROW elements act as proxy for the underlying rows. The changes
    are straightforward as expected.
    
    What works:
    * the contents is drawn
    * insets are broken as needed
    * works too when nested in other insets (e.g. Note)
    * text justification across normal text and broken insets
    * setting cursor using mouse
    
    What sort of works:
    * very basic decoration
    * navigation with cursor left/right (mostly, see below)
    
    What does not work:
    * Right-to-Left rows are not drawn correctly
    * no selection support
    * entering an inset by the right with cursor-left does not work
    * up/down navigation does not work
    * SinglePar fails (does a Update::Force) inside a breakable inset
---
 src/Row.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------
 src/Row.h   | 12 ++++++++---
 2 files changed, 66 insertions(+), 13 deletions(-)

diff --git a/src/Row.cpp b/src/Row.cpp
index e8c4be3734..75a4c0ad3c 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -82,17 +82,52 @@ int Row::Element::countExpanders() const
 
 int Row::Element::expansionAmount() const
 {
-       if (type != STRING || font.fontInfo().family() == TYPEWRITER_FAMILY)
+       if (font.fontInfo().family() == TYPEWRITER_FAMILY)
                return 0;
-       return countExpanders() * theFontMetrics(font).em();
+
+       switch (type) {
+       case STRING:
+               return countExpanders() * theFontMetrics(font).em();
+               break;
+       case INSETROW:
+               return irow.get()->expansionAmount();
+               break;
+       case VIRTUAL:
+       case PREEDIT:
+       case INSET:
+       case INSETBEGIN:
+       case INSETEND:
+       case SPACE:
+       case MARGINSPACE:
+               break;
+       }
+       return 0;
 }
 
 
 void Row::Element::setExtra(double extra_per_em)
 {
-       if (type != STRING || font.fontInfo().family() == TYPEWRITER_FAMILY)
+       if (font.fontInfo().family() == TYPEWRITER_FAMILY)
                return;
-       extra = extra_per_em * theFontMetrics(font).em();
+
+       switch (type) {
+       case STRING:
+               extra = extra_per_em * theFontMetrics(font).em();
+               break;
+       case INSETROW: {
+               Row * row = const_cast<Row *>(irow.get());
+               row->setExtraWidth(extra_per_em * 
irow.get()->expansionAmount());
+               break;
+       }
+       case VIRTUAL:
+       case PREEDIT:
+       case INSET:
+       case INSETBEGIN:
+       case INSETEND:
+       case SPACE:
+       case MARGINSPACE:
+               break;
+       }
 }
 
 
@@ -452,6 +487,22 @@ int Row::right_x() const
 }
 
 
+int Row::expansionAmount() const
+{
+       int exp_amount = 0;
+       for (Element const & e : elements_)
+               exp_amount += e.expansionAmount();
+       return exp_amount;
+}
+
+
+void Row::setExtra(double extra_per_em)
+{
+       for (Element & e : elements_)
+               e.setExtra(extra_per_em);
+}
+
+
 bool Row::setExtraWidth(int w)
 {
        if (w < 0)
@@ -459,9 +510,7 @@ bool Row::setExtraWidth(int w)
                return false;
        // amount of expansion: number of expanders time the em value for each
        // string element
-       int exp_amount = 0;
-       for (Element const & e : elements_)
-               exp_amount += e.expansionAmount();
+       int exp_amount = expansionAmount();
        if (!exp_amount)
                return false;
        // extra length per expander per em
@@ -470,9 +519,7 @@ bool Row::setExtraWidth(int w)
                // do not stretch more than MAX_SPACE_STRETCH em per expander
                return false;
        // add extra length to each element proportionally to its em.
-       for (Element & e : elements_)
-               if (e.type == STRING)
-                       e.setExtra(extra_per_em);
+       setExtra(extra_per_em);
        // update row dimension
        dim_.wid += w;
        return true;
diff --git a/src/Row.h b/src/Row.h
index 777af7ae79..a577ebaecf 100644
--- a/src/Row.h
+++ b/src/Row.h
@@ -128,7 +128,6 @@ public:
                int countExpanders() const;
                // Return the amount of expansion: the number of expanding 
characters
                // that get stretched during justification, times the em of the 
font
-               // (only STRING type).
                int expansionAmount() const;
                // set extra proportionally to the font em value.
                void setExtra(double extra_per_em);
@@ -309,10 +308,17 @@ public:
        int left_x() const;
        /// The offset of the right-most cursor position on the row
        int right_x() const;
+       // Return the amount of expansion: the number of expanding characters
+       // that get stretched during justification, times the em of the fonts
+       int expansionAmount() const;
+       // set extra for each element proportionally to the font em value.
+       void setExtra(double extra_per_em);
 
        // Set the extra spacing for every expanding character in STRING-type
-       // elements.  \param w is the total amount of extra width for the row 
to be
-       // distributed among expanders.  \return false if the justification 
fails.
+       // elements.
+       // \param w is the total amount of extra width for the row to be
+       // distributed among expanders.
+       // \return false if the justification fails.
        bool setExtraWidth(int w);
 
        /** Return character position and boundary value that are the
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to