bool changed = false;
unsigned int h = 0;
for (pit_type pit = 0; pit != npar; ++pit) {
- changed |= redoParagraph(pit);
+ // create rows, but do not set alignment yet
+ changed |= redoParagraph(pit, false);
ParagraphMetrics const & pm = par_metrics_[pit];
h += pm.height();
if (dim_.wid < pm.width())
dim_.wid = pm.width();
}
+ // Now set alignment for all rows (the width might not have been known before).
+ for (pit_type pit = 0; pit != npar; ++pit) {
+ ParagraphMetrics & pm = par_metrics_[pit];
+ for (Row & row : pm.rows())
+ setRowAlignment(row, dim_.wid);
+ }
+
dim_.asc = par_metrics_[0].ascent();
dim_.des = h - dim_.asc;
//lyxerr << "dim_.wid " << dim_.wid << endl;
}
-bool TextMetrics::redoParagraph(pit_type const pit)
+bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
{
Paragraph & par = text_->getPar(pit);
// IMPORTANT NOTE: We pass 'false' explicitly in order to not call
/* If there is more than one row or the row has been
* broken by a display inset or a newline, expand the text
* to the full allowable width. This setting here is
- * needed for the computeRowMetrics() below.
+ * needed for the setRowAlignment() below.
* We do nothing when inside a table cell.
*/
if (dim_.wid < max_width_)
dim_.wid = max_width_;
}
- int const max_row_width = max(dim_.wid, row.width());
- computeRowMetrics(row, max_row_width);
+ if (align_rows)
+ setRowAlignment(row, max(dim_.wid, row.width()));
first = row.endpos();
++row_index;
}
-void TextMetrics::computeRowMetrics(Row & row, int width) const
+void TextMetrics::setRowAlignment(Row & row, int width) const
{
row.label_hfill = 0;
row.separator = 0;
/// Rebreaks the given paragraph.
/// \retval true if a full screen redraw is needed.
/// \retval false if a single paragraph redraw is enough.
- bool redoParagraph(pit_type const pit);
+ bool redoParagraph(pit_type const pit, bool align_rows = true);
/// Clear cache of paragraph metrics
void clear() { par_metrics_.clear(); }
/// Is cache of paragraph metrics empty ?
/// \return true when another row is required (after a newline)
bool breakRow(Row & row, int right_margin) const;
- // Expand the alignment of row \param row in paragraph \param par
+ // Expands the alignment of row \param row in paragraph \param par
LyXAlignment getAlign(Paragraph const & par, Row const & row) const;
- /** this calculates the specified parameters. needed when setting
- * the cursor and when creating a visible row */
- void computeRowMetrics(Row & row, int width) const;
+ /// Aligns properly the row contents (computes spaces and fills)
+ void setRowAlignment(Row & row, int width) const;
/// Set the height of the row (without space above/below paragraph)
void setRowHeight(Row & row) const;