[LyX/master] Upgrade ColorSet class to be based on 32bit colors
Koji Yokota <[email protected]> Tue, 02 Jun 2026 04:51:32 +0000
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit abdb06e5f64f1d6f78bdd58552b8d2bf3c63db3f Author: Koji Yokota <[email protected]> Date: Sun May 31 22:03:22 2026 +0900 Upgrade ColorSet class to be based on 32bit colors --- src/Color.cpp | 270 +++++++++++++++++++++++++--------------- src/Color.h | 7 +- src/ColorSet.h | 26 ++-- src/LyXRC.cpp | 8 +- src/frontends/qt/ColorCache.cpp | 8 +- src/frontends/qt/GuiPrefs.cpp | 2 +- 6 files changed, 202 insertions(+), 119 deletions(-) diff --git a/src/Color.cpp b/src/Color.cpp index 6c3387fe41..f277de10b4 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -41,8 +41,8 @@ struct ColorSet::ColorEntry { ColorCode lcolor; char const * guiname; char const * latexname; - char const * x11hexname; - char const * x11darkhexname; + char const * hex32name; + char const * darkhex32name; char const * lyxname; }; @@ -80,24 +80,43 @@ string const X11hexname(RGBColor const & col) } -RGBColor rgbFromHexName(string const & x11hexname) +RGBColor rgbFromHexName(string const & hexname) { - LASSERT((x11hexname.size() == 7 || x11hexname.size() == 9) - && x11hexname[0] == '#', return RGBColor()); - if (x11hexname.size() == 7) { - RGBColor c; - c.r = hexstrToInt(x11hexname.substr(1, 2)); - c.g = hexstrToInt(x11hexname.substr(3, 2)); - c.b = hexstrToInt(x11hexname.substr(5, 2)); - return c; + // hexname accepts both 16bit and 32bit hex codes + LASSERT((hexname.size() == 7 || hexname.size() == 9) + && hexname[0] == '#', return RGBColor()); + RGBColor c; + if (hexname.size() == 7) { + c.r = hexstrToInt(hexname.substr(1, 2)); + c.g = hexstrToInt(hexname.substr(3, 2)); + c.b = hexstrToInt(hexname.substr(5, 2)); } else { - ARGBColor c; - c.a = hexstrToInt(x11hexname.substr(1, 2)); - c.r = hexstrToInt(x11hexname.substr(3, 2)); - c.g = hexstrToInt(x11hexname.substr(5, 2)); - c.b = hexstrToInt(x11hexname.substr(7, 2)); - return c; + c.r = hexstrToInt(hexname.substr(3, 2)); + c.g = hexstrToInt(hexname.substr(5, 2)); + c.b = hexstrToInt(hexname.substr(7, 2)); } + return c; +} + + +ARGBColor argbFromHexName(string const & hexname) +{ + // hexname accepts both 16bit and 32bit hex codes + LASSERT((hexname.size() == 7 || hexname.size() == 9) + && hexname[0] == '#', return ARGBColor()); + ARGBColor c; + if (hexname.size() == 7) { + c.a = 255; + c.r = hexstrToInt(hexname.substr(1, 2)); + c.g = hexstrToInt(hexname.substr(3, 2)); + c.b = hexstrToInt(hexname.substr(5, 2)); + } else { + c.a = hexstrToInt(hexname.substr(1, 2)); + c.r = hexstrToInt(hexname.substr(3, 2)); + c.g = hexstrToInt(hexname.substr(5, 2)); + c.b = hexstrToInt(hexname.substr(7, 2)); + } + return c; } @@ -217,39 +236,40 @@ std::ostream & operator<<(std::ostream & os, Color color) ColorSet::ColorSet() { - char const * grey40 = "#666666"; - char const * grey60 = "#999999"; - char const * grey80 = "#cccccc"; + char const * grey40 = "#ff666666"; + char const * grey60 = "#ff999999"; + char const * grey80 = "#ffcccccc"; // latex colors (xcolor package) - char const * black = "#000000"; - char const * white = "#ffffff"; - char const * blue = "#0000ff"; - char const * brown = "#bf8040"; - char const * cyan = "#00ffff"; - char const * darkgray = "#404040"; - char const * gray = "#808080"; - char const * green = "#00ff00"; - char const * lightgray = "#bfbfbf"; - char const * lime = "#bfff00"; - char const * magenta = "#ff00ff"; - char const * olive = "#808000"; - char const * orange = "#ff8000"; - char const * pink = "#ffbfbf"; - char const * purple = "#bf0040"; - char const * red = "#ff0000"; - char const * teal = "#008080"; - char const * violet = "#800080"; - char const * yellow = "#ffff00"; + char const * black = "#ff000000"; + char const * white = "#ffffffff"; + char const * blue = "#ff0000ff"; + char const * brown = "#ffbf8040"; + char const * cyan = "#ff00ffff"; + char const * darkgray = "#ff404040"; + char const * gray = "#ff808080"; + char const * green = "#ff00ff00"; + char const * lightgray = "#ffbfbfbf"; + char const * lime = "#ffbfff00"; + char const * magenta = "#ffff00ff"; + char const * olive = "#ff808000"; + char const * orange = "#ffff8000"; + char const * pink = "#ffffbfbf"; + char const * purple = "#ffbf0040"; + char const * red = "#ffff0000"; + char const * teal = "#ff008080"; + char const * violet = "#ff800080"; + char const * yellow = "#ffffff00"; // svg colors - char const * Brown = "#a52a2a"; - char const * DarkRed = "#8b0000"; - char const * Green = "#008000"; - char const * IndianRed = "#cd5c5c"; - char const * Linen = "#faf0e6"; - char const * RoyalBlue = "#4169e1"; - - //char const * grey90 = "#e5e5e5"; - // ColorCode, gui, latex, x11hexname, x11darkhexname, lyx + char const * Brown = "#ffa52a2a"; + char const * DarkRed = "#ff8b0000"; + char const * Green = "#ff008000"; + char const * IndianRed = "#ffcd5c5c"; + char const * Linen = "#fffaf0e6"; + char const * RoyalBlue = "#ff4169e1"; + char const * Transparent = "#00000000"; + + //char const * grey90 = "#ffe5e5e5"; + // ColorCode, gui, latex, hex32name, darkhex32name, lyx // Warning: several of these entries are overridden in GuiApplication constructor // lyx color names are collected for users in Customization manual (B.# Dynamic colors) static ColorEntry const items[] = { @@ -278,60 +298,60 @@ ColorSet::ColorSet() { Color_background, N_("background"), "background", Linen, black, "background" }, { Color_foreground, N_("text"), "foreground", black, Linen, "foreground" }, { Color_foreground_inverted, N_("text (inverted background)"), "foreground_inverted", Linen, black, "foreground_inverted" }, - { Color_selection, N_("selection"), "selection", "#add8e6", "#add8e6", "selection" }, - { Color_selectionmath, N_("selected math"), "selectionmath", "#00008B", "#00008B", "selectionmath" }, + { Color_selection, N_("selection"), "selection", "#ffadd8e6", "#ffadd8e6", "selection" }, + { Color_selectionmath, N_("selected math"), "selectionmath", "#ff00008b", "#ff00008b", "selectionmath" }, { Color_selectiontext, N_("selected text"), "selectiontext", black, black, "selectiontext" }, - { Color_preeditfocus, N_("preedit focus background"), "preeditfocus", "#add8e6", "#add8e6", "preeditfocus" }, + { Color_preeditfocus, N_("preedit focus background"), "preeditfocus", "#ffadd8e6", "#ffadd8e6", "preeditfocus" }, { Color_preeditfocustext, N_("preedit focus text"), "preeditfocustext", black, black, "preeditfocustext" }, - { Color_preeditbg, N_("preedit background"), "preeditbg", Linen, black, "preeditbg" }, + { Color_preeditbg, N_("preedit background"), "preeditbg", Transparent, Transparent, "preeditbg" }, { Color_preedittext, N_("preedit text"), "preedittext", black, Linen, "preedittext" }, - { Color_latex, N_("LaTeX text"), "latex", DarkRed, "#D66613", "latex" }, + { Color_latex, N_("LaTeX text"), "latex", DarkRed, "#ffd66613", "latex" }, { Color_preview, N_("previewed snippet"), "preview", black, Linen, "preview" }, { Color_inlinecompletion, N_("inline completion"), "inlinecompletion", grey60, grey40, "inlinecompletion" }, { Color_nonunique_inlinecompletion, N_("inline completion (non-unique)"), "nonuniqueinlinecompletion", grey80, grey60, "nonuniqueinlinecompletion" }, - { Color_notelabel, N_("note label"), "note", yellow, "#FF6200", "note" }, - { Color_notebg, N_("note background"), "notebg", yellow, "#5b5903", "notebg" }, + { Color_notelabel, N_("note label"), "note", yellow, "#ffff6200", "note" }, + { Color_notebg, N_("note background"), "notebg", yellow, "#ff5b5903", "notebg" }, { Color_commentlabel, N_("comment label"), "comment", magenta, olive, "comment" }, { Color_commentbg, N_("comment background"), "commentbg", Linen, black, "commentbg" }, - { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ff0080", "#ff0080", "greyedout" }, + { Color_greyedoutlabel, N_("greyedout inset label"), "greyedout", "#ffff0080", "#ffff0080", "greyedout" }, { Color_greyedouttext, N_("greyedout inset text"), "greyedouttext", grey80, grey40, "greyedouttext" }, { Color_greyedoutbg, N_("greyedout inset background"), "greyedoutbg", Linen, black, "greyedoutbg" }, - { Color_shadedbg, N_("shaded box"), "shaded", "#ff0000", "#f2af7d", "shaded" }, + { Color_shadedbg, N_("shaded box"), "shaded", "#ffff0000", "#fff2af7d", "shaded" }, { Color_listingsbg, N_("listings background"), "listingsbg", white, black, "listingsbg" }, - { Color_branchlabel, N_("branch label"), "branchlabel", "#c88000", "#c88000", "branchlabel" }, - { Color_footlabel, N_("footnote label"), "footlabel", "#00aaff", blue, "footlabel" }, + { Color_branchlabel, N_("branch label"), "branchlabel", "#ffc88000", "#ffc88000", "branchlabel" }, + { Color_footlabel, N_("footnote label"), "footlabel", "#ff00aaff", blue, "footlabel" }, { Color_indexlabel, N_("index label"), "indexlabel", Green, teal, "indexlabel" }, - { Color_marginlabel, N_("margin note label"), "marginlabel", "#aa55ff", violet, "marginlabel" }, - { Color_nomlabel, N_("nomenclature label"), "nomlabel", "#ff6d2f", "#ff6d2f", "nomlabel" }, - { Color_phantomtext, N_("phantom inset text"), "phantomtext", "#7f7f7f", "#7f7f7f", "phantomtext" }, + { Color_marginlabel, N_("margin note label"), "marginlabel", "#ffaa55ff", violet, "marginlabel" }, + { Color_nomlabel, N_("nomenclature label"), "nomlabel", "#ffff6d2f", "#ffff6d2f", "nomlabel" }, + { Color_phantomtext, N_("phantom inset text"), "phantomtext", "#ff7f7f7f", "#ff7f7f7f", "phantomtext" }, { Color_urllabel, N_("URL label"), "urllabel", blue, blue, "urllabel" }, - { Color_textlabel1, N_("Text label 1"), "textlabel1", blue, "#86a4ff", "textlabel1" }, + { Color_textlabel1, N_("Text label 1"), "textlabel1", blue, "#ff86a4ff", "textlabel1" }, { Color_textlabel2, N_("Text label 2"), "textlabel2", Green, green, "textlabel2" }, { Color_textlabel3, N_("Text label 3"), "textlabel3", magenta, magenta, "textlabel3" }, - { Color_urltext, N_("URL text"), "urltext", blue, "#86a4ff", "urltext" }, + { Color_urltext, N_("URL text"), "urltext", blue, "#ff86a4ff", "urltext" }, { Color_depthbar, N_("depth bar"), "depthbar", IndianRed, IndianRed, "depthbar" }, { Color_scroll, N_("scroll indicator"), "scroll", IndianRed, IndianRed, "scroll" }, - { Color_language, N_("language"), "language", blue, "#86a4ff", "language" }, + { Color_language, N_("language"), "language", blue, "#ff86a4ff", "language" }, { Color_command, N_("command inset"), "command", black, black, "command" }, - { Color_commandbg, N_("command inset background"), "commandbg", "#f0ffff", "#f0ffff", "commandbg" }, + { Color_commandbg, N_("command inset background"), "commandbg", "#fff0ffff", "#fff0ffff", "commandbg" }, { Color_commandframe, N_("command inset frame"), "commandframe", black, Linen, "commandframe" }, { Color_special, N_("special character"), "special", RoyalBlue, RoyalBlue, "special" }, - { Color_graphicsbg, N_("graphics background"), "graphicsbg", Linen, black, "graphicsbg" }, - { Color_math, N_("math text"), "math", "#00008B", "#85F0FE", "math" }, - { Color_mathbg, N_("math background"), "mathbg", Linen, black, "mathbg" }, + { Color_graphicsbg, N_("graphics background"), "graphicsbg", Transparent, Transparent, "graphicsbg" }, + { Color_math, N_("math text"), "math", "#ff00008b", "#ff85f0fe", "math" }, + { Color_mathbg, N_("math background"), "mathbg", Transparent, Transparent, "mathbg" }, { Color_mathmacrobg, N_("math macro background"), "mathmacrobg", Linen, black, "mathmacrobg" }, - { Color_mathmacrohoverbg, N_("math macro hovered background"), "mathmacrohoverbg", "#cdc3b8", + { Color_mathmacrohoverbg, N_("math macro hovered background"), "mathmacrohoverbg", "#ffcdc3b8", grey80, "mathmacrohoverbg" }, - { Color_mathmacrolabel, N_("math macro label"), "mathmacrolabel", "#a19992", "#a19992", "mathmacrolabel" }, - { Color_mathmacroframe, N_("math macro frame"), "mathmacroframe", "#ede2d8", black, "mathmacroframe" }, + { Color_mathmacrolabel, N_("math macro label"), "mathmacrolabel", "#ffa19992", "#ffa19992", "mathmacrolabel" }, + { Color_mathmacroframe, N_("math macro frame"), "mathmacroframe", "#ffede2d8", black, "mathmacroframe" }, { Color_mathmacroblend, N_("math macro blended out"), "mathmacroblend", black, Linen, "mathmacroblend" }, { Color_mathmacrooldarg, N_("math macro old parameter"), "mathmacrooldarg", grey80, grey40, "mathmacrooldarg" }, { Color_mathmacronewarg, N_("math macro new parameter"), "mathmacronewarg", black, Linen, "mathmacronewarg" }, { Color_mathframe, N_("math frame"), "mathframe", magenta, magenta, "mathframe" }, { Color_mathcorners, N_("math corners"), "mathcorners", Linen, black, "mathcorners" }, - { Color_mathline, N_("math line"), "mathline", blue, "#86a4ff", "mathline" }, + { Color_mathline, N_("math line"), "mathline", blue, "#ff86a4ff", "mathline" }, { Color_collapsible, N_("collapsible inset text"), "collapsible", DarkRed, DarkRed, "collapsible" }, { Color_collapsibleframe, N_("collapsible inset frame"), "collapsibleframe", IndianRed, IndianRed, "collapsibleframe" }, { Color_insetbg, N_("inset background"), "insetbg", grey80, grey80, "insetbg" }, @@ -341,29 +361,29 @@ ColorSet::ColorSet() { Color_eolmarker, N_("end-of-line marker"), "eolmarker", Brown, Brown, "eolmarker" }, { Color_added_space, N_("added space markers"), "added_space", Brown, Brown, "added_space" }, { Color_appendix, N_("appendix marker"), "appendix", Brown, Brown, "appendix" }, - { Color_changebar, N_("change bar"), "changebar", blue, "#86a4ff", "changebar" }, - { Color_deletedtext_output, N_("changes - deleted text (exported output)"), "deletedtext", "#ff0000", "#ff0000", "deletedtext" }, - { Color_addedtext_output, N_("changes - added text (exported output)"), "addedtext", "#0000ff", "#0000ff", "addedtext" }, - { Color_changedtext_workarea_author1, N_("changed text (workarea, 1st author)"), "changedtextauthor1", "#0000ff", "#86a4ff", "changedtextauthor1" }, - { Color_changedtext_workarea_author2, N_("changed text (workarea, 2nd author)"), "changedtextauthor2", "#ff00ff", "#ee86ee", "changedtextauthor2" }, - { Color_changedtext_workarea_author3, N_("changed text (workarea, 3rd author)"), "changedtextauthor3", "#ff0000", "#ea8989", "changedtextauthor3" }, - { Color_changedtext_workarea_author4, N_("changed text (workarea, 4th author)"), "changedtextauthor4", "#aa00ff", "#c371ec", "changedtextauthor4" }, - { Color_changedtext_workarea_author5, N_("changed text (workarea, 5th author)"), "changedtextauthor5", "#55aa00", "#acd780", "changedtextauthor5" }, - { Color_changedtext_workarea_comparison, N_("changed text (workarea, document comparison)"), "changedtextcomparison", "#008080", "#719FB0", "changedtextcomparison" }, + { Color_changebar, N_("change bar"), "changebar", blue, "#ff86a4ff", "changebar" }, + { Color_deletedtext_output, N_("changes - deleted text (exported output)"), "deletedtext", "#ffff0000", "#ffff0000", "deletedtext" }, + { Color_addedtext_output, N_("changes - added text (exported output)"), "addedtext", "#ff0000ff", "#ff0000ff", "addedtext" }, + { Color_changedtext_workarea_author1, N_("changed text (workarea, 1st author)"), "changedtextauthor1", "#ff0000ff", "#ff86a4ff", "changedtextauthor1" }, + { Color_changedtext_workarea_author2, N_("changed text (workarea, 2nd author)"), "changedtextauthor2", "#ffff00ff", "#ffee86ee", "changedtextauthor2" }, + { Color_changedtext_workarea_author3, N_("changed text (workarea, 3rd author)"), "changedtextauthor3", "#ffff0000", "#ffea8989", "changedtextauthor3" }, + { Color_changedtext_workarea_author4, N_("changed text (workarea, 4th author)"), "changedtextauthor4", "#ffaa00ff", "#ffc371ec", "changedtextauthor4" }, + { Color_changedtext_workarea_author5, N_("changed text (workarea, 5th author)"), "changedtextauthor5", "#ff55aa00", "#ffacd780", "changedtextauthor5" }, + { Color_changedtext_workarea_comparison, N_("changed text (workarea, document comparison)"), "changedtextcomparison", "#ff008080", "#ff719fb0", "changedtextcomparison" }, { Color_deletedtext_workarea_modifier, N_("changes - deleted text brightness (workarea)"), "deletedtextmodifier", white, white, "deletedtextmodifier" }, { Color_tabularline, N_("table line"), "tabularline", black, Linen, "tabularline" }, - { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline", "#b0c4de", "#23497b", "tabularonoffline" }, + { Color_tabularonoffline, N_("table on/off line"), "tabularonoffline", "#ffb0c4de", "#ff23497b", "tabularonoffline" }, { Color_bottomarea, N_("bottom area"), "bottomarea", grey40, grey80, "bottomarea" }, - { Color_newpage, N_("new page"), "newpage", blue, "#86a4ff", "newpage" }, + { Color_newpage, N_("new page"), "newpage", blue, "#ff86a4ff", "newpage" }, { Color_pagebreak, N_("page break / line break"), "pagebreak", RoyalBlue, RoyalBlue, "pagebreak" }, - { Color_buttonframe, N_("button frame"), "buttonframe", "#dcd2c8", "#dcd2c8", "buttonframe" }, - { Color_buttonbg, N_("button background"), "buttonbg", "#dcd2c8", "#dcd2c8", "buttonbg" }, - { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#C7C7CA", "#C7C7CA", "buttonhoverbg" }, + { Color_buttonframe, N_("button frame"), "buttonframe", "#ffdcd2c8", "#ffdcd2c8", "buttonframe" }, + { Color_buttonbg, N_("button background"), "buttonbg", "#ffdcd2c8", "#ffdcd2c8", "buttonbg" }, + { Color_buttonhoverbg, N_("button background under focus"), "buttonhoverbg", "#ffc7c7ca", "#ffc7c7ca", "buttonhoverbg" }, { Color_command_broken, N_("command inset (broken reference)"), "command", white, white, "command_broken" }, { Color_buttonbg_broken, N_("button background (broken reference)"), "commandbg", red, red, "commandbg_broken" }, { Color_buttonframe_broken, N_("button frame (broken reference)"), "commandframe", red, red, "commandframe_broken" }, { Color_buttonhoverbg_broken, N_("button background (broken reference) under focus"), - "buttonhoverbg", "#DB0B0B", "#DB0B0B", "buttonhoverbg_broken" }, + "buttonhoverbg", "#ffdb0b0b", "#ffdb0b0b", "buttonhoverbg_broken" }, { Color_paragraphmarker, N_("paragraph marker"), "paragraphmarker", grey80, grey40, "paragraphmarker"}, { Color_previewframe, N_("preview frame"), "previewframe", black, Linen, "previewframe"}, { Color_bookmark, N_("bookmark"), "bookmark", RoyalBlue, RoyalBlue, "bookmark" }, @@ -384,8 +404,8 @@ void ColorSet::fill(ColorEntry const & entry) Information in; in.lyxname = entry.lyxname; in.latexname = entry.latexname; - in.x11hexname = entry.x11hexname; - in.x11darkhexname = entry.x11darkhexname; + in.hex32name = entry.hex32name; + in.darkhex32name = entry.darkhex32name; in.guiname = entry.guiname; infotab[entry.lcolor] = in; lyxcolors[entry.lyxname] = entry.lcolor; @@ -406,7 +426,8 @@ string const ColorSet::getX11HexName(ColorCode c, bool const darkmode) const { InfoTab::const_iterator it = infotab.find(c); if (it != infotab.end()) - return darkmode ? it->second.x11darkhexname : it->second.x11hexname; + return darkmode ? "#" + it->second.darkhex32name.substr(3, 6) : + "#" + it->second.hex32name.substr(3, 6); lyxerr << "LyX internal error: Missing color" " entry in Color.cpp for " << c << '\n' @@ -425,7 +446,8 @@ pair<string, string> const ColorSet::getAllX11HexNames(ColorCode c) const { InfoTab::const_iterator it = infotab.find(c); if (it != infotab.end()) - return make_pair(it->second.x11hexname, it->second.x11darkhexname); + return make_pair("#" + it->second.hex32name.substr(3, 6), + "#" + it->second.darkhex32name.substr(3, 6)); lyxerr << "LyX internal error: Missing color" " entry in Color.cpp for " << c << '\n' @@ -434,6 +456,38 @@ pair<string, string> const ColorSet::getAllX11HexNames(ColorCode c) const } +string const ColorSet::get32bitHexName(ColorCode c, bool const darkmode) const +{ + InfoTab::const_iterator it = infotab.find(c); + if (it != infotab.end()) + return darkmode ? it->second.darkhex32name : it->second.hex32name; + + lyxerr << "LyX internal error: Missing color" + " entry in Color.cpp for " << c << '\n' + << "Using black." << endl; + return darkmode ? "#fffaf0e6" : "black"; +} + + +string const ColorSet::get32bitHexName(string const & lyxname, bool const darkmode) const +{ + return getX11HexName(getFromLyXName(lyxname), darkmode); +} + + +pair<string, string> const ColorSet::getAll32bitHexNames(ColorCode c) const +{ + InfoTab::const_iterator it = infotab.find(c); + if (it != infotab.end()) + return make_pair(it->second.hex32name, it->second.darkhex32name); + + lyxerr << "LyX internal error: Missing color" + " entry in Color.cpp for " << c << '\n' + << "Using black." << endl; + return make_pair("black", "#fffaf0e6"); +} + + string const ColorSet::getLaTeXName(ColorCode c) const { InfoTab::const_iterator it = infotab.find(c); @@ -452,8 +506,8 @@ string const ColorSet::getLyXName(ColorCode c) const } -bool ColorSet::setColor(ColorCode col, string const & x11hexname, - string const & x11darkhexname) +bool ColorSet::setColor(ColorCode col, string const & hexname, + string const & darkhexname) { InfoTab::iterator it = infotab.find(col); if (it == infotab.end()) { @@ -468,15 +522,30 @@ bool ColorSet::setColor(ColorCode col, string const & x11hexname, return false; } - if (!x11hexname.empty()) - it->second.x11hexname = x11hexname; - it->second.x11darkhexname = (x11darkhexname.empty()) ? x11hexname : x11darkhexname; + LASSERT((hexname.empty() + || ((hexname.size() == 7 || hexname.size() == 9) + && hexname[0] == '#')) + && (darkhexname.empty() + || ((darkhexname.size() == 7 || darkhexname.size() == 9) + && darkhexname[0] == '#')), + return true); + + if (!hexname.empty()) + it->second.hex32name = hexname.size() == 7 ? + "#ff" + hexname.substr(1, 6) : hexname; + + if (!darkhexname.empty()) + it->second.darkhex32name = darkhexname.size() == 7 ? + "#ff" + darkhexname.substr(1, 6) : darkhexname; + else + it->second.darkhex32name = hexname.size() == 7 ? + "#ff" + hexname.substr(1, 6) : hexname; return true; } -bool ColorSet::setColor(string const & lyxname, string const & x11hexname, - string const & x11darkhexname) +bool ColorSet::setColor(string const & lyxname, string const & hexname, + string const & darkhexname) { string const lcname = ascii_lowercase(lyxname); if (lyxcolors.find(lcname) == lyxcolors.end()) { @@ -485,7 +554,7 @@ bool ColorSet::setColor(string const & lyxname, string const & x11hexname, addColor(static_cast<ColorCode>(infotab.size()), lcname); } - return setColor(lyxcolors[lcname], x11hexname, x11darkhexname); + return setColor(lyxcolors[lcname], hexname, darkhexname); } @@ -608,5 +677,4 @@ ColorSet lcolor; // An equally evil global system Color instance ColorSet system_lcolor; - } // namespace lyx diff --git a/src/Color.h b/src/Color.h index e85efbfbae..8ba9587831 100644 --- a/src/Color.h +++ b/src/Color.h @@ -60,7 +60,12 @@ public: std::ostream & operator<<(std::ostream & os, Color color); std::string const X11hexname(RGBColor const & col); -RGBColor rgbFromHexName(std::string const & x11hexname); +/// Returns RGBColor from 16- or 32-bit hex name +/// Alpha value is omitted for 32-bit hex name +RGBColor rgbFromHexName(std::string const & hexname); +/// Returns ARGBColor from 16- or 32-bit hex name +/// 16-bit hex name is interpreted as a solid color +ARGBColor argbFromHexName(std::string const & hexname); std::string const outputLaTeXColor(RGBColor const & color); /// Inverse of outputLaTeXColor RGBColor const RGBColorFromLaTeX(std::string const & color); diff --git a/src/ColorSet.h b/src/ColorSet.h index c9dbaa3da2..78e3f2a08e 100644 --- a/src/ColorSet.h +++ b/src/ColorSet.h @@ -52,16 +52,16 @@ public: * \returns true if successful. The optional third argument passes * a color for dark mode. */ - bool setColor(ColorCode col, std::string const & x11hexname, - std::string const & x11darkhexname = std::string()); + bool setColor(ColorCode col, std::string const & hexname, + std::string const & darkhexname = std::string()); /** set the given LyX color to the color defined by the X11 * hex name given \returns true if successful. A new color entry * is created if the color is unknown. The optional third argument passes * a color for dark mode. */ - bool setColor(std::string const & lyxname, std::string const & x11hexname, - std::string const & x11darkhexname = std::string()); + bool setColor(std::string const & lyxname, std::string const & hexname, + std::string const & darkhexname = std::string()); /** set the given LyX color to a latexcolor if not yet defined * \returns true if successful. A new color entry @@ -87,6 +87,16 @@ public: /// Get the X11 hexname of \c color. std::pair<std::string, std::string> const getAllX11HexNames(ColorCode c) const; + /// Get the 32bit hexname of \c color. + std::string const get32bitHexName(ColorCode c, bool const darkmode = false) const; + + /// Get the 32bit hexname of \c color. + std::string const get32bitHexName(std::string const & lyxname, + bool const darkmode = false) const; + + /// Get the 32bit hexname of \c color. + std::pair<std::string, std::string> const getAll32bitHexNames(ColorCode c) const; + /// Get the LaTeX name of \c color. std::string const getLaTeXName(ColorCode c) const; @@ -115,10 +125,10 @@ private: std::string guiname; /// the name used in LaTeX std::string latexname; - /// the name for X11 - std::string x11hexname; - /// matching X11 color for dark mode - std::string x11darkhexname; + /// the 32bit hex name + std::string hex32name; + /// matching 32bit color for dark mode + std::string darkhex32name; /// the name for LyX std::string lyxname; }; diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index b26b948139..6ab8044b64 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -2108,11 +2108,11 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c case RC_SET_COLOR: for (int i = 0; i < Color_ignore; ++i) { ColorCode lc = static_cast<ColorCode>(i); - string const col = lcolor.getAllX11HexNames(lc).first; - string const darkcol = lcolor.getAllX11HexNames(lc).second; + string const col = lcolor.getAll32bitHexNames(lc).first; + string const darkcol = lcolor.getAll32bitHexNames(lc).second; if (ignore_system_lyxrc - || col != system_lcolor.getAllX11HexNames(lc).first - || darkcol != system_lcolor.getAllX11HexNames(lc).second) { + || col != system_lcolor.getAll32bitHexNames(lc).first + || darkcol != system_lcolor.getAll32bitHexNames(lc).second) { os << "\\set_color \"" << lcolor.getLyXName(lc) << "\" \"" << col << "\" \"" diff --git a/src/frontends/qt/ColorCache.cpp b/src/frontends/qt/ColorCache.cpp index ec0676d79b..210f5c68c4 100644 --- a/src/frontends/qt/ColorCache.cpp +++ b/src/frontends/qt/ColorCache.cpp @@ -71,10 +71,10 @@ void ColorCache::init() for (int col = 0; col <= Color_ignore; ++col) { // light-mode color lcolors_[col].first = - QColor(lcolor.getX11HexName(ColorCode(col), false).c_str()); + QColor(lcolor.get32bitHexName(ColorCode(col), false).c_str()); // dark-mode color lcolors_[col].second = - QColor(lcolor.getX11HexName(ColorCode(col), true).c_str()); + QColor(lcolor.get32bitHexName(ColorCode(col), true).c_str()); } initialized_ = true; @@ -134,8 +134,8 @@ ColorPair ColorCache::getAll(Color const & color, bool syscolors) const }; } // used by branches - return {QColor(lcolor.getX11HexName(color.baseColor, false).c_str()), - QColor(lcolor.getX11HexName(color.baseColor, true).c_str())}; + return {QColor(lcolor.get32bitHexName(color.baseColor, false).c_str()), + QColor(lcolor.get32bitHexName(color.baseColor, true).c_str())}; } diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp index f75f914a3c..29aa070489 100644 --- a/src/frontends/qt/GuiPrefs.cpp +++ b/src/frontends/qt/GuiPrefs.cpp @@ -1932,7 +1932,7 @@ void PrefColors::initializeColorsTV() QColor PrefColors::getCurrentColor(ColorCode color_code, bool const is_dark_mode) const { - return lcolor.getX11HexName(color_code, is_dark_mode).c_str(); + return lcolor.get32bitHexName(color_code, is_dark_mode).c_str(); } -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs