#include "Encoding.h"
-#include "Buffer.h"
-#include "BufferList.h"
-#include "InsetIterator.h"
-#include "LaTeXFeatures.h"
#include "Lexer.h"
-#include "LyXRC.h"
#include "support/debug.h"
#include "support/gettext.h"
-#include "support/FileName.h"
#include "support/lstrings.h"
#include "support/textutils.h"
#include "support/unicode.h"
char_type const arabic_end = 0x06cc;
-enum CharInfoFlags {
- ///
- CharInfoCombining = 1,
- ///
- CharInfoTextFeature = 2,
- ///
- CharInfoMathFeature = 4,
- ///
- CharInfoForce = 8,
- ///
- CharInfoTextNoTermination = 16,
- ///
- CharInfoMathNoTermination = 32,
- ///
- CharInfoForceSelected = 64,
-};
-
-/// Information about a single UCS4 character
-struct CharInfo {
- /// LaTeX command (text mode) for this character
- docstring textcommand;
- /// LaTeX command (math mode) for this character
- docstring mathcommand;
- /// Needed LaTeX preamble (or feature) for text mode
- string textpreamble;
- /// Needed LaTeX preamble (or feature) for math mode
- string mathpreamble;
- /// Is this a combining character?
- bool combining() const { return flags & CharInfoCombining ? true : false; }
- /// Is \c textpreamble a feature known by LaTeXFeatures, or a raw LaTeX
- /// command?
- bool textfeature() const { return flags & CharInfoTextFeature ? true : false; }
- /// Is \c mathpreamble a feature known by LaTeXFeatures, or a raw LaTeX
- /// command?
- bool mathfeature() const { return flags & CharInfoMathFeature ? true : false; }
- /// Always force the LaTeX command, even if the encoding contains
- /// this character?
- bool force() const { return flags & CharInfoForce ? true : false; }
- /// Force the LaTeX command for some encodings?
- bool forceselected() const { return flags & CharInfoForceSelected ? true : false; }
- /// TIPA shortcut
- string tipashortcut;
- /// \c textcommand needs no termination (such as {} or space).
- bool textnotermination() const { return flags & CharInfoTextNoTermination ? true : false; }
- /// \c mathcommand needs no termination (such as {} or space).
- bool mathnotermination() const { return flags & CharInfoMathNoTermination ? true : false; }
- ///
- unsigned int flags;
-};
-
-
typedef map<char_type, CharInfo> CharInfoMap;
CharInfoMap unicodesymbols;
-typedef std::set<char_type> CharSet;
-typedef std::map<string, CharSet> CharSetMap;
+typedef set<char_type> CharSet;
+typedef map<string, CharSet> CharSetMap;
CharSet forced;
CharSetMap forcedselected;
-typedef std::set<char_type> MathAlphaSet;
+typedef set<char_type> MathAlphaSet;
MathAlphaSet mathalpha;
}
+CharInfo::CharInfo(
+ docstring const textcommand, docstring const mathcommand,
+ std::string const textpreamble, std::string const mathpreamble,
+ std::string const tipashortcut, unsigned int flags)
+ : textcommand_(textcommand), mathcommand_(mathcommand),
+ textpreamble_(textpreamble), mathpreamble_(mathpreamble),
+ tipashortcut_(tipashortcut), flags_(flags)
+{
+}
+
Encoding::Encoding(string const & n, string const & l, string const & g,
string const & i, bool f, bool u, Encoding::Package p)
: name_(n), latexName_(l), guiName_(g), iconvName_(i), fixedwidth_(f),
if (it == unicodesymbols.end())
throw EncodingException(c);
// at least one of mathcommand and textcommand is nonempty
- if (it->second.textcommand.empty())
+ if (it->second.textcommand().empty())
return make_pair(
- "\\ensuremath{" + it->second.mathcommand + '}', false);
- return make_pair(it->second.textcommand, !it->second.textnotermination());
+ "\\ensuremath{" + it->second.mathcommand() + '}', false);
+ return make_pair(it->second.textcommand(), !it->second.textnotermination());
}
return false;
}
// at least one of mathcommand and textcommand is nonempty
- bool use_math = (mathmode && !it->second.mathcommand.empty()) ||
- (!mathmode && it->second.textcommand.empty());
+ bool use_math = (mathmode && !it->second.mathcommand().empty()) ||
+ (!mathmode && it->second.textcommand().empty());
if (use_math) {
- command = it->second.mathcommand;
+ command = it->second.mathcommand();
needsTermination = !it->second.mathnotermination();
addMathCmd(c);
} else {
if (!encoding || command.empty()) {
- command = it->second.textcommand;
+ command = it->second.textcommand();
needsTermination = !it->second.textnotermination();
addTextCmd(c);
}
CharInfoMap::const_iterator const end = unicodesymbols.end();
CharInfoMap::const_iterator it = unicodesymbols.begin();
for (combining = false; it != end; ++it) {
- docstring const math = it->second.mathcommand;
- docstring const text = it->second.textcommand;
+ docstring const math = it->second.mathcommand();
+ docstring const text = it->second.textcommand();
if ((cmdtype & MATH_CMD) && math == cmd) {
combining = it->second.combining();
needsTermination = !it->second.mathnotermination();
if (req && it->second.mathfeature() &&
- !it->second.mathpreamble.empty())
- req->insert(it->second.mathpreamble);
+ !it->second.mathpreamble().empty())
+ req->insert(it->second.mathpreamble());
return it->first;
}
if ((cmdtype & TEXT_CMD) && text == cmd) {
combining = it->second.combining();
needsTermination = !it->second.textnotermination();
if (req && it->second.textfeature() &&
- !it->second.textpreamble.empty())
- req->insert(it->second.textpreamble);
+ !it->second.textpreamble().empty())
+ req->insert(it->second.textpreamble());
return it->first;
}
}
size_t unicmd_size = 0;
char_type c = 0;
for (; it != uniend; ++it) {
- docstring const math = mathmode ? it->second.mathcommand
+ docstring const math = mathmode ? it->second.mathcommand()
: docstring();
- docstring const text = textmode ? it->second.textcommand
+ docstring const text = textmode ? it->second.textcommand()
: docstring();
if (!combcmd.empty() && it->second.combining() &&
(math == combcmd || text == combcmd))
needsTermination = !it->second.textnotermination();
if (req) {
if (math == tmp && it->second.mathfeature() &&
- !it->second.mathpreamble.empty())
- req->insert(it->second.mathpreamble);
+ !it->second.mathpreamble().empty())
+ req->insert(it->second.mathpreamble());
if (text == tmp && it->second.textfeature() &&
- !it->second.textpreamble.empty())
- req->insert(it->second.textpreamble);
+ !it->second.textpreamble().empty())
+ req->insert(it->second.textpreamble());
}
}
}
// after its base
symbols += a;
symbols += combining->first;
+ i = j + 1;
unicmd_size = 2;
}
}
}
-void Encodings::initUnicodeMath(Buffer const & buffer, bool for_master)
-{
-#ifdef TEX2LYX
- // The code below is not needed in tex2lyx and requires additional stuff
- (void)buffer;
- (void)for_master;
-#else
- if (for_master) {
- mathcmd.clear();
- textcmd.clear();
- mathsym.clear();
- }
-
- // Check this buffer
- Inset & inset = buffer.inset();
- InsetIterator it = inset_iterator_begin(inset);
- InsetIterator const end = inset_iterator_end(inset);
- for (; it != end; ++it)
- it->initUnicodeMath();
-
- if (!for_master)
- return;
-
- // Check children
- ListOfBuffers blist = buffer.getDescendents();
- ListOfBuffers::const_iterator bit = blist.begin();
- ListOfBuffers::const_iterator const bend = blist.end();
- for (; bit != bend; ++bit)
- initUnicodeMath(**bit, false);
-#endif
-}
-
-
-void Encodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
-{
-#ifdef TEX2LYX
- // The code below is not needed in tex2lyx and requires additional stuff
- (void)c;
- (void)features;
- (void)for_mathed;
-#else
- CharInfoMap::const_iterator const it = unicodesymbols.find(c);
- if (it != unicodesymbols.end()) {
- // In mathed, c could be used both in textmode and mathmode
- bool const math_mode = for_mathed && isMathCmd(c);
- bool const use_math = math_mode ||
- (!for_mathed && it->second.textcommand.empty());
- bool const use_text = (for_mathed && isTextCmd(c)) ||
- (!for_mathed && !it->second.textcommand.empty());
- bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain");
- bool const unicode_math = (features.isRequired("unicode-math")
- && features.isAvailable("unicode-math"));
- // with utf8-plain, we only load packages when in mathed (see #7766)
- // and if we do not use unicode-math
- if ((math_mode && !unicode_math)
- || (use_math && !plain_utf8)) {
- if (!it->second.mathpreamble.empty()) {
- if (it->second.mathfeature()) {
- string feats = it->second.mathpreamble;
- while (!feats.empty()) {
- string feat;
- feats = split(feats, feat, ',');
- features.require(feat);
- }
- } else
- features.addPreambleSnippet(it->second.mathpreamble);
- }
- }
- // with utf8-plain, we do not load packages (see #7766)
- if (use_text && !plain_utf8) {
- if (!it->second.textpreamble.empty()) {
- if (it->second.textfeature()) {
- string feats = it->second.textpreamble;
- while (!feats.empty()) {
- string feat;
- feats = split(feats, feat, ',');
- features.require(feat);
- }
- } else
- features.addPreambleSnippet(it->second.textpreamble);
- }
- }
- }
- if (for_mathed && isMathSym(c)) {
- features.require("amstext");
- features.require("lyxmathsym");
- }
-#endif
-}
-
-
bool Encodings::isHebrewComposeChar(char_type c)
{
return c <= 0x05c2 && c >= 0x05b0 && c != 0x05be && c != 0x05c0;
}
+CharInfo const & Encodings::unicodeCharInfo(char_type c)
+{
+ static CharInfo empty;
+ CharInfoMap::const_iterator const it = unicodesymbols.find(c);
+ return it != unicodesymbols.end() ? it->second : empty;
+}
+
+
char_type Encodings::transformChar(char_type c, Encodings::LetterForm form)
{
return isArabicChar(c) ? arabic_table[c-arabic_start][form] : c;
{
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
if (it != unicodesymbols.end())
- return it->second.tipashortcut;
+ return it->second.tipashortcut();
return string();
}
if (it == unicodesymbols.end())
return false;
- if (it->second.textpreamble != "textgreek" && it->second.textpreamble != "textcyr")
+ if (it->second.textpreamble() != "textgreek" && it->second.textpreamble() != "textcyr")
return false;
if (preamble.empty()) {
- preamble = it->second.textpreamble;
+ preamble = it->second.textpreamble();
return true;
}
- return it->second.textpreamble == preamble;
+ return it->second.textpreamble() == preamble;
}
bool getNextToken = true;
while (symbolslex.isOK()) {
char_type symbol;
- CharInfo info;
- string flags;
if (getNextToken) {
if (!symbolslex.next(true))
if (!symbolslex.next(true))
break;
- info.textcommand = symbolslex.getDocString();
+ docstring textcommand = symbolslex.getDocString();
if (!symbolslex.next(true))
break;
- info.textpreamble = symbolslex.getString();
+ string textpreamble = symbolslex.getString();
if (!symbolslex.next(true))
break;
- flags = symbolslex.getString();
-
- info.flags = 0;
- if (suffixIs(info.textcommand, '}'))
- info.flags |= CharInfoTextNoTermination;
- if (suffixIs(info.mathcommand, '}'))
- info.flags |= CharInfoMathNoTermination;
- while (!flags.empty()) {
+ string sflags = symbolslex.getString();
+
+ string tipashortcut;
+ int flags = 0;
+
+ if (suffixIs(textcommand, '}'))
+ flags |= CharInfoTextNoTermination;
+ while (!sflags.empty()) {
string flag;
- flags = split(flags, flag, ',');
+ sflags = split(sflags, flag, ',');
if (flag == "combining") {
- info.flags |= CharInfoCombining;
+ flags |= CharInfoCombining;
} else if (flag == "force") {
- info.flags |= CharInfoForce;
+ flags |= CharInfoForce;
forced.insert(symbol);
} else if (prefixIs(flag, "force=")) {
vector<string> encodings =
getVectorFromString(flag.substr(6), ";");
for (size_t i = 0; i < encodings.size(); ++i)
forcedselected[encodings[i]].insert(symbol);
- info.flags |= CharInfoForceSelected;
+ flags |= CharInfoForceSelected;
} else if (prefixIs(flag, "force!=")) {
vector<string> encodings =
getVectorFromString(flag.substr(7), ";");
for (size_t i = 0; i < encodings.size(); ++i)
forcednotselected[encodings[i]].insert(symbol);
- info.flags |= CharInfoForceSelected;
+ flags |= CharInfoForceSelected;
} else if (flag == "mathalpha") {
mathalpha.insert(symbol);
} else if (flag == "notermination=text") {
- info.flags |= CharInfoTextNoTermination;
+ flags |= CharInfoTextNoTermination;
} else if (flag == "notermination=math") {
- info.flags |= CharInfoMathNoTermination;
+ flags |= CharInfoMathNoTermination;
} else if (flag == "notermination=both") {
- info.flags |= CharInfoTextNoTermination;
- info.flags |= CharInfoMathNoTermination;
+ flags |= CharInfoTextNoTermination;
+ flags |= CharInfoMathNoTermination;
} else if (flag == "notermination=none") {
- info.flags &= ~CharInfoTextNoTermination;
- info.flags &= ~CharInfoMathNoTermination;
+ flags &= ~CharInfoTextNoTermination;
+ flags &= ~CharInfoMathNoTermination;
} else if (contains(flag, "tipashortcut=")) {
- info.tipashortcut = split(flag, '=');
+ tipashortcut = split(flag, '=');
} else {
lyxerr << "Ignoring unknown flag `" << flag
<< "' for symbol `0x"
// make them optional so that old files still work.
int const lineno = symbolslex.lineNumber();
bool breakout = false;
+ docstring mathcommand;
+ string mathpreamble;
if (symbolslex.next(true)) {
if (symbolslex.lineNumber() != lineno) {
// line in old format without mathcommand and mathpreamble
getNextToken = false;
} else {
- info.mathcommand = symbolslex.getDocString();
+ mathcommand = symbolslex.getDocString();
+ if (suffixIs(mathcommand, '}'))
+ flags |= CharInfoMathNoTermination;
if (symbolslex.next(true)) {
if (symbolslex.lineNumber() != lineno) {
// line in new format with mathcommand only
getNextToken = false;
} else {
// line in new format with mathcommand and mathpreamble
- info.mathpreamble = symbolslex.getString();
+ mathpreamble = symbolslex.getString();
}
} else
breakout = true;
}
// backward compatibility
- if (info.mathpreamble == "esintoramsmath")
- info.mathpreamble = "esint|amsmath";
-
- if (!info.textpreamble.empty())
- if (info.textpreamble[0] != '\\')
- info.flags |= CharInfoTextFeature;
- if (!info.mathpreamble.empty())
- if (info.mathpreamble[0] != '\\')
- info.flags |= CharInfoMathFeature;
-
+ if (mathpreamble == "esintoramsmath")
+ mathpreamble = "esint|amsmath";
+
+ if (!textpreamble.empty())
+ if (textpreamble[0] != '\\')
+ flags |= CharInfoTextFeature;
+ if (!mathpreamble.empty())
+ if (mathpreamble[0] != '\\')
+ flags |= CharInfoMathFeature;
+
+ CharInfo info = CharInfo(
+ textcommand, mathcommand,
+ textpreamble, mathpreamble,
+ tipashortcut, flags);
LYXERR(Debug::INFO, "Read unicode symbol " << symbol << " '"
- << to_utf8(info.textcommand) << "' '" << info.textpreamble
- << " '" << info.textfeature() << ' ' << info.textnotermination()
- << ' ' << to_utf8(info.mathcommand) << "' '" << info.mathpreamble
- << "' " << info.mathfeature() << ' ' << info.mathnotermination()
- << ' ' << info.combining() << ' ' << info.force()
- << ' ' << info.forceselected());
+ << to_utf8(info.textcommand()) << "' '" << info.textpreamble()
+ << " '" << info.textfeature() << ' ' << info.textnotermination()
+ << ' ' << to_utf8(info.mathcommand()) << "' '" << info.mathpreamble()
+ << "' " << info.mathfeature() << ' ' << info.mathnotermination()
+ << ' ' << info.combining() << ' ' << info.force()
+ << ' ' << info.forceselected());
// we assume that at least one command is nonempty when using unicodesymbols
- if (!info.textcommand.empty() || !info.mathcommand.empty())
+ if (info.isUnicodeSymbol()) {
unicodesymbols[symbol] = info;
+ }
if (breakout)
break;