Multicolor text recolor bug

Problem

Found bug replacing text color if TextFrame contained many colors. The case is specific. Let’s create a text object without changing its dimensions. We save the old color of some character into a variable, assign the new color to the text, and then paint the text in the color of the saved character.

var oldColor = selection[0].textRange.characters[0].characterAttributes.fillColor;
var newColor = new RGBColor();
newColor.red = 255;
selection[0].textRange.characterAttributes.fillColor = newColor;
redraw();
var msg = 'First character color: ' + oldColor.red + ' ';
msg += newColor.blue + ' ' + newColor.green + '\nTemp color: ';
msg += newColor.red + ' ' + newColor.blue + ' ' + newColor.green;
alert(msg);
selection[0].textRange.characterAttributes.fillColor = oldColor;
redraw();
The text did not turn black

Solution

Experimentally, I found that the problem is similar to the Paragraph panel script bugs in the note “Forced change of paragraph properties” and the solution method is the same. If you change the text frame scale, the problem is solved. If the text in the document has already been scaled manually before running the script, there is no bug. There is no logical explanation for this Illustrator problem.

After resizing the text, it is filled with black
var oldColor = selection[0].textRange.characters[0].characterAttributes.fillColor;
var newColor = new RGBColor();
newColor.red = 255;
selection[0].textRange.characterAttributes.fillColor = newColor;
redraw();
selection[0].resize(200, 200); // fix recolor bug
selection[0].textRange.characterAttributes.fillColor = oldColor;
selection[0].resize(50, 50); // fix recolor bug
redraw();

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
AiScripts

AiScripts

Sergey Osokin. I’m a illustrator & Script Developer (Ai, Ps). Writing about bugs and tricks.