chunky_text 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7c23bd5bbca025ed0245bb2f38689ff6b2878b9
4
- data.tar.gz: dd39cffeae219256779d5fcf877bdb091758e83c
3
+ metadata.gz: 0b79850aa417f82c54d8d08109a14452f9132422
4
+ data.tar.gz: 18b2879ef519f4319d4f967df2c4a234bc2f5c11
5
5
  SHA512:
6
- metadata.gz: 28eb14433896d1aa1041494332e4c8bd2edc937459018ae528704c63b2be9962fcc2f31145123a6442be43b39d9e7c47cb1d652607b39a161ca426397db2ff87
7
- data.tar.gz: 8465b104d3095f363c4ba8d49bea6f62992b54a8c518723c64a45cc2bec31c3ddf4c447669818efd430dd6c3767c04029b2e49fd8389e8b49e08e44579e05b10
6
+ metadata.gz: 25cab87599347cf8ac9227cc9a36d5311fb4556540fd4375bb1c535d0698f3e1f77c5da0573e3e2b8bc52eb5664991b806eb417cfae858f600e0b6f4b543136f
7
+ data.tar.gz: 8767d8c300e94fecfe6c69aa7d5b0f66a4db635bd1c74f745087eb621dde1d0a89ae0ed74c5cc0fc0bb44a885641d257ce46642f6e84d7301d07fca84d5904e7
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'))
5
5
  s.license = "MIT"
6
6
  s.requirements= ['chunky_png gem must be installed.']
7
- s.version = "0.2.5"
7
+ s.version = "0.2.6"
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
@@ -1,6 +1,14 @@
1
1
 
2
2
  require './chunky_text/font_metrics'
3
3
 
4
+ =begin rdoc
5
+ This module contains everything about chunky_text.
6
+
7
+ The only exposed class is ChunkyText::Writer .
8
+
9
+ See ChunkyText::Writer for more documentation and examples.
10
+ =end
11
+
4
12
  module ChunkyText
5
13
 
6
14
  =begin rdoc
@@ -8,12 +16,19 @@ module ChunkyText
8
16
  Actually 'default_font' is the only font included.
9
17
  Example :
10
18
 
19
+
11
20
  img = ChunkyPNG::Image.new(600, 300, ChunkyPNG::Color::WHITE)
21
+
12
22
  wr = ChunkyText::Writer.new(img,'default_font')
23
+
13
24
  wr.size = 30
14
- wr.color = ChunkyPNG::Color::BLACK
25
+
26
+ wr.color = ChunkyPNG::Color::BLACK
27
+
15
28
  wr.write("CHUNKY",100,150)
29
+
16
30
  wr.write("~TEXT~",130,220)
31
+
17
32
  img.save("my_sample.png")
18
33
 
19
34
  =end
data/chunky_text.rb~ ADDED
@@ -0,0 +1,62 @@
1
+
2
+ require './chunky_text/font_metrics'
3
+
4
+ module ChunkyText
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
+
21
+ class Writer
22
+
23
+ attr_reader :scale_factor
24
+ attr_accessor :color
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
32
+ def initialize(img,font_name)
33
+ @img = img
34
+ @font_metrics = ChunkyText::FontMetrics.new(font_name)
35
+ @color = ChunkyPNG::Color::BLACK
36
+ @scale_factor = 1.0
37
+ end
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
43
+ def size=(px)
44
+ @scale_factor = px.to_f/@font_metrics.char_size.to_f
45
+ end
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
54
+ def write(text,x,y)
55
+ caret_x = x
56
+ text.chars.each do |ch|
57
+ caret_x+= @font_metrics.write_char(@img,caret_x,y,ch,@scale_factor,@color) + (@font_metrics.char_spacing*@scale_factor)
58
+ end
59
+ end
60
+ end
61
+
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chunky_text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Bagnaresi
@@ -70,6 +70,7 @@ files:
70
70
  - README
71
71
  - chunky_text.gemspec
72
72
  - chunky_text.rb
73
+ - chunky_text.rb~
73
74
  - font/default_font.rb
74
75
  - font/default_font.rb~
75
76
  - font_metrics.rb