Colors
This document is about how to give a document color: process colors, spot colors, tint colors, gradients, mixed inks and the special none color. Whatever you set up here can be used as a fill color, stroke color or text color everywhere else in the documentation.
Table of contents
Process and Spot Colors
Set up a Color object with the Factory — it is registered in the Content object automatically:
<?php
use BitAndBlack\IdmlCreator\Factory;
$factory = new Factory();
$color = $factory->createColor();
If you want to set your own unique identifier — which is recommended here —, create the Color like that: $factory->createColor('UniqueName');
A color object can be set to style another element, for example:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\Style\ParagraphStyle $paragraphStyle a paragraph style, created in the "styling text" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $color the color created above */
$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;
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $color the color created above */
$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 BitAndBlack\IdmlCreator\Content\Enum\Color\Model;
/**
* @var \BitAndBlack\IdmlCreator\Content\Color\Color $color the color created above
* 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 BitAndBlack\IdmlCreator\Content\Enum\Color\Space;
/**
* @var \BitAndBlack\IdmlCreator\Content\Color\Color $color the color created above
* 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
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $color the color created above */
$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.
Create a Tint with the Factory — it is registered in the Content object automatically:
<?php
/** @var \BitAndBlack\IdmlCreator\Factory $factory the factory, initialized in the "Process and Spot Colors" section */
$color = $factory->createColor('myColor');
$tintColor = $factory->createTint($color);
A tint color object can be set to style another element, for example:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\Style\ParagraphStyle $paragraphStyle a paragraph style, created in the "styling text" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Color\Tint $tintColor the tint color created above */
$paragraphStyle->setFillColor($tintColor);
Tint value
<?php
/**
* @var \BitAndBlack\IdmlCreator\Content\Color\Tint $tintColor the tint color created above
* 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;
/** @var \BitAndBlack\IdmlCreator\Factory $factory the factory, initialized in the "Process and Spot Colors" section */
$firstColor = $factory->createColor('My first color')
->setColorValue(
new CMYK(0, 100, 100, 0)
)
;
$secondColor = $factory->createColor('My second color')
->setColorValue(
new CMYK(100, 0, 50, 0)
)
;
Those colors can be added to a gradient object:
<?php
use BitAndBlack\IdmlCreator\Content\Color\Gradient;
$gradient = new Gradient();
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $firstColor the first color created above */
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $secondColor the second color created above */
$gradient
->addColor($firstColor)
->addColor($secondColor)
;
For sure, the gradient needs to be added to the content object — the colors were registered by the factory already:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\Color\Gradient $gradient the gradient created above */
$factory->getContent()
->add($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 BitAndBlack\IdmlCreator\Content\Rectangle;
$rectangle = new Rectangle();
/** @var \BitAndBlack\IdmlCreator\Content\Color\Gradient $gradient the gradient created above */
$rectangle
->setFillColor($gradient)
->setGradientFillAngle(90)
;
Mixed inks
A mixed ink — e.g. a PANTONE 432 C 60% + PANTONE 872 C 40% — is built from one or more spot colors. Each spot color contributes a percentage:
<?php
/** @var \BitAndBlack\IdmlCreator\Factory $factory the factory, initialized in the "Process and Spot Colors" section */
$mixedInk = $factory->createMixedInk();
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $spotColor1 a spot color, set up with `Model::SPOT` as shown above */
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $spotColor2 a second spot color */
$mixedInk
->addColor($spotColor1, 60)
->addColor($spotColor2, 40)
;
The spot color must have an ink defined, which is the case for spot colors set up with Model::SPOT. The MixedInk object is registered in the content object like any other color — the factory did that when it was created.
A mixed ink can replace a regular color everywhere — for example in a setFillColor() call.
The none color
To explicitly remove a color from an element — for example a fill — use the none color:
<?php
use BitAndBlack\IdmlCreator\Content\Color\NoneColor;
$noneColor = new NoneColor();
It resolves to the None swatch in the IDML file and can be used everywhere a color is expected.