Ass method to add a latexname to a local color (needed for #9283)

This commit is contained in:
Juergen Spitzmueller 2021-01-20 13:55:48 +01:00
parent c041bb667a
commit 77c8a2df0f
2 changed files with 35 additions and 0 deletions

View 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() };

View 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;