}
-void Encoding::validate(char_type c, LaTeXFeatures & features) const
+void Encodings::validate(char_type c, LaTeXFeatures & features)
{
- // Add the preamble stuff even if c can be encoded in this encoding,
- // since the inputenc package only maps the code point c to a command,
- // it does not make this command available.
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
if (it != unicodesymbols.end() && !it->second.preamble.empty()) {
if (it->second.feature)
* character is returned.
*/
docstring const latexChar(char_type c) const;
- /// Add the preamble snippet needed for the output of latexChar(c)
- /// to \p features.
- void validate(char_type c, LaTeXFeatures & features) const;
private:
///
std::string Name_;
static char_type transformChar(char_type c, Letter_Form form);
/// Is this a combining char?
static bool isCombiningChar(char_type c);
+ /**
+ * Add the preamble snippet needed for the output of \p c to
+ * \p features.
+ * This does not depend on the used encoding, since the inputenc
+ * package only maps the code point \p c to a command, it does not
+ * make this command available.
+ */
+ static void validate(char_type c, LaTeXFeatures & features);
private:
///
}
}
+ // Switch file encoding if necessary
+ if (bparams.inputenc == "auto") {
+ // Look ahead for future encoding changes.
+ // We try to output them at the beginning of the paragraph,
+ // since the \inputencoding command is not allowed e.g. in
+ // sections.
+ for (pos_type i = 0; i < pit->size(); ++i) {
+ char_type const c = pit->getChar(i);
+ if (c < 0x80)
+ continue;
+ if (pit->isInset(i))
+ break;
+ // All characters before c are in the ASCII range, and
+ // c is non-ASCII (but no inset), so change the
+ // encoding to that required by the language of c.
+ Encoding const * const encoding =
+ pit->getFontSettings(bparams, i).language()->encoding();
+ if (switchEncoding(os, bparams, false,
+ *(runparams.encoding), *encoding) > 0) {
+ runparams.encoding = encoding;
+ os << '\n';
+ texrow.newline();
+ }
+ break;
+ }
+ }
+
// In an inset with unlimited length (all in one row),
// don't allow any special options in the paragraph
if (!pit->forceDefaultParagraphs()) {
int switchEncoding(odocstream & os, BufferParams const & bparams,
- Encoding const & oldEnc, Encoding const & newEnc)
+ bool moving_arg, Encoding const & oldEnc,
+ Encoding const & newEnc)
{
// FIXME thailatex does not support the inputenc package, so we
// ignore switches from/to tis620-0 encoding here. This does of
// course only work as long as the non-thai text contains ASCII
// only, but it is the best we can do.
- if ((bparams.inputenc == "auto" || bparams.inputenc == "default") &&
+ // Since the \inputencoding command does not work inside sections
+ // we ignore the encoding switch also in moving arguments.
+ if (((bparams.inputenc == "auto" && !moving_arg) ||
+ bparams.inputenc == "default") &&
oldEnc.name() != newEnc.name() &&
oldEnc.name() != "ascii" && newEnc.name() != "ascii" &&
oldEnc.name() != "tis620-0" && newEnc.name() != "tis620-0") {
/// Switch the encoding of \p os from \p oldEnc to \p newEnc if needed.
/// \return the number of characters written to \p os.
int switchEncoding(odocstream & os, BufferParams const & bparams,
- Encoding const & oldEnc, Encoding const & newEnc);
+ bool moving_arg, Encoding const & oldEnc,
+ Encoding const & newEnc);
} // namespace lyx
runparams.moving_arg);
}
- // Computed only once per paragraph since bparams.encoding() is expensive
- Encoding const & doc_encoding = bparams.encoding();
-
for (pos_type i = 0; i < size(); ++i) {
// First char in paragraph or after label?
if (i == body_pos) {
// Switch file encoding if necessary
int const count = switchEncoding(os, bparams,
- *(runparams.encoding),
+ runparams.moving_arg, *(runparams.encoding),
*(font.language()->encoding()));
if (count > 0) {
column += count;
// style->pass_thru is false.
if (i != body_pos - 1) {
if (pimpl_->simpleTeXBlanks(bparams,
- doc_encoding, os, texrow,
+ *(runparams.encoding), os, texrow,
i, column, font, *style))
// A surrogate pair was output. We
// must not call simpleTeXSpecialChars
rp.free_spacing = style->free_spacing;
rp.local_font = &font;
rp.intitle = style->intitle;
- pimpl_->simpleTeXSpecialChars(buf, bparams, doc_encoding, os,
+ pimpl_->simpleTeXSpecialChars(buf, bparams, os,
texrow, rp, running_font,
basefont, outerfont, open_font,
runningChangeType, *style, i, column, c);
size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
-
-/// Get the real encoding of a character with font \p font.
-/// doc_encoding == bparams.encoding(), but we use a precomputed variable
-/// since bparams.encoding() is expensive
-inline Encoding const & getEncoding(BufferParams const & bparams,
- Encoding const & doc_encoding, LyXFont const & font)
-{
- if (bparams.inputenc == "auto" || bparams.inputenc == "default")
- return *(font.language()->encoding());
- return doc_encoding;
-}
-
} // namespace anon
bool Paragraph::Pimpl::simpleTeXBlanks(BufferParams const & bparams,
- Encoding const & doc_encoding,
+ Encoding const & encoding,
odocstream & os, TexRow & texrow,
pos_type & i,
unsigned int & column,
char_type next = getChar(i + 1);
if (Encodings::isCombiningChar(next)) {
// This space has an accent, so we must always output it.
- Encoding const & encoding = getEncoding(bparams, doc_encoding, font);
column += latexSurrogatePair(os, ' ', next, encoding) - 1;
++i;
return true;
void Paragraph::Pimpl::simpleTeXSpecialChars(Buffer const & buf,
BufferParams const & bparams,
- Encoding const & doc_encoding,
odocstream & os,
TexRow & texrow,
OutputParams const & runparams,
}
if (pnr == phrases_nr && c != '\0') {
- Encoding const & encoding =
- getEncoding(bparams, doc_encoding, running_font);
+ Encoding const & encoding = *(runparams.encoding);
if (i < size() - 1) {
char_type next = getChar(i + 1);
if (Encodings::isCombiningChar(next)) {
}
// then the contents
- Encoding const & doc_encoding = bparams.encoding();
for (pos_type i = 0; i < size() ; ++i) {
for (size_t pnr = 0; pnr < phrases_nr; ++pnr) {
if (!special_phrases[pnr].builtin
break;
}
}
- // We do not need the completely realized font, since we are
- // only interested in the language, and that is never inherited.
- // Therefore we can use getFontSettings instead of getFont.
- LyXFont const & font = owner_->getFontSettings(bparams, i);
- Encoding const & encoding = getEncoding(bparams, doc_encoding, font);
- encoding.validate(getChar(i), features);
+ Encodings::validate(getChar(i), features);
}
}
LyXLayout const & style);
///
void simpleTeXSpecialChars(Buffer const &, BufferParams const &,
- Encoding const &, odocstream &,
+ odocstream &,
TexRow & texrow, OutputParams const &,
LyXFont & running_font,
LyXFont & basefont,