Class: Ruby2D::Font
- Inherits:
-
Object
- Object
- Ruby2D::Font
- Defined in:
- lib/ruby2d/font.rb
Class Method Summary collapse
-
.all ⇒ Object
List all fonts, names only.
-
.all_paths ⇒ Object
Get all fonts with full file paths.
-
.default ⇒ Object
Get the default font.
-
.directory ⇒ Object
Get the fonts directory for the current platform.
-
.path(font_name) ⇒ Object
Find a font file path from its name.
Class Method Details
.all ⇒ Object
List all fonts, names only
9 10 11 |
# File 'lib/ruby2d/font.rb', line 9 def all all_paths.map { |path| path.split('/').last.chomp('.ttf').downcase }.uniq.sort end |
.all_paths ⇒ Object
Get all fonts with full file paths
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby2d/font.rb', line 19 def all_paths fonts = `find #{directory} -name *.ttf`.split("\n") fonts = fonts.reject do |f| f.downcase.include?('bold') || f.downcase.include?('italic') || f.downcase.include?('oblique') || f.downcase.include?('narrow') || f.downcase.include?('black') end fonts.sort_by { |f| f.downcase.chomp '.ttf' } end |
.default ⇒ Object
Get the default font
32 33 34 35 36 37 38 |
# File 'lib/ruby2d/font.rb', line 32 def default if all.include? 'arial' path 'arial' else all_paths.first end end |
.directory ⇒ Object
Get the fonts directory for the current platform
41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby2d/font.rb', line 41 def directory if `uname`.include? 'Darwin' # macOS "/Library/Fonts" elsif `uname`.include? 'Linux' "/usr/share/fonts/truetype" elsif `uname`.include? 'MINGW' "C:/Windows/Fonts" end end |
.path(font_name) ⇒ Object
Find a font file path from its name
14 15 16 |
# File 'lib/ruby2d/font.rb', line 14 def path(font_name) all_paths.find { |path| path.downcase.include?(font_name) } end |