Assure language is properly closed before non-inheriting inset.

This commit is contained in:
Juergen Spitzmueller 2020-08-14 09:08:46 +02:00
parent 8bc76ad9bb
commit ef11fdc77d

View File

@ -1027,6 +1027,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
close = true;
}
if (open_font && (!inset->inheritFont() || inset->allowMultiPar())) {
// Some insets cannot be inside a font change command.
// However, even such insets *can* be placed in \L or \R
// or their equivalents (for RTL language switches), so we don't
@ -1034,22 +1035,41 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
// ArabTeX, though, cannot handle this special behavior, it seems.
bool arabtex = basefont.language()->lang() == "arabic_arabtex"
|| running_font.language()->lang() == "arabic_arabtex";
if (open_font && (!inset->inheritFont() || inset->allowMultiPar())) {
bool closeLanguage = arabtex
|| basefont.isRightToLeft() == running_font.isRightToLeft();
bool lang_closed = false;
bool lang_switched_at_inset = false;
// Close language if needed
if (closeLanguage) {
// We need prev_font here as language changes directly at inset
// will only be started inside the inset.
Font const prev_font = (i > 0) ?
owner_->getFont(bparams, i - 1, outerfont)
: running_font;
Font tmpfont(basefont);
tmpfont.setLanguage(prev_font.language());
bool needPar = false;
unsigned int count = tmpfont.latexWriteEndChanges(os, bparams, runparams,
basefont, basefont,
needPar, closeLanguage);
column += count;
lang_closed = count > 0;
lang_switched_at_inset = prev_font.language() != running_font.language();
}
// Now re-do font changes in a way needed here
// (using switches with multi-par insets)
InsetText const * textinset = inset->asInsetText();
bool const cprotect = textinset
? textinset->hasCProtectContent(runparams.moving_arg)
&& !textinset->text().isMainText()
: false;
unsigned int count = running_font.latexWriteStartChanges(os, bparams,
unsigned int count2 = running_font.latexWriteStartChanges(os, bparams,
runparams, basefont,
running_font, true,
cprotect);
column += count;
// if any font properties were closed, update the running_font,
// making sure, however, to leave the language as it was
if (count > 0) {
column += count2;
// Update the running_font, making sure, however,
// to leave the language as it was.
// FIXME: probably a better way to keep track of the old
// language, than copying the entire font?
Font const copy_font(running_font);
@ -1057,14 +1077,17 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
running_font = basefont;
if (!closeLanguage)
running_font.setLanguage(copy_font.language());
// For these, we use switches, so no need to close
// For these, we use switches, so they should be taken as
// base inside the inset.
basefont.fontInfo().setSize(copy_font.fontInfo().size());
basefont.fontInfo().setFamily(copy_font.fontInfo().family());
basefont.fontInfo().setSeries(copy_font.fontInfo().series());
if (count2 == 0 && (lang_closed || lang_switched_at_inset))
// All fonts closed
open_font = false;
if (closeLanguage)
runparams.local_font = &basefont;
}
}
size_t const previous_row_count = os.texrow().rows();