Skip to content
Deepak Jois edited this page Dec 8, 2015 · 7 revisions

You can specify OpenType features to be applied during shaping when calling harfbuzz.shape like this:

harfbuzz.shape(font, 
  buf,
  { 
    script = "latn", 
    lang = "eng", 
    direction = "ltr", 
    features = "feature1,feature2,feature3"
  })

Here, feature1,feature2,feature3 is a list of comma-separated feature strings. The format of the feature strings is given in the sections below.

From Harfbuzz documentation

Here is the Harfbuzz documentation for specifying feature strings, taken from the help output of the hb-shape tool.

    Features can be enabled or disabled, either globally or limited to
    specific character ranges.  The format for specifying feature settings
    follows.  All valid CSS font-feature-settings values other than 'normal'
    and 'inherited' are also accepted, though, not documented below.

    The range indices refer to the positions between Unicode characters,
    unless the --utf8-clusters is provided, in which case range indices
    refer to UTF-8 byte indices. The position before the first character
    is always 0.

    The format is Python-esque.  Here is how it all works:

      Syntax:       Value:    Start:    End:

    Setting value:
      "kern"        1         0         ∞         # Turn feature on
      "+kern"       1         0         ∞         # Turn feature on
      "-kern"       0         0         ∞         # Turn feature off
      "kern=0"      0         0         ∞         # Turn feature off
      "kern=1"      1         0         ∞         # Turn feature on
      "aalt=2"      2         0         ∞         # Choose 2nd alternate

    Setting index:
      "kern[]"      1         0         ∞         # Turn feature on
      "kern[:]"     1         0         ∞         # Turn feature on
      "kern[5:]"    1         5         ∞         # Turn feature on, partial
      "kern[:5]"    1         0         5         # Turn feature on, partial
      "kern[3:5]"   1         3         5         # Turn feature on, range
      "kern[3]"     1         3         3+1       # Turn feature on, single char

    Mixing it all:

      "aalt[3:5]=2" 2         3         5         # Turn 2nd alternate on for range

From CSS Font

As mentioned above “All valid CSS font-feature-settings values other than 'normal' and 'inherited' are also accepted”. Shown below is a sample CSS document containing some examples.

/* 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";
}

References

Clone this wiki locally