Module: NSWTopo::Font

Extended by:
Font
Included in:
Font
Defined in:
lib/nswtopo/font.rb

Defined Under Namespace

Modules: Chrome

Instance Method Summary collapse

Instance Method Details

#glyph_length(*args) ⇒ Object



50
51
52
53
# File 'lib/nswtopo/font.rb', line 50

def glyph_length(*args)
  self.extend Chrome
  glyph_length *args
end

#in_two(string, attributes) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/nswtopo/font.rb', line 55

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