]> git.lyx.org Git - features.git/blob - src/Color.cpp
InsetIndex: hide printTree behind a LYX_INSET_INDEX_DEBUG flag
[features.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         static ColorEntry const items[] = {
242         { Color_none, N_("none"), "none", black, black, "none" },
243         { Color_black, N_("black"), "black", black, black, "black" },
244         { Color_white, N_("white"), "white", white, white, "white" },
245         { Color_blue, N_("blue"), "blue", blue, blue, "blue" },
246         { Color_brown, N_("brown"), "brown", brown, brown, "brown" },
247         { Color_cyan, N_("cyan"), "cyan", cyan, cyan, "cyan" },
248         { Color_darkgray, N_("darkgray"), "darkgray", darkgray, darkgray, "darkgray" },
249         { Color_gray, N_("gray"), "gray", gray, gray, "gray" },
250         { Color_green, N_("green"), "green", green, green, "green" },
251         { Color_lightgray, N_("lightgray"), "lightgray", lightgray, lightgray, "lightgray" },
252         { Color_lime, N_("lime"), "lime", lime, lime, "lime" },
253         { Color_magenta, N_("magenta"), "magenta", magenta, magenta, "magenta" },
254         { Color_olive, N_("olive"), "olive", olive, olive, "olive" },
255         { Color_orange, N_("orange"), "orange", orange, orange, "orange" },
256         { Color_pink, N_("pink"), "pink", pink, pink, "pink" },
257         { Color_purple, N_("purple"), "purple", purple, purple, "purple" },
258         { Color_red, N_("red"), "red", red, red, "red" },
259         { Color_teal, N_("teal"), "teal", teal, teal, "teal" },
260         { Color_violet, N_("violet"), "violet", violet, violet, "violet" },
261         { Color_yellow, N_("yellow"), "yellow", yellow, yellow, "yellow" },
262         { Color_cursor, N_("cursor"), "cursor", black, Linen, "cursor" },
263         { Color_background, N_("background"), "background", Linen, black, "background" },
264         { Color_foreground, N_("text"), "foreground", black, Linen, "foreground" },
265         { Color_selection, N_("selection"), "selection", "#add8e6", "#add8e6", "selection" },
266         { Color_selectiontext, N_("selected text"), "selectiontext", black, black, "selectiontext" },
267         { Color_latex, N_("LaTeX text"), "latex", DarkRed, "#D66613", "latex" },
268         { Color_textlabel1, N_("Text label 1"), "textlabel1", blue, "#86a4ff", "textlabel1" },
269         { Color_textlabel2, N_("Text label 2"), "textlabel2", Green, green, "textlabel2" },
270         { Color_textlabel3, N_("Text label 3"), "textlabel3", magenta, magenta, "textlabel3" },
271         { Color_inlinecompletion, N_("inline completion"),
272                 "inlinecompletion", grey60, grey40, "inlinecompletion" },
273         { Color_nonunique_inlinecompletion, N_("non-unique inline completion"),
274                 "nonuniqueinlinecompletion", grey80, grey60, "nonuniqueinlinecompletion" },
275         { Color_preview, N_("previewed snippet"), "preview", black, Linen, "preview" },
276         { Color_notelabel, N_("note label"), "note", yellow, "#FF6200", "note" },
277         { Color_notebg, N_("note background"), "notebg", yellow, "#5b5903", "notebg" },
278         { Color_commentlabel, N_("comment label"), "comment", magenta, olive, "comment" },
279         { Color_commentbg, N_("comment background"), "commentbg", Linen, black, "commentbg" },
280         { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "#ff0080", "greyedout" },
281         { Color_greyedouttext, N_("greyedout inset text"), "greyedouttext", grey80, grey40, "greyedouttext" },
282         { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", Linen, black, "greyedoutbg" },
283         { Color_phantomtext, N_("phantom inset text"), "phantomtext", "#7f7f7f", "#7f7f7f", "phantomtext" },
284         { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "#f2af7d", "shaded" },
285         { Color_listingsbg, N_("listings background"), "listingsbg", white, black, "listingsbg" },
286         { Color_branchlabel, N_("branch label"), "branchlabel", "#c88000", "#c88000", "branchlabel" },
287         { Color_footlabel, N_("footnote label"), "footlabel", "#00aaff", blue, "footlabel" },
288         { Color_indexlabel, N_("index label"), "indexlabel", Green, teal, "indexlabel" },
289         { Color_marginlabel, N_("margin note label"), "marginlabel", "#aa55ff", violet, "marginlabel" },
290         { Color_urllabel, N_("URL label"), "urllabel", blue, blue, "urllabel" },
291         { Color_urltext, N_("URL text"), "urltext", blue, "#86a4ff", "urltext" },
292         { Color_depthbar, N_("depth bar"), "depthbar", IndianRed, IndianRed, "depthbar" },
293         { Color_scroll, N_("scroll indicator"), "scroll", IndianRed, IndianRed, "scroll" },
294         { Color_language, N_("language"), "language", blue, "#86a4ff", "language" },
295         { Color_command, N_("command inset"), "command", black, black, "command" },
296         { Color_commandbg, N_("command inset background"), "commandbg", "#f0ffff", "#f0ffff", "commandbg" },
297         { Color_commandframe, N_("command inset frame"), "commandframe", black, Linen, "commandframe" },
298         { Color_command_broken, N_("command inset (broken reference)"), "command", white, white, "command_broken" },
299         { Color_buttonbg_broken, N_("button background (broken reference)"), "commandbg", red, red, "commandbg_broken" },
300         { Color_buttonframe_broken, N_("button frame (broken reference)"), "commandframe", red, red, "commandframe_broken" },
301         { Color_buttonhoverbg_broken, N_("button background (broken reference) under focus"), "buttonhoverbg", "#DB0B0B", "#DB0B0B", "buttonhoverbg_broken" },
302         { Color_special, N_("special character"), "special", RoyalBlue, RoyalBlue, "special" },
303         { Color_math, N_("math"), "math", "#00008B", "#85F0FE", "math" },
304         { Color_mathbg, N_("math background"), "mathbg", Linen, black, "mathbg" },
305         { Color_graphicsbg, N_("graphics background"), "graphicsbg", Linen, black, "graphicsbg" },
306         { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", Linen, black, "mathmacrobg" },
307         { Color_mathframe, N_("math frame"), "mathframe", magenta, magenta, "mathframe" },
308         { Color_mathcorners, N_("math corners"), "mathcorners", Linen, black, "mathcorners" },
309         { Color_mathline, N_("math line"), "mathline", blue, "#86a4ff", "mathline" },
310         { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", "#ede2d8", black, "mathmacrobg" },
311         { Color_mathmacrohoverbg, N_("math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", grey80, "mathmacrohoverbg" },
312         { Color_mathmacrolabel, N_("math macro label"), "mathmacrolabel", "#a19992", "#a19992", "mathmacrolabel" },
313         { Color_mathmacroframe, N_("math macro frame"), "mathmacroframe", "#ede2d8", black, "mathmacroframe" },
314         { Color_mathmacroblend, N_("math macro blended out"), "mathmacroblend", black, Linen, "mathmacroblend" },
315         { Color_mathmacrooldarg, N_("math macro old parameter"), "mathmacrooldarg", grey80, grey40, "mathmacrooldarg" },
316         { Color_mathmacronewarg, N_("math macro new parameter"), "mathmacronewarg", black, Linen, "mathmacronewarg" },
317         { Color_collapsible, N_("collapsible inset text"), "collapsible", DarkRed, DarkRed, "collapsible" },
318         { Color_collapsibleframe, N_("collapsible inset frame"), "collapsibleframe", IndianRed, IndianRed, "collapsibleframe" },
319         { Color_insetbg, N_("inset background"), "insetbg", grey80, grey80, "insetbg" },
320         { Color_insetframe, N_("inset frame"), "insetframe", IndianRed, IndianRed, "insetframe" },
321         { Color_error, N_("LaTeX error"), "error", red, DarkRed, "error" },
322         { Color_eolmarker, N_("end-of-line marker"), "eolmarker", Brown, Brown, "eolmarker" },
323         { Color_appendix, N_("appendix marker"), "appendix", Brown, Brown, "appendix" },
324         { Color_changebar, N_("change bar"), "changebar", blue, "#86a4ff", "changebar" },
325         { Color_deletedtext_output, N_("deleted text (output)"), "deletedtext", "#ff0000", "#ff0000", "deletedtext" },
326         { Color_addedtext_output, N_("added text (output)"), "addedtext", "#0000ff", "#0000ff", "addedtext" },
327         { Color_changedtext_workarea_author1, N_("changed text (workarea, 1st author)"), "changedtextauthor1", "#0000ff", "#86a4ff", "changedtextauthor1" },
328         { Color_changedtext_workarea_author2, N_("changed text (workarea, 2nd author)"), "changedtextauthor2", "#ff00ff", "#ee86ee", "changedtextauthor2" },
329         { Color_changedtext_workarea_author3, N_("changed text (workarea, 3rd author)"), "changedtextauthor3", "#ff0000", "#ea8989", "changedtextauthor3" },
330         { Color_changedtext_workarea_author4, N_("changed text (workarea, 4th author)"), "changedtextauthor4", "#aa00ff", "#c371ec", "changedtextauthor4" },
331         { Color_changedtext_workarea_author5, N_("changed text (workarea, 5th author)"), "changedtextauthor5", "#55aa00", "#acd780", "changedtextauthor5" },
332         { Color_deletedtext_workarea_modifier, N_("deleted text modifier (workarea)"), "deletedtextmodifier", white, white, "deletedtextmodifier" },
333         { Color_added_space, N_("added space markers"), "added_space", Brown, Brown, "added_space" },
334         { Color_tabularline, N_("table line"), "tabularline", black, Linen, "tabularline" },
335         { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline", "#b0c4de", "#23497b", "tabularonoffline" },
336         { Color_bottomarea, N_("bottom area"), "bottomarea", grey40, grey80, "bottomarea" },
337         { Color_newpage, N_("new page"), "newpage", blue, "#86a4ff", "newpage" },
338         { Color_pagebreak, N_("page break / line break"), "pagebreak", RoyalBlue, RoyalBlue, "pagebreak" },
339         { Color_buttonframe, N_("button frame"), "buttonframe", "#dcd2c8", "#dcd2c8", "buttonframe" },
340         { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "#dcd2c8", "buttonbg" },
341         { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "#C7C7CA", "buttonhoverbg" },
342         { Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, grey40, "paragraphmarker"},
343         { Color_previewframe, N_("preview frame"), "previewframe", black, Linen, "previewframe"},
344         { Color_regexpframe, N_("regexp frame"), "regexpframe", Green, green, "regexpframe" },
345         { Color_bookmark, N_("bookmark"), "bookmark", RoyalBlue, RoyalBlue, "bookmark" },
346         { Color_inherit, N_("inherit"), "inherit", black, Linen, "inherit" },
347         { Color_ignore, N_("ignore"), "ignore", black, Linen, "ignore" },
348         { Color_ignore, nullptr, nullptr, nullptr, nullptr, nullptr }
349         };
350
351         for (int i = 0; items[i].guiname; ++i)
352                 fill(items[i]);
353 }
354
355
356 /// initialise a color entry
357 void ColorSet::fill(ColorEntry const & entry)
358 {
359         Information in;
360         in.lyxname   = entry.lyxname;
361         in.latexname = entry.latexname;
362         in.x11hexname   = entry.x11hexname;
363         in.x11darkhexname   = entry.x11darkhexname;
364         in.guiname   = entry.guiname;
365         infotab[entry.lcolor] = in;
366         lyxcolors[entry.lyxname] = entry.lcolor;
367         latexcolors[entry.latexname] = entry.lcolor;
368 }
369
370
371 docstring const ColorSet::getGUIName(ColorCode c) const
372 {
373         InfoTab::const_iterator it = infotab.find(c);
374         if (it != infotab.end())
375                 return _(it->second.guiname);
376         return from_ascii("none");
377 }
378
379
380 string const ColorSet::getX11HexName(ColorCode c, bool const darkmode) const
381 {
382         InfoTab::const_iterator it = infotab.find(c);
383         if (it != infotab.end())
384                 return darkmode ? it->second.x11darkhexname : it->second.x11hexname;
385
386         lyxerr << "LyX internal error: Missing color"
387                   " entry in Color.cpp for " << c << '\n'
388                << "Using black." << endl;
389         return darkmode ? "#faf0e6" : "black";
390 }
391
392
393 pair<string, string> const ColorSet::getAllX11HexNames(ColorCode c) const
394 {
395         InfoTab::const_iterator it = infotab.find(c);
396         if (it != infotab.end())
397                 return make_pair(it->second.x11hexname, it->second.x11darkhexname);
398
399         lyxerr << "LyX internal error: Missing color"
400                   " entry in Color.cpp for " << c << '\n'
401                << "Using black." << endl;
402         return make_pair("black", "#faf0e6");
403 }
404
405
406 string const ColorSet::getLaTeXName(ColorCode c) const
407 {
408         InfoTab::const_iterator it = infotab.find(c);
409         if (it != infotab.end())
410                 return it->second.latexname;
411         return "black";
412 }
413
414
415 string const ColorSet::getLyXName(ColorCode c) const
416 {
417         InfoTab::const_iterator it = infotab.find(c);
418         if (it != infotab.end())
419                 return it->second.lyxname;
420         return "black";
421 }
422
423
424 bool ColorSet::setColor(ColorCode col, string const & x11hexname,
425                         string const & x11darkhexname)
426 {
427         InfoTab::iterator it = infotab.find(col);
428         if (it == infotab.end()) {
429                 LYXERR0("Color " << col << " not found in database.");
430                 return false;
431         }
432
433         // "inherit" is returned for colors not in the database
434         // (and anyway should not be redefined)
435         if (col == Color_none || col == Color_inherit || col == Color_ignore) {
436                 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
437                 return false;
438         }
439
440         if (!x11hexname.empty())
441                 it->second.x11hexname = x11hexname;
442         it->second.x11darkhexname = (x11darkhexname.empty()) ? x11hexname : x11darkhexname;
443         return true;
444 }
445
446
447 bool ColorSet::setColor(string const & lyxname, string const & x11hexname,
448                         string const & x11darkhexname)
449 {
450         string const lcname = ascii_lowercase(lyxname);
451         if (lyxcolors.find(lcname) == lyxcolors.end()) {
452                 LYXERR(Debug::GUI, "ColorSet::setColor: Unknown color \""
453                        << lyxname << '"');
454                 addColor(static_cast<ColorCode>(infotab.size()), lcname);
455         }
456
457         return setColor(lyxcolors[lcname], x11hexname, x11darkhexname);
458 }
459
460
461 bool ColorSet::setLaTeXName(string const & lyxname, string const & latexname)
462 {
463         string const lcname = ascii_lowercase(lyxname);
464         if (lyxcolors.find(lcname) == lyxcolors.end()) {
465                 LYXERR(Debug::GUI, "ColorSet::setLaTeXName: Unknown color \""
466                        << lyxname << '"');
467                 addColor(static_cast<ColorCode>(infotab.size()), lcname);
468         }
469
470         ColorCode col = lyxcolors[lcname];
471         InfoTab::iterator it = infotab.find(col);
472         if (it == infotab.end()) {
473                 LYXERR0("Color " << col << " not found in database.");
474                 return false;
475         }
476
477         // "inherit" is returned for colors not in the database
478         // (and anyway should not be redefined)
479         if (col == Color_none || col == Color_inherit || col == Color_ignore) {
480                 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
481                 return false;
482         }
483
484         if (!latexname.empty())
485                 it->second.latexname = latexname;
486         return true;
487 }
488
489
490 bool ColorSet::setGUIName(string const & lyxname, string const & guiname)
491 {
492         string const lcname = ascii_lowercase(lyxname);
493         if (lyxcolors.find(lcname) == lyxcolors.end()) {
494                 LYXERR(Debug::GUI, "ColorSet::setGUIName: Unknown color \""
495                        << lyxname << '"');
496                 return false;
497         }
498
499         ColorCode col = lyxcolors[lcname];
500         InfoTab::iterator it = infotab.find(col);
501         if (it == infotab.end()) {
502                 LYXERR0("Color " << col << " not found in database.");
503                 return false;
504         }
505
506         // "inherit" is returned for colors not in the database
507         // (and anyway should not be redefined)
508         if (col == Color_none || col == Color_inherit || col == Color_ignore) {
509                 LYXERR0("Color " << getLyXName(col) << " may not be redefined.");
510                 return false;
511         }
512
513         if (!guiname.empty())
514                 it->second.guiname = guiname;
515         return true;
516 }
517
518
519 void ColorSet::addColor(ColorCode c, string const & lyxname)
520 {
521         ColorEntry ce = { c, "", "", "", "", lyxname.c_str() };
522         fill(ce);
523 }
524
525
526 ColorCode ColorSet::getFromLyXName(string const & lyxname) const
527 {
528         string const lcname = ascii_lowercase(lyxname);
529         Transform::const_iterator it = lyxcolors.find(lcname);
530         if (it == lyxcolors.end()) {
531                 LYXERR0("ColorSet::getFromLyXName: Unknown color \""
532                        << lyxname << '"');
533                 return Color_none;
534         }
535
536         return it->second;
537 }
538
539
540 ColorCode ColorSet::getFromLaTeXName(string const & latexname) const
541 {
542         Transform::const_iterator it = latexcolors.find(latexname);
543         if (it == latexcolors.end()) {
544                 lyxerr << "ColorSet::getFromLaTeXName: Unknown color \""
545                        << latexname << '"' << endl;
546                 return Color_none;
547         }
548
549         return it->second;
550 }
551
552
553 // The evil global Color instance
554 ColorSet lcolor;
555 // An equally evil global system Color instance
556 ColorSet system_lcolor;
557
558
559 } // namespace lyx