chunky_text 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/chunky_text.gemspec +1 -1
- data/chunky_text.rb +33 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a26c4a249e72debe6b641e822e8a8ec208fd959
|
4
|
+
data.tar.gz: 4b57b64b85f70946a9399b791481cea6561787f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ee93e6f9f8a312632cc77eb9c4fab4b65b89bd25f839dcf6c36adee4a03486f11ebc1d457022550277ca7b9e55f6fd82b04e2d1fb8136e36321d0e11d415b94
|
7
|
+
data.tar.gz: 9aa8d8e489f6887f93ef954234ef5c40bfb1f1c9983cc29dee665e75cb910434ab3d72d18e2c0c578be7577ae785224aadbb8a7fb642b9537d67b85e475d8ddb
|
data/chunky_text.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.description = File.read(File.join(File.dirname(__FILE__), 'README.md'))
|
5
5
|
s.license = "MIT"
|
6
6
|
s.requirements= ['chunky_png gem must be installed.']
|
7
|
-
s.version = "0.2.
|
7
|
+
s.version = "0.2.2"
|
8
8
|
s.author = "Marco Bagnaresi"
|
9
9
|
s.email = "info@mbcraft.it"
|
10
10
|
s.homepage = "http://www.mbcraft.it/products/chunky_text.php"
|
data/chunky_text.rb
CHANGED
@@ -3,22 +3,54 @@ require './chunky_text/font_metrics'
|
|
3
3
|
|
4
4
|
module ChunkyText
|
5
5
|
|
6
|
+
=begin rdoc
|
7
|
+
This class is used to write vector text over images. It's the only exposed class.
|
8
|
+
Actually 'default_font' is the only font included.
|
9
|
+
Example :
|
10
|
+
|
11
|
+
img = ChunkyPNG::Image.new(600, 300, ChunkyPNG::Color::WHITE)
|
12
|
+
wr = ChunkyText::Writer.new(img,'default_font')
|
13
|
+
wr.size = 30
|
14
|
+
wr.color = ChunkyPNG::Color::BLACK
|
15
|
+
wr.write("CHUNKY",100,150)
|
16
|
+
wr.write("~TEXT~",130,220)
|
17
|
+
img.save("my_sample.png")
|
18
|
+
|
19
|
+
=end
|
20
|
+
|
6
21
|
class Writer
|
7
22
|
|
8
23
|
attr_reader :scale_factor
|
9
24
|
attr_accessor :color
|
10
25
|
|
26
|
+
=begin rdoc
|
27
|
+
Initializes a writer for the specified image using the specified font name.
|
28
|
+
Params :
|
29
|
+
- img : a chunky_png image
|
30
|
+
- font_name : the name without extension of the font file inside the font directory.
|
31
|
+
=end
|
11
32
|
def initialize(img,font_name)
|
12
33
|
@img = img
|
13
34
|
@font_metrics = ChunkyText::FontMetrics.new(font_name)
|
14
35
|
@color = ChunkyPNG::Color::BLACK
|
15
36
|
@scale_factor = 1.0
|
16
37
|
end
|
17
|
-
|
38
|
+
=begin rdoc
|
39
|
+
Sets the (approximate) size in pixel of the font.
|
40
|
+
Params :
|
41
|
+
- px : integer size in pixels of font height
|
42
|
+
=end
|
18
43
|
def size=(px)
|
19
44
|
@scale_factor = px.to_f/@font_metrics.char_size.to_f
|
20
45
|
end
|
21
46
|
|
47
|
+
=begin rdoc
|
48
|
+
Writes a string of text in position x and y.
|
49
|
+
Params :
|
50
|
+
- text : a string of text to write
|
51
|
+
- x : integer position
|
52
|
+
- y : integer position
|
53
|
+
=end
|
22
54
|
def write(text,x,y)
|
23
55
|
caret_x = x
|
24
56
|
text.chars.each do |ch|
|