matlab-schemer
matlab-schemer copied to clipboard
Import hex values
I expect a reasonable number of people will want to create a new color scheme based on an existing one implemented for a different editor.
At the moment people can port the color scheme across by manually choosing how to map the between the entities in the two formats and converting any hexadecimal colours with color2javaRGBint. However, having to convert all the colours into RGB integer format one at a time is tedious. Also, it becomes hard to keep track of what colour the value encodes.
It would make it much easier for users to simply copy over the hexadecimal values into the template prf file. Not only would such a thing be much faster, it will also make porting a colour scheme more accessible.
This will make the format incompatible with the actual MATLAB .prf format (which does not have any hexadecimal values), but this can be fixed by importing the color scheme and exporting it again with schemer_export. After the hex values are successfully imported, the colour values will be exported into RGB int format instead.
I'm not sure if this is just an old issue, but in case people are not aware, this actually already works, as long as the hex code is prefixed with "0x". This works because str2double in Matlab (at least in R2022b which I'm using at the moment) can take hex literals when prefixed like this:
>> str2double('0x002b36')
ans =
11062
Also note that the java.awt.Color constructor that takes a single int (https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html#Color-int-) does not use the first byte for alpha, so as far as I understand, it is not necessary to add FF in front of all color codes.
As a proof of concept, see this copy of solarized-dark that uses all hex color codes: https://github.com/auxym/matlab-schemer/blob/hex/schemes/solarized-dark-hex.prf. It was converted from the original with the quick python script I wrote: https://github.com/auxym/matlab-schemer/blob/hex/scripts/convert_prf_to_hex.py
I retract the above comment. str2double's support of hexadecimal numbers is undocumented and buggy. Notably, it fails when the hex string ends in the letter e, presumably because e is also used in scientific notation.
>> str2double("0x81c8be")
ans = NaN