// An inset
INSET,
// Some spacing described by its width, not a string
- SPACE,
- // Something that should not happen (for error handling)
- INVALID
+ SPACE
};
/**
* 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) {}
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; };
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;
* 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
* 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; }
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.