diff --git a/src/core/text/TextStyle.js b/src/core/text/TextStyle.js index 779de13..faeb91c 100644 --- a/src/core/text/TextStyle.js +++ b/src/core/text/TextStyle.js @@ -435,22 +435,43 @@ * @param {number|number[]} color * @return {string} The color as a string. */ -function getColor(color) +function getSingleColor(color) { if (typeof color === 'number') { return hex2string(color); } - else if (Array.isArray(color)) + else if ( typeof color === 'string' ) { - for (let i = 0; i < color.length; ++i) + if ( color.indexOf('0x') === 0 ) { - if (typeof color[i] === 'number') - { - color[i] = hex2string(color[i]); - } + color = color.replace('0x', '#'); } } return color; } + +/** + * Utility function to convert hexadecimal colors to strings, and simply return the color if it's a string. + * This version can also convert array of colors + * + * @param {number|number[]} color + * @return {string} The color as a string. + */ +function getColor(color) +{ + if (!Array.isArray(color)) + { + return getSingleColor(color); + } + else + { + for (let i = 0; i < color.length; ++i) + { + color[i] = getSingleColor(color[i]); + } + + return color; + } +}