Module: NSWTopo::Font
- Extended by:
- Font
- Includes:
- Log
- Included in:
- Font
- Defined in:
- lib/nswtopo/font.rb,
lib/nswtopo/font/chrome.rb,
lib/nswtopo/font/generic.rb
Defined Under Namespace
Constant Summary
Constants included from Log
Log::FAILURE, Log::NEUTRAL, Log::SUCCESS, Log::UPDATE
Instance Method Summary collapse
Methods included from Log
#log_abort, #log_neutral, #log_success, #log_update, #log_warn
Instance Method Details
#glyph_length(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nswtopo/font.rb', line 9 def glyph_length(*args) chrome_path = Config["chrome"] case when !defined? PTY self.extend Generic when !chrome_path log_warn "chrome browser not configured - using generic font measurements" self.extend Generic else begin stdout, stderr, status = Open3.capture3 chrome_path, "--version" raise unless status.success? self.extend Chrome rescue Errno::ENOENT, RuntimeError log_warn "couldn't run chrome - using generic font measurements" self.extend Generic end end glyph_length *args end |
#in_two(string, attributes) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nswtopo/font.rb', line 30 def in_two(string, attributes) words = string.split(string[?\n] || string[?/] || ?\s).map(&:strip) (1...words.size).map do |index| [words[0...index].join(?\s), words[index...words.size].join(?\s)] end.map do |lines| lines.map do |line| [line, glyph_length(line, attributes)] end end.min_by do |lines_widths| lines_widths.map(&:last).max end || [[words[0], glyph_length(words[0], attributes)]] end |