mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Prevent insets in table cells from expanding artificially to max width
This replaces ad-hoc hacks and does a better job by propagating the the tightness recursively. Fixes bug #9363.
This commit is contained in:
parent
bc01f50955
commit
5e396c3f0c
@ -120,8 +120,8 @@ int MetricsBase::inPixels(Length const & len) const
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MetricsInfo::MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
|
||||
MacroContext const & mc, bool vm)
|
||||
: base(bv, font, textwidth), macrocontext(mc), vmode(vm)
|
||||
MacroContext const & mc, bool vm, bool tight)
|
||||
: base(bv, font, textwidth), macrocontext(mc), vmode(vm), tight_insets(tight)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
MetricsInfo();
|
||||
///
|
||||
MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
|
||||
MacroContext const & mc, bool vm);
|
||||
MacroContext const & mc, bool vm, bool tight_insets);
|
||||
|
||||
///
|
||||
MetricsBase base;
|
||||
@ -103,6 +103,8 @@ public:
|
||||
MacroContext const & macrocontext;
|
||||
/// Are we at the start of a paragraph (vertical mode)?
|
||||
bool vmode;
|
||||
/// if true, do not expand insets to max width artificially
|
||||
bool tight_insets;
|
||||
};
|
||||
|
||||
|
||||
|
@ -106,14 +106,9 @@ int numberOfHfills(Row const & row, ParagraphMetrics const & pm,
|
||||
|
||||
|
||||
TextMetrics::TextMetrics(BufferView * bv, Text * text)
|
||||
: bv_(bv), text_(text)
|
||||
{
|
||||
LBUFERR(bv_);
|
||||
max_width_ = bv_->workWidth();
|
||||
dim_.wid = max_width_;
|
||||
dim_.asc = 10;
|
||||
dim_.des = 10;
|
||||
}
|
||||
: bv_(bv), text_(text), dim_(bv_->workWidth(), 10, 10),
|
||||
max_width_(dim_.wid), tight_(false)
|
||||
{}
|
||||
|
||||
|
||||
bool TextMetrics::contains(pit_type pit) const
|
||||
@ -216,18 +211,18 @@ void TextMetrics::newParMetricsUp()
|
||||
}
|
||||
|
||||
|
||||
bool TextMetrics::metrics(MetricsInfo const & mi, Dimension & dim, int min_width,
|
||||
bool const expand_on_multipars)
|
||||
bool TextMetrics::metrics(MetricsInfo const & mi, Dimension & dim, int min_width)
|
||||
{
|
||||
LBUFERR(mi.base.textwidth > 0);
|
||||
max_width_ = mi.base.textwidth;
|
||||
tight_ = mi.tight_insets;
|
||||
// backup old dimension.
|
||||
Dimension const old_dim = dim_;
|
||||
// reset dimension.
|
||||
dim_ = Dimension();
|
||||
dim_.wid = min_width;
|
||||
pit_type const npar = text_->paragraphs().size();
|
||||
if (npar > 1 && expand_on_multipars)
|
||||
if (npar > 1 && !tight_)
|
||||
// If there is more than one row, expand the text to
|
||||
// the full allowable width.
|
||||
dim_.wid = max_width_;
|
||||
@ -512,7 +507,7 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
|
||||
Font const & font = e.inset->inheritFont() ?
|
||||
displayFont(pit, e.pos) : bufferfont;
|
||||
MacroContext mc(&buffer, parPos);
|
||||
MetricsInfo mi(bv_, font.fontInfo(), w, mc, e.pos == 0);
|
||||
MetricsInfo mi(bv_, font.fontInfo(), w, mc, e.pos == 0, tight_);
|
||||
e.inset->metrics(mi, dim);
|
||||
if (!insetCache.has(e.inset) || insetCache.dim(e.inset) != dim) {
|
||||
insetCache.add(e.inset, dim);
|
||||
@ -536,12 +531,12 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
|
||||
setRowHeight(row);
|
||||
row.changed(true);
|
||||
if ((row_index || row.endpos() < par.size() || row.right_boundary())
|
||||
&& par.inInset().lyxCode() != CELL_CODE) {
|
||||
&& !tight_) {
|
||||
/* 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 setRowAlignment() below.
|
||||
* We do nothing when inside a table cell.
|
||||
* We do nothing when tight insets are requested.
|
||||
*/
|
||||
if (dim_.wid < max_width_)
|
||||
dim_.wid = max_width_;
|
||||
|
@ -39,7 +39,7 @@ class TextMetrics
|
||||
void operator=(TextMetrics const &);
|
||||
public:
|
||||
/// Default constructor (only here for STL containers).
|
||||
TextMetrics() : bv_(0), text_(0), max_width_(0) {}
|
||||
TextMetrics() : bv_(0), text_(0), max_width_(0), tight_(false) {}
|
||||
/// The only useful constructor.
|
||||
TextMetrics(BufferView *, Text *);
|
||||
|
||||
@ -72,8 +72,7 @@ public:
|
||||
void newParMetricsUp();
|
||||
|
||||
/// compute text metrics.
|
||||
bool metrics(MetricsInfo const & mi, Dimension & dim, int min_width = 0,
|
||||
bool const expand_on_multipars = true);
|
||||
bool metrics(MetricsInfo const & mi, Dimension & dim, int min_width = 0);
|
||||
|
||||
/// The "nodraw" drawing stage for one single paragraph: set the
|
||||
/// positions of the insets contained in this paragraph in metrics
|
||||
@ -257,6 +256,8 @@ private:
|
||||
mutable ParMetricsCache par_metrics_;
|
||||
Dimension dim_;
|
||||
int max_width_;
|
||||
/// if true, do not expand insets to max width artificially
|
||||
bool tight_;
|
||||
mutable Point origin_;
|
||||
|
||||
// temporary public:
|
||||
|
@ -57,6 +57,7 @@
|
||||
#include "frontends/Painter.h"
|
||||
#include "frontends/Selection.h"
|
||||
|
||||
#include "support/Changer.h"
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/docstream.h"
|
||||
@ -4341,10 +4342,11 @@ void InsetTableCell::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
|
||||
// We tell metrics here not to expand on multiple pars
|
||||
// This is the difference to InsetText::Metrics
|
||||
if (hasFixedWidth() || isVarwidth)
|
||||
tm.metrics(mi, dim, mi.base.textwidth, false);
|
||||
Changer changetight = changeVar(mi.tight_insets, true);
|
||||
if (hasFixedWidth())
|
||||
tm.metrics(mi, dim, mi.base.textwidth);
|
||||
else
|
||||
tm.metrics(mi, dim, 0, false);
|
||||
tm.metrics(mi, dim, 0);
|
||||
mi.base.textwidth += horiz_offset;
|
||||
dim.asc += topOffset(mi.base.bv);
|
||||
dim.des += bottomOffset(mi.base.bv);
|
||||
|
Loading…
Reference in New Issue
Block a user