Styling objects
This document is about how to style whole objects — Rectangle, Oval, TextFrame, Group — with an ObjectStyle. While paragraph and character styles describe text (see styling text), an object style bundles the look of a frame: its fill, its stroke, its corners and its text formatting.
Table of contents
First steps
An object style is created with the Factory. It is registered at the Content object automatically:
<?php
use BitAndBlack\IdmlCreator\Factory;
$factory = new Factory();
$objectStyle = $factory->createObjectStyle();
If you want to set your own unique identifier — which is recommended here — set up the ObjectStyle like that: $factory->createObjectStyle('UniqueName');
What an object style holds
An object style combines the visual properties of a frame — corners, fill, stroke — and can point to a paragraph style for the text inside:
<?php
use BitAndBlack\IdmlCreator\Content\Enum\CornerOptions;
use BitAndBlack\IdmlCreator\Content\Enum\Styles\EndCap;
use BitAndBlack\IdmlCreator\Content\Enum\Styles\EndJoin;
use BitAndBlack\IdmlCreator\Content\Enum\StrokeType;
use BitAndBlack\IdmlCreator\Factory;
$factory = new Factory();
/** @var \BitAndBlack\IdmlCreator\Content\Color\Color $blue a color, created in the "colors" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Style\ParagraphStyle $paragraphStyle a paragraph style, created in the "styling text" chapter */
$objectStyle = $factory->createObjectStyle('Fancy frame')
->setTopLeftCornerOption(CornerOptions::ROUNDED)
->setTopLeftCornerRadius(5)
->setFillColor($blue)
->setStrokeWeight(2)
->setStrokeType(StrokeType::DASHED)
->setEndCap(EndCap::ROUND_CAP)
->setEndJoin(EndJoin::ROUND_JOIN)
->setAppliedParagraphStyle($paragraphStyle)
;
A style can be based on another style, so it inherits all its properties and only overrides what it defines:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\Style\ObjectStyle $objectStyle the object style created above */
/** @var \BitAndBlack\IdmlCreator\Content\Style\ObjectStyle $baseObjectStyle another object style the current one is based on */
$objectStyle->setBasedOn($baseObjectStyle);
Applying an object style
Every object that can carry a fill and a stroke can use an object style — a rectangle or oval, a text frame or a group:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame a text frame, created in the "text frames" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Style\ObjectStyle $objectStyle the object style created above */
$textFrame->setAppliedObjectStyle($objectStyle);
/** @var \BitAndBlack\IdmlCreator\Content\Rectangle $rectangle a rectangle, created in the "shapes" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Style\ObjectStyle $objectStyle the object style created above */
$rectangle->setAppliedObjectStyle($objectStyle);