Font
This document is about how to set up and use Fonts.
Table of contents
First steps
Every font consists of a font family and a font style. Those are two different objects in IDML-Creator, and those two can be handled differently in InDesign. Set them up like that:
<?php
use IDML\Content\Font\FontFamily;
use IDML\Content\Font\FontStyle;
$helveticaNeue = new FontFamily('Helvetica Neue');
$helveticaNeueRegular = new FontStyle($helveticaNeue, 'Helvetica Neue Regular');
$helveticaNeueItalic = new FontStyle($helveticaNeue, 'Helvetica Neue Italic');
$content->add(
$helveticaNeueRegular,
$helveticaNeueItalic
);
Since IDML-Creator version 4.0
, you can use the Factory to create and register a FontStyle:
$helveticaNeueRegular = $factory->createFontStyle($helveticaNeue, 'Helvetica Neue Regular');
$helveticaNeueItalic = $factory->createFontStyle($helveticaNeue, 'Helvetica Neue Italic');
Family name and style name are required attributes here.
Using fonts in styles
The font family and the font style can be used in styles like that:
<?php
$paragraphStyle
->setFontFamily($helveticaNeue)
->setFontStyle($helveticaNeueRegular)
;
$characterStyle
->setFontStyle($helveticaNeueItalic)
;
It's not important here if a font is available on a system!
NOTICE: If you want to provide fonts along with your idml
files, create a folder Document fonts
in the same directory. When opening an idml
(or indd
) file, InDesign will look for this folder and activate all fonts inside.