]> git.lyx.org Git - features.git/blobdiff - src/Row.h
Restore correct version check for AA_UseHighDpiPixmaps - amend change ae56fb6171
[features.git] / src / Row.h
index 72d7a860b73b6f890ca0c14e30b441b0c4591e31..2c60638f344d2731c32a452a2b28e776225fc873 100644 (file)
--- a/src/Row.h
+++ b/src/Row.h
@@ -50,9 +50,7 @@ public:
                // An inset
                INSET,
                // Some spacing described by its width, not a string
-               SPACE,
-               // Something that should not happen (for error handling)
-               INVALID
+               SPACE
        };
 
 /**
@@ -60,8 +58,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,26 +90,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; };
@@ -121,11 +114,11 @@ 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;
+               pos_type endpos;
                // The dimension of the chunk (does not contains the
                // separator correction)
                Dimension dim;
@@ -293,10 +286,10 @@ 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.
         */
-       bool shortenIfNeeded(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
@@ -308,10 +301,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; }
@@ -382,6 +377,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.