X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FRow.h;h=156fd9f671eefb166af633ebb99f1d6609b6aa85;hb=2abde5d16254e8aac29e344442b09e6272000f13;hp=72d7a860b73b6f890ca0c14e30b441b0c4591e31;hpb=49115315ea751332d3f8f8a0770cf8427a2c9640;p=lyx.git diff --git a/src/Row.h b/src/Row.h index 72d7a860b7..156fd9f671 100644 --- 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,16 +61,11 @@ 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) {} - // Return the number of separator in the element (only STRING type) - int countSeparators() const; - // Return total width of element, including separator overhead // FIXME: Cache this value or the number of expanders? double full_width() const { return dim.wid + extra * countExpanders(); } @@ -93,27 +89,26 @@ 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. + * than the required values. + * \return true if something has been done ; false if this is + * not needed or not possible. + * \param width: maximum width of the row. + * \param next_width: available width on next rows. + * \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. + * \param tail: a vector of elements where the remainder of + * the text will be appended (empty if nothing happened). */ - 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 & 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,14 +116,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; @@ -144,7 +141,7 @@ 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) + // properties with respect to row breaking (made of RowFlag enumerators) int row_flags = Inline; friend std::ostream & operator<<(std::ostream & os, Element const & row); @@ -209,9 +206,9 @@ public: /// pos_type endpos() const { return end_; } /// - void right_boundary(bool b) { right_boundary_ = b; } + void end_boundary(bool b) { end_boundary_ = b; } /// - bool right_boundary() const { return right_boundary_; } + bool end_boundary() const { return end_boundary_; } /// void flushed(bool b) { flushed_ = b; } /// @@ -240,8 +237,6 @@ public: /// The offset of the right-most cursor position on the row int right_x() const; - // Return the number of separators in the row - int countSeparators() const; // 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. @@ -252,12 +247,14 @@ public: Font const & f, Change const & ch); /// void add(pos_type pos, char_type const c, - Font const & f, Change const & ch, bool can_break); + Font const & f, Change const & ch); /// 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 Elements; @@ -293,10 +290,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 +305,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; } @@ -369,7 +368,7 @@ private: /// one behind last pos covered by this row pos_type end_ = 0; // Is there a boundary at the end of the row (display inset...) - bool right_boundary_ = false; + bool end_boundary_ = false; // Shall the row be flushed when it is supposed to be justified? bool flushed_ = false; /// Row dimension. @@ -382,6 +381,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.