Class: Fontisan::Ufo::Compile::FeatureWriters::Curs

Inherits:
Base
  • Object
show all
Defined in:
lib/fontisan/ufo/compile/feature_writers/curs.rb

Overview

GPOS Cursive (lookup type 3) — cursive attachment.

Pairs glyphs via their entry and exit anchors for cursive (joining) scripts. UFO convention: a glyph's <name>entry and <name>exit anchors define where it connects to its neighbors.

Pairs every glyph that has at least one entry anchor with every glyph that has the corresponding exit anchor. Multiple entry/exit class names are supported.

Constant Summary collapse

LOOKUP_TYPE =
3
FEATURE_TAG =
"curs"
TABLE_TAG =
"GPOS"

Instance Attribute Summary

Attributes inherited from Base

#font

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Fontisan::Ufo::Compile::FeatureWriters::Base

Instance Method Details

#writeFeatureOutput?

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fontisan/ufo/compile/feature_writers/curs.rb', line 23

def write
  attachments = {}

  entry_glyphs = glyphs_with_anchor(/entry\z/)
  exit_glyphs = glyphs_with_anchor(/exit\z/)

  return nil if entry_glyphs.empty? && exit_glyphs.empty?

  # Cursive attachment: each glyph can be both a "previous"
  # (with exit anchor) and "next" (with entry anchor) in
  # a cursive chain. The GPOS builder handles the
  # cross-references; we emit every glyph with its entry
  # and/or exit anchor positions.
  font.glyphs.each_value do |glyph|
    entry = find_anchor(glyph, /entry\z/)
    exit = find_anchor(glyph, /exit\z/)
    next unless entry || exit

    attachments[glyph.name] = {
      entry: entry && [entry.x, entry.y],
      exit: exit && [exit.x, exit.y],
    }
  end

  return nil if attachments.empty?

  FeatureOutput.new(
    table_tag: TABLE_TAG,
    feature_tag: FEATURE_TAG,
    lookup_type: LOOKUP_TYPE,
    data: { attachments: attachments },
  )
end