+ // Possible types of row elements
+ enum Type {
+ // a string of character
+ STRING,
+ /**
+ * Something (completion, end-of-par marker)
+ * that occupies space one screen but does not
+ * correspond to any paragraph contents
+ */
+ VIRTUAL,
+ // An inset
+ INSET,
+ // Some spacing described by its width, not a string
+ SPACE,
+ // Spacing until the left margin, with a minimal value given
+ // by the initial width
+ MARGINSPACE
+ };
+
+/**
+ * One element of a Row. It has a set of attributes that can be used
+ * by other methods that need to parse the Row contents.
+ */
+ struct Element {
+ //
+ 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 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(); }
+ // Return the number of expanding characters in the element (only STRING
+ // type).
+ int countExpanders() const;
+ // Return the amount of expansion: the number of expanding characters
+ // that get stretched during justification, times the em of the font
+ // (only STRING type).
+ int expansionAmount() const;
+ // set extra proportionally to the font em value.
+ void setExtra(double extra_per_em);
+
+ /** Return position in pixels (from the left) of position
+ * \param i in the row element.
+ */
+ double pos2x(pos_type const i) const;
+ /** Return character position that is the closest to
+ * pixel position \param x. The value \param x is
+ * adjusted to the actual pixel position.
+ */
+ pos_type x2pos(int &x) const;
+ /** Break the element in two if possible, so that its width is less
+ * 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).
+ */
+ // 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; }
+
+ // Returns the position on left side of the element.
+ pos_type left_pos() const { return isRTL() ? endpos : pos; };
+ // Returns the position on right side of the element.
+ pos_type right_pos() const { return isRTL() ? pos : endpos; };
+
+ // The kind of row element
+ Type type;
+ // position of the element in the paragraph
+ pos_type pos;
+ // first position after the element in the paragraph
+ 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;
+
+ // Only non-null for justified rows
+ double extra = 0;
+
+ // Non-empty if element is a string or is virtual
+ docstring str;
+ //
+ Font font;
+ //
+ Change change;
+ // is it possible to add contents to this element?
+ bool final = false;
+ // properties with respect to row breaking (made of RowFlag enumerators)
+ int row_flags = Inline;
+
+ friend std::ostream & operator<<(std::ostream & os, Element const & row);
+ };
+