mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 22:41:09 +00:00
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:
parent
f6bcf2a29e
commit
1f0305509b
@ -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
|
bool ParagraphMetrics::hfillExpansion(Row const & row, pos_type pos) const
|
||||||
{
|
{
|
||||||
if (!par_->isHfill(pos))
|
if (!par_->isHfill(pos))
|
||||||
|
@ -584,15 +584,19 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
|
|||||||
row.label_hfill = labelFill(pit, row) / double(nlh);
|
row.label_hfill = labelFill(pit, row) / double(nlh);
|
||||||
}
|
}
|
||||||
|
|
||||||
double hfill = 0;
|
|
||||||
// are there any hfills in the row?
|
// are there any hfills in the row?
|
||||||
if (int const nh = numberOfHfills(row, par.beginOfBody())) {
|
int nh = numberOfHfills(row, par.beginOfBody());
|
||||||
if (w > 0)
|
int hfill = 0;
|
||||||
hfill = double(w) / nh;
|
int hfill_rem = 0;
|
||||||
// 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 don't have to look at the alignment if
|
||||||
// we force the LEFT_ALIGN'edness!
|
// * we use hfills, or
|
||||||
} else if (int(row.width()) < max_width_) {
|
// * 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?
|
// is it block, flushleft or flushright?
|
||||||
// set x how you need it
|
// set x how you need it
|
||||||
switch (getAlign(par, row)) {
|
switch (getAlign(par, row)) {
|
||||||
@ -641,11 +645,15 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
|
|||||||
cit->dim.wid -= int(row.label_hfill * (nlh - 1));
|
cit->dim.wid -= int(row.label_hfill * (nlh - 1));
|
||||||
if (!cit->inset || !cit->inset->isHfill())
|
if (!cit->inset || !cit->inset->isHfill())
|
||||||
continue;
|
continue;
|
||||||
if (pm.hfillExpansion(row, cit->pos))
|
if (pm.hfillExpansion(row, cit->pos)) {
|
||||||
cit->dim.wid = int(cit->pos >= body_pos ?
|
if (cit->pos >= body_pos) {
|
||||||
max(hfill, 5.0) : row.label_hfill);
|
cit->dim.wid += hfill;
|
||||||
else
|
--nh;
|
||||||
cit->dim.wid = 5;
|
if (nh == 0)
|
||||||
|
cit->dim.wid += hfill_rem;
|
||||||
|
} else
|
||||||
|
cit->dim.wid += int(row.label_hfill);
|
||||||
|
}
|
||||||
// Cache the inset dimension.
|
// Cache the inset dimension.
|
||||||
insetCache.add(cit->inset, cit->dim);
|
insetCache.add(cit->inset, cit->dim);
|
||||||
}
|
}
|
||||||
|
@ -200,9 +200,10 @@ int const arrow_size = 8;
|
|||||||
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
|
void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
if (isHfill()) {
|
if (isHfill()) {
|
||||||
// The metrics for this kinds are calculated externally in
|
// The width for hfills is calculated externally in
|
||||||
// \c TextMetrics::computeRowMetrics. Those are dummy value:
|
// TextMetrics::computeRowMetrics. The value of 5 is the
|
||||||
dim = Dimension(10, 10, 10);
|
// minimal value when the hfill is not active.
|
||||||
|
dim = Dimension(5, 10, 10);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user