Class: Fontico::Emitters::Font
- Inherits:
-
Object
- Object
- Fontico::Emitters::Font
- Defined in:
- lib/fontico/emitters/font.rb
Overview
A TTF for Prawn. Not for the web: at this icon count the sprite is both smaller over the wire and not render-blocking. Prawn reads TTF/OTF via ttfunk and cannot read woff2, so TTF is the right container here.
Instance Method Summary collapse
-
#accepts?(icon) ⇒ Boolean
Glyphs store no colour, so multicolour icons cannot be represented at all.
- #call ⇒ Object
-
#initialize(manifest, build, lock: nil, outliner: nil, output: nil) ⇒ Font
constructor
A new instance of Font.
- #rules_only? ⇒ Boolean
Constructor Details
#initialize(manifest, build, lock: nil, outliner: nil, output: nil) ⇒ Font
Returns a new instance of Font.
9 10 11 12 13 14 15 |
# File 'lib/fontico/emitters/font.rb', line 9 def initialize(manifest, build, lock: nil, outliner: nil, output: nil) @manifest = manifest @build = build @lock = lock @outliner = outliner || Outliner.new @output = output end |
Instance Method Details
#accepts?(icon) ⇒ Boolean
Glyphs store no colour, so multicolour icons cannot be represented at all. They stay in the sprite and the build names each one it dropped.
19 |
# File 'lib/fontico/emitters/font.rb', line 19 def accepts?(icon) = !(@lock&.multicolor?(icon.name) || icon.multicolor?) |
#call ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fontico/emitters/font.rb', line 22 def call unsupported = @build.select { |icon, body| @outliner.strategy_for(icon, body) == :none } @outliner.refuse(unsupported.map(&:first)) if unsupported.any? outlines = @outliner.outlines(@build, size: @manifest.size) glyphs = @build.map do |icon, body| { name: icon.key, codepoint: @lock.codepoint_for(icon.name), svg: document(outlines[icon.name], body) } end result = @outliner.instance_variable_get(:@runner) .run("build_font.mjs", { fontName: "fontico", size: @manifest.size, output: @output, glyphs: glyphs }) if result["empty"]&.any? raise Fontico::Error, <<~MSG #{result["empty"].size} icon(s) produced an empty glyph and would ship invisible: #{result["empty"].join("\n ")} The usual cause is live <text> in the source SVG, which has no outline to convert. Convert text to paths (Path > Object to Path), or remove the icon from the font target. MSG end result end |
#rules_only? ⇒ Boolean
20 |
# File 'lib/fontico/emitters/font.rb', line 20 def rules_only? = false |