Class: SFML::Font
- Inherits:
-
Object
- Object
- SFML::Font
- Defined in:
- lib/sfml/graphics/font.rb
Overview
Constant Summary collapse
- SEARCH_PATHS =
[ "/usr/share/fonts", "/usr/local/share/fonts", "/Library/Fonts", "/System/Library/Fonts", File.("~/Library/Fonts"), "C:/Windows/Fonts", ].freeze
- DEFAULT_PATH =
Path to the font ruby-sfml ships with: DejaVu Sans (Bitstream Vera license, redistributable). See lib/sfml/assets/fonts/DejaVuSans.LICENSE.txt.
File.("../assets/fonts/DejaVuSans.ttf", __dir__).freeze
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.default ⇒ Object
The default font bundled with ruby-sfml.
-
.find(name) ⇒ Object
Look up a font on disk by basename (with or without extension).
- .load(path) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#handle ⇒ Object (readonly)
:nodoc:
59 60 61 |
# File 'lib/sfml/graphics/font.rb', line 59 def handle @handle end |
Class Method Details
.default ⇒ Object
The default font bundled with ruby-sfml. Use this when you don’t care which typeface as long as you can render text — examples, debug HUDs, prototypes. Memoized so subsequent calls return the same Font instance.
34 35 36 |
# File 'lib/sfml/graphics/font.rb', line 34 def self.default @default ||= load(DEFAULT_PATH) end |
.find(name) ⇒ Object
Look up a font on disk by basename (with or without extension). Useful for examples that should “just run” — production code should ship its own font files. Returns nil if nothing is found.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sfml/graphics/font.rb', line 41 def self.find(name) target = name.to_s.downcase.sub(/\.(ttf|otf)\z/, "") SEARCH_PATHS.each do |dir| next unless File.directory?(dir) match = Dir.glob(File.join(dir, "**", "*.{ttf,otf}")).find do |path| File.basename(path).downcase.sub(/\.(ttf|otf)\z/, "") == target end return load(match) if match end nil end |