]> git.lyx.org Git - lyx.git/blob - src/Color.cpp
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / Color.cpp
1 /**
2  * \file Color.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author Lars Gullik Bjønnes
8  * \author Matthias Ettrich
9  * \author Jean-Marc Lasgouttes
10  * \author John Levon
11  * \author André Pönitz
12  * \author Martin Vermeer
13  *
14  * Full author contact details are available in file CREDITS.
15  */
16
17 #include <config.h>
18
19 #include "Color.h"
20 #include "ColorSet.h"
21
22 #include "support/convert.h"
23 #include "support/debug.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
26 #include "support/lassert.h"
27
28 #include <map>
29 #include <cmath>
30 #include <sstream>
31 #include <iomanip>
32
33
34 using namespace std;
35 using namespace lyx::support;
36
37 namespace lyx {
38
39
40 struct ColorSet::ColorEntry {
41         ColorCode lcolor;
42         char const * guiname;
43         char const * latexname;
44         char const * x11hexname;
45         char const * x11darkhexname;
46         char const * lyxname;
47 };
48
49
50 static int hexstrToInt(string const & str)
51 {
52         int val = 0;
53         istringstream is(str);
54         is >> setbase(16) >> val;
55         return val;
56 }
57
58
59 /////////////////////////////////////////////////////////////////////
60 //
61 // RGBColor
62 //
63 /////////////////////////////////////////////////////////////////////
64
65
66 string const X11hexname(RGBColor const & col)
67 {
68         ostringstream ostr;
69
70         ostr << '#' << setbase(16) << setfill('0')
71              << setw(2) << col.r
72              << setw(2) << col.g
73              << setw(2) << col.b;
74
75         return ostr.str();
76 }
77
78
79 RGBColor rgbFromHexName(string const & x11hexname)
80 {
81         RGBColor c;
82         LASSERT(x11hexname.size() == 7 && x11hexname[0] == '#',
83                 return c);
84         c.r = hexstrToInt(x11hexname.substr(1, 2));
85         c.g = hexstrToInt(x11hexname.substr(3, 2));
86         c.b = hexstrToInt(x11hexname.substr(5, 2));
87         return c;
88 }
89
90
91 string const outputLaTeXColor(RGBColor const & color)
92 {
93         // this routine returns a LaTeX readable color string in the form
94         // "red, green, blue" where the colors are a number in the range 0-1
95         int red = color.r;
96         int green = color.g;
97         int blue = color.b;
98 #ifdef USE_CORRECT_RGB_CONVERSION
99         int const scale = 255;
100 #else
101         // the color values are given in the range of 0-255, so to get
102         // an output of "0.5" for the value 127 we need to do the following
103         // FIXME: This is wrong, since it creates a nonlinear mapping:
104         //        There is a gap between 0/256 and 2/256!
105         //        0.5 cannot be represented in 8bit hex RGB, it would be 127.5.
106         if (red != 0)
107                 ++red;
108         if (green != 0)
109                 ++green;
110         if (blue != 0)
111                 ++blue;
112         int const scale = 256;
113 #endif
114         string output;
115         output = convert<string>(float(red) / scale) + ", "
116                          + convert<string>(float(green) / scale) + ", "
117                          + convert<string>(float(blue) / scale);
118         return output;
119 }
120
121
122 RGBColor const RGBColorFromLaTeX(string const & color)
123 {
124         vector<string> rgb = getVectorFromString(color);
125         while (rgb.size() < 3)
126                 rgb.push_back("0");
127         RGBColor c;
128         for (int i = 0; i < 3; ++i) {
129                 rgb[i] = trim(rgb[i]);
130                 if (!isStrDbl(rgb[i]))
131                         return c;
132         }
133 #ifdef USE_CORRECT_RGB_CONVERSION
134         int const scale = 255;
135 #else
136         // FIXME: This is wrong, since it creates a nonlinear mapping:
137         //        Both 0/256 and 1/256 are mapped to 0!
138         //        The wrong code exists only to match outputLaTeXColor().
139         int const scale = 256;
140 #endif
141         c.r = static_cast<unsigned int>(scale * convert<double>(rgb[0]) + 0.5);
142         c.g = static_cast<unsigned int>(scale * convert<double>(rgb[1]) + 0.5);
143         c.b = static_cast<unsigned int>(scale * convert<double>(rgb[2]) + 0.5);
144 #ifndef USE_CORRECT_RGB_CONVERSION
145         if (c.r != 0)
146                 c.r--;
147         if (c.g != 0)
148                 c.g--;
149         if (c.b != 0)
150                 c.b--;
151 #endif
152         return c;
153 }
154
155
156 RGBColor const inverseRGBColor(RGBColor color)
157 {
158         color.r = 255 - color.r;
159         color.g = 255 - color.g;
160         color.b = 255 - color.b;
161
162         return color;
163 }
164
165
166 Color::Color(ColorCode base_color) : baseColor(base_color),
167         mergeColor(Color_ignore)
168 {}
169
170
171 bool Color::operator==(Color const & color) const
172 {
173         return baseColor == color.baseColor;
174 }
175
176
177 bool Color::operator!=(Color const & color) const
178 {
179         return baseColor != color.baseColor;
180 }
181
182
183 bool Color::operator<(Color const & color) const
184 {
185         return baseColor < color.baseColor;
186 }
187
188
189 bool Color::operator<=(Color const & color) const
190 {
191         return baseColor <= color.baseColor;
192 }
193
194
195 std::ostream & operator<<(std::ostream & os, Color color)
196 {
197         os << to_ascii(lcolor.getGUIName(color.baseColor));
198         if (color.mergeColor != Color_ignore)
199                 os << "[merged with:"
200                         << to_ascii(lcolor.getGUIName(color.mergeColor)) << "]";
201         return os;
202 }
203
204
205 ColorSet::ColorSet()
206 {
207         char const * grey40 = "#666666";
208         char const * grey60 = "#999999";
209         char const * grey80 = "#cccccc";
210         // latex colors (xcolor package)
211         char const * black = "#000000";
212         char const * white = "#ffffff";
213         char const * blue = "#0000ff";
214         char const * brown = "#bf8040";
215         char const * cyan = "#00ffff";
216         char const * darkgray = "#404040";
217         char const * gray = "#808080";
218         char const * green = "#00ff00";
219         char const * lightgray = "#bfbfbf";
220         char const * lime = "#bfff00";
221         char const * magenta = "#ff00ff";
222         char const * olive = "#808000";
223         char const * orange = "#ff8000";
224         char const * pink = "#ffbfbf";
225         char const * purple = "#bf0040";
226         char const * red = "#ff0000";
227         char const * teal = "#008080";
228         char const * violet = "#800080";
229         char const * yellow = "#ffff00";
230         // svg colors
231         char const * Brown = "#a52a2a";
232         char const * DarkRed = "#8b0000";
233         char const * Green = "#008000";
234         char const * IndianRed = "#cd5c5c";
235         char const * Linen = "#faf0e6";
236         char const * RoyalBlue = "#4169e1";
237
238         //char const * grey90 = "#e5e5e5";
239         //  ColorCode, gui, latex, x11hexname, x11darkhexname, lyx
240         // Warning: several of these entries are overridden in GuiApplication constructor
241         // lyx color names are collected for users in Customization manual (B.# Dynamic colors)
242         static ColorEntry const items[] = {
243         { Color_none, N_("none"), "none", black, black, "none" },
244         { Color_black, N_("black"), "black", black, black, "black" },
245         { Color_white, N_("white"), "white", white, white, "white" },
246         { Color_blue, N_("blue"), "blue", blue, blue, "blue" },
247         { Color_brown, N_("brown"), "brown", brown, brown, "brown" },
248         { Color_cyan, N_("cyan"), "cyan", cyan, cyan, "cyan" },
249         { Color_darkgray, N_("darkgray"), "darkgray", darkgray, darkgray, "darkgray" },
250         { Color_gray, N_("gray"), "gray", gray, gray, "gray" },
251         { Color_green, N_("green"), "green", green, green, "green" },
252         { Color_lightgray, N_("lightgray"), "lightgray", lightgray, lightgray, "lightgray" },
253         { Color_lime, N_("lime"), "lime", lime, lime, "lime" },
254         { Color_magenta, N_("magenta"), "magenta", magenta, magenta, "magenta" },
255         { Color_olive, N_("olive"), "olive", olive, olive, "olive" },
256         { Color_orange, N_("orange"), "orange", orange, orange, "orange" },
257         { Color_pink, N_("pink"), "pink", pink, pink, "pink" },
258         { Color_purple, N_("purple"), "purple", purple, purple, "purple" },
259         { Color_red, N_("red"), "red", red, red, "red" },
260         { Color_teal, N_("teal"), "teal", teal, teal, "teal" },
261         { Color_violet, N_("violet"), "violet", violet, violet, "violet" },
262         { Color_yellow, N_("yellow"), "yellow", yellow, yellow, "yellow" },
263         { Color_cursor, N_("cursor"), "cursor", black, Linen, "cursor" },
264         { Color_background, N_("background"), "background", Linen, black, "background" },
265         { Color_foreground, N_("text"), "foreground", black, Linen, "foreground" },
266         { Color_selection, N_("selection"), "selection", "#add8e6", "#add8e6", "selection" },
267         { Color_selectionmath, N_("selected math"), "selectionmath", "#00008B", "#00008B", "selectionmath" },
268         { Color_selectiontext, N_("selected text"), "selectiontext", black, black, "selectiontext" },
269         { Color_latex, N_("LaTeX text"), "latex", DarkRed, "#D66613", "latex" },
270         { Color_textlabel1, N_("Text label 1"), "textlabel1", blue, "#86a4ff", "textlabel1" },
271         { Color_textlabel2, N_("Text label 2"), "textlabel2", Green, green, "textlabel2" },
272         { Color_textlabel3, N_("Text label 3"), "textlabel3", magenta, magenta, "textlabel3" },
273         { Color_inlinecompletion, N_("inline completion"),
274                 "inlinecompletion", grey60, grey40, "inlinecompletion" },
275         { Color_nonunique_inlinecompletion, N_("inline completion (non-unique)"),
276                 "nonuniqueinlinecompletion", grey80, grey60, "nonuniqueinlinecompletion" },
277         { Color_preview, N_("previewed snippet"), "preview", black, Linen, "preview" },
278         { Color_notelabel, N_("note label"), "note", yellow, "#FF6200", "note" },
279         { Color_notebg, N_("note background"), "notebg", yellow, "#5b5903", "notebg" },
280         { Color_commentlabel, N_("comment label"), "comment", magenta, olive, "comment" },
281         { Color_commentbg, N_("comment background"), "commentbg", Linen, black, "commentbg" },
282         { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "#ff0080", "greyedout" },
283         { Color_greyedouttext, N_("greyedout inset text"), "greyedouttext", grey80, grey40, "greyedouttext" },
284         { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", Linen, black, "greyedoutbg" },
285         { Color_phantomtext, N_("phantom inset text"), "phantomtext", "#7f7f7f", "#7f7f7f", "phantomtext" },
286         { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "#f2af7d", "shaded" },
287         { Color_listingsbg, N_("listings background"), "listingsbg", white, black, "listingsbg" },
288         { Color_branchlabel, N_("branch label"), "branchlabel", "#c88000", "#c88000", "branchlabel" },
289         { Color_footlabel, N_("footnote label"), "footlabel", "#00aaff", blue, "footlabel" },
290         { Color_indexlabel, N_("index label"), "indexlabel", Green, teal, "indexlabel" },
291         { Color_marginlabel, N_("margin note label"), "marginlabel", "#aa55ff", violet, "marginlabel" },
292         { Color_urllabel, N_("URL label"), "urllabel", blue, blue, "urllabel" },
293         { Color_urltext, N_("URL text"), "urltext", blue, "#86a4ff", "urltext" },
294         { Color_depthbar, N_("depth bar"), "depthbar", IndianRed, IndianRed, "depthbar" },
295         { Color_scroll, N_("scroll indicator"), "scroll", IndianRed, IndianRed, "scroll" },
296         { Color_language, N_("language"), "language", blue, "#86a4ff", "language" },
297         { Color_command, N_("command inset"), "command", black, black, "command" },
298         { Color_commandbg, N_("command inset background"), "commandbg", "#f0ffff", "#f0ffff", "commandbg" },
299         { Color_commandframe, N_("command inset frame"), "commandframe", black, Linen, "commandframe" },
300         { Color_command_broken, N_("command inset (broken reference)"), "command", white, white, "command_broken" },
301         { Color_buttonbg_broken, N_("button background (broken reference)"), "commandbg", red, red, "commandbg_broken" },
302         { Color_buttonframe_broken, N_("button frame (broken reference)"), "commandframe", red, red, "commandframe_broken" },
303         { Color_buttonhoverbg_broken, N_("button background (broken reference) under focus"), "buttonhoverbg", "#DB0B0B", "#DB0B0B", "buttonhoverbg_broken" },
304         { Color_special, N_("special character"), "special", RoyalBlue, RoyalBlue, "special" },
305         { Color_math, N_("math text"), "math", "#00008B", "#85F0FE", "math" },
306         { Color_mathbg, N_("math background"), "mathbg", Linen, black, "mathbg" },
307         { Color_graphicsbg, N_("graphics background"), "graphicsbg", Linen, black, "graphicsbg" },
308         { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", Linen, black, "mathmacrobg" },
309         { Color_mathframe, N_("math frame"), "mathframe", magenta, magenta, "mathframe" },
310         { Color_mathcorners, N_("math corners"), "mathcorners", Linen, black, "mathcorners" },
311         { Color_mathline, N_("math line"), "mathline", blue, "#86a4ff", "mathline" },
312         { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", "#ede2d8", black, "mathmacrobg" },
313         { Color_mathmacrohoverbg, N_("math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", grey80, "mathmacrohoverbg" },
314         { Color_mathmacrolabel, N_("math macro label"), "mathmacrolabel", "#a19992", "#a19992", "mathmacrolabel" },
315         { Color_mathmacroframe, N_("math macro frame"), "mathmacroframe", "#ede2d8", black, "mathmacroframe" },
316         { Color_mathmacroblend, N_("math macro blended out"), "mathmacroblend", black, Linen, "mathmacroblend" },
317         { Color_mathmacrooldarg, N_("math macro old parameter"), "mathmacrooldarg", grey80, grey40, "mathmacrooldarg" },
318         { Color_mathmacronewarg, N_("math macro new parameter"), "mathmacronewarg", black, Linen, "mathmacronewarg" },
319         { Color_collapsible, N_("collapsible inset text"), "collapsible", DarkRed, DarkRed, "collapsible" },
320         { Color_collapsibleframe, N_("collapsible inset frame"), "collapsibleframe", IndianRed, IndianRed, "collapsibleframe" },
321         { Color_insetbg, N_("inset background"), "insetbg", grey80, grey80, "insetbg" },
322         { Color_insetlabel, N_("inset label"), "insetlabel", black, black, "insetlabel" },
323         { Color_insetframe, N_("inset frame"), "insetframe", IndianRed, IndianRed, "insetframe" },
324         { Color_error, N_("LaTeX error"), "error", red, DarkRed, "error" },
325         { Color_eolmarker, N_("end-of-line marker"), "eolmarker", Brown, Brown, "eolmarker" },
326         { Color_appendix, N_("appendix marker"), "appendix", Brown, Brown, "appendix" },
327         { Color_changebar, N_("change bar"), "changebar", blue, "#86a4ff", "changebar" },
328         { Color_deletedtext_output, N_("changes - deleted text (exported output)"), "deletedtext", "#ff0000", "#ff0000", "deletedtext" },
329         { Color_addedtext_output, N_("changes - added text (exported output)"), "addedtext", "#0000ff", "#0000ff", "addedtext" },
330         { Color_changedtext_workarea_author1, N_("changed text (workarea, 1st author)"), "changedtextauthor1", "#0000ff", "#86a4ff", "changedtextauthor1" },
331         { Color_changedtext_workarea_author2, N_("changed text (workarea, 2nd author)"), "changedtextauthor2", "#ff00ff", "#ee86ee", "changedtextauthor2" },
332         { Color_changedtext_workarea_author3, N_("changed text (workarea, 3rd author)"), "changedtextauthor3", "#ff0000", "#ea8989", "changedtextauthor3" },
333         { Color_changedtext_workarea_author4, N_("changed text (workarea, 4th author)"), "changedtextauthor4", "#aa00ff", "#c371ec", "changedtextauthor4" },
334         { Color_changedtext_workarea_author5, N_("changed text (workarea, 5th author)"), "changedtextauthor5", "#55aa00", "#acd780", "changedtextauthor5" },
335         { Color_changedtext_workarea_comparison, N_("changed text (workarea, document comparison)"), "changedtextcomparison", "#008080", "#719FB0", "changedtextcomparison" },
336         { Color_deletedtext_workarea_modifier, N_("changes - deleted text brightness (workarea)"), "deletedtextmodifier", white, white, "deletedtextmodifier" },
337         { Color_added_space, N_("added space markers"), "added_space", Brown, Brown, "added_space" },
338         { Color_tabularline, N_("table line"), "tabularline", black, Linen, "tabularline" },
339         { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline", "#b0c4de", "#23497b", "tabularonoffline" },
340         { Color_bottomarea, N_("bottom area"), "bottomarea", grey40, grey80, "bottomarea" },
341         { Color_newpage, N_("new page"), "newpage", blue, "#86a4ff", "newpage" },
342         { Color_pagebreak, N_("page break / line break"), "pagebreak", RoyalBlue, RoyalBlue, "pagebreak" },
343         { Color_buttonframe, N_("button frame"), "buttonframe", "#dcd2c8", "#dcd2c8", "buttonframe" },
344         { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "#dcd2c8", "buttonbg" },
345         { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "#C7C7CA", "buttonhoverbg" },
346         { Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, grey40, "paragraphmarker"},
347         { Color_previewframe, N_("preview frame"), "previewframe", black, Linen, "previewframe"},
348         { Color_regexpframe, N_("regexp frame"), "regexpframe", Green, green, "regexpframe" },
349         { Color_bookmark, N_("bookmark"), "bookmark", RoyalBlue, RoyalBlue, "bookmark" },
350         { Color_inherit, N_("inherit"), "inherit", black, Linen, "inherit" },
351         { Color_ignore, N_("ignore"), "ignore", black, Linen, "ignore" },
352         { Color_ignore, nullptr, nullptr, nullptr, nullptr, nullptr }
353         };
354
355         for (int i = 0; items[i].guiname; ++i)
356                 fill(items[i]);
357 }
358
359
360 /// initialise a color entry
361 void ColorSet::fill(ColorEntry const & entry)
362 {
363         Information in;
364         in.lyxname   = entry.lyxname;
365         in.latexname = entry.latexname;
366         in.x11hexname   = entry.x11hexname;
367         in.x11darkhexname   = entry.x11darkhexname;
368         in.guiname   = entry.guiname;
369         infotab[entry.lcolor] = in;
370         lyxcolors[entry.lyxname] = entry.lcolor;
371         latexcolors[entry.latexname] = entry.lcolor;
372 }
373
374
375 docstring const ColorSet::getGUIName(ColorCode c) const
376 {
377         InfoTab::const_iterator it = infotab.find(c);
378         if (it != infotab.end())
379                 return _(it->second.guiname);
380         return from_ascii("none");
381 }
382
383
384 string const ColorSet::getX11HexName(ColorCode c, bool const darkmode) const
385 {
386         InfoTab::const_iterator it = infotab.find(c);
387         if (it != infotab.end())
388                 return darkmode ? it->second.x11darkhexname : it->second.x11hexname;
389
390         lyxerr << "LyX internal error: Missing color"
391                   " entry in Color.cpp for " << c << '\n'
392                << "Using black." << endl;
393         return darkmode ? "#faf0e6" : "black";
394 }
395
396
397 pair<string, string> const ColorSet::getAllX11HexNames(ColorCode c) const
398 {
399         InfoTab::const_iterator it = infotab.find(c);
400         if (it != infotab.end())
401                 return make_pair(it->second.x11hexname, it->second.x11darkhexname);
402
403         lyxerr << "LyX internal error: Missing color"
404                   " entry in Color.cpp for " << c << '\n'
405                << "Using black." << endl;
406         return make_pair("black", "#faf0e6");
407 }
408
409
410 string const ColorSet::getLaTeXName(ColorCode c) const
411 {
412         InfoTab::const_iterator it = infotab.find(c);
413         if (it != infotab.end())
414                 return it->second.latexname;
415         return "black";
416 }
417
418
419 string const ColorSet::getLyXName(ColorCode c) const
420 {
421         InfoTab::const_iterator it = infotab.find(c);
422         if (it != infotab.end())
423                 return it->second.lyxname;
424         return "black";
425 }
426
427
428 bool ColorSet::setColor(ColorCode col, string const & x11hexname,
429                         string const & x11darkhexname)
430 {
431         InfoTab::iterator it = infotab.find(col);
432         if (it == infotab.end()) {
433                 LYXERR0("Color " << col << " not found in database.");
434                 return false;
435         }
436
437         // "inherit" is returned for colors not in the database
438         // (and anyway should not be redefined)
439         if (col == Color_none || col == Color_inherit || col == Color_ignore) {
440                 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
441                 return false;
442         }
443
444         if (!x11hexname.empty())
445                 it->second.x11hexname = x11hexname;
446         it->second.x11darkhexname = (x11darkhexname.empty()) ? x11hexname : x11darkhexname;
447         return true;
448 }
449
450
451 bool ColorSet::setColor(string const & lyxname, string const & x11hexname,
452                         string const & x11darkhexname)
453 {
454         string const lcname = ascii_lowercase(lyxname);
455         if (lyxcolors.find(lcname) == lyxcolors.end()) {
456                 LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \""
457                        << lyxname << '"');
458                 addColor(static_cast<ColorCode>(infotab.size()), lcname);
459         }
460
461         return setColor(lyxcolors[lcname], x11hexname, x11darkhexname);
462 }
463
464
465 bool ColorSet::setLaTeXName(string const & lyxname, string const & latexname)
466 {
467         string const lcname = ascii_lowercase(lyxname);
468         if (lyxcolors.find(lcname) == lyxcolors.end()) {
469                 LYXERR(Debug::GUI, "ColorSet::setLaTeXName: Unknown color \""
470                        << lyxname << '"');
471                 addColor(static_cast<ColorCode>(infotab.size()), lcname);
472         }
473
474         ColorCode col = lyxcolors[lcname];
475         InfoTab::iterator it = infotab.find(col);
476         if (it == infotab.end()) {
477                 LYXERR0("Color " << col << " not found in database.");
478                 return false;
479         }
480
481         // "inherit" is returned for colors not in the database
482         // (and anyway should not be redefined)
483         if (col == Color_none || col == Color_inherit || col == Color_ignore) {
484                 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
485                 return false;
486         }
487
488         if (!latexname.empty())
489                 it->second.latexname = latexname;
490         return true;
491 }
492
493
494 bool ColorSet::setGUIName(string const & lyxname, string const & guiname)
495 {
496         string const lcname = ascii_lowercase(lyxname);
497         if (lyxcolors.find(lcname) == lyxcolors.end()) {
498                 LYXERR(Debug::GUI, "ColorSet::setGUIName: Unknown color \""
499                        << lyxname << '"');
500                 return false;
501         }
502
503         ColorCode col = lyxcolors[lcname];
504         InfoTab::iterator it = infotab.find(col);
505         if (it == infotab.end()) {
506                 LYXERR0("Color " << col << " not found in database.");
507                 return false;
508         }
509
510         // "inherit" is returned for colors not in the database
511         // (and anyway should not be redefined)
512         if (col == Color_none || col == Color_inherit || col == Color_ignore) {
513                 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
514                 return false;
515         }
516
517         if (!guiname.empty())
518                 it->second.guiname = guiname;
519         return true;
520 }
521
522
523 void ColorSet::addColor(ColorCode c, string const & lyxname)
524 {
525         ColorEntry ce = { c, "", "", "", "", lyxname.c_str() };
526         fill(ce);
527 }
528
529
530 ColorCode ColorSet::getFromLyXName(string const & lyxname) const
531 {
532         string const lcname = ascii_lowercase(lyxname);
533         Transform::const_iterator it = lyxcolors.find(lcname);
534         if (it == lyxcolors.end()) {
535                 LYXERR0("ColorSet::getFromLyXName: Unknown color \""
536                        << lyxname << '"');
537                 return Color_none;
538         }
539
540         return it->second;
541 }
542
543
544 ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
545 {
546         Transform::const_iterator it = latexcolors.find(latexname);
547         if (it == latexcolors.end()) {
548                 lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
549                        << latexname << '"' << endl;
550                 return Color_none;
551         }
552
553         return it->second;
554 }
555
556
557 // The evil global Color instance
558 ColorSet lcolor;
559 // An equally evil global system Color instance
560 ColorSet system_lcolor;
561
562
563 } // namespace lyx