diff --git a/README.md b/README.md index ec09f3f..1bace07 100644 --- a/README.md +++ b/README.md @@ -113,21 +113,18 @@ refer to the annotated screenshot, ![Annotated screenshot](develop/annotated_default.png) -The values for each colour in the .prf stylesheet must be recorded as single -RGB integers, with each colour channel in 8-bit (0-255), R as big endian, -and a opaque alpha channel. Because the format for RGB colours in Java allows -for an alpha channel and the integers are signed, all the colours you record -in your .prf file should be negative, spanning the range -`-16777216` (black, `[0,0,0]`) to `-1` (white, `[255,255,255]`). - -The text file for your pre-existing theme will typically specify its colous in -hexadecimal format, or in terms of R, G, B values. You will need -to convert the colours from this format into the format which MATLAB preference -files use to specify colours instead. -The Schemer package comes with a utility function -[develop/color2javaRGBint.m](develop/color2javaRGBint.m) -to help make this easier. See the `color2javaRGBint` documentation for more -details. +As of MATLAB Schemer v1.5.0, the values for each colour in the .prf +stylesheet may be recorded as a standard hexadecimal RGB color in the +format `C0xRRGGBB` where `RR`, `GG`, `BB` are hexadecimal values in the +range `00` to `FF`. For example, `C0xFFFFFF` for white, `C0x000000` for +black or `C0x00FF00` for green. + +Alternatively, the "legacy" colour format used in previous versions of +MATLAB Schemer is still supported. This format consists of expressing the +6-digit RGB colour code as a 32-bit signed integer literal, optionally +including an unused dalpha channel of `FF` in the highest byte position, +resulting in a negative integer value. For example, the hex color code +`C0x002b36` would be expressed as `C-16766154` in the legacy format. ### Setting colours for additional languages diff --git a/schemer_import.m b/schemer_import.m index 9749ee6..de2b0c0 100644 --- a/schemer_import.m +++ b/schemer_import.m @@ -112,7 +112,7 @@ function varargout = schemer_import(fname, inc_bools) % ------------------------ Parameters ------------------------------------- -SCHEMER_VERSION = 'v1.4.0'; +SCHEMER_VERSION = 'v1.5.0'; % ------------------------ Input handling --------------------------------- % ------------------------ Default inputs --------------------------------- @@ -572,7 +572,11 @@ elseif ismember(n.name, names_color(:, 1)) % Deal with colour type (final type to consider) - if ~strcmpi('C', n.pref(1)) + if strcmpi(n.pref(1:3), 'C0x') + rgb = hex2dec(n.pref(2:end)); + elseif strcmpi('C', n.pref(1)) + rgb = str2double(n.pref(2:end)); + else warning('Bad color for %s: %s', n.name, n.pref); continue; end @@ -581,7 +585,7 @@ previousVal = ... com.mathworks.services.Prefs.getColorPref(names_color{idx, 1}); % Set the colour to the target value - rgb = str2double(n.pref(2:end)); + jc = java.awt.Color(rgb); com.mathworks.services.Prefs.setColorPref(n.name, jc); com.mathworks.services.ColorPrefs.notifyColorListeners(n.name);