Class: Fontisan::Ufo::Compile::TtfCompiler

Inherits:
BaseCompiler show all
Defined in:
lib/fontisan/ufo/compile/ttf_compiler.rb

Overview

UFO → TTF. Same tables as the OTF compiler plus glyf + loca (no CFF). Maxp version 1.0 carries the TrueType metrics.

Before glyf encoding, the TTF-required filters run:

- cubic_to_quadratic (TTF only supports quadratic Beziers)
- reverse_contour_direction (TTF winding convention)

Constant Summary collapse

SFNT_VERSION =
SFNT_VERSION_TRUE_TYPE

Constants inherited from BaseCompiler

BaseCompiler::SFNT_VERSION_OPEN_TYPE, BaseCompiler::SFNT_VERSION_TRUE_TYPE

Instance Attribute Summary

Attributes inherited from BaseCompiler

#font

Instance Method Summary collapse

Methods inherited from BaseCompiler

#build_outline_tables, #initialize, #sfnt_version

Constructor Details

This class inherits a constructor from Fontisan::Ufo::Compile::BaseCompiler

Instance Method Details

#build_tablesHash<String, #to_binary_s>

Returns all TTF tables, not yet written.

Returns:

  • (Hash<String, #to_binary_s>)

    all TTF tables, not yet written



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fontisan/ufo/compile/ttf_compiler.rb', line 16

def build_tables
  glyphs = font.glyphs.values

  # Deep-clone glyphs so filters don't mutate the source UFO.
  filtered = clone_glyphs(glyphs)
  Filters.apply(Filters::TTF_REQUIRED, filtered)

  glyf_loca = GlyfLoca.build(font, glyphs: filtered)
  loca_format = glyf_loca.delete(:loca_format)

  {
    "head" => Head.build(font, glyphs: filtered,
                               loca_format: loca_format || Head::LOCA_FORMAT_LONG),
    "hhea" => Hhea.build(font, glyphs: filtered),
    "maxp" => Maxp.build(font, glyphs: filtered,
                               version: Maxp::VERSION_TRUE_TYPE),
    "OS/2" => Os2.build(font, glyphs: filtered),
    "name" => Name.build(font),
    "post" => Post.build(font),
    "hmtx" => Hmtx.build(font, glyphs: filtered),
    "cmap" => Cmap.build(font, glyphs: filtered),
    "glyf" => glyf_loca["glyf"],
    "loca" => glyf_loca["loca"],
  }
end

#compile(output_path:) ⇒ Object



42
43
44
45
# File 'lib/fontisan/ufo/compile/ttf_compiler.rb', line 42

def compile(output_path:)
  write(build_tables, output_path)
  output_path
end