Class: Fontisan::Ufo::Compile::FeatureWriters::Gdef

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

Overview

GDEF GlyphClassDef — classifies every glyph into one of the four OpenType glyph classes:

1 — Base glyph
2 — Ligature glyph
3 — Combining mark
4 — Glyph spacing variant (e.g. alternate space)

The classification drives how GSUB/GPOS lookups apply. UFO sources carry this in the glyph's lib plist under the public.openTypeCategory key; this writer translates that into the structured form the GDEF builder expects.

Constant Summary collapse

TABLE_TAG =
"GDEF"
CATEGORY_TO_CLASS =

Map UFO public.openTypeCategory values → OpenType glyph class integers. Glyphs whose category isn't listed get class 0 (unclassified — the GDEF ClassDef omits them).

{
  "base" => 1,
  "ligature" => 2,
  "mark" => 3,
  "component" => 3, # UFO treats component as mark for GDEF
  "spacing" => 4,
}.freeze

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:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fontisan/ufo/compile/feature_writers/gdef.rb', line 34

def write
  classifications = {}

  font.glyphs.each_value do |glyph|
    cls = classify(glyph)
    classifications[glyph.name] = cls if cls
  end

  # A GDEF without any classified glyphs is meaningless —
  # return nil so the compiler skips the table.
  return nil if classifications.empty?

  FeatureOutput.new(
    table_tag: TABLE_TAG,
    feature_tag: nil,
    lookup_type: nil,
    data: { classes: classifications },
  )
end