Skip to content

Commit

Permalink
Allow theme colors to use the sRGB color profile
Browse files Browse the repository at this point in the history
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 d70ccc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Frameworks/theme/src/theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -224,6 +238,9 @@ void theme_t::shared_styles_t::setup_styles ()
}
}

if(!_color_space)
_color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);

// =======================================
// = Find “global” foreground/background =
// =======================================
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/theme/src/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d70ccc7

Please sign in to comment.