1*2d1272b8SAndroid Build Coastguard Worker<?xml version="1.0"?> 2*2d1272b8SAndroid Build Coastguard Worker<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" 3*2d1272b8SAndroid Build Coastguard Worker "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [ 4*2d1272b8SAndroid Build Coastguard Worker <!ENTITY % local.common.attrib "xmlns:xi CDATA #FIXED 'http://www.w3.org/2003/XInclude'"> 5*2d1272b8SAndroid Build Coastguard Worker <!ENTITY version SYSTEM "version.xml"> 6*2d1272b8SAndroid Build Coastguard Worker]> 7*2d1272b8SAndroid Build Coastguard Worker<chapter id="what-is-harfbuzz"> 8*2d1272b8SAndroid Build Coastguard Worker <title>What is HarfBuzz?</title> 9*2d1272b8SAndroid Build Coastguard Worker <para> 10*2d1272b8SAndroid Build Coastguard Worker HarfBuzz is a <emphasis>text-shaping engine</emphasis>. If you 11*2d1272b8SAndroid Build Coastguard Worker give HarfBuzz a font and a string containing a sequence of Unicode 12*2d1272b8SAndroid Build Coastguard Worker codepoints, HarfBuzz selects and positions the corresponding 13*2d1272b8SAndroid Build Coastguard Worker glyphs from the font, applying all of the necessary layout rules 14*2d1272b8SAndroid Build Coastguard Worker and font features. HarfBuzz then returns the string to you in the 15*2d1272b8SAndroid Build Coastguard Worker form that is correctly arranged for the language and writing 16*2d1272b8SAndroid Build Coastguard Worker system. 17*2d1272b8SAndroid Build Coastguard Worker </para> 18*2d1272b8SAndroid Build Coastguard Worker <para> 19*2d1272b8SAndroid Build Coastguard Worker HarfBuzz can properly shape all of the world's major writing 20*2d1272b8SAndroid Build Coastguard Worker systems. It runs on all major operating systems and software 21*2d1272b8SAndroid Build Coastguard Worker platforms and it supports the major font formats in use 22*2d1272b8SAndroid Build Coastguard Worker today. 23*2d1272b8SAndroid Build Coastguard Worker </para> 24*2d1272b8SAndroid Build Coastguard Worker <section id="what-is-text-shaping"> 25*2d1272b8SAndroid Build Coastguard Worker <title>What is text shaping?</title> 26*2d1272b8SAndroid Build Coastguard Worker <para> 27*2d1272b8SAndroid Build Coastguard Worker Text shaping is the process of translating a string of character 28*2d1272b8SAndroid Build Coastguard Worker codes (such as Unicode codepoints) into a properly arranged 29*2d1272b8SAndroid Build Coastguard Worker sequence of glyphs that can be rendered onto a screen or into 30*2d1272b8SAndroid Build Coastguard Worker final output form for inclusion in a document. 31*2d1272b8SAndroid Build Coastguard Worker </para> 32*2d1272b8SAndroid Build Coastguard Worker <para> 33*2d1272b8SAndroid Build Coastguard Worker The shaping process is dependent on the input string, the active 34*2d1272b8SAndroid Build Coastguard Worker font, the script (or writing system) that the string is in, and 35*2d1272b8SAndroid Build Coastguard Worker the language that the string is in. 36*2d1272b8SAndroid Build Coastguard Worker </para> 37*2d1272b8SAndroid Build Coastguard Worker <para> 38*2d1272b8SAndroid Build Coastguard Worker Modern software systems generally only deal with strings in the 39*2d1272b8SAndroid Build Coastguard Worker Unicode encoding scheme (although legacy systems and documents may 40*2d1272b8SAndroid Build Coastguard Worker involve other encodings). 41*2d1272b8SAndroid Build Coastguard Worker </para> 42*2d1272b8SAndroid Build Coastguard Worker <para> 43*2d1272b8SAndroid Build Coastguard Worker There are several font formats that a program might 44*2d1272b8SAndroid Build Coastguard Worker encounter, each of which has a set of standard text-shaping 45*2d1272b8SAndroid Build Coastguard Worker rules. 46*2d1272b8SAndroid Build Coastguard Worker </para> 47*2d1272b8SAndroid Build Coastguard Worker <para>The dominant format is <ulink 48*2d1272b8SAndroid Build Coastguard Worker url="http://www.microsoft.com/typography/otspec/">OpenType</ulink>. The 49*2d1272b8SAndroid Build Coastguard Worker OpenType specification defines a series of <ulink url="https://github.com/n8willis/opentype-shaping-documents">shaping models</ulink> for 50*2d1272b8SAndroid Build Coastguard Worker various scripts from around the world. These shaping models depend on 51*2d1272b8SAndroid Build Coastguard Worker the font incorporating certain features as 52*2d1272b8SAndroid Build Coastguard Worker <emphasis>lookups</emphasis> in its <literal>GSUB</literal> 53*2d1272b8SAndroid Build Coastguard Worker and <literal>GPOS</literal> tables. 54*2d1272b8SAndroid Build Coastguard Worker </para> 55*2d1272b8SAndroid Build Coastguard Worker <para> 56*2d1272b8SAndroid Build Coastguard Worker Alternatively, OpenType fonts can include shaping features for 57*2d1272b8SAndroid Build Coastguard Worker the <ulink url="https://graphite.sil.org/">Graphite</ulink> shaping model. 58*2d1272b8SAndroid Build Coastguard Worker </para> 59*2d1272b8SAndroid Build Coastguard Worker <para> 60*2d1272b8SAndroid Build Coastguard Worker TrueType fonts can also include OpenType shaping 61*2d1272b8SAndroid Build Coastguard Worker features. Alternatively, TrueType fonts can also include <ulink url="https://developer.apple.com/fonts/TrueType-Reference-Manual/RM09/AppendixF.html">Apple 62*2d1272b8SAndroid Build Coastguard Worker Advanced Typography</ulink> (AAT) tables to implement shaping 63*2d1272b8SAndroid Build Coastguard Worker support. AAT fonts are generally only found on macOS and iOS systems. 64*2d1272b8SAndroid Build Coastguard Worker </para> 65*2d1272b8SAndroid Build Coastguard Worker <para> 66*2d1272b8SAndroid Build Coastguard Worker Text strings will usually be tagged with a script and language 67*2d1272b8SAndroid Build Coastguard Worker tag that provide the context needed to perform text shaping 68*2d1272b8SAndroid Build Coastguard Worker correctly. The necessary <ulink 69*2d1272b8SAndroid Build Coastguard Worker url="https://docs.microsoft.com/en-us/typography/opentype/spec/scripttags">script</ulink> 70*2d1272b8SAndroid Build Coastguard Worker and <ulink 71*2d1272b8SAndroid Build Coastguard Worker url="https://docs.microsoft.com/en-us/typography/opentype/spec/languagetags">language</ulink> 72*2d1272b8SAndroid Build Coastguard Worker tags are defined by OpenType. 73*2d1272b8SAndroid Build Coastguard Worker </para> 74*2d1272b8SAndroid Build Coastguard Worker </section> 75*2d1272b8SAndroid Build Coastguard Worker 76*2d1272b8SAndroid Build Coastguard Worker <section id="why-do-i-need-a-shaping-engine"> 77*2d1272b8SAndroid Build Coastguard Worker <title>Why do I need a shaping engine?</title> 78*2d1272b8SAndroid Build Coastguard Worker <para> 79*2d1272b8SAndroid Build Coastguard Worker Text shaping is an integral part of preparing text for 80*2d1272b8SAndroid Build Coastguard Worker display. Before a Unicode sequence can be rendered, the 81*2d1272b8SAndroid Build Coastguard Worker codepoints in the sequence must be mapped to the corresponding 82*2d1272b8SAndroid Build Coastguard Worker glyphs provided in the font, and those glyphs must be positioned 83*2d1272b8SAndroid Build Coastguard Worker correctly relative to each other. For many of the scripts 84*2d1272b8SAndroid Build Coastguard Worker supported in Unicode, these steps involve script-specific layout 85*2d1272b8SAndroid Build Coastguard Worker rules, including complex joining, reordering, and positioning 86*2d1272b8SAndroid Build Coastguard Worker behavior. Implementing these rules is the job of the shaping engine. 87*2d1272b8SAndroid Build Coastguard Worker </para> 88*2d1272b8SAndroid Build Coastguard Worker <para> 89*2d1272b8SAndroid Build Coastguard Worker Text shaping is a fairly low-level operation. HarfBuzz is 90*2d1272b8SAndroid Build Coastguard Worker used directly by text-handling libraries like <ulink 91*2d1272b8SAndroid Build Coastguard Worker url="https://www.pango.org/">Pango</ulink>, as well as by the layout 92*2d1272b8SAndroid Build Coastguard Worker engines in Firefox, LibreOffice, and Chromium. Unless you are 93*2d1272b8SAndroid Build Coastguard Worker <emphasis>writing</emphasis> one of these layout engines 94*2d1272b8SAndroid Build Coastguard Worker yourself, you will probably not need to use HarfBuzz: normally, 95*2d1272b8SAndroid Build Coastguard Worker a layout engine, toolkit, or other library will turn text into 96*2d1272b8SAndroid Build Coastguard Worker glyphs for you. 97*2d1272b8SAndroid Build Coastguard Worker </para> 98*2d1272b8SAndroid Build Coastguard Worker <para> 99*2d1272b8SAndroid Build Coastguard Worker However, if you <emphasis>are</emphasis> writing a layout engine 100*2d1272b8SAndroid Build Coastguard Worker or graphics library yourself, then you will need to perform text 101*2d1272b8SAndroid Build Coastguard Worker shaping, and this is where HarfBuzz can help you. 102*2d1272b8SAndroid Build Coastguard Worker </para> 103*2d1272b8SAndroid Build Coastguard Worker <para> 104*2d1272b8SAndroid Build Coastguard Worker Here are some specific scenarios where a text-shaping engine 105*2d1272b8SAndroid Build Coastguard Worker like HarfBuzz helps you: 106*2d1272b8SAndroid Build Coastguard Worker </para> 107*2d1272b8SAndroid Build Coastguard Worker <itemizedlist> 108*2d1272b8SAndroid Build Coastguard Worker <listitem> 109*2d1272b8SAndroid Build Coastguard Worker <para> 110*2d1272b8SAndroid Build Coastguard Worker OpenType fonts contain a set of glyphs (that is, shapes 111*2d1272b8SAndroid Build Coastguard Worker to represent the letters, numbers, punctuation marks, and 112*2d1272b8SAndroid Build Coastguard Worker all other symbols), which are indexed by a <literal>glyph ID</literal>. 113*2d1272b8SAndroid Build Coastguard Worker </para> 114*2d1272b8SAndroid Build Coastguard Worker <para> 115*2d1272b8SAndroid Build Coastguard Worker A particular glyph ID within the font does not necessarily 116*2d1272b8SAndroid Build Coastguard Worker correlate to a predictable Unicode codepoint. For instance, 117*2d1272b8SAndroid Build Coastguard Worker some fonts have the letter "a" as glyph ID 1, but 118*2d1272b8SAndroid Build Coastguard Worker many others do not. In order to retrieve the right glyph 119*2d1272b8SAndroid Build Coastguard Worker from the font to display "a", you need to consult 120*2d1272b8SAndroid Build Coastguard Worker the table inside the font (the <literal>cmap</literal> 121*2d1272b8SAndroid Build Coastguard Worker table) that maps Unicode codepoints to glyph IDs. In other 122*2d1272b8SAndroid Build Coastguard Worker words, <emphasis>text shaping turns codepoints into glyph 123*2d1272b8SAndroid Build Coastguard Worker IDs</emphasis>. 124*2d1272b8SAndroid Build Coastguard Worker </para> 125*2d1272b8SAndroid Build Coastguard Worker </listitem> 126*2d1272b8SAndroid Build Coastguard Worker <listitem> 127*2d1272b8SAndroid Build Coastguard Worker <para> 128*2d1272b8SAndroid Build Coastguard Worker Many OpenType fonts contain ligatures: combinations of 129*2d1272b8SAndroid Build Coastguard Worker characters that are rendered as a single unit. For instance, 130*2d1272b8SAndroid Build Coastguard Worker it is common for the "f, i" letter 131*2d1272b8SAndroid Build Coastguard Worker sequence to appear in print as the single ligature glyph 132*2d1272b8SAndroid Build Coastguard Worker "fi". 133*2d1272b8SAndroid Build Coastguard Worker </para> 134*2d1272b8SAndroid Build Coastguard Worker <para> 135*2d1272b8SAndroid Build Coastguard Worker Whether you should render an "f, i" sequence 136*2d1272b8SAndroid Build Coastguard Worker as <literal>fi</literal> or as "fi" does not 137*2d1272b8SAndroid Build Coastguard Worker depend on the input text. Instead, it depends on the whether 138*2d1272b8SAndroid Build Coastguard Worker or not the font includes an "fi" glyph and on the 139*2d1272b8SAndroid Build Coastguard Worker level of ligature application you wish to perform. The font 140*2d1272b8SAndroid Build Coastguard Worker and the amount of ligature application used are under your 141*2d1272b8SAndroid Build Coastguard Worker control. In other words, <emphasis>text shaping involves 142*2d1272b8SAndroid Build Coastguard Worker querying the font's ligature tables and determining what 143*2d1272b8SAndroid Build Coastguard Worker substitutions should be made</emphasis>. 144*2d1272b8SAndroid Build Coastguard Worker </para> 145*2d1272b8SAndroid Build Coastguard Worker </listitem> 146*2d1272b8SAndroid Build Coastguard Worker <listitem> 147*2d1272b8SAndroid Build Coastguard Worker <para> 148*2d1272b8SAndroid Build Coastguard Worker While ligatures like "fi" are optional typographic 149*2d1272b8SAndroid Build Coastguard Worker refinements, some languages <emphasis>require</emphasis> certain 150*2d1272b8SAndroid Build Coastguard Worker substitutions to be made in order to display text correctly. 151*2d1272b8SAndroid Build Coastguard Worker </para> 152*2d1272b8SAndroid Build Coastguard Worker <para> 153*2d1272b8SAndroid Build Coastguard Worker For example, in Tamil, when the letter "TTA" (ட) 154*2d1272b8SAndroid Build Coastguard Worker letter is followed by the vowel sign "U" (ு), the pair 155*2d1272b8SAndroid Build Coastguard Worker must be replaced by the single glyph "டு". The 156*2d1272b8SAndroid Build Coastguard Worker sequence of Unicode characters "ட,ு" needs to be 157*2d1272b8SAndroid Build Coastguard Worker substituted with a single "டு" glyph from the 158*2d1272b8SAndroid Build Coastguard Worker font. 159*2d1272b8SAndroid Build Coastguard Worker </para> 160*2d1272b8SAndroid Build Coastguard Worker <para> 161*2d1272b8SAndroid Build Coastguard Worker But "டு" does not have a Unicode codepoint. To 162*2d1272b8SAndroid Build Coastguard Worker find this glyph, you need to consult the table inside 163*2d1272b8SAndroid Build Coastguard Worker the font (the <literal>GSUB</literal> table) that contains 164*2d1272b8SAndroid Build Coastguard Worker substitution information. In other words, <emphasis>text shaping 165*2d1272b8SAndroid Build Coastguard Worker chooses the correct glyph for a sequence of characters 166*2d1272b8SAndroid Build Coastguard Worker provided</emphasis>. 167*2d1272b8SAndroid Build Coastguard Worker </para> 168*2d1272b8SAndroid Build Coastguard Worker </listitem> 169*2d1272b8SAndroid Build Coastguard Worker <listitem> 170*2d1272b8SAndroid Build Coastguard Worker <para> 171*2d1272b8SAndroid Build Coastguard Worker Similarly, each Arabic character has four different variants 172*2d1272b8SAndroid Build Coastguard Worker corresponding to the different positions it might appear in 173*2d1272b8SAndroid Build Coastguard Worker within a sequence. Inside a font, there will be separate 174*2d1272b8SAndroid Build Coastguard Worker glyphs for the initial, medial, final, and isolated forms of 175*2d1272b8SAndroid Build Coastguard Worker each letter, each at a different glyph ID. 176*2d1272b8SAndroid Build Coastguard Worker </para> 177*2d1272b8SAndroid Build Coastguard Worker <para> 178*2d1272b8SAndroid Build Coastguard Worker Unicode only assigns one codepoint per character, so a 179*2d1272b8SAndroid Build Coastguard Worker Unicode string will not tell you which glyph variant to use 180*2d1272b8SAndroid Build Coastguard Worker for each character. To decide, you need to analyze the whole 181*2d1272b8SAndroid Build Coastguard Worker string and determine the appropriate glyph for each character 182*2d1272b8SAndroid Build Coastguard Worker based on its position. In other words, <emphasis>text 183*2d1272b8SAndroid Build Coastguard Worker shaping chooses the correct form of the letter by its 184*2d1272b8SAndroid Build Coastguard Worker position and returns the correct glyph from the font</emphasis>. 185*2d1272b8SAndroid Build Coastguard Worker </para> 186*2d1272b8SAndroid Build Coastguard Worker </listitem> 187*2d1272b8SAndroid Build Coastguard Worker <listitem> 188*2d1272b8SAndroid Build Coastguard Worker <para> 189*2d1272b8SAndroid Build Coastguard Worker Other languages involve marks and accents that need to be 190*2d1272b8SAndroid Build Coastguard Worker rendered in specific positions relative a base character. For 191*2d1272b8SAndroid Build Coastguard Worker instance, the Moldovan language includes the Cyrillic letter 192*2d1272b8SAndroid Build Coastguard Worker "zhe" (ж) with a breve accent, like so: "ӂ". 193*2d1272b8SAndroid Build Coastguard Worker </para> 194*2d1272b8SAndroid Build Coastguard Worker <para> 195*2d1272b8SAndroid Build Coastguard Worker Some fonts will provide this character as a single 196*2d1272b8SAndroid Build Coastguard Worker zhe-with-breve glyph, but other fonts will not and, instead, 197*2d1272b8SAndroid Build Coastguard Worker will expect the rendering engine to form the character by 198*2d1272b8SAndroid Build Coastguard Worker superimposing the separate "ж" and "˘" 199*2d1272b8SAndroid Build Coastguard Worker glyphs. 200*2d1272b8SAndroid Build Coastguard Worker </para> 201*2d1272b8SAndroid Build Coastguard Worker <para> 202*2d1272b8SAndroid Build Coastguard Worker But exactly where you should draw the breve depends on the 203*2d1272b8SAndroid Build Coastguard Worker height and width of the preceding zhe glyph. To find the 204*2d1272b8SAndroid Build Coastguard Worker right position, you need to consult the table inside 205*2d1272b8SAndroid Build Coastguard Worker the font (the <literal>GPOS</literal> table) that contains 206*2d1272b8SAndroid Build Coastguard Worker positioning information. 207*2d1272b8SAndroid Build Coastguard Worker In other words, <emphasis>text shaping tells you whether you 208*2d1272b8SAndroid Build Coastguard Worker have a precomposed glyph within your font or if you need to 209*2d1272b8SAndroid Build Coastguard Worker compose a glyph yourself out of combining marks—and, 210*2d1272b8SAndroid Build Coastguard Worker if so, where to position those marks.</emphasis> 211*2d1272b8SAndroid Build Coastguard Worker </para> 212*2d1272b8SAndroid Build Coastguard Worker </listitem> 213*2d1272b8SAndroid Build Coastguard Worker </itemizedlist> 214*2d1272b8SAndroid Build Coastguard Worker <para> 215*2d1272b8SAndroid Build Coastguard Worker If tasks like these are something that you need to do, then you 216*2d1272b8SAndroid Build Coastguard Worker need a text shaping engine. You could use Uniscribe if you are 217*2d1272b8SAndroid Build Coastguard Worker writing Windows software; you could use CoreText on macOS; or 218*2d1272b8SAndroid Build Coastguard Worker you could use HarfBuzz. 219*2d1272b8SAndroid Build Coastguard Worker </para> 220*2d1272b8SAndroid Build Coastguard Worker <note> 221*2d1272b8SAndroid Build Coastguard Worker <para> 222*2d1272b8SAndroid Build Coastguard Worker In the rest of this manual, the text will assume that the reader 223*2d1272b8SAndroid Build Coastguard Worker is that implementor of a text-layout engine. 224*2d1272b8SAndroid Build Coastguard Worker </para> 225*2d1272b8SAndroid Build Coastguard Worker </note> 226*2d1272b8SAndroid Build Coastguard Worker </section> 227*2d1272b8SAndroid Build Coastguard Worker 228*2d1272b8SAndroid Build Coastguard Worker 229*2d1272b8SAndroid Build Coastguard Worker <section id="what-does-harfbuzz-do"> 230*2d1272b8SAndroid Build Coastguard Worker <title>What does HarfBuzz do?</title> 231*2d1272b8SAndroid Build Coastguard Worker <para> 232*2d1272b8SAndroid Build Coastguard Worker HarfBuzz provides text shaping through a cross-platform 233*2d1272b8SAndroid Build Coastguard Worker C API that accepts sequences of Unicode codepoints as input. Currently, 234*2d1272b8SAndroid Build Coastguard Worker the following OpenType shaping models are supported: 235*2d1272b8SAndroid Build Coastguard Worker </para> 236*2d1272b8SAndroid Build Coastguard Worker <itemizedlist> 237*2d1272b8SAndroid Build Coastguard Worker <listitem> 238*2d1272b8SAndroid Build Coastguard Worker <para> 239*2d1272b8SAndroid Build Coastguard Worker Indic (covering Devanagari, Bengali, Gujarati, 240*2d1272b8SAndroid Build Coastguard Worker Gurmukhi, Kannada, Malayalam, Oriya, Tamil, and Telugu) 241*2d1272b8SAndroid Build Coastguard Worker </para> 242*2d1272b8SAndroid Build Coastguard Worker </listitem> 243*2d1272b8SAndroid Build Coastguard Worker <listitem> 244*2d1272b8SAndroid Build Coastguard Worker <para> 245*2d1272b8SAndroid Build Coastguard Worker Arabic (covering Arabic, N'Ko, Syriac, and Mongolian) 246*2d1272b8SAndroid Build Coastguard Worker </para> 247*2d1272b8SAndroid Build Coastguard Worker </listitem> 248*2d1272b8SAndroid Build Coastguard Worker <listitem> 249*2d1272b8SAndroid Build Coastguard Worker <para> 250*2d1272b8SAndroid Build Coastguard Worker Thai and Lao 251*2d1272b8SAndroid Build Coastguard Worker </para> 252*2d1272b8SAndroid Build Coastguard Worker </listitem> 253*2d1272b8SAndroid Build Coastguard Worker <listitem> 254*2d1272b8SAndroid Build Coastguard Worker <para> 255*2d1272b8SAndroid Build Coastguard Worker Khmer 256*2d1272b8SAndroid Build Coastguard Worker </para> 257*2d1272b8SAndroid Build Coastguard Worker </listitem> 258*2d1272b8SAndroid Build Coastguard Worker <listitem> 259*2d1272b8SAndroid Build Coastguard Worker <para> 260*2d1272b8SAndroid Build Coastguard Worker Myanmar 261*2d1272b8SAndroid Build Coastguard Worker </para> 262*2d1272b8SAndroid Build Coastguard Worker </listitem> 263*2d1272b8SAndroid Build Coastguard Worker 264*2d1272b8SAndroid Build Coastguard Worker <listitem> 265*2d1272b8SAndroid Build Coastguard Worker <para> 266*2d1272b8SAndroid Build Coastguard Worker Tibetan 267*2d1272b8SAndroid Build Coastguard Worker </para> 268*2d1272b8SAndroid Build Coastguard Worker </listitem> 269*2d1272b8SAndroid Build Coastguard Worker 270*2d1272b8SAndroid Build Coastguard Worker <listitem> 271*2d1272b8SAndroid Build Coastguard Worker <para> 272*2d1272b8SAndroid Build Coastguard Worker Hangul 273*2d1272b8SAndroid Build Coastguard Worker </para> 274*2d1272b8SAndroid Build Coastguard Worker </listitem> 275*2d1272b8SAndroid Build Coastguard Worker 276*2d1272b8SAndroid Build Coastguard Worker <listitem> 277*2d1272b8SAndroid Build Coastguard Worker <para> 278*2d1272b8SAndroid Build Coastguard Worker Hebrew 279*2d1272b8SAndroid Build Coastguard Worker </para> 280*2d1272b8SAndroid Build Coastguard Worker </listitem> 281*2d1272b8SAndroid Build Coastguard Worker <listitem> 282*2d1272b8SAndroid Build Coastguard Worker <para> 283*2d1272b8SAndroid Build Coastguard Worker The Universal Shaping Engine or <emphasis>USE</emphasis> 284*2d1272b8SAndroid Build Coastguard Worker (covering complex scripts not covered by the above shaping 285*2d1272b8SAndroid Build Coastguard Worker models) 286*2d1272b8SAndroid Build Coastguard Worker </para> 287*2d1272b8SAndroid Build Coastguard Worker </listitem> 288*2d1272b8SAndroid Build Coastguard Worker <listitem> 289*2d1272b8SAndroid Build Coastguard Worker <para> 290*2d1272b8SAndroid Build Coastguard Worker A default shaping model for non-complex scripts 291*2d1272b8SAndroid Build Coastguard Worker (covering Latin, Cyrillic, Greek, Armenian, Georgian, Tifinagh, 292*2d1272b8SAndroid Build Coastguard Worker and many others) 293*2d1272b8SAndroid Build Coastguard Worker </para> 294*2d1272b8SAndroid Build Coastguard Worker </listitem> 295*2d1272b8SAndroid Build Coastguard Worker <listitem> 296*2d1272b8SAndroid Build Coastguard Worker <para> 297*2d1272b8SAndroid Build Coastguard Worker Emoji (including emoji modifier sequences, flag sequences, 298*2d1272b8SAndroid Build Coastguard Worker and ZWJ sequences) 299*2d1272b8SAndroid Build Coastguard Worker </para> 300*2d1272b8SAndroid Build Coastguard Worker </listitem> 301*2d1272b8SAndroid Build Coastguard Worker </itemizedlist> 302*2d1272b8SAndroid Build Coastguard Worker 303*2d1272b8SAndroid Build Coastguard Worker <para> 304*2d1272b8SAndroid Build Coastguard Worker In addition to OpenType shaping, HarfBuzz supports the latest 305*2d1272b8SAndroid Build Coastguard Worker version of Graphite shaping (the "Graphite 2" model) and AAT 306*2d1272b8SAndroid Build Coastguard Worker shaping. 307*2d1272b8SAndroid Build Coastguard Worker </para> 308*2d1272b8SAndroid Build Coastguard Worker 309*2d1272b8SAndroid Build Coastguard Worker <para> 310*2d1272b8SAndroid Build Coastguard Worker HarfBuzz can read and understand TrueType fonts (.ttf), TrueType 311*2d1272b8SAndroid Build Coastguard Worker collections (.ttc), and OpenType fonts (.otf, including those 312*2d1272b8SAndroid Build Coastguard Worker fonts that contain TrueType-style outlines and those that 313*2d1272b8SAndroid Build Coastguard Worker contain PostScript CFF or CFF2 outlines). 314*2d1272b8SAndroid Build Coastguard Worker </para> 315*2d1272b8SAndroid Build Coastguard Worker 316*2d1272b8SAndroid Build Coastguard Worker <para> 317*2d1272b8SAndroid Build Coastguard Worker HarfBuzz is designed and tested to run on top of the FreeType 318*2d1272b8SAndroid Build Coastguard Worker font renderer. It can run on Linux, Android, Windows, macOS, and 319*2d1272b8SAndroid Build Coastguard Worker iOS systems. 320*2d1272b8SAndroid Build Coastguard Worker </para> 321*2d1272b8SAndroid Build Coastguard Worker 322*2d1272b8SAndroid Build Coastguard Worker <para> 323*2d1272b8SAndroid Build Coastguard Worker In addition to its core shaping functionality, HarfBuzz provides 324*2d1272b8SAndroid Build Coastguard Worker functions for accessing other font features, including optional 325*2d1272b8SAndroid Build Coastguard Worker GSUB and GPOS OpenType features, as well as 326*2d1272b8SAndroid Build Coastguard Worker all color-font formats (<literal>CBDT</literal>, 327*2d1272b8SAndroid Build Coastguard Worker <literal>sbix</literal>, <literal>COLR/CPAL</literal>, and 328*2d1272b8SAndroid Build Coastguard Worker <literal>SVG-OT</literal>) and OpenType variable fonts. HarfBuzz 329*2d1272b8SAndroid Build Coastguard Worker also includes a font-subsetting feature. HarfBuzz can perform 330*2d1272b8SAndroid Build Coastguard Worker some low-level math-shaping operations, although it does not 331*2d1272b8SAndroid Build Coastguard Worker currently perform full shaping for mathematical typesetting. 332*2d1272b8SAndroid Build Coastguard Worker </para> 333*2d1272b8SAndroid Build Coastguard Worker 334*2d1272b8SAndroid Build Coastguard Worker <para> 335*2d1272b8SAndroid Build Coastguard Worker A suite of command-line utilities is also provided in the 336*2d1272b8SAndroid Build Coastguard Worker source-code tree, designed to help users test and debug 337*2d1272b8SAndroid Build Coastguard Worker HarfBuzz's features on real-world fonts and input. 338*2d1272b8SAndroid Build Coastguard Worker </para> 339*2d1272b8SAndroid Build Coastguard Worker </section> 340*2d1272b8SAndroid Build Coastguard Worker 341*2d1272b8SAndroid Build Coastguard Worker <section id="what-harfbuzz-doesnt-do"> 342*2d1272b8SAndroid Build Coastguard Worker <title>What HarfBuzz doesn't do</title> 343*2d1272b8SAndroid Build Coastguard Worker <para> 344*2d1272b8SAndroid Build Coastguard Worker HarfBuzz will take a Unicode string, shape it, and give you the 345*2d1272b8SAndroid Build Coastguard Worker information required to lay it out correctly on a single 346*2d1272b8SAndroid Build Coastguard Worker horizontal (or vertical) line using the font provided. That is the 347*2d1272b8SAndroid Build Coastguard Worker extent of HarfBuzz's responsibility. 348*2d1272b8SAndroid Build Coastguard Worker </para> 349*2d1272b8SAndroid Build Coastguard Worker <para> 350*2d1272b8SAndroid Build Coastguard Worker It is important to note that if you are implementing a complete 351*2d1272b8SAndroid Build Coastguard Worker text-layout engine you may have other responsibilities that 352*2d1272b8SAndroid Build Coastguard Worker HarfBuzz will <emphasis>not</emphasis> help you with. For example: 353*2d1272b8SAndroid Build Coastguard Worker </para> 354*2d1272b8SAndroid Build Coastguard Worker <itemizedlist> 355*2d1272b8SAndroid Build Coastguard Worker <listitem> 356*2d1272b8SAndroid Build Coastguard Worker <para> 357*2d1272b8SAndroid Build Coastguard Worker HarfBuzz won't help you with bidirectionality. If you want to 358*2d1272b8SAndroid Build Coastguard Worker lay out text that includes a mix of Hebrew and English, you 359*2d1272b8SAndroid Build Coastguard Worker will need to ensure that each buffer provided to HarfBuzz 360*2d1272b8SAndroid Build Coastguard Worker has all of its characters in the same order and that the 361*2d1272b8SAndroid Build Coastguard Worker directionality of the buffer is set correctly. This may mean 362*2d1272b8SAndroid Build Coastguard Worker segmenting the text before it is placed into HarfBuzz buffers. In 363*2d1272b8SAndroid Build Coastguard Worker other words, the user will hit the keys in the following 364*2d1272b8SAndroid Build Coastguard Worker sequence: 365*2d1272b8SAndroid Build Coastguard Worker </para> 366*2d1272b8SAndroid Build Coastguard Worker <programlisting> 367*2d1272b8SAndroid Build Coastguard Worker A B C [space] ג ב א [space] D E F 368*2d1272b8SAndroid Build Coastguard Worker </programlisting> 369*2d1272b8SAndroid Build Coastguard Worker <para> 370*2d1272b8SAndroid Build Coastguard Worker but will expect to see in the output: 371*2d1272b8SAndroid Build Coastguard Worker </para> 372*2d1272b8SAndroid Build Coastguard Worker <programlisting> 373*2d1272b8SAndroid Build Coastguard Worker ABC אבג DEF 374*2d1272b8SAndroid Build Coastguard Worker </programlisting> 375*2d1272b8SAndroid Build Coastguard Worker <para> 376*2d1272b8SAndroid Build Coastguard Worker This reordering is called <emphasis>bidi processing</emphasis> 377*2d1272b8SAndroid Build Coastguard Worker ("bidi" is short for bidirectional), and there's an 378*2d1272b8SAndroid Build Coastguard Worker algorithm as an annex to the Unicode Standard which tells you how 379*2d1272b8SAndroid Build Coastguard Worker to process a string of mixed directionality. 380*2d1272b8SAndroid Build Coastguard Worker Before sending your string to HarfBuzz, you may need to apply the 381*2d1272b8SAndroid Build Coastguard Worker bidi algorithm to it. Libraries such as <ulink 382*2d1272b8SAndroid Build Coastguard Worker url="http://icu-project.org/">ICU</ulink> and <ulink 383*2d1272b8SAndroid Build Coastguard Worker url="http://fribidi.org/">fribidi</ulink> can do this for you. 384*2d1272b8SAndroid Build Coastguard Worker </para> 385*2d1272b8SAndroid Build Coastguard Worker </listitem> 386*2d1272b8SAndroid Build Coastguard Worker <listitem> 387*2d1272b8SAndroid Build Coastguard Worker <para> 388*2d1272b8SAndroid Build Coastguard Worker HarfBuzz won't help you with text that contains different font 389*2d1272b8SAndroid Build Coastguard Worker properties. For instance, if you have the string "a 390*2d1272b8SAndroid Build Coastguard Worker <emphasis>huge</emphasis> breakfast", and you expect 391*2d1272b8SAndroid Build Coastguard Worker "huge" to be italic, then you will need to send three 392*2d1272b8SAndroid Build Coastguard Worker strings to HarfBuzz: <literal>a</literal>, in your Roman font; 393*2d1272b8SAndroid Build Coastguard Worker <literal>huge</literal> using your italic font; and 394*2d1272b8SAndroid Build Coastguard Worker <literal>breakfast</literal> using your Roman font again. 395*2d1272b8SAndroid Build Coastguard Worker </para> 396*2d1272b8SAndroid Build Coastguard Worker <para> 397*2d1272b8SAndroid Build Coastguard Worker Similarly, if you change the font, font size, script, 398*2d1272b8SAndroid Build Coastguard Worker language, or direction within your string, then you will 399*2d1272b8SAndroid Build Coastguard Worker need to shape each run independently and output them 400*2d1272b8SAndroid Build Coastguard Worker independently. HarfBuzz expects to shape a run of characters 401*2d1272b8SAndroid Build Coastguard Worker that all share the same properties. 402*2d1272b8SAndroid Build Coastguard Worker </para> 403*2d1272b8SAndroid Build Coastguard Worker </listitem> 404*2d1272b8SAndroid Build Coastguard Worker <listitem> 405*2d1272b8SAndroid Build Coastguard Worker <para> 406*2d1272b8SAndroid Build Coastguard Worker HarfBuzz won't help you with line breaking, hyphenation, or 407*2d1272b8SAndroid Build Coastguard Worker justification. As mentioned above, HarfBuzz lays out the string 408*2d1272b8SAndroid Build Coastguard Worker along a <emphasis>single line</emphasis> of, notionally, 409*2d1272b8SAndroid Build Coastguard Worker infinite length. If you want to find out where the potential 410*2d1272b8SAndroid Build Coastguard Worker word, sentence and line break points are in your text, you 411*2d1272b8SAndroid Build Coastguard Worker could use the ICU library's break iterator functions. 412*2d1272b8SAndroid Build Coastguard Worker </para> 413*2d1272b8SAndroid Build Coastguard Worker <para> 414*2d1272b8SAndroid Build Coastguard Worker HarfBuzz can tell you how wide a shaped piece of text is, which is 415*2d1272b8SAndroid Build Coastguard Worker useful input to a justification algorithm, but it knows nothing 416*2d1272b8SAndroid Build Coastguard Worker about paragraphs, lines or line lengths. Nor will it adjust the 417*2d1272b8SAndroid Build Coastguard Worker space between words to fit them proportionally into a line. 418*2d1272b8SAndroid Build Coastguard Worker </para> 419*2d1272b8SAndroid Build Coastguard Worker </listitem> 420*2d1272b8SAndroid Build Coastguard Worker </itemizedlist> 421*2d1272b8SAndroid Build Coastguard Worker <para> 422*2d1272b8SAndroid Build Coastguard Worker As a layout-engine implementor, HarfBuzz will help you with the 423*2d1272b8SAndroid Build Coastguard Worker interface between your text and your font, and that's something 424*2d1272b8SAndroid Build Coastguard Worker that you'll need—what you then do with the glyphs that your font 425*2d1272b8SAndroid Build Coastguard Worker returns is up to you. 426*2d1272b8SAndroid Build Coastguard Worker </para> 427*2d1272b8SAndroid Build Coastguard Worker </section> 428*2d1272b8SAndroid Build Coastguard Worker 429*2d1272b8SAndroid Build Coastguard Worker <section id="why-is-it-called-harfbuzz"> 430*2d1272b8SAndroid Build Coastguard Worker <title>Why is it called HarfBuzz?</title> 431*2d1272b8SAndroid Build Coastguard Worker <para> 432*2d1272b8SAndroid Build Coastguard Worker HarfBuzz began its life as text-shaping code within the FreeType 433*2d1272b8SAndroid Build Coastguard Worker project (and you will see references to the FreeType authors 434*2d1272b8SAndroid Build Coastguard Worker within the source code copyright declarations), but was then 435*2d1272b8SAndroid Build Coastguard Worker extracted out to its own project. This project is maintained by 436*2d1272b8SAndroid Build Coastguard Worker Behdad Esfahbod, who named it HarfBuzz. Originally, it was a 437*2d1272b8SAndroid Build Coastguard Worker shaping engine for OpenType fonts—"HarfBuzz" is 438*2d1272b8SAndroid Build Coastguard Worker the Persian for "open type". 439*2d1272b8SAndroid Build Coastguard Worker </para> 440*2d1272b8SAndroid Build Coastguard Worker </section> 441*2d1272b8SAndroid Build Coastguard Worker</chapter> 442