commit 4010ccafbd95fed56892038c2d3e1a8a9eae8832
Author: Juergen Spitzmueller <[email protected]>
Date: Sat Apr 21 12:55:11 2018 +0200
Factor out test for script wrapper in given font enc
---
src/Encoding.cpp | 14 ++++++++++++++
src/Encoding.h | 3 +++
src/Paragraph.cpp | 8 ++------
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/Encoding.cpp b/src/Encoding.cpp
index b9cad8d..9966e71 100644
--- a/src/Encoding.cpp
+++ b/src/Encoding.cpp
@@ -599,6 +599,20 @@ bool Encodings::isKnownScriptChar(char_type const c,
string & preamble)
}
+bool Encodings::needsScriptWrapper(string const & script, string const &
fontenc)
+{
+ if (script == "textgreek")
+ return (fontenc != "LGR");
+ if (script == "textcyr") {
+ return (fontenc != "T2A" && fontenc != "T2B"
+ && fontenc != "T2C" && fontenc != "X2");
+ }
+ if (script == "textbaltic")
+ return (fontenc != "L7x");
+ return false;
+}
+
+
bool Encodings::isMathAlpha(char_type c)
{
return mathalpha.count(c);
diff --git a/src/Encoding.h b/src/Encoding.h
index 7400127..ed1ec47 100644
--- a/src/Encoding.h
+++ b/src/Encoding.h
@@ -280,6 +280,9 @@ public:
* \p c is a known character matching the preamble entry.
*/
static bool isKnownScriptChar(char_type const c, std::string &
preamble);
+ /// Do we need to wrap scripts into \text<script> macros?
+ static bool needsScriptWrapper(std::string const & script,
+ std::string const & fontenc);
/**
* Do we have to display in italics this character when in mathmode?
* This is true if the "mathalpha" flag is set. We use this for
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 452ce14..14c9c9e 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -920,9 +920,7 @@ int Paragraph::Private::latexSurrogatePair(otexstream & os,
char_type c,
length -= pos;
latex2 = latex2.substr(pos, length);
// We only need the script macro with non-native font encodings
- if ((script == "textgreek" && fontenc != "LGR")
- || (script == "textcyr" && fontenc != "T2A" && fontenc !=
"T2B"
- && fontenc != "T2C" && fontenc != "X2")) {
+ if (Encodings::needsScriptWrapper(script, fontenc)) {
scriptmacro = from_ascii("\\" + script + "{");
cb = from_ascii("}");
}
@@ -1013,9 +1011,7 @@ int Paragraph::Private::writeScriptChars(OutputParams
const & runparams,
int pos = 0;
int length = brace2;
bool closing_brace = true;
- if ((script == "textgreek" && fontenc == "LGR")
- ||(script == "textcyr" && (fontenc == "T2A" || fontenc == "T2B"
- || fontenc == "T2C" || fontenc ==
"X2"))) {
+ if (!Encodings::needsScriptWrapper(script, fontenc)) {
// Correct font encoding is being used, so we can avoid
\text[greek|cyr].
pos = brace1 + 1;
length -= pos;