]> git.lyx.org Git - features.git/commitdiff
Ass method to add a latexname to a local color (needed for #9283)
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 20 Jan 2021 12:55:48 +0000 (13:55 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Wed, 20 Jan 2021 12:55:48 +0000 (13:55 +0100)
src/Color.cpp
src/ColorSet.h

index c627e5b6549d29802386a8210ef210c2e280487a..c3d3f493d80b9d3234ba061e450afb40111721b0 100644 (file)
@@ -458,6 +458,35 @@ bool ColorSet::setColor(string const & lyxname, string const & x11hexname,
 }
 
 
+bool ColorSet::setLaTeXName(string const & lyxname, string const & latexname)
+{
+       string const lcname = ascii_lowercase(lyxname);
+       if (lyxcolors.find(lcname) == lyxcolors.end()) {
+               LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \""
+                      << lyxname << '"');
+               addColor(static_cast<ColorCode>(infotab.size()), lcname);
+       }
+
+       ColorCode col = lyxcolors[lcname];
+       InfoTab::iterator it = infotab.find(col);
+       if (it == infotab.end()) {
+               LYXERR0("Color " << col << " not found in database.");
+               return false;
+       }
+
+       // "inherit" is returned for colors not in the database
+       // (and anyway should not be redefined)
+       if (col == Color_none || col == Color_inherit || col == Color_ignore) {
+               LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
+               return false;
+       }
+
+       if (!latexname.empty())
+               it->second.latexname = latexname;
+       return true;
+}
+
+
 void ColorSet::addColor(ColorCode c, string const & lyxname)
 {
        ColorEntry ce = { c, "", "", "", "", lyxname.c_str() };
index d688f4494ae9e7532cf100bb22153480e70becec..b1a984427fbe8fe2671e3ee7096abf6f5cfc4b5c 100644 (file)
@@ -63,6 +63,12 @@ public:
        bool setColor(std::string const & lyxname, std::string const & x11hexname,
                      std::string const & x11darkhexname = std::string());
 
+       /** set the given LyX color to a latexcolor if not yet defined
+        *  \returns true if successful. A new color entry
+        *  is created if the color is unknown.
+        */
+       bool setLaTeXName(std::string const & lyxname, std::string const & latexname);
+
        /// Get the GUI name of \c color.
        docstring const getGUIName(ColorCode c) const;