glyph_imager 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/VERSION +1 -1
- data/glyph_imager.gemspec +1 -1
- data/lib/glyph_imager.rb +8 -4
- data/test/test_glyph_imager.rb +5 -3
- metadata +2 -2
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.13
|
data/glyph_imager.gemspec
CHANGED
data/lib/glyph_imager.rb
CHANGED
@@ -85,7 +85,7 @@ module GlyphImager
|
|
85
85
|
class Imager
|
86
86
|
|
87
87
|
def initialize(opts = {})
|
88
|
-
@options = { :size => "80x80" }.merge(opts)
|
88
|
+
@options = { :size => "80x80", :pointsize_percentage => 100 }.merge(opts)
|
89
89
|
%w[code_point font_path output_dir].each do |k|
|
90
90
|
if @options[k.to_sym].nil?
|
91
91
|
raise ArgumentError, "missing value for :#{k}"
|
@@ -97,15 +97,19 @@ module GlyphImager
|
|
97
97
|
"#{@options[:output_dir]}/#{@options[:code_point]}-#{@options[:size]}.png"
|
98
98
|
end
|
99
99
|
|
100
|
+
def pointsize
|
101
|
+
@options[:size].split("x").last.to_i * @options[:pointsize_percentage] / 100.0
|
102
|
+
end
|
103
|
+
|
100
104
|
def command_string
|
101
105
|
# need to escape apostrophe
|
102
106
|
case @options[:code_point]
|
103
107
|
when "0027"
|
104
|
-
"convert -font #{@options[:font_path]} -size #{@options[:size]} -gravity center label:\\#{[@options[:code_point].hex].pack("U*")} #{output_path}"
|
108
|
+
"convert -font #{@options[:font_path]} -size #{@options[:size]} -gravity center -pointsize #{pointsize} label:\\#{[@options[:code_point].hex].pack("U*")} #{output_path}"
|
105
109
|
when "005C"
|
106
|
-
"convert -font #{@options[:font_path]} -size #{@options[:size]} -gravity center label:'\\#{[@options[:code_point].hex].pack("U*")}' #{output_path}"
|
110
|
+
"convert -font #{@options[:font_path]} -size #{@options[:size]} -gravity center -pointsize #{pointsize} label:'\\#{[@options[:code_point].hex].pack("U*")}' #{output_path}"
|
107
111
|
else
|
108
|
-
"convert -font #{@options[:font_path]} -size #{@options[:size]} -gravity center label:'#{[@options[:code_point].hex].pack("U*")}' #{output_path}"
|
112
|
+
"convert -font #{@options[:font_path]} -size #{@options[:size]} -gravity center -pointsize #{pointsize} label:'#{[@options[:code_point].hex].pack("U*")}' #{output_path}"
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
data/test/test_glyph_imager.rb
CHANGED
@@ -3,8 +3,10 @@ require 'helper'
|
|
3
3
|
class TestGlyphImager < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@
|
6
|
+
@fonts_dir = File.join(File.dirname(__FILE__), 'fonts')
|
7
|
+
@font_path = File.join(@fonts_dir, 'DejaVuSerif.ttf')
|
7
8
|
@font = GlyphImager::FontRecord.new(@font_path)
|
9
|
+
@times = GlyphImager::FontRecord.new(File.join(@fonts_dir, 'other', 'TimesRoman.ttf'))
|
8
10
|
@output_dir = "/tmp"
|
9
11
|
end
|
10
12
|
|
@@ -31,8 +33,8 @@ class TestGlyphImager < Test::Unit::TestCase
|
|
31
33
|
end
|
32
34
|
|
33
35
|
should "return false when glyph is control char" do
|
34
|
-
assert !@
|
35
|
-
assert !@
|
36
|
+
assert !@times.has_glyph_for_unicode_char?("0000")
|
37
|
+
assert !@times.has_glyph_for_unicode_char?("009F")
|
36
38
|
end
|
37
39
|
|
38
40
|
should "return false when glyph doesn't exist for character" do
|