Sg2.9
pointText colouring
Recent RSS
pointText colouring
From:  sushi
Date:  24. May 2007, 13:36

Hi,

I've been trying to do the simple task of creating some scriptographer generated text (using PointText), and setting the fill colour, but it doesn't seem to be working!! I am currently using the following code, and am scratching my head as to why it doesn't work.

var theText = new PointText(Point(50,50));
theText.content = "this is a test of coloured text";
theText.characterStyle.fontSize = 14;
var theColour = new RGBColor(Math.random(), Math.random(), Math.random());
theText.style.fill.color = theColour;

...I have also tried using theText.createOutline() before setting the colour, but this does not seem to help either!

Any help would be greatly appreciated.

Re: pointText colouring
From:  sushi
Date:  24. May 2007, 14:43

No I'm not getting any errors. The text is printing out fine, but it is not setting the colours. What is wierd is that if I use...

theText.style.stroke.color = theColour;

...then it set a coloured stroke around the font. However, I am wanting to set the fill specifically which it is not doing!!

Re: pointText colouring
From:  Jürg Lehni
Date:  24. May 2007, 15:37

I will look into this.
You could try this workaround in the meantime:

theText.range.characterStyle.fill.color = theColor;
Re: pointText colouring
From:  sushi
Date:  24. May 2007, 16:11

Thanks for replying... I have tried that method, but it doesn't seem to be working either.

In the script, I have tested the property before and after setting it i.e.

print(theText.range.characterStyle.fill.color);
theText.characterStyle.fill.color = theColour;
print(theText.range.characterStyle.fill.color);

and it does appear to be setting the color property as it should be. However the text appears as black in illustrator.

Re: pointText colouring
Date:  25. May 2007, 10:50

The following works fine for me:

var theText = new PointText(new Point(50,50)); 
theText.content = "this is a test of coloured text"; 
var theColour = new RGBColor(Math.random(), Math.random(), Math.random()); 
theText.characterStyle.fill.color = theColour;
Re: pointText colouring
From:  sushi
Date:  25. May 2007, 13:31

Thanks Jonathan, that works on mine too. I can't believe I didn't try that one before!

...perhaps in future versions this could do with clarifying, as it is not clear at all which property of text you are supposed to set in order to colour it.

Thanks for all the help.

Re: pointText colouring
From:  Jürg Lehni
Date:  25. May 2007, 15:07

Technically it is not possible that theText.characterStyle.fill.color works and theText.range.characterStyle.fill.color does not, as the first ist just a short-cut to the second. Are you shure it did not work?

I will look into why setting theText.style.fill.color does not work.

Re: pointText colouring
From:  sushi
Date:  26. May 2007, 00:15

thanks for all the responses on this...

...all I know is that the example that Jonathan gave me works - you can try it out for yourself. And all the other methods that I have tried have not worked (apart from creating outlines, and looping through the elements of the newly created group and colouring them all).

neither...

theText.style.fill.color

or...

theText.range.characterStyle.fill.color

...worked for me. For both of these methods the colour is setting in the api... but the output is simply black text.

I'll let you decipher why!!

Thanks again.

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
The Allineatorium 15.05.14