+LyXAlignment TextMetrics::getAlign(Paragraph const & par, Row const & row) const
+{
+ Layout const & layout = par.layout();
+
+ LyXAlignment align;
+ if (par.params().align() == LYX_ALIGN_LAYOUT)
+ align = layout.align;
+ else
+ align = par.params().align();
+
+ // handle alignment inside tabular cells
+ Inset const & owner = text_->inset();
+ bool forced_block = false;
+ switch (owner.contentAlignment()) {
+ case LYX_ALIGN_BLOCK:
+ // In general block align is the default state, but here it is
+ // an explicit choice. Therefore it should not be overridden
+ // later.
+ forced_block = true;
+ // fall through
+ case LYX_ALIGN_CENTER:
+ case LYX_ALIGN_LEFT:
+ case LYX_ALIGN_RIGHT:
+ if (align == LYX_ALIGN_NONE || align == LYX_ALIGN_BLOCK)
+ align = owner.contentAlignment();
+ break;
+ default:
+ // unchanged (use align)
+ break;
+ }
+
+ // Display-style insets should always be on a centered row
+ if (Inset const * inset = par.getInset(row.pos())) {
+ switch (inset->display()) {
+ case Inset::AlignLeft:
+ align = LYX_ALIGN_BLOCK;
+ break;
+ case Inset::AlignCenter:
+ align = LYX_ALIGN_CENTER;
+ break;
+ case Inset::Inline:
+ // unchanged (use align)
+ break;
+ case Inset::AlignRight:
+ align = LYX_ALIGN_RIGHT;
+ break;
+ }
+ }
+
+ if (align == LYX_ALIGN_BLOCK) {
+ // If this row has been broken abruptly by a display inset, or
+ // it is the end of the paragraph, or the user requested we
+ // not justify stuff, then don't stretch.
+ // A forced block alignment can only be overridden the 'no
+ // justification on screen' setting.
+ if (((row.right_boundary() || row.endpos() == par.size())
+ && !forced_block)
+ || !bv_->buffer().params().justification)
+ align = text_->isRTL(par) ? LYX_ALIGN_RIGHT : LYX_ALIGN_LEFT;
+ }
+
+ return align;
+}
+
+