Typography and stories
This document is about text itself: how a story is built from style ranges, how it is oriented, and which special characters exist.
Table of contents
The story
A Story is the text flow of a document. Create one with the Factory — it is registered in the Content object automatically:
<?php
use BitAndBlack\IdmlCreator\Factory;
$factory = new Factory();
$story = $factory->createStory();
If you want to set your own unique identifier, create the Story like that: $factory->createStory('UniqueName');
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) — the styles chapter shows how to create them.
<?php
use BitAndBlack\IdmlCreator\Content\Story\ParagraphStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\CharacterStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\LineBreak;
use BitAndBlack\IdmlCreator\Content\Story\Text;
/** @var \BitAndBlack\IdmlCreator\Content\Style\ParagraphStyle $firstParagraphStyle a paragraph style, created in the "styling text" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Style\CharacterStyle $firstCharacterStyle a character style, created in the "styling text" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Style\ParagraphStyle $secondParagraphStyle the second paragraph style */
/** @var \BitAndBlack\IdmlCreator\Content\Style\CharacterStyle $secondCharacterStyle the second character style */
$story = $factory->createStory()
->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 CharacterStyleRange(
$secondCharacterStyle,
new Text('Another character style now. ')
)
)
)
;
Appending to a TextFrame
Every story needs to be added to a TextFrame:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame a text frame, created in the "text frames" chapter */
/** @var \BitAndBlack\IdmlCreator\Content\Story\Story $story the story created above */
$textFrame->setParentStory($story);
And don't forget to add it also to your Content object.
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 BitAndBlack\IdmlCreator\Content\Enum\Story\Direction;
use BitAndBlack\IdmlCreator\Content\Enum\Story\Orientation;
/** @var \BitAndBlack\IdmlCreator\Content\Story\Story $story the story created above */
$story
->setStoryOrientation(Orientation::VERTICAL)
->setStoryDirection(Direction::RIGHT_TO_LEFT)
;
Special characters
There are a lot of special characters in Adobe InDesign, which aren't difficult to access. IDML-Creator makes use of bitandblack/indesign-characters to access those characters.
Break characters
To get a specific break character, call the class BreakCharacter with its static methods, for example:
<?php
use BitAndBlack\InDesignCharacters\BreakCharacter;
/** @var string $lineBreak the string with the forced line break character */
$lineBreak = BreakCharacter::getForcedLineBreak();
Insert this one into a story.
Spaces
To get a specific space, just call the class Space with its static methods, for example:
<?php
use BitAndBlack\InDesignCharacters\Space;
/** @var string $emSpace the string with the em space character */
$emSpace = Space::getEmSpace();
Insert this one into a story.
Subscript and Superscript
The library brings the two most common text roles as own classes. They hold the text
like a normal Text, but when they are added to a CharacterStyleRange, the range
is rendered with a Position attribute, so InDesign raises or lowers the whole range
relative to the baseline:
<?php
use BitAndBlack\IdmlCreator\Content\Story\CharacterStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\ParagraphStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\Subscript;
$paragraphStyleRange = new ParagraphStyleRange(
null,
new CharacterStyleRange(
null,
new Subscript('H2O')
)
);
This renders the whole H2O as a subscript.
Please note that Position is set on the whole CharacterStyleRange, and that the
last Subscript or Superscript in the range wins. So do not mix normal text or
different roles within one range — use a separate range for each of them. The ranges
are then combined within a ParagraphStyleRange:
<?php
use BitAndBlack\IdmlCreator\Content\Story\CharacterStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\ParagraphStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\Subscript;
use BitAndBlack\IdmlCreator\Content\Story\Text;
$paragraphStyleRange = new ParagraphStyleRange(
null,
new CharacterStyleRange(null, new Text('Water is H')),
new CharacterStyleRange(null, new Subscript('2')),
new CharacterStyleRange(null, new Text('O.')),
);
The ParagraphStyleRange holds one paragraph of the Story and can be added to it
with Story::addContent().
If you need more control, e.g. the OpenType position variants OTSuperscript,
OTSubscript, OTNumerator or OTDenominator, set the position on a CharacterStyle
instead:
<?php
use BitAndBlack\IdmlCreator\Content\Enum\Styles\Position;
/** @var \BitAndBlack\IdmlCreator\Factory $factory the factory, initialized in "The story" */
$superscript = $factory->createCharacterStyle()
->setPosition(Position::OPEN_TYPE_SUPERSCRIPT)
;