Stylesheet Development with PTC ALD > Adding PTC ALD Code to Stylesheet Source > Samples > Colors > Set Text, Line, and Background Color > Text Color — Reference a Color Definition Object
Text Color — Reference a Color Definition Object
The sample listed here describes how to set text color using a user-defined custom color described in an fColor object. The benefit of describing the color in this way, rather than making a direct property setting as in previous examples, is that the color can be reused in other areas of the template.
Refer to the emphasis everywhere context in the Arbortext-path/samples/ALD/Colour/SettingColours.xml sample file. The context includes a set of conditions based on the value of the role attribute in the associated stylesheet. Each condition references a different property set.
For example, the condition ELSE IF attribute “role” = “CMYK text colour 4” of the emphasis everywhere context references the CMYK text colour 3 property set. This property set sets a text color in CMYK format, where each of the four values is specified as a number in the range 0-255. Each of the values are configured separately. The relevant code in that property set is given below.
var myColour = new fColor("{0,0,0,0}");
myColour.cyan = 120;
myColour.magenta = 20;
myColour.yellow = 180; = 30;
Here you have created a new color based on the fColor object, and set up the variable myColour to hold the color description. The("{0,0,0,0}") declaration for the object, issued via the fColor() method, specifies that the color will be described in four values, i.e. CMYK format.
You specify the individual components of the color by declaring them as cyan, magenta, yellow, and black properties of the fColor object and passing their values to the myColour variable.
Now you need to add an instruction that will add the color to the styling assigned to the inline text.
style.color = myColour;
Here you have set the color property for the inline text to the value described in the myColour variable, i.e. the custom color.
You may set colors in this way in both CMYK and RGB formats. Refer to the ELSE IF attribute “role” = “RGB text colour 4” condition for the emphasis everywhere context, and its associated property set in the stylesheet, for an example of describing a custom color in RGB format.