The branch, kill-tex2lyx-define, has been updated. - Log -----------------------------------------------------------------
commit 75817d7a3f9508d0e9f5f8bd950b9b206f7a1adc Author: Stephan Witt <[email protected]> Date: Fri Sep 27 20:52:55 2013 +0200 rename class files BufferEncoding to BufferEncodings diff --git a/src/BufferEncodings.cpp b/src/BufferEncodings.cpp new file mode 100644 index 0000000..362a1dd --- /dev/null +++ b/src/BufferEncodings.cpp @@ -0,0 +1,116 @@ +/** + * \file BufferEncodings.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes + * \author Dekel Tsur + * \author Stephan Witt + * + * Full author contact details are available in file CREDITS. + */ + +#include <config.h> + +#include "BufferEncodings.h" + +#include "Buffer.h" +#include "InsetIterator.h" +#include "LaTeXFeatures.h" + +#include "support/lstrings.h" + +#include <boost/cstdint.hpp> + +#include <sstream> + +using namespace std; +using namespace lyx::support; + + +namespace lyx { + + +void BufferEncodings::initUnicodeMath(Buffer const & buffer, bool for_master) +{ + 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); +} + + +void BufferEncodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed) +{ + CharInfo const & ci = Encodings::unicodeCharInfo(c); + if (Encodings::isUnicodeSymbol(ci)) { + // In mathed, c could be used both in textmode and mathmode + docstring const textcommand = Encodings::unicodeTextCommand(ci); + bool const math_mode = for_mathed && isMathCmd(c); + bool const use_math = math_mode || + (!for_mathed && textcommand.empty()); + bool const use_text = (for_mathed && isTextCmd(c)) || + (!for_mathed && !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)) { + string const mathpreamble = Encodings::unicodeMathPreamble(ci); + if (!mathpreamble.empty()) { + if (Encodings::unicodeMathFeature(ci)) { + string feats = mathpreamble; + while (!feats.empty()) { + string feat; + feats = split(feats, feat, ','); + features.require(feat); + } + } else + features.addPreambleSnippet(mathpreamble); + } + } + // with utf8-plain, we do not load packages (see #7766) + if (use_text && !plain_utf8) { + string const textpreamble = Encodings::unicodeTextPreamble(ci); + if (!textpreamble.empty()) { + if (Encodings::unicodeTextFeature(ci)) { + string feats = textpreamble; + while (!feats.empty()) { + string feat; + feats = split(feats, feat, ','); + features.require(feat); + } + } else + features.addPreambleSnippet(textpreamble); + } + } + } + if (for_mathed && isMathSym(c)) { + features.require("amstext"); + features.require("lyxmathsym"); + } +} + + +} // namespace lyx diff --git a/src/BufferEncodings.h b/src/BufferEncodings.h new file mode 100644 index 0000000..1d8ac46 --- /dev/null +++ b/src/BufferEncodings.h @@ -0,0 +1,44 @@ +// -*- C++ -*- +/** + * \file BufferEncodings.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes + * \author Stephan Witt + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef BUFFER_ENCODINGS_H +#define BUFFER_ENCODINGS_H + +#include "support/docstring.h" +#include "support/types.h" +#include "Encoding.h" + +namespace lyx { + +class Buffer; +class LaTeXFeatures; + +class BufferEncodings : public Encodings { +public: + /** + * Initialize mathcmd, textcmd, and mathsym sets. + */ + static void initUnicodeMath(Buffer const & buffer, bool for_master = true); + /** + * If \p c cannot be encoded in the given \p encoding, convert + * it to something that LaTeX can understand in mathmode. + * \p needsTermination indicates whether the command needs to be + * terminated by {} or a space. + * \return whether \p command is a mathmode command + */ + static void validate(char_type c, LaTeXFeatures & features, bool for_mathed = false); +}; + +} // namespace lyx + +#endif ----------------------------------------------------------------------- Summary of changes: src/{BufferEncoding.cpp => BufferEncodings.cpp} | 4 ++-- src/{BufferEncoding.h => BufferEncodings.h} | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) copy src/{BufferEncoding.cpp => BufferEncodings.cpp} (98%) copy src/{BufferEncoding.h => BufferEncodings.h} (92%) hooks/post-receive -- Repository for new features
