]> git.lyx.org Git - features.git/blobdiff - src/Row.h
Fix computation of LABEL_MANUAL label separation
[features.git] / src / Row.h
index 74667976efba1e54741cac9cd773e09cd2171a99..62ee6cfb5e55aa8359790f0624a9c79c8e79315b 100644 (file)
--- a/src/Row.h
+++ b/src/Row.h
@@ -51,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
        };
 
 /**
@@ -60,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) {}
@@ -94,13 +93,16 @@ 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.
+                * \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.
                 */
-               Element splitAt(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();
 
@@ -108,8 +110,6 @@ public:
                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; };
@@ -117,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;
@@ -254,6 +256,8 @@ public:
                        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;
@@ -289,8 +293,8 @@ public:
         * separator and update endpos if necessary. If all that
         * remains is a large word, cut it to \param width.
         * \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.
         */
        Elements shortenIfNeeded(int const width, int const next_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.