]> git.lyx.org Git - lyx.git/blobdiff - src/Language.cpp
Revert "Make formal table lines exagerately thick to identify \cmidrule"
[lyx.git] / src / Language.cpp
index 13e43c29686c36004dac55c2b370bad531e21f6e..8110c174016664385b52113b52d046e9b3382116 100644 (file)
@@ -16,6 +16,7 @@
 #include "Language.h"
 
 #include "Encoding.h"
+#include "LaTeXFonts.h"
 #include "Lexer.h"
 #include "LyXRC.h"
 
@@ -38,6 +39,18 @@ Language const * latex_language = 0;
 Language const * reset_language = 0;
 
 
+bool Language::isPolyglossiaExclusive() const
+{
+       return babel().empty() && !polyglossia().empty() && requires().empty();
+}
+
+
+bool Language::isBabelExclusive() const
+{
+       return !babel().empty() && polyglossia().empty() && requires().empty();
+}
+
+
 docstring const Language::translateLayout(string const & m) const
 {
        if (m.empty())
@@ -59,6 +72,37 @@ docstring const Language::translateLayout(string const & m) const
 }
 
 
+string Language::fontenc(BufferParams const & params) const
+{
+       // Don't use LaTeX fonts, so just return the language's preferred
+       // (although this is not used with nonTeXFonts anyway).
+       if (params.useNonTeXFonts)
+               return fontenc_.front() == "ASCII" ? "T1" : fontenc_.front();
+
+       // Determine optimal font encoding
+       // We check whether the used rm font supports an encoding our language supports
+       LaTeXFont const & lf =
+               theLaTeXFonts().getLaTeXFont(from_ascii(params.fontsRoman()));
+       vector<string> const lfe = lf.fontencs();
+       for (auto & fe : fontenc_) {
+               // ASCII means: support all T* encodings plus OT1
+               if (fe == "ASCII") {
+                       for (auto & afe : lfe) {
+                               if (afe == "OT1" || prefixIs(afe, "T"))
+                                       // we found a suitable one; return that.
+                                       return afe;
+                       }
+               }
+               // For other encodings, just check whether the font supports it
+               if (lf.hasFontenc(fe))
+                       return fe;
+       }
+       // We did not find a suitable one; just take the first in the list,
+       // the priorized one (which is "T1" for ASCII).
+       return fontenc_.front() == "ASCII" ? "T1" : fontenc_.front();
+}
+
+
 bool Language::readLanguage(Lexer & lex)
 {
        enum LanguageTags {
@@ -66,16 +110,19 @@ bool Language::readLanguage(Lexer & lex)
                LA_BABELNAME,
                LA_ENCODING,
                LA_END,
+               LA_FONTENC,
                LA_GUINAME,
+               LA_HAS_GUI_SUPPORT,
                LA_INTERNAL_ENC,
                LA_LANG_CODE,
                LA_LANG_VARIETY,
                LA_POLYGLOSSIANAME,
                LA_POLYGLOSSIAOPTS,
                LA_POSTBABELPREAMBLE,
-               LA_QUOTESTYLE,
                LA_PREBABELPREAMBLE,
+               LA_PROVIDES,
                LA_REQUIRES,
+               LA_QUOTESTYLE,
                LA_RTL
        };
 
@@ -85,7 +132,9 @@ bool Language::readLanguage(Lexer & lex)
                { "babelname",            LA_BABELNAME },
                { "encoding",             LA_ENCODING },
                { "end",                  LA_END },
+               { "fontencoding",         LA_FONTENC },
                { "guiname",              LA_GUINAME },
+               { "hasguisupport",        LA_HAS_GUI_SUPPORT },
                { "internalencoding",     LA_INTERNAL_ENC },
                { "langcode",             LA_LANG_CODE },
                { "langvariety",          LA_LANG_VARIETY },
@@ -93,6 +142,7 @@ bool Language::readLanguage(Lexer & lex)
                { "polyglossiaopts",      LA_POLYGLOSSIAOPTS },
                { "postbabelpreamble",    LA_POSTBABELPREAMBLE },
                { "prebabelpreamble",     LA_PREBABELPREAMBLE },
+               { "provides",             LA_PROVIDES },
                { "quotestyle",           LA_QUOTESTYLE },
                { "requires",             LA_REQUIRES },
                { "rtl",                  LA_RTL }
@@ -114,7 +164,7 @@ bool Language::readLanguage(Lexer & lex)
                        error = true;
                        continue;
 
-               default: 
+               default:
                        break;
                }
                switch (static_cast<LanguageTags>(le)) {
@@ -139,9 +189,19 @@ bool Language::readLanguage(Lexer & lex)
                case LA_ENCODING:
                        lex >> encodingStr_;
                        break;
+               case LA_FONTENC: {
+                       lex.eatLine();
+                       vector<string> const fe =
+                               getVectorFromString(lex.getString(true), "|");
+                       fontenc_.insert(fontenc_.end(), fe.begin(), fe.end());
+                       break;
+               }
                case LA_GUINAME:
                        lex >> display_;
                        break;
+               case LA_HAS_GUI_SUPPORT:
+                       lex >> has_gui_support_;
+                       break;
                case LA_INTERNAL_ENC:
                        lex >> internal_enc_;
                        break;
@@ -153,15 +213,18 @@ bool Language::readLanguage(Lexer & lex)
                        break;
                case LA_POSTBABELPREAMBLE:
                        babel_postsettings_ =
-                               lex.getLongString("EndPostBabelPreamble");
+                               lex.getLongString(from_ascii("EndPostBabelPreamble"));
                        break;
                case LA_PREBABELPREAMBLE:
                        babel_presettings_ =
-                               lex.getLongString("EndPreBabelPreamble");
+                               lex.getLongString(from_ascii("EndPreBabelPreamble"));
                        break;
                case LA_REQUIRES:
                        lex >> requires_;
                        break;
+               case LA_PROVIDES:
+                       lex >> provides_;
+                       break;
                case LA_RTL:
                        lex >> rightToLeft_;
                        break;
@@ -196,10 +259,8 @@ bool Language::read(Lexer & lex)
                encoding_ = encodings.fromLyXName("iso8859-1");
                LYXERR0("Unknown encoding " << encodingStr_);
        }
-       // cache translation status. Calling getMessages() directly in
-       // PrefLanguage::PrefLanguage() did only work if the gui language
-       // was set to auto (otherwise all languages would be marked as available).
-       translated_ = getMessages(code()).available();
+       if (fontenc_.empty())
+               fontenc_.push_back("ASCII");
        return true;
 }
 
@@ -311,7 +372,7 @@ Match match(string const & code, Language const & lang)
        return NoMatch;
 }
 
-}
+} // namespace
 
 
 void Languages::readLayoutTranslations(support::FileName const & filename)