diff --git a/src/ParagraphMetrics.cpp b/src/ParagraphMetrics.cpp index 9a9ecf0552..ad217cfa60 100644 --- a/src/ParagraphMetrics.cpp +++ b/src/ParagraphMetrics.cpp @@ -194,6 +194,7 @@ int ParagraphMetrics::rightMargin(BufferView const & bv) const } +// FIXME: this code seems bogus. Audit and rewrite (see bug #9860). bool ParagraphMetrics::hfillExpansion(Row const & row, pos_type pos) const { if (!par_->isHfill(pos)) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 1a033d5fd2..ee101b3987 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -584,15 +584,19 @@ void TextMetrics::computeRowMetrics(pit_type const pit, row.label_hfill = labelFill(pit, row) / double(nlh); } - double hfill = 0; // are there any hfills in the row? - if (int const nh = numberOfHfills(row, par.beginOfBody())) { - if (w > 0) - hfill = double(w) / nh; - // we don't have to look at the alignment if it is ALIGN_LEFT and - // if the row is already larger then the permitted width as then - // we force the LEFT_ALIGN'edness! - } else if (int(row.width()) < max_width_) { + int nh = numberOfHfills(row, par.beginOfBody()); + int hfill = 0; + int hfill_rem = 0; + + // We don't have to look at the alignment if + // * we use hfills, or + // * the row is already larger then the permitted width as then we + // force the LEFT_ALIGN'edness! + if (nh > 0) { + hfill = w / nh; + hfill_rem = w % nh; + } else if (nh == 0 && int(row.width()) < max_width_) { // is it block, flushleft or flushright? // set x how you need it switch (getAlign(par, row)) { @@ -641,11 +645,15 @@ void TextMetrics::computeRowMetrics(pit_type const pit, cit->dim.wid -= int(row.label_hfill * (nlh - 1)); if (!cit->inset || !cit->inset->isHfill()) continue; - if (pm.hfillExpansion(row, cit->pos)) - cit->dim.wid = int(cit->pos >= body_pos ? - max(hfill, 5.0) : row.label_hfill); - else - cit->dim.wid = 5; + if (pm.hfillExpansion(row, cit->pos)) { + if (cit->pos >= body_pos) { + cit->dim.wid += hfill; + --nh; + if (nh == 0) + cit->dim.wid += hfill_rem; + } else + cit->dim.wid += int(row.label_hfill); + } // Cache the inset dimension. insetCache.add(cit->inset, cit->dim); } diff --git a/src/insets/InsetSpace.cpp b/src/insets/InsetSpace.cpp index b8cab16fd0..6ab6f9a8d7 100644 --- a/src/insets/InsetSpace.cpp +++ b/src/insets/InsetSpace.cpp @@ -200,9 +200,10 @@ int const arrow_size = 8; void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const { if (isHfill()) { - // The metrics for this kinds are calculated externally in - // \c TextMetrics::computeRowMetrics. Those are dummy value: - dim = Dimension(10, 10, 10); + // The width for hfills is calculated externally in + // TextMetrics::computeRowMetrics. The value of 5 is the + // minimal value when the hfill is not active. + dim = Dimension(5, 10, 10); return; }