(root)/
harfbuzz-8.3.0/
docs/
html/
shaping-opentype-features.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>OpenType features: HarfBuzz Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="HarfBuzz Manual">
<link rel="up" href="shaping-and-shape-plans.html" title="Shaping and shape plans">
<link rel="prev" href="shaping-and-shape-plans.html" title="Shaping and shape plans">
<link rel="next" href="shaping-shaper-selection.html" title="Shaper selection">
<meta name="generator" content="GTK-Doc V1.33.1 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="shaping-and-shape-plans.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="shaping-and-shape-plans.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="shaping-shaper-selection.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="shaping-opentype-features"></a>OpenType features</h2></div></div></div>
<p>
      OpenType features enable fonts to include smart behavior,
      implemented as "lookup" rules stored in the GSUB and GPOS
      tables. The OpenType specification defines a long list of
      standard features that fonts can use for these behaviors; each
      feature has a four-character reserved name and a well-defined
      semantic meaning.
    </p>
<p>
      Some OpenType features are defined for the purpose of supporting
      script-specific shaping, and are automatically activated, but
      only when a buffer's script property is set to a script that the
      feature supports.
    </p>
<p>
      Other features are more generic and can apply to several (or
      any) script, and shaping engines are expected to implement
      them. By default, HarfBuzz activates several of these features
      on every text run. They include <code class="literal">abvm</code>,
      <code class="literal">blwm</code>, <code class="literal">ccmp</code>,
      <code class="literal">locl</code>, <code class="literal">mark</code>,
      <code class="literal">mkmk</code>, and <code class="literal">rlig</code>.
    </p>
<p>
      In addition, if the text direction is horizontal, HarfBuzz
      also applies the <code class="literal">calt</code>,
      <code class="literal">clig</code>, <code class="literal">curs</code>,
      <code class="literal">dist</code>, <code class="literal">kern</code>,
      <code class="literal">liga</code> and <code class="literal">rclt</code>, features.
    </p>
<p>
      Additionally, when HarfBuzz encounters a fraction slash
      (<code class="literal">U+2044</code>), it looks backward and forward for decimal
      digits (Unicode General Category = Nd), and enables features
      <code class="literal">numr</code> on the sequence before the fraction slash,
      <code class="literal">dnom</code> on the sequence after the fraction slash,
      and <code class="literal">frac</code> on the whole sequence including the fraction
      slash.
    </p>
<p>
      Some script-specific shaping models
      (see <a class="xref" href="opentype-shaping-models.html" title="OpenType shaping models">the section called “OpenType shaping models”</a>) disable some of the
      features listed above:
    </p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
          Hangul: <code class="literal">calt</code>
	</p></li>
<li class="listitem"><p>
          Indic: <code class="literal">liga</code>
	</p></li>
<li class="listitem"><p>
          Khmer: <code class="literal">liga</code>
	</p></li>
</ul></div>
<p>
      If the text direction is vertical, HarfBuzz applies
      the <code class="literal">vert</code> feature by default.
    </p>
<p>
      Still other features are designed to be purely optional and left
      up to the application or the end user to enable or disable as desired.
    </p>
<p>
      You can adjust the set of features that HarfBuzz applies to a
      buffer by supplying an array of <span class="type">hb_feature_t</span>
      features as the third argument to
      <code class="function">hb_shape()</code>. For a simple case, let's just
      enable the <code class="literal">dlig</code> feature, which turns on any
      "discretionary" ligatures in the font:
    </p>
<pre class="programlisting">
      hb_feature_t userfeatures[1];
      userfeatures[0].tag = HB_TAG('d','l','i','g');
      userfeatures[0].value = 1;
      userfeatures[0].start = HB_FEATURE_GLOBAL_START;
      userfeatures[0].end = HB_FEATURE_GLOBAL_END;
    </pre>
<p>
      <code class="literal">HB_FEATURE_GLOBAL_END</code> and
      <code class="literal">HB_FEATURE_GLOBAL_END</code> are macros we can use
      to indicate that the features will be applied to the entire
      buffer. We could also have used a literal <code class="literal">0</code>
      for the start and a <code class="literal">-1</code> to indicate the end of
      the buffer (or have selected other start and end positions, if needed).
    </p>
<p>
      When we pass the <code class="varname">userfeatures</code> array to
      <code class="function">hb_shape()</code>, any discretionary ligature
      substitutions from our font that match the text in our buffer
      will get performed:
    </p>
<pre class="programlisting">
      hb_shape(font, buf, userfeatures, num_features);
    </pre>
<p>
      Just like we enabled the <code class="literal">dlig</code> feature by
      setting its <em class="parameter"><code>value</code></em> to
      <code class="literal">1</code>, you would disable a feature by setting its
      <em class="parameter"><code>value</code></em> to <code class="literal">0</code>. Some
      features can take other <em class="parameter"><code>value</code></em> settings;
      be sure you read the full specification of each feature tag to
      understand what it does and how to control it.
    </p>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.33.1</div>
</body>
</html>