]> git.lyx.org Git - features.git/blobdiff - src/Row.h
Fix computation of LABEL_MANUAL label separation
[features.git] / src / Row.h
index 3048cf1ccf78ef24274e34e562e466756c0fef1d..62ee6cfb5e55aa8359790f0624a9c79c8e79315b 100644 (file)
--- a/src/Row.h
+++ b/src/Row.h
@@ -18,6 +18,7 @@
 #include "Changes.h"
 #include "Dimension.h"
 #include "Font.h"
+#include "RowFlags.h"
 
 #include "support/docstring.h"
 #include "support/types.h"
@@ -50,8 +51,9 @@ public:
                INSET,
                // Some spacing described by its width, not a string
                SPACE,
-               // Something that should not happen (for error handling)
-               INVALID
+               // Spacing until the left margin, with a minimal value given
+               // by the initial width
+               MARGINSPACE
        };
 
 /**
@@ -59,8 +61,6 @@ public:
  * by other methods that need to parse the Row contents.
  */
        struct Element {
-               //
-               Element() = default;
                //
                Element(Type const t, pos_type p, Font const & f, Change const & ch)
                        : type(t), pos(p), endpos(p + 1), font(f), change(ch) {}
@@ -93,26 +93,23 @@ public:
                pos_type x2pos(int &x) const;
                /** Break the element in two if possible, so that its width is less
                 * than \param w.
-                * \return an element containing the remainder of the text, or
-                *   an invalid element if nothing happened.
-                * \param w: the desired maximum width
-                * \param force: if true, the string is cut at any place, otherwise it
-                *   respects the row breaking rules of characters.
-                */
-               Element splitAt(int w, bool force);
-               /** Break the element if possible, so that its width is less
-                * than \param w. Returns true on success. When \param force
-                * is true, the string is cut at any place, otherwise it
-                * respects the row breaking rules of characters.
+                * \return a vector of elements containing the remainder of
+                *   the text (empty if nothing happened).
+                * \param width maximum width of the row.
+                * \param next_width available width on next row.
+                * \param force: if true, cut string at any place, even for
+                *   languages that wrap at word delimiters; if false, do not
+                *   break at all if first element would larger than \c width.
                 */
-               bool breakAt(int w, bool force);
+               // FIXME: ideally last parameter should be Elements&, but it is not possible.
+               bool splitAt(int width, int next_width, bool force, std::vector<Element> & tail);
+               // remove trailing spaces (useful for end of row)
+               void rtrim();
 
                //
                bool isRTL() const { return font.isVisibleRightToLeft(); }
                // This is true for virtual elements.
                bool isVirtual() const { return type == VIRTUAL; }
-               // Invalid element, for error handling
-               bool isValid() const { return type !=INVALID; }
 
                // Returns the position on left side of the element.
                pos_type left_pos() const { return isRTL() ? endpos : pos; };
@@ -120,14 +117,16 @@ public:
                pos_type right_pos() const { return isRTL() ? pos : endpos; };
 
                // The kind of row element
-               Type type = INVALID;
+               Type type;
                // position of the element in the paragraph
-               pos_type pos = 0;
+               pos_type pos;
                // first position after the element in the paragraph
-               pos_type endpos = 0;
-               // The dimension of the chunk (does not contains the
+               pos_type endpos;
+               // The dimension of the chunk (does not contain the
                // separator correction)
                Dimension dim;
+               // The width of the element without trailing spaces
+               int nspc_wid = 0;
 
                // Non-zero only if element is an inset
                Inset const * inset = nullptr;
@@ -143,10 +142,14 @@ public:
                Change change;
                // is it possible to add contents to this element?
                bool final = false;
+               // properties with respect to row breaking (made of RowFlag enums)
+               int row_flags = Inline;
 
                friend std::ostream & operator<<(std::ostream & os, Element const & row);
        };
 
+       ///
+       typedef Element value_type;
 
        ///
        Row() {}
@@ -247,12 +250,14 @@ public:
                 Font const & f, Change const & ch);
        ///
        void add(pos_type pos, char_type const c,
-                Font const & f, Change const & ch);
+                Font const & f, Change const & ch, bool can_break);
        ///
        void addVirtual(pos_type pos, docstring const & s,
                        Font const & f, Change const & ch);
        ///
        void addSpace(pos_type pos, int width, Font const & f, Change const & ch);
+       ///
+       void addMarginSpace(pos_type pos, int width, Font const & f, Change const & ch);
 
        ///
        typedef std::vector<Element> Elements;
@@ -287,12 +292,11 @@ public:
         * if row width is too large, remove all elements after last
         * separator and update endpos if necessary. If all that
         * remains is a large word, cut it to \param width.
-        * \param body_pos minimum amount of text to keep.
         * \param width maximum width of the row.
-        * \param available width on next row.
-        * \return true if the row has been shortened.
+        * \param next_width available width on next row.
+        * \return list of elements remaining after breaking.
         */
-       bool shortenIfNeeded(pos_type const body_pos, int const width, int const next_width);
+       Elements shortenIfNeeded(int const width, int const next_width);
 
        /**
         * If last element of the row is a string, compute its width
@@ -304,10 +308,12 @@ public:
         * Find sequences of right-to-left elements and reverse them.
         * This should be called once the row is completely built.
         */
-       void reverseRTL(bool rtl_par);
+       void reverseRTL();
        ///
        bool isRTL() const { return rtl_; }
        ///
+       void setRTL(bool rtl) { rtl_ = rtl; }
+       ///
        bool needsChangeBar() const { return changebar_; }
        ///
        void needsChangeBar(bool ncb) { changebar_ = ncb; }
@@ -378,6 +384,8 @@ private:
        bool changebar_ = false;
 };
 
+std::ostream & operator<<(std::ostream & os, Row::Elements const & elts);
+
 
 /**
  * Each paragraph is broken up into a number of rows on the screen.