Colors

XSL-FO defines various attributes for managing color. By default a block is displayed with the foreground color (that is the text) being black and the background color being white. Colors are most commonly expressed using the RGB color scheme, where there are three parts to a color: red, green and blue.
Ibex also supports the CMYK color scheme commonly used in the printing industry.

Text color

The color of text is specified using the color attribute. Figure 12-1 shows a simple example of some FO to make text blue.

<fo:block color="blue">
		To be, or not to be: that is the question:
		</fo:block>

Figure 12-1: FO for blue text

Background color

The background color of any element is defined using the background-color attribute. Figure 12-2 shows FO for a block with a gray background.

<fo:block background-color="gray">
	To be, or not to be: that is the question:
</fo:block>

Figure 12-2: FO for gray background

Available colors

The value used for the color and background-color attributes can be a predefined color such as "red", an RGB color defined using a hex value such as "#eeffdd" or a CMYK color.

Predefined colors

XSL-FO uses the list of colors defined for HTML 4.0, which contains these values:

Name Color
aqua Ibex
black Ibex
blue Ibex
fuchsia Ibex
gray Ibex
green Ibex
lime Ibex
maroon Ibex
navy Ibex
olive Ibex
purple Ibex
red Ibex
silver Ibex
teal Ibex
white Ibex
yellow Ibex

Hexadecimal RGB colors

A color can be defined as a string of six digits preceded by a "#" character. The first two digits define the red component of the color, in a range from 0 to 255. The second two digits define the green component and the last two digits define the blue component. This is the same scheme for defining colors as is used in HTML.

CMYK colors

CMYK colors are four-part colors using values for cyan, magenta, yellow and black respectively. The CMYK system is subtractive, meaning that higher values mean less color, unlike RGB where higher values mean more color. CMYK colors are used in the printing industry to define a color which will appear the same across all media. Typically a color defined using RGB will not appear exactly the same on the screen and on a printed page, or even on two different computer screens.

CMYK colors are used to ensure that colors are the same on screen and on the printed page. PDF files are usually created with single color scheme. You would not usually mix CMYK and RGB colors in one document. Note that when creating a CMYK PDF file any images included in the document should be in CMYK format. A CMYK color is defined using the rgb-icc() function. This takes eight parameters. The first three define the red, green and blue components of a fallback RGB color, the fourth defines the color profile name, and the last four define the four parts of the CMYK color. The color profile must have been declared in the fo:declarations formatting object using a fo:color-profile element.

Figure 12-3 shows an example of the rgb-icc() function.

<fo:block color="rgb-icc( 0, 0, 0, cmyk, 0.7,0.3,0.3,0.4 )">
		in cmyk .5,.5,.5,0
</fo:block>

Figure 12-3: The rgb-icc function

In Figure 12-3 the three components of the fallback RGB color are zero. This is normal because we are creating a CMYK PDF file and will not be using any fallback RGB colors. The color profile name is "cmyk". Ibex requires that the color profile name be "cmyk" when creating a CMYK color. A complete document using the CMYK color space is shown in Figure 12-4. This shows how to use the fo:declarations and fo:color-profile elements to define a color profile.

<fo:?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns="http://www.w3.org/1999/XSL/Format">
	<fo:layout-master-set>
		<fo:simple-page-master master-name="page">
			<fo:region-body margin="1in" region-name="body"/>
		</fo:simple-page-master>
	</fo:layout-master-set>
	
	<fo:declarations>
	    <fo:color-profile src="src" color-profile-name="cmyk"/>
	</fo:declarations>
		
	<fo:page-sequence master-reference="page">
		<fo:flow flow-name="body">
			<fo:block color="rgb-icc( 0, 0, 0, cmyk, 0.7,0.3,0.3,0.4 )">
			in cmyk .5,.5,.5,0
			</fo:block>
		</fo:flow>
	</fo:page-sequence>
</fo:root>

Figure 12-4: FO for a CMYK PDF file

PDF/X color profiles

Ibex can create PDF files which conform to the PDF/X standard. These files can include embedded color profiles, used to define a common color scheme across different devices. Color profiles are loaded from files on disk and included in the PDF file. Some color profiles are very large (i.e. > 500k) and can result in large PDF files. Loading a color profile from a file on disk is an Ibex extension. The name of the color profile file is specified using the color-profile-file-name attribute of the ibex:pdfx element, as shown in Figure 12-5 below.

<fo:?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns="http://www.w3.org/1999/XSL/Format" xmlns:ibex="http://www.xmlpdf.com/2003/ibex/Format">
	<fo:layout-master-set>
		<fo:simple-page-master master-name="page" page-width="20cm">
			<fo:region-body region-name="body" margin="3cm" reference-orientation='0'/>
		</fo:simple-page-master>
	</fo:layout-master-set>
										
	<fo:ibex:pdfx color-profile-file-name="colorprofiles\USWebCoatedSWOP.icc" output-condition="TR001 SWOP/CGATS"/>
										
	<fo:page-sequence master-reference="page">
		<fo:flow flow-name="body">
			<fo:block font="10pt arial">
			hello world
			</fo:block>
		</fo:flow>
	</fo:page-sequence>
</fo:root>

Figure 12-5: FO for a PDF/X showing the loading of a color profile