Permalink
Browse files

Allow theme colors to use the sRGB color profile

This is enabled by adding the following to your theme:

    colorSpaceName = sRGB;

The default color space used for themes is “Apple Generic RGB” which is a bad choice for interoperability with other software (e.g. exporting a theme to CSS, creating theme colors in Photoshop, and similar).

Related to issue #768.
  • Loading branch information...
sorbits committed Feb 18, 2013
1 parent 08534e7 commit d70ccc7cdf4750eed00672cff77ddf23f4e96251
Showing with 20 additions and 3 deletions.
  1. +19 −2 Frameworks/theme/src/theme.cc
  2. +1 −1 Frameworks/theme/src/theme.h
@@ -185,26 +185,40 @@ static CGColorRef OakColorCreateCopySoften (CGColorPtr cgColor, CGFloat factor)
theme_t::shared_styles_t::shared_styles_t (bundles::item_ptr const& themeItem): _item(themeItem), _callback(*this)
{
- _color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
setup_styles();
bundles::add_callback(&_callback);
}
theme_t::shared_styles_t::~shared_styles_t ()
{
bundles::remove_callback(&_callback);
- CGColorSpaceRelease(_color_space);
+ if(_color_space)
+ CGColorSpaceRelease(_color_space);
}
void theme_t::shared_styles_t::setup_styles ()
{
_styles.clear();
+ if(_color_space)
+ {
+ CGColorSpaceRelease(_color_space);
+ _color_space = NULL;
+ }
+
if(_item)
{
if(bundles::item_ptr newItem = bundles::lookup(_item->uuid()))
_item = newItem;
+ std::string colorSpaceName;
+ if(plist::get_key_path(_item->plist(), "colorSpaceName", colorSpaceName) && colorSpaceName == "sRGB")
+ {
+ if(_color_space)
+ CGColorSpaceRelease(_color_space);
+ _color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+ }
+
plist::array_t items;
if(plist::get_key_path(_item->plist(), "settings", items))
{
@@ -224,6 +238,9 @@ void theme_t::shared_styles_t::setup_styles ()
}
}
+ if(!_color_space)
+ _color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+
// =======================================
// = Find “global” foreground/background =
// =======================================
@@ -121,7 +121,7 @@ struct PUBLIC theme_t
static decomposed_style_t parse_styles (plist::dictionary_t const& plist);
bundles::item_ptr _item;
- CGColorSpaceRef _color_space;
+ CGColorSpaceRef _color_space = NULL;
std::vector<decomposed_style_t> _styles;
gutter_styles_t _gutter_styles;
CGColorPtr _foreground;

0 comments on commit d70ccc7

Please sign in to comment.