OpenType layout features were introduced in mPDF ≥ 6.0
Many TrueType fonts contain OpenType Layout (OTL) tables. These Advanced Typographic tables contain additionalinformation that extend the capabilities of the fonts to support high-quality international typography:
mPDF 6 introduces the power and flexibility of the OpenType Layout font model into PDF. mPDF supports GSUB, GPOSand GDEF tables for now. mPDF doesnot support BASE and JSTF at present.
Other mPDF features to enhance complex scripts:
:lang selectorNote: There are other smart-font technologies around to deal with complex scripts, namely Graphite fonts (SIL International) and Apple Advanced Typography (AAT by Apple/Mac). mPDF 6 does not support these.
Support for OTL fonts allows the faithful display of almost all complex scripts:
OTL features allow:
A full list of feature tags is athttp://www.microsoft.com/typography/otspec/featurelist.htm
In mPDF, the following features are on by default:
locl ccmp pref blwf abvf pstf pres abvs blws psts haln rlig calt liga clig mset (all scripts)isol fina fin2 fin3 medi med2 init nukt akhn rphf rkrf half vatu cjct cfar (for appropriate scripts e.g. Indic, Arabic)abvm blwm mark mkmk curs cpsp dist requ kernNBrequ is not listed in the Microsoft registry of Feature tags; however it is found in the Arial Unicode MS font(it repositions the baseline for punctuation in Kannada script).
kern is used in some fonts to reposition marks etc. and is essential for correct display, so in mPDFkern is on bydefault when any non-Latin script is used.
Complex scripts require a “shaping engine” to re-order glyphs and apply the OTL features by syllable. MS Word andWordpad run on the Windows platform use “Uniscribe”, whereas some browsers such as FireFox and OpenOffice usePango/HarfBuzz. The different shaping engines (and indeed different versions of them) can produce different results.
Different applications have different defaults (on/off) for some of the features e.g. kerning.
When testing mPDF, if text does not appear as you expect, ensure that the font is installed on your computer, andview the HTML in a browser. Also try copying/pasting the text into Wordpad/Word/OpenOffice and ensure that the correctfont has been applied.
Note that Wordpad sometimes substitutes a different font if it does not like the one you have chosen, and does noteven indicate that the substitution has occurred.
Seehttp://www.w3.org/TR/css3-fonts/#font-rend-propsfor information about CSS3 and font-features.
The following are supported in mPDF:
font-variant-positionfont-variant-capsfont-variant-ligaturesfont-variant-numericfont-variant-alternates - Only [normal |historical-forms] supported (i.e. most are NOT supported) e.g.stylistic, styleset, character-variant, swash, ornaments, annotation (usefont-feature-settings for these)font-variant - as above, and except for:east-asian-variant-values, east-asian-width-values, rubyfont-language-overridefont-feature-settingsfont-variant-east-asian is NOT supported
NB@font-face is NOT supported
NB@font-feature-values is NOT supported
Note:font-variant specifies a single property in CSS2, whereas in CSS3 it has become a shorthandfor all the otherfont-variant-* properties.font-variant: small-caps was the form supported in CSS2, and willwork in mPDF.
See notes later about font kerning.
/* use small-cap alternate glyphs */.smallcaps{font-feature-settings:"smcp"on;}/* convert both upper and lowercase to small caps (affects punctuation also) */.allsmallcaps{font-feature-settings:"c2sc","smcp";}/* enable historical forms */.hist{font-feature-settings:"hist";}/* disable common ligatures, usually on by default */.noligs{font-feature-settings:"liga"0;}/* enable tabular (monospaced) figures */td.tabular{font-feature-settings:"tnum";}/* enable automatic fractions */.fractions{font-feature-settings:"frac";}/* use the second available swash character */.swash{font-feature-settings:"swsh"2;}/* enable stylistic set 7 */.fancystyle{font-family:Gabriola;/* available on Windows 7, and on Mac OS */font-feature-settings:"ss07";}Infont configuration variablesthere are 2 variables which affect OTL features for each font family e.g.:
"dejavusanscondensed"=>array('R'=>"DejaVuSansCondensed.ttf",'B'=>"DejaVuSansCondensed-Bold.ttf",'I'=>"DejaVuSansCondensed-Oblique.ttf",'BI'=>"DejaVuSansCondensed-BoldOblique.ttf",'useOTL'=>0xFF,'useKashida'=>75,),useOTL should be set to an integer between 0 and 255. Each bit will enable OTL features for a different group of scripts:
| Bit | dec | hex | Enabled |
|---|---|---|---|
| 1 | 1 | 0x01 | GSUB/GPOS - Latin script |
| 2 | 2 | 0x02 | GSUB/GPOS - Cyrillic script |
| 3 | 4 | 0x04 | GSUB/GPOS - Greek script |
| 4 | 8 | 0x08 | GSUB/GPOS - CJK scripts (excluding Hangul-Jamo) |
| 5 | 16 | 0x10 | (Reserved) |
| 6 | 32 | 0x20 | (Reserved) |
| 7 | 64 | 0x40 | (Reserved) |
| 8 | 128 | 0x80 | GSUB/GPOS - All other scripts (including all RTL scripts, complex scripts etc) |
SettinguseOTL to 0 (or omitting it) will disable all OTL features. SettinguseOTL to 255 or 0xFF will enable OTLfor all scripts. SettinguseOTL to 0x82 will enable OTL features for Cyrillic and complex scripts.
In a font like Free Serif, it may be useful to enable OTL features for complex scripts, but disable OTL for Latinscripts (to save processing time). However, see above - this may disable kerning in Latin scripts in certaincircumstances.
useKashida should be set for arabic fonts if you wish to enable text justification using kashida. The value shouldbe an integer between 0 and 100 and represents the percentage of additional space required to justify the text on aline as a ratio of kashida/inter-word spacing.
Fonts with OTL need to have GDEF, GSUB and GPOS tables in the font file. Although TrueType font files are binaryfiles, the table names and script/feature tags are written as ASCII characters; open the .ttf or .otf file in a texteditor such as Windows Notepad, and you will see GDEF, GSUB and GPOS in the first few lines if they are present. Youcan also search the file to see if the script tags are present for your desired scripts cf.http://www.microsoft.com/typography/otspec/scripttags.htm.
Note: The OTL specification for Indic fonts was updated in 2005 to version 2. The v2 script tag for Bengali is“bng2” whereas prior to this it was “beng”. Many open-source font files are still written for the old specification.This is supported by mPDF, although v2 fonts give better results.
Note: mPDF does not support Graphite or AAT font features.
To add a font, first copy the font file to yourfontDir directory.
Then setfontdataconfiguration variableto add the font. See the manual for details if you are not already familiar with this.
mPDF caches some font information in the directory configured astempDir to improve performance.This is regenerated if you change the value ofuseOTL for a font.
There may be circumstances when you wish to use OTL features with different scripts depending on the document e.g.for everyday use you may want to disable OTL for FreeSerif to save processing time, but on occasions use OTL forIndic and/or Arabic scripts. The recommended way to do this is to create 2 instances of the font e.g. infontdataconfiguration variable.
"freeserif"=>array('R'=>"FreeSerif.ttf",'B'=>"FreeSerifBold.ttf",'I'=>"FreeSerifItalic.ttf",'BI'=>"FreeSerifBoldItalic.ttf",'useOTL'=>0x00,),"freeserif2"=>array('R'=>"FreeSerif.ttf",'B'=>"FreeSerifBold.ttf",'I'=>"FreeSerifItalic.ttf",'BI'=>"FreeSerifBoldItalic.ttf",'useOTL'=>0xFF,/* Uses OTL for all scripts */'useKashida'=>75,),You could then either use this second font name in your stylesheets e.g.
HelloWorld(inArabic)or, you could use font translation e.g.
<?php$mpdf->fonttrans['freeserif']='freeserif2';