Blame docs/usermanual-what-is-harfbuzz.xml

Packit 874993
<chapter id="what-is-harfbuzz">
Packit 874993
  <title>What is Harfbuzz?</title>
Packit 874993
  <para>
Packit 874993
    Harfbuzz is a <emphasis>text shaping engine</emphasis>. It solves
Packit 874993
    the problem of selecting and positioning glyphs from a font given a
Packit 874993
    Unicode string.
Packit 874993
  </para>
Packit 874993
  <section id="why-do-i-need-it">
Packit 874993
    <title>Why do I need it?</title>
Packit 874993
    <para>
Packit 874993
      Text shaping is an integral part of preparing text for display. It
Packit 874993
      is a fairly low level operation; Harfbuzz is used directly by
Packit 874993
      graphic rendering libraries such as Pango, and the layout engines
Packit 874993
      in Firefox, LibreOffice and Chromium. Unless you are
Packit 874993
      <emphasis>writing</emphasis> one of these layout engines yourself,
Packit 874993
      you will probably not need to use Harfbuzz - normally higher level
Packit 874993
      libraries will turn text into glyphs for you.
Packit 874993
    </para>
Packit 874993
    <para>
Packit 874993
      However, if you <emphasis>are</emphasis> writing a layout engine
Packit 874993
      or graphics library yourself, you will need to perform text
Packit 874993
      shaping, and this is where Harfbuzz can help you. Here are some
Packit 874993
      reasons why you need it:
Packit 874993
    </para>
Packit 874993
    <itemizedlist>
Packit 874993
      <listitem>
Packit 874993
        <para>
Packit 874993
          OpenType fonts contain a set of glyphs, indexed by glyph ID.
Packit 874993
          The glyph ID within the font does not necessarily relate to a
Packit 874993
          Unicode codepoint. For instance, some fonts have the letter
Packit 874993
          "a" as glyph ID 1. To pull the right glyph out of
Packit 874993
          the font in order to display it, you need to consult a table
Packit 874993
          within the font (the "cmap" table) which maps
Packit 874993
          Unicode codepoints to glyph IDs. Text shaping turns codepoints
Packit 874993
          into glyph IDs.
Packit 874993
        </para>
Packit 874993
      </listitem>
Packit 874993
      <listitem>
Packit 874993
        <para>
Packit 874993
          Many OpenType fonts contain ligatures: combinations of
Packit 874993
          characters which are rendered together. For instance, it's
Packit 874993
          common for the <literal>fi</literal> combination to appear in
Packit 874993
          print as the single ligature "fi". Whether you should
Packit 874993
          render text as <literal>fi</literal> or "fi" does not
Packit 874993
          depend on the input text, but on the capabilities of the font
Packit 874993
          and the level of ligature application you wish to perform.
Packit 874993
          Text shaping involves querying the font's ligature tables and
Packit 874993
          determining what substitutions should be made.
Packit 874993
        </para>
Packit 874993
      </listitem>
Packit 874993
      <listitem>
Packit 874993
        <para>
Packit 874993
          While ligatures like "fi" are typographic
Packit 874993
          refinements, some languages <emphasis>require</emphasis> such
Packit 874993
          substitutions to be made in order to display text correctly.
Packit 874993
          In Tamil, when the letter "TTA" (ட) letter is
Packit 874993
          followed by "U" (உ), the combination should appear
Packit 874993
          as the single glyph "டு". The sequence of Unicode
Packit 874993
          characters "டஉ" needs to be rendered as a single
Packit 874993
          glyph from the font - text shaping chooses the correct glyph
Packit 874993
          from the sequence of characters provided.
Packit 874993
        </para>
Packit 874993
      </listitem>
Packit 874993
      <listitem>
Packit 874993
        <para>
Packit 874993
          Similarly, each Arabic character has four different variants:
Packit 874993
          within a font, there will be glyphs for the initial, medial,
Packit 874993
          final, and isolated forms of each letter. Unicode only encodes
Packit 874993
          one codepoint per character, and so a Unicode string will not
Packit 874993
          tell you which glyph to use. Text shaping chooses the correct
Packit 874993
          form of the letter and returns the correct glyph from the font
Packit 874993
          that you need to render.
Packit 874993
        </para>
Packit 874993
      </listitem>
Packit 874993
      <listitem>
Packit 874993
        <para>
Packit 874993
          Other languages have marks and accents which need to be
Packit 874993
          rendered in certain positions around a base character. For
Packit 874993
          instance, the Moldovan language has the Cyrillic letter
Packit 874993
          "zhe" (ж) with a breve accent, like so: ӂ. Some
Packit 874993
          fonts will contain this character as an individual glyph,
Packit 874993
          whereas other fonts will not contain a zhe-with-breve glyph
Packit 874993
          but expect the rendering engine to form the character by
Packit 874993
          overlaying the two glyphs ж and ˘. Where you should draw the
Packit 874993
          combining breve depends on the height of the preceding glyph.
Packit 874993
          Again, for Arabic, the correct positioning of vowel marks
Packit 874993
          depends on the height of the character on which you are
Packit 874993
          placing the mark. Text shaping tells you whether you have a
Packit 874993
          precomposed glyph within your font or if you need to compose a
Packit 874993
          glyph yourself out of combining marks, and if so, where to
Packit 874993
          position those marks.
Packit 874993
        </para>
Packit 874993
      </listitem>
Packit 874993
    </itemizedlist>
Packit 874993
    <para>
Packit 874993
      If this is something that you need to do, then you need a text
Packit 874993
      shaping engine: you could use Uniscribe if you are using Windows;
Packit 874993
      you could use CoreText on OS X; or you could use Harfbuzz. In the
Packit 874993
      rest of this manual, we are going to assume that you are the
Packit 874993
      implementor of a text layout engine.
Packit 874993
    </para>
Packit 874993
  </section>
Packit 874993
  <section id="why-is-it-called-harfbuzz">
Packit 874993
    <title>Why is it called Harfbuzz?</title>
Packit 874993
    <para>
Packit 874993
      Harfbuzz began its life as text shaping code within the FreeType
Packit 874993
      project, (and you will see references to the FreeType authors
Packit 874993
      within the source code copyright declarations) but was then
Packit 874993
      abstracted out to its own project. This project is maintained by
Packit 874993
      Behdad Esfahbod, and named Harfbuzz. Originally, it was a shaping
Packit 874993
      engine for OpenType fonts - "Harfbuzz" is the Persian
Packit 874993
      for "open type".
Packit 874993
    </para>
Packit 874993
  </section>
Packit 874993
</chapter>