Story

This document is about how to set up and use a Story object.

First steps

Create a Story object. Add the Story to the Content object then:

<?php 

use IDML\Content\Story\Story;

$myStory = new Story();

$content->addStory($myStory);

If you want to set your own unique identifier, set up the Story like that: new Story('UniqueName');

Adding content

Every text content needs to be wrapped in a Content element, then in a CharacterStyleRange element and then in a ParagraphStyleRange element. This is why we need multiple objects here. The third parameter with a line break object is optional.

<?php

use IDML\Content\Story\ParagraphStyleRange;
use IDML\Content\Story\CharacterStyleRange;
use IDML\Content\Story\Content;
use IDML\Content\Story\LineBreak;

$myStory->setContent(
    new ParagraphStyleRange(
        $myParagraphStyle,
        new CharacterStyleRange(
            $myCharacterStyle,
            new Content('Hello World! '),
            new LineBreak()
        ) 
    ),
    new ParagraphStyleRange(
        $myParagraphStyle,
        new CharacterStyleRange(
            $myCharacterStyle,
            new Content('New line, new styles. ')
        ) 
    )
);

$content->addStory($myStory);

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;

$myStory
    ->setStoryOrientation(Orientation::VERTICAL())
    ->setStoryDirection(Direction::RIGHT_TO_LEFT())
;

Appending to a TextFrame

To make a Story visible it needs to be added to a TextFrame.

<?php

$textFrame->setParentStory($myStory);