Fix length of hfills

The computation of the legth of expanded hfills did not take into account their unexpanded size. This is done now by increasing the dimension (+=) instead of merely setting it.

Moreover, since the insets sizes are integer number, rounding effects have to be taken in account. To this end, the extra number of pixels is added to the last hfill in the row.

This fixes part of bug #9860.

Note not everything is fixed by this patch: the logic of ParagraphMetrics::hfillExpansion seems bogus to me. I do not see why consecutive hfills at the beginning of a row should not be all expanded. Since I do not know what are the peculiarities of hfill handling in LaTeX, I did not change it (yet).

I did not either try to investigate the label hfill part, because I do not even know what is so special about it. I think there is a lot of old logic that nobody ever tried to question.
This commit is contained in:
Jean-Marc Lasgouttes 2015-11-13 10:57:26 +01:00
parent f6bcf2a29e
commit 1f0305509b
3 changed files with 26 additions and 16 deletions

View File

@ -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))

View File

@ -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);
}

View File

@ -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;
}