]> git.lyx.org Git - lyx.git/blob - src/BufferEncodings.cpp
Update ru.po
[lyx.git] / src / BufferEncodings.cpp
1 /**
2  * \file BufferEncodings.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author Dekel Tsur
9  * \author Stephan Witt
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "BufferEncodings.h"
17
18 #include "Buffer.h"
19 #include "InsetIterator.h"
20 #include "LaTeXFeatures.h"
21
22 #include "support/lstrings.h"
23
24 using namespace std;
25 using namespace lyx::support;
26
27 namespace lyx {
28
29 void BufferEncodings::initUnicodeMath(Buffer const & buffer, bool for_master)
30 {
31         if (for_master) {
32                 mathcmd.clear();
33                 textcmd.clear();
34                 mathsym.clear();
35         }
36
37         // Check this buffer
38         Inset & inset = buffer.inset();
39         InsetIterator it = inset_iterator_begin(inset);
40         InsetIterator const end = inset_iterator_end(inset);
41         for (; it != end; ++it)
42                 it->initUnicodeMath();
43
44         if (!for_master)
45                 return;
46
47         // Check children
48         ListOfBuffers blist = buffer.getDescendents();
49         ListOfBuffers::const_iterator bit = blist.begin();
50         ListOfBuffers::const_iterator const bend = blist.end();
51         for (; bit != bend; ++bit)
52                 initUnicodeMath(**bit, false);
53 }
54
55
56 void BufferEncodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
57 {
58         CharInfo const & ci = Encodings::unicodeCharInfo(c);
59         if (ci.isUnicodeSymbol()) {
60                 // In mathed, c could be used both in textmode and mathmode
61                 docstring const textcommand = ci.textcommand();
62                 bool const math_mode = for_mathed && isMathCmd(c);
63                 bool const use_math = math_mode ||
64                                       (!for_mathed && textcommand.empty());
65                 bool const use_text = (for_mathed && isTextCmd(c)) ||
66                                       (!for_mathed && !textcommand.empty());
67                 bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain");
68                 bool const unicode_math = (features.isRequired("unicode-math")
69                         && features.isAvailable("unicode-math"));
70                 // with utf8-plain, we only load packages when in mathed (see #7766)
71                 // and if we do not use unicode-math
72                 if ((math_mode && !unicode_math)
73                      || (use_math && !plain_utf8)) {
74                         string const mathpreamble = ci.mathpreamble();
75                         if (!mathpreamble.empty()) {
76                                 if (ci.mathfeature()) {
77                                         string feats = mathpreamble;
78                                         while (!feats.empty()) {
79                                                 string feat;
80                                                 feats = split(feats, feat, ',');
81                                                 features.require(feat);
82                                         }
83                                 } else
84                                         features.addPreambleSnippet(from_utf8(mathpreamble));
85                         }
86                 }
87                 // with utf8-plain, we do not load packages (see #7766)
88                 if (use_text && !plain_utf8) {
89                         string const textpreamble = ci.textpreamble();
90                         if (!textpreamble.empty()) {
91                                 if (ci.textfeature()) {
92                                         string feats = textpreamble;
93                                         while (!feats.empty()) {
94                                                 string feat;
95                                                 feats = split(feats, feat, ',');
96                                                 features.require(feat);
97                                         }
98                                 } else
99                                         features.addPreambleSnippet(from_utf8(textpreamble));
100                         }
101                 }
102         }
103         if (for_mathed && isMathSym(c)) {
104                 features.require("amstext");
105                 features.require("lyxmathsym");
106         }
107 }
108
109 } // namespace lyx