+ // go through row and draw from RTL boundary to RTL boundary
+ double x = xo_ + row_.left_margin;
+ for (auto const & e : row_) {
+ // These are the same tests as in paintStringAndSel, except
+ // that all_sel has an additional clause that triggers for end
+ // of paragraph markers. The clause was not used in
+ // paintStringAndSel to avoid changing the drawing color.
+ // at least part of text selected?
+ bool const some_sel = (e.endpos >= row_.sel_beg && e.pos < row_.sel_end)
+ || pi_.selected;
+ // all the text selected?
+ bool const all_sel = (e.pos >= row_.sel_beg && e.endpos < row_.sel_end)
+ || (e.isVirtual() && e.pos == row_.endpos() && row_.end_margin_sel)
+ || pi_.selected;
+
+ if (all_sel) {
+ // the 3rd argument is written like that to avoid rounding issues
+ pi_.pain.fillRectangle(int(x), y1,
+ int(x + e.full_width()) - int(x), y2 - y1,
+ Color_selection);
+ } else if (some_sel) {
+ pos_type const from = min(max(row_.sel_beg, e.pos), e.endpos);
+ pos_type const to = max(min(row_.sel_end, e.endpos), e.pos);
+ double x1 = e.pos2x(from);
+ double x2 = e.pos2x(to);
+ if (x1 > x2)
+ swap(x1, x2);
+ // the 3rd argument is written like that to avoid rounding issues
+ pi_.pain.fillRectangle(int(x + x1), y1, int(x2 + x) - int(x1 + x),
+ y2 - y1, Color_selection);