Colors
IDML-Creator supports process colors, spot colors, and tint colors.
Table of contents
Process and Spot Colors
Set up a Color object and add it to the Content object like that:
<?php
use IDML\Content\Color\Color;
$color = new Color();
$content->add($color);
If you want to set your own unique identifier — which is recommended here —, set up the Color like that: new Color('UniqueName');
Since IDML-Creator version 4.0
, you can use the Factory to create and register a Color:
$color = $factory->createColor();
A color object can be set to style another element, for example:
<?php
$paragraphStyle->setFillColor($color);
Setting the color value
The color value can be set by using the bitandblack/colors
library. This library is required by default and provides a lot of color spaces. Supported color spaces are:
- CIELab
- CMY
- CMYK
- HEX
- HKS
- HSL
- HSLA
- PANTONE
- RAL
- RGB
- RGBA
- XYZ
So adding a color value works like that:
<?php
use Color\Value\CMYK;
$color->setColorValue(
new CMYK(0, 100, 100, 0)
);
The color library provides also all color values of PANTONE, HKS and RAL, so it's worth having a look at it. More information about the color library is available under bitbucket.org/wirbelwild/colors.
Setting the color model
The color model can be set with the help of the Color Model Enum.
<?php
use IDML\Content\Enum\Color\Model;
/**
* This will create a process color
*/
$color->setModel(Model::PROCESS);
/**
* This will create a spot color
*/
$color->setModel(Model::SPOT);
Setting the color space
The color space can be set with the help of the Color Space Enum.
<?php
use IDML\Content\Enum\Color\Space;
/**
* This will set the space to RGB
*/
$color->setSpace(Space::RGB);
/**
* This will set the space to CMYK
*/
$color->setSpace(Space::CMYK);
/**
* This will set the space to LAB
*/
$color->setSpace(Space::LAB);
Hiding colors from the swatches panel
Per default, every color will be set to visible
what means that it will become visible in the swatches panel. If you want to use a color without adding it to the swatches panel, set it to invisible
:
<?php
$color->setVisible(false);
Tint Colors
Tint Colors are a percentual part of a process or spot color. You need a process or spot color to create a tint color.
Set up a Tint object and add it to the Content object like that:
<?php
use IDML\Content\Color\Color;
use IDML\Content\Color\Tint;
$color = new Color('myColor');
$tintColor = new Tint($color);
$content->add($tintColor);
A tint color object can be set to style another element, for example:
<?php
$paragraphStyle->setFillColor($tintColor);
Tint value
<?php
/**
* This will define a Tint Color with a value of 50%
*/
$tintColor->setTintValue(50);
Gradients
To create a gradient, there are at least two colors needed:
<?php
use Color\Value\CMYK;
use IDML\Content\Color\Color;
use IDML\Content\Color\Tint;
$firstColor = new Color('My first color');
$firstColor->setColorValue(
new CMYK(0, 100, 100, 0)
);
$secondColor = new Color('My second color');
$secondColor->setColorValue(
new CMYK(100, 0, 50, 0)
);
Those colors can be added to a gradient object:
<?php
use IDML\Content\Color\Gradient;
$gradient = new Gradient();
$gradient
->addColor($firstColor)
->addColor($secondColor)
;
For sure, those colors and the gradient need to be added to the content object:
<?php
$content->add($firstColor, $secondColor, $gradient);
The gradient can be used, for example, as a background of a rectangle. The angle of the gradient can be defined there, too.
<?php
use IDML\Content\Rectangle;
$rectangle = new Rectangle();
$rectangle
->setFillColor($gradient)
->setGradientFillAngle(90)
;