Do not terminate size switches in front of insets with InheritFont() false

and inherit the size.

This reduces formatting clutter (#8384) in table and fixes some wrongly
set sizes (#9923, #9285) in tables.
This commit is contained in:
Juergen Spitzmueller 2020-07-15 09:11:05 +02:00
parent bce21e8975
commit 3b6fec3835
3 changed files with 38 additions and 44 deletions

View File

@ -218,8 +218,6 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
Font const & base,
Font const & prev) const
{
bool env = false;
int count = 0;
// polyglossia or babel?
@ -297,26 +295,31 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
FontInfo p = bits_;
p.reduce(prev.bits_);
if (f.size() != INHERIT_SIZE) {
os << '{';
++count;
os << '\\'
<< LaTeXSizeNames[f.size()]
<< "{}";
count += strlen(LaTeXSizeNames[f.size()]) + 3;
}
if (f.family() != INHERIT_FAMILY) {
os << '\\'
<< LaTeXFamilyNames[f.family()]
<< '{';
count += strlen(LaTeXFamilyNames[f.family()]) + 2;
env = true; //We have opened a new environment
}
if (f.series() != INHERIT_SERIES) {
os << '\\'
<< LaTeXSeriesNames[f.series()]
<< '{';
count += strlen(LaTeXSeriesNames[f.series()]) + 2;
env = true; //We have opened a new environment
}
if (f.shape() != INHERIT_SHAPE) {
os << '\\'
<< LaTeXShapeNames[f.shape()]
<< '{';
count += strlen(LaTeXShapeNames[f.shape()]) + 2;
env = true; //We have opened a new environment
}
if (f.color() != Color_inherit && f.color() != Color_ignore) {
if (f.color() == Color_none && p.color() != Color_none) {
@ -329,7 +332,6 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
<< "}{";
count += lcolor.getLaTeXName(f.color()).length() + 13;
}
env = true; //We have opened a new environment
}
// FIXME: uncomment this when we support background.
/*
@ -364,24 +366,11 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
if (f.emph() == FONT_ON) {
os << "\\emph{";
count += 6;
env = true; //We have opened a new environment
}
// \noun{} is a LyX special macro
if (f.noun() == FONT_ON) {
os << "\\noun{";
count += 6;
env = true; //We have opened a new environment
}
if (f.size() != INHERIT_SIZE) {
// If we didn't open an environment above, we open one here
if (!env) {
os << '{';
++count;
}
os << '\\'
<< LaTeXSizeNames[f.size()]
<< "{}";
count += strlen(LaTeXSizeNames[f.size()]) + 3;
}
// The ulem commands need to be on the deepest nesting level
// because ulem puts every nested group or macro in a box,
@ -429,10 +418,10 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
Font const & base,
Font const & next,
bool & needPar,
bool const & closeLanguage) const
bool const & closeLanguage,
bool const & non_inherit_inset) const
{
int count = 0;
bool env = false;
// reduce the current font to changes against the base
// font (of the layout). We use a temporary for this to
@ -443,36 +432,32 @@ int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
if (f.family() != INHERIT_FAMILY) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.series() != INHERIT_SERIES) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.shape() != INHERIT_SHAPE) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.color() != Color_inherit && f.color() != Color_ignore && f.color() != Color_none) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.emph() == FONT_ON) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.noun() == FONT_ON) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.size() != INHERIT_SIZE) {
// We only have to close if only size changed
if (!env) {
// We do not close size group in front of
// insets with InheritFont() false (as opposed
// to all other font properties) (#8384)
if (!non_inherit_inset) {
if (needPar && !closeLanguage) {
os << "\\par";
count += 4;

View File

@ -86,7 +86,8 @@ public:
Font const & base,
Font const & next,
bool & needPar,
bool const & closeLanguage = true) const;
bool const & closeLanguage = true,
bool const & non_inherit_inset = false) const;
/// Build GUI description of font state

View File

@ -1053,9 +1053,11 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
bool needPar = false;
bool closeLanguage = arabtex
|| basefont.isRightToLeft() == running_font.isRightToLeft();
// We pass non_inherit_inset = true here since size switches
// ought not to be terminated here (#8384).
unsigned int count = running_font.latexWriteEndChanges(os,
bparams, runparams, basefont, basefont,
needPar, closeLanguage);
needPar, closeLanguage, true);
column += count;
// if any font properties were closed, update the running_font,
// making sure, however, to leave the language as it was
@ -1067,8 +1069,10 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
running_font = basefont;
if (!closeLanguage)
running_font.setLanguage(copy_font.language());
basefont.fontInfo().setSize(copy_font.fontInfo().size());
// leave font open if language is still open
open_font = (running_font.language() == basefont.language());
open_font = (running_font.language() == basefont.language()
|| running_font.fontInfo().size() == basefont.fontInfo().size());
if (closeLanguage)
runparams.local_font = &basefont;
}
@ -2394,6 +2398,10 @@ void Paragraph::latex(BufferParams const & bparams,
pos_type body_pos = beginOfBody();
unsigned int column = 0;
// If we are inside an inset, the real outerfont is local_font
Font const real_outerfont = (runparams.local_font != nullptr)
? Font(runparams.local_font->fontInfo()) : outerfont;
if (body_pos > 0) {
// the optional argument is kept in curly brackets in
// case it contains a ']'
@ -2403,9 +2411,9 @@ void Paragraph::latex(BufferParams const & bparams,
// braces when it parses \item.
os << "[{";
column += 2;
basefont = getLabelFont(bparams, outerfont);
basefont = getLabelFont(bparams, real_outerfont);
} else {
basefont = getLayoutFont(bparams, outerfont);
basefont = getLayoutFont(bparams, real_outerfont);
}
// Which font is currently active?
@ -2450,7 +2458,7 @@ void Paragraph::latex(BufferParams const & bparams,
basefont, basefont, needPar);
open_font = false;
}
basefont = getLayoutFont(bparams, outerfont);
basefont = getLayoutFont(bparams, real_outerfont);
running_font = basefont;
column += Changes::latexMarkChange(os, bparams,
@ -2517,8 +2525,8 @@ void Paragraph::latex(BufferParams const & bparams,
basefont, needPar);
open_font = false;
}
basefont = (body_pos > i) ? getLabelFont(bparams, outerfont)
: getLayoutFont(bparams, outerfont);
basefont = (body_pos > i) ? getLabelFont(bparams, real_outerfont)
: getLayoutFont(bparams, real_outerfont);
running_font = basefont;
column += Changes::latexMarkChange(os, bparams,
Change(Change::INSERTED), change, rp);
@ -2538,8 +2546,8 @@ void Paragraph::latex(BufferParams const & bparams,
basefont, basefont, needPar);
open_font = false;
}
basefont = (body_pos > i) ? getLabelFont(bparams, outerfont)
: getLayoutFont(bparams, outerfont);
basefont = (body_pos > i) ? getLabelFont(bparams, real_outerfont)
: getLayoutFont(bparams, real_outerfont);
running_font = basefont;
column += Changes::latexMarkChange(os, bparams, runningChange,
change, runparams);
@ -2737,10 +2745,10 @@ void Paragraph::latex(BufferParams const & bparams,
pit < 0 || pars[pit].empty()
? pars[pit].getLayoutFont(
bparams,
outerfont)
real_outerfont)
: pars[pit].getFont(bparams,
pars[pit].size() - 1,
outerfont);
real_outerfont);
if (lastfont.fontInfo().size() !=
basefont.fontInfo().size()) {
++parInline;
@ -2748,7 +2756,7 @@ void Paragraph::latex(BufferParams const & bparams,
}
}
d->latexInset(bparams, os, rp, running_font,
basefont, outerfont, open_font,
basefont, real_outerfont, open_font,
runningChange, style, i, column);
if (incremented)
--parInline;
@ -2833,8 +2841,8 @@ void Paragraph::latex(BufferParams const & bparams,
// since this produces unwanted whitespace.
Font const font = empty()
? getLayoutFont(bparams, outerfont)
: getFont(bparams, size() - 1, outerfont);
? getLayoutFont(bparams, real_outerfont)
: getFont(bparams, size() - 1, real_outerfont);
InsetText const * textinset = inInset().asInsetText();