Story
This document is about how to set up and use a Story object.
Table of contents
First steps
Create a Story object. Add the Story to the Content object then:
<?php
use IDML\Content\Story\Story;
$story = new Story();
$content->add($story);
If you want to set your own unique identifier, set up the Story like that: new Story('UniqueName');
Since IDML-Creator version 4.0
, you can use the Factory to create and register the Story:
$story = $factory->createStory();
Adding content
Every text content is written inside a CharacterStyleRange
element and that one lays inside a ParagraphStyleRange
element. This is why we need multiple objects here. The first parameter is always a style object (or null).
<?php
use IDML\Content\Story\ParagraphStyleRange;
use IDML\Content\Story\CharacterStyleRange;
use IDML\Content\SpecialChars\Tabulator;
use IDML\Content\Story\Story;
use IDML\Content\Story\Text;
use IDML\Content\Story\LineBreak;
$story = new Story();
$story->addContent(
new ParagraphStyleRange(
$firstParagraphStyle,
new CharacterStyleRange(
$firstCharacterStyle,
new Text('Hello World! '),
new LineBreak()
)
),
new ParagraphStyleRange(
$secondParagraphStyle,
new CharacterStyleRange(
$firstCharacterStyle,
new Text('New line, new paragraph style. '),
new Tabulator(),
new Text('Wow, we had a tabulator here! ')
),
new CharacterStyleRange(
$secondCharacterStyle,
new Text('Another character style now. ')
)
)
);
$content->add($story);
Orientation and Direction
Per default, orientation and direction are defined from left to right and from top to bottom. If you need to set the story orientation and the direction manually, you can reach this with the help of enums:
<?php
use IDML\Content\Enum\Story\Orientation;
use IDML\Content\Enum\Story\Direction;
$story
->setStoryOrientation(Orientation::VERTICAL)
->setStoryDirection(Direction::RIGHT_TO_LEFT)
;
Appending to a TextFrame
Every Story needs to be added to a TextFrame.
<?php
$textFrame->setParentStory($story);
And don't forget to add it also to your Content object.