Skip to content

Commit d70ccc7

Browse files
committed
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.
1 parent 08534e7 commit d70ccc7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Frameworks/theme/src/theme.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,40 @@ static CGColorRef OakColorCreateCopySoften (CGColorPtr cgColor, CGFloat factor)
185185

186186
theme_t::shared_styles_t::shared_styles_t (bundles::item_ptr const& themeItem): _item(themeItem), _callback(*this)
187187
{
188-
_color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
189188
setup_styles();
190189
bundles::add_callback(&_callback);
191190
}
192191

193192
theme_t::shared_styles_t::~shared_styles_t ()
194193
{
195194
bundles::remove_callback(&_callback);
196-
CGColorSpaceRelease(_color_space);
195+
if(_color_space)
196+
CGColorSpaceRelease(_color_space);
197197
}
198198

199199
void theme_t::shared_styles_t::setup_styles ()
200200
{
201201
_styles.clear();
202202

203+
if(_color_space)
204+
{
205+
CGColorSpaceRelease(_color_space);
206+
_color_space = NULL;
207+
}
208+
203209
if(_item)
204210
{
205211
if(bundles::item_ptr newItem = bundles::lookup(_item->uuid()))
206212
_item = newItem;
207213

214+
std::string colorSpaceName;
215+
if(plist::get_key_path(_item->plist(), "colorSpaceName", colorSpaceName) && colorSpaceName == "sRGB")
216+
{
217+
if(_color_space)
218+
CGColorSpaceRelease(_color_space);
219+
_color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
220+
}
221+
208222
plist::array_t items;
209223
if(plist::get_key_path(_item->plist(), "settings", items))
210224
{
@@ -224,6 +238,9 @@ void theme_t::shared_styles_t::setup_styles ()
224238
}
225239
}
226240

241+
if(!_color_space)
242+
_color_space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
243+
227244
// =======================================
228245
// = Find “global” foreground/background =
229246
// =======================================

Frameworks/theme/src/theme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct PUBLIC theme_t
121121
static decomposed_style_t parse_styles (plist::dictionary_t const& plist);
122122

123123
bundles::item_ptr _item;
124-
CGColorSpaceRef _color_space;
124+
CGColorSpaceRef _color_space = NULL;
125125
std::vector<decomposed_style_t> _styles;
126126
gutter_styles_t _gutter_styles;
127127
CGColorPtr _foreground;

0 commit comments

Comments
 (0)