summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Black <[email protected]>2016-04-19 22:52:26 -0400
committerTom Black <[email protected]>2016-04-19 22:52:26 -0400
commit3341f29e4e3e6f470534bf5843863138bd3a1778 (patch)
treea3a05c0ce92c3c9e0f175b1694bb2c6f42c6cfc5
parent5f8630124e288c04209092601443f78e0b3bf65a (diff)
downloadruby2d-3341f29e4e3e6f470534bf5843863138bd3a1778.tar.gz
ruby2d-3341f29e4e3e6f470534bf5843863138bd3a1778.zip
Fixing font file path and error checking
-rw-r--r--lib/ruby2d/text.rb27
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb
index 2dd36e9..93c2862 100644
--- a/lib/ruby2d/text.rb
+++ b/lib/ruby2d/text.rb
@@ -5,20 +5,17 @@ module Ruby2D
attr_accessor :x, :y, :size, :text
- def initialize(x=0, y=0, size=20, text="Hello World!", font="Arial", c="white")
- if font.include? '.'
- unless File.exists? font
- raise Error, "Cannot find font file!"
- else
- @font = font
- end
+ def initialize(x=0, y=0, size=20, msg="Hello World!", font="Arial", c="white")
+
+ if File.exists? font
+ @font = font
else
@font = resolve_path(font)
end
@type_id = 4
@x, @y, @size = x, y, size
- @text, @color = text, c
+ @text, @color = msg, c
update_color(c)
if defined? Ruby2D::DSL
@@ -44,14 +41,18 @@ module Ruby2D
private
def resolve_path(font)
- # TODO: Consider CSS names, like 'serif', 'san-serif', 'monospace'
if RUBY_PLATFORM =~ /darwin/
font_path = "/Library/Fonts/#{font}.ttf"
- unless File.exists? font_path
- raise Error, "Cannot find system font!"
- end
+ else
+ # Linux
+ font_path = "/usr/share/fonts/truetype/#{font}.ttf"
+ end
+
+ unless File.exists? font_path
+ raise Error, "Cannot find system font"
+ else
+ font_path
end
- font_path
end
def update_color(c)