commit 8c14d9e0413978aa11f581e9c6f2d0587bb0b189
Author: Enrico Forestieri <[email protected]>
Date: Sun Sep 25 08:20:34 2016 +0200
Correctly track opened polyglossia languages
A language switch may also occur outside of output_latex.cpp, apparently.
---
src/Font.cpp | 3 +++
src/OutputParams.cpp | 3 ++-
src/OutputParams.h | 10 ++++++++++
src/Paragraph.cpp | 2 ++
src/output_latex.cpp | 25 +++++++++++++++++++++++++
src/output_latex.h | 8 ++++++++
6 files changed, 50 insertions(+), 1 deletions(-)
diff --git a/src/Font.cpp b/src/Font.cpp
index 0ca4080..f6eb6b9 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -287,6 +287,7 @@ int Font::latexWriteStartChanges(odocstream & os,
BufferParams const & bparams,
tmp += "{";
os << from_ascii(tmp);
count += tmp.length();
+
runparams.pushPolyglossiaLang(language()->polyglossia());
} else if (language()->encoding()->package() != Encoding::CJK) {
os << '{';
count += 1;
@@ -545,6 +546,8 @@ int Font::latexWriteEndChanges(otexstream & os,
BufferParams const & bparams,
&& language()->encoding()->package() != Encoding::CJK) {
os << '}';
++count;
+ if (runparams.use_polyglossia)
+ runparams.popPolyglossiaLang();
}
return count;
diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp
index 20c3a65..2b4c9d9 100644
--- a/src/OutputParams.cpp
+++ b/src/OutputParams.cpp
@@ -21,7 +21,8 @@ namespace lyx {
OutputParams::OutputParams(Encoding const * enc)
: flavor(LATEX), math_flavor(NotApplicable), nice(false),
is_child(false),
moving_arg(false), intitle(false), inulemcmd(0), local_font(0),
master_language(0),
- encoding(enc), free_spacing(false), use_babel(false),
use_polyglossia(false),
+ encoding(enc), pushPolyglossiaLang(0), popPolyglossiaLang(0),
+ free_spacing(false), use_babel(false), use_polyglossia(false),
use_indices(false), use_japanese(false), linelen(0), depth(0),
exportdata(new ExportData),
inComment(false), inTableCell(NO), inFloat(NONFLOAT),
diff --git a/src/OutputParams.h b/src/OutputParams.h
index 3914617..4927085 100644
--- a/src/OutputParams.h
+++ b/src/OutputParams.h
@@ -141,6 +141,16 @@ public:
*/
mutable Encoding const * encoding;
+ /** Pointer to a function for registering a language switch
+ when using polyglossia.
+ */
+ mutable void (* pushPolyglossiaLang)(std::string const & lang_name);
+
+ /** Pointer to a function for unregistering the last language
+ switch when using polyglossia.
+ */
+ mutable void (* popPolyglossiaLang)();
+
/** free_spacing == true means that the inset is in a free-spacing
paragraph.
*/
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 94cf931..fd0f7fa 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -2441,6 +2441,8 @@ void Paragraph::latex(BufferParams const & bparams,
running_lang);
os << from_ascii(end_tag);
column += end_tag.length();
+ if (runparams.use_polyglossia)
+ runparams.popPolyglossiaLang();
}
// Switch file encoding if necessary (and allowed)
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index b584626..0875fbf 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -478,6 +478,24 @@ void getArgInsets(otexstream & os, OutputParams const &
runparams, Layout::LaTeX
} // namespace anon
+void pushPolyglossiaLang(string const & lang_name)
+{
+ OutputState * state = getOutputState();
+
+ state->lang_switch_depth_.push(state->nest_level_);
+ state->open_polyglossia_lang_.push(lang_name);
+}
+
+
+void popPolyglossiaLang()
+{
+ OutputState * state = getOutputState();
+
+ state->lang_switch_depth_.pop();
+ state->open_polyglossia_lang_.pop();
+}
+
+
void latexArgInsets(Paragraph const & par, otexstream & os,
OutputParams const & runparams, Layout::LaTeXArgMap const & latexargs,
string const & prefix)
{
@@ -1265,8 +1283,15 @@ void latexParagraphs(Buffer const & buf,
: subst(lang_begin_command, "$$lang", mainlang);
os << bc;
os << '\n';
+ if (runparams.use_polyglossia) {
+ state->lang_switch_depth_.push(state->nest_level_);
+ state->open_polyglossia_lang_.push(mainlang);
+ }
}
+ runparams.pushPolyglossiaLang = pushPolyglossiaLang;
+ runparams.popPolyglossiaLang = popPolyglossiaLang;
+
ParagraphList const & paragraphs = text.paragraphs();
if (runparams.par_begin == runparams.par_end) {
diff --git a/src/output_latex.h b/src/output_latex.h
index 8bfeb6a..71af322 100644
--- a/src/output_latex.h
+++ b/src/output_latex.h
@@ -29,6 +29,14 @@ class Paragraph;
class OutputParams;
class Text;
+/** Register a language switch when using polyglossia.
+ */
+void pushPolyglossiaLang(std::string const & lang);
+
+/** Unregister the last language switch when using polyglossia.
+ */
+void popPolyglossiaLang();
+
/** Export optional and required arguments of the paragraph \p par.
Non-existing required arguments are output empty: {}.
*/