+ // 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
+ };
+
+/**
+ * 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), inset(0),
+ extra(0), font(f), change(ch), final(false) {}
+
+ // 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(); }
+ // 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 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, other wise it
+ * respects the row breaking rules of characters.
+ */
+ bool breakAt(int w, bool force);
+
+ // Returns the position on left side of the element.
+ pos_type left_pos() const;
+ // Returns the position on right side of the element.
+ pos_type right_pos() const;
+
+ //
+ bool isRTL() const { return font.isVisibleRightToLeft(); }
+ // This is true for virtual elements.
+ // Note that we do not use the type here. The two definitions
+ // should be equivalent
+ bool isVirtual() const { return 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 contains the
+ // separator correction)
+ Dimension dim;
+
+ // Non-zero only if element is an inset
+ Inset const * inset;
+
+ // Only non-null for justified rows
+ double extra;
+
+ // 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;
+
+ friend std::ostream & operator<<(std::ostream & os, Element const & row);
+ };
+
+