Class: Fontisan::Stitcher::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/fontisan/stitcher/source.rb

Overview

Wraps a source font (UFO or loaded TTF/OTF) behind a single extraction API used by the selectors.

For UFO sources, glyphs are accessed by name directly. For TTF or OTF sources, the source is lazily converted to a UFO::Font via Ufo::Convert::FromBinData on first glyph access, then cached. This is O(n) in donor glyph count but amortized across all codepoint extractions from that donor.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(font) ⇒ Source

Returns a new instance of Source.



16
17
18
19
# File 'lib/fontisan/stitcher/source.rb', line 16

def initialize(font)
  @font = font
  @ufo_cache = nil
end

Instance Attribute Details

#fontObject (readonly)

Returns the value of attribute font.



14
15
16
# File 'lib/fontisan/stitcher/source.rb', line 14

def font
  @font
end

Instance Method Details

#formatSymbol

Returns :ufo, :ttf, :otf.

Returns:

  • (Symbol)

    :ufo, :ttf, :otf



22
23
24
25
26
27
28
29
# File 'lib/fontisan/stitcher/source.rb', line 22

def format
  case @font
  when Fontisan::Ufo::Font then :ufo
  when Fontisan::TrueTypeFont then :ttf
  when Fontisan::OpenTypeFont then :otf
  else :unknown
  end
end

#gid_for_codepoint(codepoint) ⇒ Integer?

Find the gid for a Unicode codepoint in this source.

Parameters:

  • codepoint (Integer)

Returns:

  • (Integer, nil)


34
35
36
37
38
39
# File 'lib/fontisan/stitcher/source.rb', line 34

def gid_for_codepoint(codepoint)
  case @font
  when Fontisan::Ufo::Font then ufo_gid_for(codepoint)
  else bin_data_gid_for(codepoint)
  end
end

#glyph_for_gid(gid) ⇒ Fontisan::Ufo::Glyph?

Extract a glyph by gid.

Parameters:

  • gid (Integer)

Returns:



44
45
46
47
48
49
# File 'lib/fontisan/stitcher/source.rb', line 44

def glyph_for_gid(gid)
  case @font
  when Fontisan::Ufo::Font then ufo_glyph_at(gid)
  else converted_ufo_glyph_at(gid)
  end
end