From: Jürgen Spitzmüller Date: Fri, 9 Mar 2012 09:05:13 +0000 (+0000) Subject: * implement possibility to use IPA shortcut notation (the actual shortcuts will follow) X-Git-Tag: 2.1.0beta1~1974 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=84971fb27ebd9f178a0147b06fa195e49cd75797;p=lyx.git * implement possibility to use IPA shortcut notation (the actual shortcuts will follow) * do not terminate macros by {} if not necessary (prevent kerning violation) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40891 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Encoding.cpp b/src/Encoding.cpp index eda99026d4..8b1eaca96d 100644 --- a/src/Encoding.cpp +++ b/src/Encoding.cpp @@ -249,6 +249,8 @@ struct CharInfo { /// Always force the LaTeX command, even if the encoding contains /// this character? bool force; + /// TIPA shortcut + string tipashortcut; }; @@ -685,6 +687,15 @@ bool Encodings::isCombiningChar(char_type c) } +string const Encodings::TIPAShortcut(char_type c) +{ + CharInfoMap::const_iterator const it = unicodesymbols.find(c); + if (it != unicodesymbols.end()) + return it->second.tipashortcut; + return string(); +} + + bool Encodings::isKnownScriptChar(char_type const c, string & preamble) { CharInfoMap::const_iterator const it = unicodesymbols.find(c); @@ -797,6 +808,8 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile) forced.insert(symbol); } else if (flag == "mathalpha") { mathalpha.insert(symbol); + } else if (contains(flag, "tipashortcut=")) { + info.tipashortcut = split(flag, '='); } else { lyxerr << "Ignoring unknown flag `" << flag << "' for symbol `0x" diff --git a/src/Encoding.h b/src/Encoding.h index effde73ffc..4d68c3b721 100644 --- a/src/Encoding.h +++ b/src/Encoding.h @@ -172,6 +172,8 @@ public: static char_type transformChar(char_type c, LetterForm form); /// Is this a combining char? static bool isCombiningChar(char_type c); + /// Return the TIPA shortcut + static std::string const TIPAShortcut(char_type c); /** * Is this a known char from some language? * If \p preamble is empty and code point \p c is known to belong diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index a0e7a1c40a..5e7d9f239d 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -25,7 +25,7 @@ OutputParams::OutputParams(Encoding const * enc) use_indices(false), use_japanese(false), linelen(0), depth(0), exportdata(new ExportData), inComment(false), inTableCell(NO), inFloat(NONFLOAT), - inIndexEntry(false), inDeletedInset(0), + inIndexEntry(false), inIPA(false), inDeletedInset(0), changeOfDeletedInset(Change::UNCHANGED), par_begin(0), par_end(0), lastid(-1), lastpos(-1), isLastPar(false), dryrun(false), pass_thru(false), diff --git a/src/OutputParams.h b/src/OutputParams.h index 5f57ac1f83..15736f667d 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -198,6 +198,11 @@ public: */ bool inIndexEntry; + /** Whether we are inside an IPA inset. + * Needed for proper IPA output. + */ + bool inIPA; + /** Whether we are inside an inset that is logically deleted. * A value > 0 indicates a deleted inset. */ diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index fa274e3f45..37c078b9c5 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -1253,8 +1253,9 @@ void Paragraph::Private::latexSpecialChar(otexstream & os, return; Encoding const & encoding = *(runparams.encoding); + char_type next = '\0'; if (i + 1 < int(text_.size())) { - char_type next = text_[i + 1]; + next = text_[i + 1]; if (Encodings::isCombiningChar(next)) { column += latexSurrogatePair(os, c, next, runparams) - 1; ++i; @@ -1262,18 +1263,37 @@ void Paragraph::Private::latexSpecialChar(otexstream & os, } } string script; - docstring const latex = encoding.latexChar(c); + docstring latex = encoding.latexChar(c); + docstring nextlatex; + if (next != '\0' && next != META_INSET) + nextlatex = encoding.latexChar(next); + bool tipas = false; + if (runparams.inIPA) { + string const tipashortcut = Encodings::TIPAShortcut(c); + if (!tipashortcut.empty()) { + latex = from_ascii(tipashortcut); + tipas = true; + } + } if (Encodings::isKnownScriptChar(c, script) && prefixIs(latex, from_ascii("\\" + script))) column += writeScriptChars(os, latex, running_change, encoding, i) - 1; - else if (latex.length() > 1 && latex[latex.length() - 1] != '}' && - latex[latex.length() - 1] != '-') { + else if (!prefixIs(nextlatex, from_ascii("\\")) + && !prefixIs(nextlatex, from_ascii("{")) + && !prefixIs(nextlatex, from_ascii("}")) + && latex.length() > 1 && latex[latex.length() - 1] != '}' + && latex[latex.length() - 1] != '-' && !tipas) { // Prevent eating of a following // space or command corruption by // following characters - column += latex.length() + 1; - os << latex << "{}"; + if (next == ' ' || next == '\0') { + column += latex.length() + 1; + os << latex << "{}"; + } else { + column += latex.length(); + os << latex << " "; + } } else { column += latex.length() - 1; os << latex; diff --git a/src/insets/InsetIPA.cpp b/src/insets/InsetIPA.cpp index bfa0ca9d5c..edee27e4b4 100644 --- a/src/insets/InsetIPA.cpp +++ b/src/insets/InsetIPA.cpp @@ -194,8 +194,10 @@ void InsetIPA::validate(LaTeXFeatures & features) const } -void InsetIPA::latex(otexstream & os, OutputParams const & runparams) const +void InsetIPA::latex(otexstream & os, OutputParams const & runparams_in) const { + OutputParams runparams(runparams_in); + runparams.inIPA = true; bool const multipar = (text().paragraphs().size() > 1); // fontspec knows \textipa, but not the IPA environment bool const nontexfonts = buffer_->params().useNonTeXFonts;