Text frames
This document is about how to set up and use TextFrame objects — the containers that hold the text of a document. For the text itself and its special characters, see the typography chapter.
Table of contents
First steps
Set up a TextFrame object and add it to a page like that:
<?php
use BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame;
$textFrame = new TextFrame();
/** @var \BitAndBlack\IdmlCreator\Content\Page $page a page, created in the "pages" chapter */
$page->addElement($textFrame);
If you want to set your own unique identifier, set up the TextFrame like that: new TextFrame('UniqueName');
Size and Position
Add a size and a position like that:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame the text frame created above */
$textFrame
->setSize(100, 200)
->setPosition(10, 10)
;
Add Unit::MILLIMETERS as third parameter of each method if you prefer numbers in millimeters.
Adding text
Text is stored in a Story object. Create one and tell the TextFrame about it:
<?php
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame the text frame created above */
/** @var \BitAndBlack\IdmlCreator\Content\Story\Story $story a story, created in the "typography" chapter */
$textFrame->setParentStory($story);
For sure, the story needs to be added to the content object as well — a story you create with the Factory is registered there automatically.
Linking TextFrames
If you want to link multiple TextFrames to enable text content to float from one TextFrame into another, you need to do two things:
- Tell every
TextFrameabout the text content by calling$textFrame->setParentStory($story). - Tell every
TextFrameabout the nextTextFrame. This is important for letting InDesign know, in which TextFrames the content will float.$textFrameA->setNextTextFrame($textFrameB).
Here's a full example:
<?php
use BitAndBlack\IdmlCreator\Content\Story\CharacterStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\LineBreak;
use BitAndBlack\IdmlCreator\Content\Story\ParagraphStyleRange;
use BitAndBlack\IdmlCreator\Content\Story\Text;
use BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame;
use BitAndBlack\IdmlCreator\Factory;
$factory = new Factory();
$story = $factory->createStory()
->addContent(
new ParagraphStyleRange(
null,
new CharacterStyleRange(
null,
new Text('Hello World!'),
new LineBreak()
)
)
)
;
$textFrameA = new TextFrame();
$textFrameA->setParentStory($story);
$textFrameB = new TextFrame();
$textFrameB->setParentStory($story);
$textFrameA->setNextTextFrame($textFrameB);
/**
* For sure, we need to add the textframes to a page —
* the story was registered by the factory automatically
*/
/** @var \BitAndBlack\IdmlCreator\Content\Page $page a page, created in the "pages" chapter */
$page
->addElement(
$textFrameA,
$textFrameB
)
;
Columns
To have the text arranged in columns, you can either use the shortcut of the TextFrame directly:
<?php
use BitAndBlack\IdmlCreator\Content\Enum\Unit;
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame the text frame created above */
$textFrame->setColumns(1, 10, Unit::MILLIMETERS);
The second parameter is the bridge between the columns. All the deeper layout options are covered by the TextFramePreference object below.
TextFrame preferences
The TextFramePreference holds all layout options of a frame: vertical justification, insets, balancing of columns, auto sizing and the column rules. Create one, configure it and assign it:
<?php
use BitAndBlack\IdmlCreator\Content\Enum\TextFramePreference\AutoSizingType;
use BitAndBlack\IdmlCreator\Content\Enum\VerticalJustification;
use BitAndBlack\IdmlCreator\Content\TextFrame\TextFramePreference;
$textFramePreference = new TextFramePreference();
$textFramePreference
->setVerticalJustification(VerticalJustification::CENTER_ALIGN)
->setUseMinimumHeightForAutoSizing(true)
->setMinimumHeightForAutoSizing(30)
->setAutoSizingType(AutoSizingType::WIDTH_AND_HEIGHT)
;
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame the text frame created above */
$textFrame->setTextFramePreference($textFramePreference);
For example, this lets a frame grow automatically with its content. The inset spacing — the space between the frame and the text — can be set directly on the TextFrame as well:
<?php
use BitAndBlack\IdmlCreator\Content\Enum\Unit;
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame the text frame created above */
$textFrame->setInsetSpacing(5, 10, 5, 10, Unit::MILLIMETERS);
Text wrap
To let other objects' text flow around this frame, add a TextWrapPreference:
<?php
use BitAndBlack\IdmlCreator\Content\Enum\TextWrapMode;
use BitAndBlack\IdmlCreator\Content\Enum\TextWrapSide;
use BitAndBlack\IdmlCreator\Content\SplineItem\TextWrapPreference;
$textWrapPreference = new TextWrapPreference();
$textWrapPreference
->setTextWrapMode(TextWrapMode::BOUNDING_BOX)
->setTextWrapSide(TextWrapSide::BOTH_SIDES)
->setTopOffset(5, Unit::MILLIMETERS)
->setBottomOffset(5, Unit::MILLIMETERS)
;
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame the text frame created above */
$textFrame->setTextWrapPreference($textWrapPreference);
The offsets define how close the surrounding text may come to the frame.
Anchored objects
Objects that are linked to a specific position in the text — like a figure in a text flow — are anchored objects. The position is controlled by an AnchoredObjectSetting:
<?php
use BitAndBlack\IdmlCreator\Content\Enum\AnchoredObjectSetting\AnchorPosition;
use BitAndBlack\IdmlCreator\Content\Enum\AnchoredObjectSetting\HorizontalAlignment;
use BitAndBlack\IdmlCreator\Content\Enum\Unit;
use BitAndBlack\IdmlCreator\Content\SplineItem\AnchoredObjectSetting;
$anchoredObjectSetting = new AnchoredObjectSetting();
$anchoredObjectSetting
->setAnchoredPosition(AnchorPosition::INLINE_POSITION)
->setHorizontalAlignment(HorizontalAlignment::CENTER_ALIGN)
->setAnchorXoffset(0, Unit::MILLIMETERS)
;
/** @var \BitAndBlack\IdmlCreator\Content\TextFrame\TextFrame $textFrame the text frame created above */
$textFrame->setAnchoredObjectSetting($anchoredObjectSetting);
Objects that can be anchored are all objects of the shapes chapter. The enums that are used here — like AnchorPosition — mirror the IDML specification, find all values in the enums chapter.