Class: Ucode::Glyphs::LastResort::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/glyphs/last_resort/source.rb

Overview

Locates the Last Resort Font UFO source on disk.

Resolution order (first match wins):

1. Explicit `root:` argument.
2. `UCODE_LAST_RESORT_FONT_ROOT` environment variable.
3. `Ucode::Config#last_resort_font_root` (if configured).
4. Conventional sibling-of-repo path `../../external/unicode/
   last-resort-font` relative to the gem root.

The UFO must contain:

* `cmap-f13.ttx` — Format 13 cmap (cp → glyph name).
* `font.ufo/glyphs/contents.plist` — glyph name → .glif file.
* `font.ufo/glyphs/*.glif` — outline files.

If any required artifact is missing, the constructor raises LastResortMissingError with a ‘context:` payload listing the resolved root and which artifact is absent. The CLI catches this to print a friendly “see README for setup” message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: nil, env: ENV, gem_root: nil) ⇒ Source

Returns a new instance of Source.

Parameters:

  • root (String, Pathname, nil) (defaults to: nil)

    explicit UFO root

  • env (Hash{String=>String}) (defaults to: ENV)

    env var source (defaults to ENV)

  • gem_root (String, Pathname, nil) (defaults to: nil)

    gem root for the conventional fallback (defaults to the directory holding ‘lib/ucode`); injectable for tests

Raises:



50
51
52
53
# File 'lib/ucode/glyphs/last_resort/source.rb', line 50

def initialize(root: nil, env: ENV, gem_root: nil)
  @root = resolve_root(root, env, gem_root)
  validate!
end

Instance Attribute Details

#cmap_pathObject (readonly)

Returns the value of attribute cmap_path.



31
32
33
# File 'lib/ucode/glyphs/last_resort/source.rb', line 31

def cmap_path
  @cmap_path
end

#contents_pathObject (readonly)

Returns the value of attribute contents_path.



31
32
33
# File 'lib/ucode/glyphs/last_resort/source.rb', line 31

def contents_path
  @contents_path
end

#glyphs_dirObject (readonly)

Returns the value of attribute glyphs_dir.



31
32
33
# File 'lib/ucode/glyphs/last_resort/source.rb', line 31

def glyphs_dir
  @glyphs_dir
end

#rootObject (readonly)

Returns the value of attribute root.



31
32
33
# File 'lib/ucode/glyphs/last_resort/source.rb', line 31

def root
  @root
end

Instance Method Details

#available?Boolean

Returns true if all required artifacts are present.

Returns:

  • (Boolean)

    true if all required artifacts are present



56
57
58
59
60
61
62
# File 'lib/ucode/glyphs/last_resort/source.rb', line 56

def available?
  [
    @cmap_path,
    @glyphs_dir,
    @contents_path,
  ].all?(&:exist?)
end

#glif_path(basename) ⇒ Pathname

Path to a specific ‘.glif` file by basename. Does NOT verify the file exists; callers resolve via Contents first.

Parameters:

  • basename (String)

    e.g. “lastresortlatin.glif”

Returns:

  • (Pathname)


69
70
71
# File 'lib/ucode/glyphs/last_resort/source.rb', line 69

def glif_path(basename)
  @glyphs_dir.join(basename)
end