Class: Fontisan::Stitcher
- Inherits:
-
Object
- Object
- Fontisan::Stitcher
show all
- Defined in:
- lib/fontisan/stitcher.rb,
lib/fontisan/stitcher/source.rb,
lib/fontisan/stitcher/selector.rb,
lib/fontisan/stitcher/glyph_limit.rb,
lib/fontisan/stitcher/deduplicator.rb,
lib/fontisan/stitcher/selector/gid.rb,
lib/fontisan/stitcher/selector/range.rb,
lib/fontisan/stitcher/glyph_signature.rb,
lib/fontisan/stitcher/selector/codepoints.rb
Overview
Multi-source font stitcher with explicit subfont declaration.
Every set of codepoints is explicitly assigned to a named subfont
via the required into: keyword. The user controls the collection
structure upfront — there are no defaults and no after-the-fact
splitting.
Single-font output: write_to requires a subfont: name.
Collection output: write_collection writes all declared subfonts.
Defined Under Namespace
Modules: GlyphLimit, GlyphSignature, Selector
Classes: Deduplicator, Source
Constant Summary
collapse
- DEFAULT_DEDUPLICATE =
true
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_source(label, font) ⇒ Object
-
#build_target_font(subfont:) ⇒ Object
-
#include_codepoints(codepoints, from:, into:) ⇒ Object
-
#include_gid(donor_gid, from:, into:) ⇒ Object
-
#include_notdef(from:, into:) ⇒ Object
-
#include_range(range, from:, into:) ⇒ Object
-
#initialize(deduplicate: DEFAULT_DEDUPLICATE) ⇒ Stitcher
constructor
A new instance of Stitcher.
-
#set_info(info_hash) ⇒ Object
-
#subfont_names ⇒ Object
-
#write_collection(path, format:) ⇒ Object
-
#write_to(path, format:, subfont:) ⇒ Object
Constructor Details
#initialize(deduplicate: DEFAULT_DEDUPLICATE) ⇒ Stitcher
Returns a new instance of Stitcher.
38
39
40
41
42
43
|
# File 'lib/fontisan/stitcher.rb', line 38
def initialize(deduplicate: DEFAULT_DEDUPLICATE)
@sources = {}
@subfonts = Hash.new { |h, k| h[k] = [] }
@info = nil
@deduplicate = deduplicate
end
|
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
36
37
38
|
# File 'lib/fontisan/stitcher.rb', line 36
def info
@info
end
|
#sources ⇒ Object
Returns the value of attribute sources.
36
37
38
|
# File 'lib/fontisan/stitcher.rb', line 36
def sources
@sources
end
|
#subfonts ⇒ Object
Returns the value of attribute subfonts.
36
37
38
|
# File 'lib/fontisan/stitcher.rb', line 36
def subfonts
@subfonts
end
|
Instance Method Details
#add_source(label, font) ⇒ Object
45
46
47
|
# File 'lib/fontisan/stitcher.rb', line 45
def add_source(label, font)
@sources[label.to_sym] = Source.new(font)
end
|
#build_target_font(subfont:) ⇒ Object
73
74
75
|
# File 'lib/fontisan/stitcher.rb', line 73
def build_target_font(subfont:)
build_target_for(subfont)
end
|
#include_codepoints(codepoints, from:, into:) ⇒ Object
53
54
55
|
# File 'lib/fontisan/stitcher.rb', line 53
def include_codepoints(codepoints, from:, into:)
Selector::Codepoints.new(codepoints).apply(source(from), @subfonts[into])
end
|
#include_gid(donor_gid, from:, into:) ⇒ Object
57
58
59
|
# File 'lib/fontisan/stitcher.rb', line 57
def include_gid(donor_gid, from:, into:)
Selector::Gid.new(donor_gid).apply(source(from), @subfonts[into])
end
|
#include_notdef(from:, into:) ⇒ Object
61
62
63
|
# File 'lib/fontisan/stitcher.rb', line 61
def include_notdef(from:, into:)
include_gid(0, from: from, into: into)
end
|
#include_range(range, from:, into:) ⇒ Object
49
50
51
|
# File 'lib/fontisan/stitcher.rb', line 49
def include_range(range, from:, into:)
Selector::Range.new(range).apply(source(from), @subfonts[into])
end
|
#set_info(info_hash) ⇒ Object
65
66
67
|
# File 'lib/fontisan/stitcher.rb', line 65
def set_info(info_hash)
@info = Ufo::Info.new(info_hash)
end
|
#subfont_names ⇒ Object
69
70
71
|
# File 'lib/fontisan/stitcher.rb', line 69
def subfont_names
@subfonts.keys
end
|
#write_collection(path, format:) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/fontisan/stitcher.rb', line 88
def write_collection(path, format:)
raise ArgumentError, "no subfonts declared" if @subfonts.empty?
compiled = @subfonts.keys.map do |name|
compile_subfont_to_loaded_font(name, format: format)
end
collection_format = collection_format_for(format)
Collection::Builder.new(compiled, format: collection_format,
optimize: true).build_to_file(path)
path
end
|
#write_to(path, format:, subfont:) ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/fontisan/stitcher.rb', line 77
def write_to(path, format:, subfont:)
target = build_target_for(subfont)
GlyphLimit.check!(target.glyphs.size, format: format)
compiler = compiler_for(format)
compiler.new(target).compile(output_path: path)
propagate_cbdt_tables(path) if cbdt_source
path
end
|