From 77c8a2df0fa2659b9edb7e56f13d0160ba96b7da Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Wed, 20 Jan 2021 13:55:48 +0100 Subject: [PATCH] Ass method to add a latexname to a local color (needed for #9283) --- src/Color.cpp | 29 +++++++++++++++++++++++++++++ src/ColorSet.h | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/src/Color.cpp b/src/Color.cpp index c627e5b654..c3d3f493d8 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -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(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() }; diff --git a/src/ColorSet.h b/src/ColorSet.h index d688f4494a..b1a984427f 100644 --- a/src/ColorSet.h +++ b/src/ColorSet.h @@ -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; -- 2.39.2