chunky_text 0.1.4 → 0.2.0

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: 3f050988611cd5e7a1c74aeb89a3b18921637cb9
4
- data.tar.gz: bbf9d94e12ee97af725728b0c4614a032418e2ec
3
+ metadata.gz: c4ad153468ac1a9687b8abd358a23be88c960a14
4
+ data.tar.gz: dd2348104e70d86d33face8870eaa319b591ba02
5
5
  SHA512:
6
- metadata.gz: 16a2bd601f20e9b9e188663e0ee28759a2181c504ef16462e79b9425636d1781caabca5480704b906eaae150cdd00ba873518de4a74145778f37c63b94b3664b
7
- data.tar.gz: 39b4f1f88fc07fb5969eacafa133352d1535c44e3d091aebee9513be545b74d397e6577486b014e55a92162857ed8e8f9ee9c93ee8e0b463df50224f04936659
6
+ metadata.gz: ac5fed152a6ab87ef1776812a7174ad699195cacc5f811c394bb773c574ac776b4e8a12ca3b99aaef7561545ee9f31733d6795dd4976dd112153bb125531bc40
7
+ data.tar.gz: 2e039e339b14486c432635cb090173285667262657417d60b0f43e155a6171bbedbc6f9f2ec21f8598bc5e2bb52848866a2e86b4985f51ba5b105938b180699a
data/README.md CHANGED
@@ -1,9 +1,14 @@
1
- ==== chunky_text : a gem for writing vector text using chunky_png ====
1
+ chunky_text is a gem for writing vector text over png images (depends on chunky_png).
2
2
 
3
3
  This library is useful for :
4
4
 
5
5
  - Writing vector text on png images (annotations)
6
6
 
7
+ FEATURES :
8
+
9
+ - Write a single line of text of any size and color.
10
+ - Accented italian/english chars, uppercase and lowercase, special charactes.
11
+
7
12
 
8
13
  I hope it can be useful. I'll add some more useful features in my spare time.
9
14
 
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.1.4"
7
+ s.version = "0.2.0"
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
@@ -4,16 +4,25 @@ require './chunky_text/font_metrics'
4
4
  module ChunkyText
5
5
 
6
6
  class Writer
7
+
8
+ attr_reader :scale_factor
9
+ attr_accessor :color
7
10
 
8
11
  def initialize(img,font_name)
9
12
  @img = img
10
13
  @font_metrics = ChunkyText::FontMetrics.new(font_name)
14
+ @color = ChunkyPNG::Color::BLACK
15
+ @scale_factor = 1.0
16
+ end
17
+
18
+ def size=(px)
19
+ @scale_factor = px.to_f/@font_metrics.char_size.to_f
11
20
  end
12
21
 
13
- def write(text,x,y,char_spacing,color)
22
+ def write(text,x,y)
14
23
  caret_x = x
15
24
  text.chars.each do |ch|
16
- caret_x+= @font_metrics.write_char(@img,caret_x,y,ch,color) + char_spacing
25
+ caret_x+= @font_metrics.write_char(@img,caret_x,y,ch,@scale_factor,@color) + (@font_metrics.char_spacing*@scale_factor)
17
26
  end
18
27
  end
19
28
  end
data/chunky_text.rb~ ADDED
@@ -0,0 +1,21 @@
1
+
2
+ require './chunky_text/font_metrics'
3
+
4
+ module ChunkyText
5
+
6
+ class Writer
7
+
8
+ def initialize(img,font_name)
9
+ @img = img
10
+ @font_metrics = ChunkyText::FontMetrics.new(font_name)
11
+ end
12
+
13
+ def write(text,x,y,char_spacing,color)
14
+ caret_x = x
15
+ text.chars.each do |ch|
16
+ caret_x+= @font_metrics.write_char(@img,caret_x,y,ch,color) + char_spacing
17
+ end
18
+ end
19
+ end
20
+
21
+ end
data/font/default_font.rb CHANGED
@@ -3,12 +3,16 @@ module ChunkyText::Font
3
3
 
4
4
  class DefaultFont
5
5
 
6
+ DEFAULT_FONT_SIZE = 60.0
7
+
6
8
  DESCRIPTION = "Default font provided with chunky_text.";
7
9
 
8
- MIN_WIDTH = 10
9
- MAX_WIDTH = 100
10
- MIN_HEIGHT = 10
11
- MAX_HEIGHT = 100
10
+ DEFAULT_CHAR_SPACING = 10.0
11
+
12
+ MIN_WIDTH = 10.0
13
+ MAX_WIDTH = 100.0
14
+ MIN_HEIGHT = 10.0
15
+ MAX_HEIGHT = 100.0
12
16
 
13
17
  FONT_DATA = {
14
18
  '1' => [[[81.0,81.0],[23.0,81.0],],[[52.0,82.0],[50.0,23.0],[22.0,43.0],],],
@@ -0,0 +1,132 @@
1
+
2
+ module ChunkyText::Font
3
+
4
+ class DefaultFont
5
+
6
+ DESCRIPTION = "Default font provided with chunky_text.";
7
+
8
+ MIN_WIDTH = 10
9
+ MAX_WIDTH = 100
10
+ MIN_HEIGHT = 10
11
+ MAX_HEIGHT = 100
12
+
13
+ FONT_DATA = {
14
+ '1' => [[[81.0,81.0],[23.0,81.0],],[[52.0,82.0],[50.0,23.0],[22.0,43.0],],],
15
+ '2' => [[[81.0,81.0],[21.0,81.0],[63.0,57.0],[78.0,42.0],[79.0,31.0],[64.0,23.0],[42.0,22.0],[23.0,32.0],],],
16
+ '3' => [[[39.0,34.0],[47.0,28.0],[56.0,24.0],[68.0,24.0],[78.0,33.0],[79.0,41.0],[76.0,47.0],[66.0,52.0],[57.0,52.0],[67.0,57.0],[73.0,66.0],[73.0,72.0],[69.0,78.0],[60.0,80.0],[47.0,80.0],[38.0,71.0],],],
17
+ '4' => [[[28.0,23.0],[28.0,74.0],[80.0,72.0],],[[51.0,88.0],[54.0,58.0],],],
18
+ '5' => [[[78.0,24.0],[25.0,23.0],[23.0,42.0],[48.0,45.0],[67.0,54.0],[71.0,67.0],[64.0,77.0],[53.0,81.0],[25.0,80.0],],],
19
+ '6' => [[[68.0,23.0],[44.0,26.0],[24.0,37.0],[22.0,54.0],[27.0,72.0],[36.0,81.0],[49.0,81.0],[60.0,81.0],[69.0,74.0],[75.0,62.0],[63.0,51.0],[44.0,47.0],[30.0,56.0],[26.0,62.0],],],
20
+ '7' => [[[36.0,80.0],[78.0,24.0],[28.0,28.0],],[[44.0,51.0],[71.0,55.0],],],
21
+ '8' => [[[50.0,50.0],[37.0,41.0],[28.0,34.0],[36.0,25.0],[51.0,23.0],[65.0,30.0],[71.0,40.0],[50.0,53.0],[31.0,71.0],[34.0,82.0],[46.0,82.0],[59.0,82.0],[69.0,77.0],[67.0,66.0],[53.0,55.0],],],
22
+ '9' => [[[59.0,50.0],[51.0,52.0],[35.0,50.0],[29.0,40.0],[34.0,27.0],[45.0,22.0],[61.0,25.0],[68.0,37.0],[66.0,52.0],[61.0,60.0],[54.0,73.0],[46.0,78.0],[34.0,78.0],[25.0,65.0],],],
23
+ '0' => [[[51.0,82.0],[44.0,79.0],[35.0,74.0],[24.0,65.0],[20.0,53.0],[23.0,39.0],[30.0,30.0],[42.0,24.0],[52.0,22.0],[64.0,26.0],[75.0,34.0],[78.0,46.0],[76.0,59.0],[72.0,70.0],[67.0,78.0],[53.0,83.0],],],
24
+ 'a' => [[[50.0,81.0],[42.0,80.0],[35.0,73.0],[37.0,68.0],[42.0,63.0],[49.0,60.0],[56.0,64.0],[61.0,72.0],[57.0,78.0],[51.0,81.0],],[[36.0,48.0],[41.0,46.0],[51.0,42.0],[57.0,47.0],[62.0,63.0],[62.0,70.0],[64.0,77.0],[69.0,79.0],[72.0,77.0],],[[211.0,181.0],],],
25
+ 'b' => [[[40.0,22.0],[41.0,82.0],],[[42.0,50.0],[53.0,50.0],[60.0,54.0],[64.0,68.0],[55.0,79.0],[41.0,82.0],],[],],
26
+ 'c' => [[[58.0,43.0],[50.0,42.0],[38.0,51.0],[36.0,57.0],[37.0,67.0],[39.0,73.0],[45.0,78.0],[60.0,79.0],],],
27
+ 'd' => [[[59.0,82.0],[58.0,21.0],],[[59.0,81.0],[50.0,79.0],[46.0,78.0],[42.0,76.0],[39.0,70.0],[39.0,61.0],[41.0,57.0],[47.0,55.0],[54.0,55.0],[58.0,55.0],],],
28
+ 'e' => [[[39.0,61.0],[64.0,61.0],[65.0,59.0],[63.0,55.0],[61.0,52.0],[54.0,46.0],[44.0,46.0],[41.0,52.0],[37.0,60.0],[38.0,69.0],[43.0,76.0],[47.0,77.0],[55.0,78.0],[60.0,78.0],[63.0,74.0],],],
29
+ 'f' => [[[42.0,82.0],[43.0,75.0],[45.0,69.0],[45.0,61.0],[45.0,53.0],[45.0,44.0],[46.0,34.0],[47.0,25.0],[53.0,21.0],[60.0,24.0],],[[39.0,52.0],[43.0,56.0],[52.0,53.0],],[],],
30
+ 'g' => [[[62.0,64.0],[61.0,70.0],[55.0,78.0],[50.0,81.0],[46.0,81.0],[42.0,77.0],[37.0,65.0],[39.0,57.0],[47.0,52.0],[54.0,53.0],[61.0,60.0],[64.0,67.0],],[[63.0,52.0],[63.0,59.0],[63.0,66.0],[63.0,76.0],[63.0,87.0],[62.0,91.0],[56.0,97.0],[45.0,97.0],[40.0,94.0],[38.0,91.0],],],
31
+ 'h' => [[[43.0,80.0],[43.0,22.0],],[[45.0,55.0],[50.0,57.0],[59.0,57.0],[64.0,62.0],[65.0,71.0],[65.0,80.0],],[],],
32
+ 'i' => [[[43.0,82.0],[57.0,82.0],],[[50.0,84.0],[50.0,52.0],],[[44.0,55.0],[57.0,54.0],],[[54.0,44.0],[50.0,43.0],[49.0,43.0],[47.0,40.0],[50.0,37.0],[54.0,38.0],[55.0,42.0],],[],],
33
+ 'j' => [[[54.0,49.0],[68.0,51.0],],[[62.0,52.0],[62.0,59.0],[60.0,67.0],[58.0,77.0],[55.0,82.0],[50.0,87.0],[43.0,92.0],[37.0,90.0],],[[63.0,43.0],[60.0,41.0],[59.0,37.0],[63.0,38.0],[64.0,41.0],],],
34
+ 'k' => [[[42.0,81.0],[42.0,44.0],],[[44.0,62.0],[55.0,50.0],],[[44.0,62.0],[60.0,80.0],],],
35
+ 'l' => [[[54.0,36.0],[54.0,73.0],[56.0,79.0],[61.0,81.0],],],
36
+ 'm' => [[[35.0,81.0],[35.0,45.0],],[[36.0,56.0],[41.0,51.0],[51.0,49.0],[54.0,56.0],[54.0,69.0],[55.0,80.0],],[[55.0,56.0],[62.0,52.0],[69.0,52.0],[76.0,60.0],[76.0,80.0],],[],],
37
+ 'n' => [[[40.0,81.0],[39.0,44.0],],[[40.0,57.0],[47.0,54.0],[54.0,51.0],[63.0,57.0],[66.0,65.0],[66.0,80.0],],],
38
+ 'o' => [[[49.0,80.0],[45.0,80.0],[38.0,74.0],[34.0,71.0],[32.0,65.0],[34.0,58.0],[41.0,55.0],[50.0,54.0],[57.0,56.0],[64.0,67.0],[63.0,72.0],[57.0,80.0],[48.0,81.0],],],
39
+ 'p' => [[[42.0,99.0],[42.0,44.0],],[[43.0,51.0],[51.0,51.0],[62.0,51.0],[68.0,58.0],[69.0,66.0],[65.0,73.0],[56.0,79.0],[42.0,79.0],],],
40
+ 'q' => [[[61.0,47.0],[61.0,98.0],],[[61.0,53.0],[49.0,52.0],[40.0,55.0],[36.0,63.0],[37.0,71.0],[42.0,76.0],[46.0,79.0],[61.0,81.0],],],
41
+ 'r' => [[[38.0,80.0],[37.0,43.0],],[[38.0,52.0],[45.0,48.0],[55.0,48.0],[62.0,51.0],[65.0,57.0],],],
42
+ 's' => [[[62.0,51.0],[58.0,48.0],[50.0,44.0],[42.0,43.0],[37.0,48.0],[36.0,56.0],[39.0,61.0],[46.0,64.0],[50.0,65.0],[56.0,66.0],[60.0,77.0],[52.0,81.0],[44.0,81.0],[35.0,75.0],],],
43
+ 't' => [[[42.0,32.0],[42.0,38.0],[42.0,49.0],[42.0,66.0],[46.0,75.0],[52.0,79.0],[60.0,80.0],[63.0,75.0],],[[37.0,43.0],[49.0,43.0],],],
44
+ 'u' => [[[30.0,41.0],[32.0,52.0],[33.0,61.0],[36.0,75.0],[42.0,78.0],[50.0,80.0],[62.0,77.0],[63.0,71.0],[64.0,60.0],[64.0,51.0],[67.0,43.0],[68.0,81.0],],],
45
+ 'v' => [[[31.0,44.0],[49.0,80.0],[64.0,45.0],],],
46
+ 'w' => [[[26.0,45.0],[44.0,79.0],[58.0,46.0],],[[41.0,48.0],[63.0,79.0],[76.0,50.0],],],
47
+ 'x' => [[[35.0,82.0],[65.0,46.0],],[[35.0,47.0],[64.0,82.0],],],
48
+ 'y' => [[[37.0,98.0],[45.0,99.0],[54.0,97.0],[57.0,92.0],[61.0,84.0],[64.0,71.0],[66.0,56.0],[69.0,44.0],],[[63.0,74.0],[53.0,73.0],[40.0,55.0],[38.0,49.0],],],
49
+ 'z' => [[[34.0,44.0],[68.0,45.0],[38.0,81.0],[66.0,81.0],],[[47.0,61.0],[61.0,63.0],],],
50
+ 'A' => [[[21.0,81.0],[50.0,22.0],[80.0,82.0],],[[37.0,54.0],[66.0,54.0],],],
51
+ 'B' => [[[24.0,81.0],[26.0,22.0],[49.0,22.0],[67.0,31.0],[70.0,43.0],[66.0,52.0],[28.0,53.0],[60.0,56.0],[68.0,63.0],[69.0,74.0],[64.0,82.0],[25.0,83.0],],],
52
+ 'C' => [[[69.0,31.0],[57.0,23.0],[33.0,22.0],[25.0,32.0],[21.0,46.0],[21.0,70.0],[32.0,77.0],[44.0,82.0],[58.0,80.0],[69.0,68.0],],],
53
+ 'D' => [[[26.0,81.0],[27.0,23.0],[47.0,24.0],[65.0,34.0],[71.0,47.0],[70.0,57.0],[65.0,70.0],[52.0,79.0],[28.0,81.0],],],
54
+ 'E' => [[[74.0,23.0],[27.0,22.0],[30.0,81.0],[72.0,82.0],],[[30.0,54.0],[47.0,54.0],],],
55
+ 'F' => [[[30.0,81.0],[29.0,23.0],[69.0,24.0],],[[31.0,51.0],[45.0,51.0],],],
56
+ 'G' => [[[67.0,28.0],[49.0,22.0],[30.0,23.0],[22.0,38.0],[21.0,51.0],[24.0,71.0],[36.0,78.0],[47.0,81.0],[61.0,79.0],[64.0,70.0],[63.0,58.0],[43.0,60.0],],],
57
+ 'H' => [[[26.0,81.0],[27.0,22.0],],[[73.0,82.0],[71.0,22.0],],[[28.0,51.0],[73.0,52.0],],],
58
+ 'I' => [[[38.0,22.0],[60.0,22.0],],[[42.0,82.0],[56.0,82.0],],[[50.0,84.0],[49.0,24.0],],],
59
+ 'J' => [[[31.0,23.0],[69.0,22.0],],[[51.0,24.0],[50.0,65.0],[46.0,74.0],[37.0,80.0],[27.0,74.0],[20.0,61.0],],],
60
+ 'K' => [[[28.0,82.0],[29.0,21.0],],[[29.0,54.0],[58.0,25.0],],[[30.0,53.0],[61.0,82.0],],],
61
+ 'L' => [[[27.0,23.0],[26.0,82.0],[75.0,83.0],],],
62
+ 'M' => [[[22.0,82.0],[22.0,22.0],[50.0,44.0],[79.0,23.0],[80.0,82.0],],],
63
+ 'N' => [[[26.0,82.0],[25.0,21.0],[73.0,81.0],[73.0,24.0],],],
64
+ 'O' => [[[45.0,82.0],[34.0,76.0],[22.0,60.0],[22.0,36.0],[36.0,22.0],[52.0,21.0],[66.0,25.0],[77.0,39.0],[80.0,51.0],[79.0,66.0],[72.0,79.0],[58.0,84.0],[46.0,83.0],],],
65
+ 'P' => [[[28.0,81.0],[28.0,23.0],[53.0,25.0],[68.0,33.0],[71.0,44.0],[60.0,50.0],[47.0,54.0],[29.0,54.0],],],
66
+ 'Q' => [[[80.0,53.0],[77.0,65.0],[63.0,73.0],[47.0,80.0],[35.0,80.0],[28.0,72.0],[22.0,57.0],[21.0,43.0],[26.0,32.0],[46.0,25.0],[63.0,23.0],[70.0,32.0],[79.0,51.0],],[[75.0,80.0],[60.0,62.0],],],
67
+ 'R' => [[[26.0,81.0],[26.0,21.0],[57.0,23.0],[69.0,34.0],[70.0,44.0],[64.0,54.0],[28.0,56.0],[67.0,81.0],],],
68
+ 'S' => [[[70.0,22.0],[33.0,24.0],[24.0,35.0],[24.0,43.0],[32.0,50.0],[45.0,52.0],[59.0,53.0],[69.0,61.0],[74.0,70.0],[68.0,79.0],[53.0,82.0],[24.0,82.0],],],
69
+ 'T' => [[[50.0,21.0],[53.0,81.0],],[[22.0,23.0],[80.0,23.0],],],
70
+ 'U' => [[[22.0,23.0],[22.0,61.0],[31.0,74.0],[43.0,79.0],[57.0,81.0],[69.0,77.0],[76.0,69.0],[79.0,60.0],[79.0,23.0],],],
71
+ 'V' => [[[21.0,21.0],[52.0,81.0],[80.0,23.0],],],
72
+ 'W' => [[[21.0,20.0],[39.0,80.0],[60.0,22.0],],[[40.0,23.0],[61.0,80.0],[79.0,23.0],],],
73
+ 'X' => [[[25.0,21.0],[75.0,81.0],],[[30.0,81.0],[73.0,22.0],],],
74
+ 'Y' => [[[27.0,82.0],[75.0,22.0],],[[55.0,50.0],[25.0,21.0],],],
75
+ 'Z' => [[[24.0,21.0],[78.0,22.0],[27.0,81.0],[76.0,81.0],],],
76
+ '!' => [[[49.0,23.0],[51.0,66.0],],[[48.0,80.0],[56.0,75.0],],[[56.0,80.0],[49.0,75.0],],],
77
+ '"' => [[[34.0,23.0],[35.0,39.0],[43.0,24.0],],[[55.0,24.0],[55.0,37.0],[65.0,23.0],],],
78
+ '£' => [[[66.0,24.0],[42.0,24.0],[34.0,31.0],[34.0,72.0],[27.0,81.0],[70.0,81.0],],[[28.0,51.0],[49.0,52.0],],],
79
+ '$' => [[[66.0,29.0],[56.0,24.0],[41.0,21.0],[31.0,27.0],[25.0,38.0],[26.0,48.0],[35.0,52.0],[45.0,52.0],[55.0,54.0],[63.0,60.0],[63.0,65.0],[62.0,73.0],[51.0,78.0],[41.0,80.0],[30.0,81.0],[22.0,74.0],],[[41.0,85.0],[38.0,20.0],],[[48.0,84.0],[47.0,20.0],],],
80
+ '%' => [[[24.0,81.0],[75.0,21.0],],[[42.0,37.0],[34.0,37.0],[27.0,34.0],[27.0,27.0],[35.0,22.0],[42.0,25.0],[46.0,33.0],[42.0,38.0],],[[65.0,76.0],[54.0,77.0],[51.0,70.0],[55.0,63.0],[63.0,60.0],[68.0,65.0],[70.0,70.0],[66.0,76.0],],],
81
+ '&' => [[[66.0,75.0],[35.0,42.0],[30.0,30.0],[37.0,19.0],[54.0,21.0],[62.0,27.0],[58.0,39.0],[50.0,48.0],[31.0,60.0],[24.0,70.0],[30.0,78.0],[47.0,81.0],[56.0,79.0],[68.0,57.0],],],
82
+ '/' => [[[27.0,80.0],[70.0,22.0],],],
83
+ '(' => [[[57.0,19.0],[43.0,26.0],[36.0,35.0],[29.0,47.0],[29.0,59.0],[36.0,71.0],[45.0,77.0],[58.0,85.0],],],
84
+ ')' => [[[36.0,16.0],[48.0,26.0],[57.0,31.0],[63.0,54.0],[59.0,65.0],[53.0,76.0],[38.0,90.0],],],
85
+ '=' => [[[21.0,39.0],[80.0,39.0],],[[22.0,57.0],[80.0,58.0],],],
86
+ '?' => [[[45.0,81.0],[53.0,76.0],],[[53.0,84.0],[45.0,74.0],],[[50.0,68.0],[49.0,61.0],[51.0,57.0],[59.0,50.0],[65.0,44.0],[65.0,36.0],[58.0,26.0],[53.0,22.0],[40.0,22.0],[33.0,28.0],[31.0,33.0],[34.0,38.0],[38.0,40.0],],],
87
+ '\'' => [[[49.0,22.0],[49.0,40.0],[44.0,23.0],],],
88
+ '^' => [[[34.0,36.0],[51.0,23.0],[67.0,38.0],],],
89
+ 'ì' => [[[49.0,81.0],[47.0,37.0],],[[52.0,30.0],[41.0,15.0],],],
90
+ '>' => [[[23.0,25.0],[81.0,50.0],[23.0,64.0],],],
91
+ '<' => [[[80.0,29.0],[21.0,49.0],[80.0,63.0],],],
92
+ ';' => [[[46.0,34.0],[40.0,29.0],[40.0,21.0],[47.0,20.0],[53.0,23.0],[54.0,29.0],[47.0,34.0],],[[48.0,44.0],[49.0,54.0],[50.0,66.0],[43.0,78.0],[33.0,88.0],],],
93
+ ',' => [[[49.0,55.0],[47.0,72.0],[40.0,90.0],[33.0,91.0],],],
94
+ ':' => [[[44.0,29.0],[51.0,37.0],],[[43.0,38.0],[51.0,31.0],],[[43.0,75.0],[49.0,68.0],],[[51.0,76.0],[42.0,68.0],],],
95
+ '.' => [[[46.0,81.0],[54.0,75.0],],[[54.0,83.0],[47.0,75.0],],],
96
+ '-' => [[[23.0,48.0],[80.0,51.0],],],
97
+ '_' => [[[21.0,81.0],[81.0,81.0],],],
98
+ '+' => [[[22.0,51.0],[82.0,52.0],],[[49.0,23.0],[50.0,81.0],],],
99
+ '*' => [[[22.0,49.0],[80.0,51.0],],[[50.0,81.0],[49.0,22.0],],[[71.0,72.0],[33.0,34.0],],[[31.0,69.0],[64.0,34.0],],],
100
+ '|' => [[[49.0,82.0],[48.0,22.0],],],
101
+ '\\' => [[[29.0,21.0],[71.0,82.0],],],
102
+ '[' => [[[63.0,21.0],[36.0,20.0],[39.0,82.0],[64.0,82.0],],],
103
+ ']' => [[[36.0,21.0],[62.0,22.0],[61.0,82.0],[39.0,82.0],],],
104
+ '{' => [[[64.0,22.0],[54.0,24.0],[49.0,26.0],[47.0,34.0],[49.0,43.0],[47.0,51.0],[36.0,53.0],[45.0,56.0],[48.0,60.0],[48.0,70.0],[45.0,75.0],[46.0,81.0],[50.0,84.0],[60.0,84.0],],],
105
+ '}' => [[[43.0,23.0],[49.0,24.0],[55.0,27.0],[58.0,33.0],[56.0,44.0],[58.0,48.0],[63.0,49.0],[69.0,51.0],[59.0,54.0],[55.0,58.0],[58.0,64.0],[60.0,72.0],[54.0,81.0],[47.0,84.0],[41.0,84.0],],],
106
+ '@' => [[[61.0,62.0],[58.0,66.0],[49.0,72.0],[40.0,69.0],[36.0,63.0],[35.0,51.0],[39.0,44.0],[50.0,43.0],[58.0,48.0],[62.0,61.0],],[[61.0,40.0],[62.0,53.0],[62.0,62.0],[62.0,68.0],[65.0,71.0],[68.0,73.0],[72.0,70.0],[72.0,65.0],[72.0,55.0],[72.0,48.0],[70.0,39.0],[64.0,29.0],[57.0,26.0],[45.0,24.0],[38.0,27.0],[27.0,33.0],[24.0,42.0],[24.0,56.0],[27.0,70.0],[33.0,75.0],[42.0,79.0],[54.0,80.0],[64.0,81.0],[76.0,76.0],],],
107
+ '#' => [[[21.0,39.0],[82.0,43.0],],[[23.0,56.0],[81.0,59.0],],[[42.0,81.0],[44.0,22.0],],[[63.0,81.0],[64.0,21.0],],],
108
+ 'ç' => [[[67.0,26.0],[60.0,23.0],[37.0,24.0],[24.0,27.0],[18.0,42.0],[19.0,58.0],[24.0,66.0],[38.0,68.0],[46.0,70.0],[61.0,68.0],[68.0,67.0],],[[37.0,70.0],[48.0,74.0],[54.0,77.0],[51.0,82.0],[41.0,83.0],[36.0,84.0],],],
109
+ '°' => [[[46.0,38.0],[39.0,36.0],[36.0,31.0],[37.0,26.0],[45.0,20.0],[52.0,22.0],[56.0,27.0],[57.0,33.0],[53.0,36.0],[47.0,39.0],],],
110
+ '§' => [[[58.0,17.0],[48.0,22.0],[41.0,26.0],[41.0,33.0],[46.0,39.0],[50.0,43.0],[56.0,47.0],[59.0,55.0],[57.0,62.0],[47.0,66.0],[40.0,65.0],[37.0,62.0],[37.0,56.0],[40.0,50.0],[48.0,44.0],],[[48.0,67.0],[56.0,72.0],[59.0,76.0],[59.0,82.0],[54.0,87.0],[44.0,88.0],[38.0,91.0],],],
111
+ '€' => [[[72.0,36.0],[67.0,31.0],[58.0,27.0],[47.0,29.0],[38.0,33.0],[29.0,42.0],[30.0,65.0],[34.0,73.0],[43.0,78.0],[52.0,79.0],[61.0,80.0],[69.0,74.0],[73.0,70.0],],[[22.0,59.0],[51.0,59.0],],[[22.0,48.0],[49.0,49.0],],],
112
+ '`' => [[[54.0,41.0],[40.0,22.0],],],
113
+ '~' => [[[22.0,54.0],[28.0,47.0],[35.0,44.0],[43.0,43.0],[51.0,49.0],[56.0,56.0],[60.0,61.0],[69.0,63.0],[75.0,59.0],[80.0,53.0],],],
114
+ 'ñ' => [[[34.0,81.0],[35.0,42.0],],[[36.0,54.0],[43.0,49.0],[50.0,45.0],[61.0,45.0],[69.0,53.0],[70.0,82.0],],[[35.0,32.0],[38.0,29.0],[42.0,28.0],[52.0,33.0],[53.0,34.0],[56.0,37.0],[60.0,36.0],[66.0,32.0],[69.0,30.0],],],
115
+ 'é' => [[[63.0,66.0],[59.0,73.0],[50.0,79.0],[43.0,79.0],[37.0,73.0],[32.0,65.0],[29.0,52.0],[31.0,43.0],[41.0,40.0],[54.0,40.0],[63.0,47.0],[64.0,53.0],[30.0,54.0],],[[42.0,31.0],[56.0,22.0],],],
116
+ 'è' => [[[62.0,69.0],[59.0,75.0],[52.0,80.0],[47.0,80.0],[41.0,80.0],[35.0,74.0],[30.0,66.0],[31.0,59.0],[34.0,50.0],[40.0,44.0],[51.0,41.0],[59.0,46.0],[63.0,55.0],[33.0,54.0],],[[55.0,35.0],[39.0,25.0],],],
117
+ 'ò' => [[[55.0,80.0],[50.0,80.0],[42.0,79.0],[34.0,70.0],[31.0,64.0],[31.0,56.0],[38.0,46.0],[52.0,45.0],[69.0,62.0],[67.0,71.0],[60.0,79.0],[50.0,80.0],],[[59.0,35.0],[37.0,22.0],],],
118
+ 'à' => [[[33.0,46.0],[39.0,43.0],[46.0,43.0],[55.0,42.0],[63.0,57.0],[62.0,66.0],[60.0,75.0],[64.0,79.0],[71.0,81.0],],[[61.0,69.0],[59.0,73.0],[53.0,77.0],[48.0,80.0],[40.0,80.0],[38.0,80.0],[33.0,74.0],[33.0,68.0],[41.0,62.0],[51.0,61.0],[57.0,66.0],[62.0,69.0],],[[55.0,32.0],[38.0,23.0],],],
119
+ 'ù' => [[[33.0,44.0],[33.0,52.0],[35.0,63.0],[40.0,72.0],[44.0,78.0],[49.0,79.0],[54.0,80.0],[61.0,77.0],[64.0,72.0],[67.0,62.0],[68.0,47.0],],[[68.0,80.0],[68.0,53.0],],[[60.0,40.0],[41.0,25.0],],],
120
+ 'ì' => [[[48.0,81.0],[47.0,42.0],],[[55.0,35.0],[41.0,26.0],],],
121
+ 'É' => [[[79.0,28.0],[21.0,28.0],[21.0,80.0],[76.0,81.0],],[[21.0,52.0],[49.0,55.0],],[[30.0,22.0],[63.0,7.0],],],
122
+ 'È' => [[[79.0,31.0],[20.0,32.0],[22.0,80.0],[80.0,82.0],],[[23.0,54.0],[48.0,56.0],],[[62.0,25.0],[36.0,7.0],],],
123
+ 'Ò' => [[[51.0,80.0],[41.0,77.0],[26.0,64.0],[24.0,56.0],[26.0,43.0],[36.0,34.0],[55.0,28.0],[67.0,34.0],[73.0,44.0],[75.0,55.0],[70.0,77.0],[50.0,82.0],],[[62.0,24.0],[36.0,8.0],],],
124
+ 'À' => [[[26.0,82.0],[51.0,25.0],[70.0,81.0],],[[40.0,56.0],[62.0,56.0],],[[63.0,23.0],[34.0,6.0],],],
125
+ 'Ù' => [[[27.0,30.0],[28.0,42.0],[27.0,60.0],[35.0,74.0],[48.0,81.0],[58.0,82.0],[70.0,76.0],[73.0,65.0],[73.0,39.0],[74.0,30.0],],[[61.0,28.0],[38.0,7.0],],],
126
+ ' ' => [],
127
+
128
+ }
129
+
130
+ end
131
+
132
+ end
data/font_metrics.rb CHANGED
@@ -85,16 +85,24 @@ module ChunkyText
85
85
  def char_metrics(ch)
86
86
  @metrics[ch]
87
87
  end
88
+
89
+ def char_spacing
90
+ @font_class::DEFAULT_CHAR_SPACING
91
+ end
92
+
93
+ def char_size
94
+ @font_class::DEFAULT_FONT_SIZE
95
+ end
88
96
 
89
- def write_line(p_old,p_cur,img,min_x,min_y,color)
90
- x0 = p_old[0]-min_x
91
- y0 = p_old[1]-min_y
92
- x1 = p_cur[0]-min_x
93
- y1 = p_cur[1]-min_y
94
- img.line(x0.to_i,y0.to_i,x1.to_i,y1.to_i,color)
97
+ def write_line(p_old,p_cur,img,x,y,metrics,scale_factor,color)
98
+ x0 = (x+(p_old[0]-metrics[:min_x])*scale_factor).to_i
99
+ y0 = (y+(p_old[1]-metrics[:min_y]-metrics[:height])*scale_factor).to_i
100
+ x1 = (x+(p_cur[0]-metrics[:min_x])*scale_factor).to_i
101
+ y1 = (y+(p_cur[1]-metrics[:min_y]-metrics[:height])*scale_factor).to_i
102
+ img.line(x0,y0,x1,y1,color)
95
103
  end
96
104
 
97
- def write_char(img,x,y,ch,color)
105
+ def write_char(img,x,y,ch,scale_factor,color)
98
106
  metrics = char_metrics(ch)
99
107
 
100
108
  char_data = @font_class::FONT_DATA[ch]
@@ -105,10 +113,10 @@ module ChunkyText
105
113
  poly.each do |point|
106
114
  p_old = p_cur
107
115
  p_cur = point
108
- write_line(p_old,p_cur,img,metrics[:min_x]-x,metrics[:min_y]-y+metrics[:height],color) unless (p_old.nil? || p_cur.nil?)
116
+ write_line(p_old,p_cur,img,x,y,metrics,scale_factor,color) unless (p_old.nil? || p_cur.nil?)
109
117
  end
110
118
  end
111
- metrics[:width]
119
+ metrics[:width]*scale_factor
112
120
  end
113
121
 
114
122
  def dump
data/font_metrics.rb~ ADDED
@@ -0,0 +1,122 @@
1
+
2
+ require 'chunky_png'
3
+
4
+ module ChunkyText
5
+
6
+ class FontMetrics
7
+
8
+ def initialize(font_name)
9
+ file = './chunky_text/font/'+font_name+'.rb'
10
+ require file
11
+
12
+ @font_class_name = font_name.split('_').map do |token|
13
+ token.capitalize
14
+ end.join
15
+ @metrics = {}
16
+ @font_class = eval("ChunkyText::Font::"+@font_class_name,TOPLEVEL_BINDING)
17
+ @font_instance = @font_class.new
18
+
19
+ calculate
20
+
21
+ end
22
+
23
+ def calculate
24
+
25
+ font_data = @font_class::FONT_DATA
26
+
27
+ font_data.each do |ix,char_def|
28
+ char_metrics = {}
29
+
30
+ min_x = @font_class::MAX_WIDTH*2
31
+ max_x = -@font_class::MAX_WIDTH
32
+ min_y = @font_class::MAX_HEIGHT*2
33
+ max_y = -@font_class::MAX_HEIGHT
34
+
35
+ char_def.each do |poly|
36
+ poly.each do |point|
37
+ px = point[0]
38
+ py = point[1]
39
+ if (px>max_x)
40
+ max_x = px
41
+ end
42
+ if (px<min_x)
43
+ min_x = px
44
+ end
45
+ if (py>max_y)
46
+ max_y = py
47
+ end
48
+ if (py<min_y)
49
+ min_y = py
50
+ end
51
+ end
52
+ end
53
+
54
+ if (max_x-min_x<0)
55
+ width = @font_class::MAX_WIDTH/2
56
+ else
57
+ if (max_x-min_x>@font_class::MIN_WIDTH)
58
+ width = max_x-min_x
59
+ else
60
+ width = @font_class::MIN_WIDTH
61
+ end
62
+ end
63
+
64
+ if (max_y-min_y<0)
65
+ height = @font_class::MAX_HEIGHT
66
+ else
67
+ if (max_y-min_y>@font_class::MIN_HEIGHT)
68
+ height = max_y-min_y
69
+ else
70
+ height = @font_class::MIN_HEIGHT
71
+ end
72
+ end
73
+
74
+ char_metrics[:min_x] = min_x
75
+ char_metrics[:max_x] = max_x
76
+ char_metrics[:min_y] = min_y
77
+ char_metrics[:max_y] = max_y
78
+ char_metrics[:width] = width
79
+ char_metrics[:height] = height
80
+
81
+ @metrics[ix] = char_metrics
82
+ end
83
+ end
84
+
85
+ def char_metrics(ch)
86
+ @metrics[ch]
87
+ end
88
+
89
+ def write_line(p_old,p_cur,img,min_x,min_y,color)
90
+ x0 = p_old[0]-min_x
91
+ y0 = p_old[1]-min_y
92
+ x1 = p_cur[0]-min_x
93
+ y1 = p_cur[1]-min_y
94
+ img.line(x0.to_i,y0.to_i,x1.to_i,y1.to_i,color)
95
+ end
96
+
97
+ def write_char(img,x,y,ch,color)
98
+ metrics = char_metrics(ch)
99
+
100
+ char_data = @font_class::FONT_DATA[ch]
101
+
102
+ char_data.each do |poly|
103
+ p_cur = nil
104
+ p_old = nil
105
+ poly.each do |point|
106
+ p_old = p_cur
107
+ p_cur = point
108
+ write_line(p_old,p_cur,img,metrics[:min_x]-x,metrics[:min_y]-y+metrics[:height],color) unless (p_old.nil? || p_cur.nil?)
109
+ end
110
+ end
111
+ metrics[:width]
112
+ end
113
+
114
+ def dump
115
+ @metrics.each do |key,value|
116
+ print key+" ==> W:"+value[:width].to_s+" H:"+value[:height].to_s+"\n"
117
+ end
118
+ end
119
+
120
+ end
121
+
122
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chunky_text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Bagnaresi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-15 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -53,12 +53,17 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.3'
55
55
  description: |+
56
- ==== chunky_text : a gem for writing vector text using chunky_png ====
56
+ chunky_text is a gem for writing vector text over png images (depends on chunky_png).
57
57
 
58
58
  This library is useful for :
59
59
 
60
60
  - Writing vector text on png images (annotations)
61
61
 
62
+ FEATURES :
63
+
64
+ - Write a single line of text of any size and color.
65
+ - Accented italian/english chars, uppercase and lowercase, special charactes.
66
+
62
67
 
63
68
  I hope it can be useful. I'll add some more useful features in my spare time.
64
69
 
@@ -73,8 +78,11 @@ files:
73
78
  - README.md
74
79
  - chunky_text.gemspec
75
80
  - chunky_text.rb
81
+ - chunky_text.rb~
76
82
  - font/default_font.rb
83
+ - font/default_font.rb~
77
84
  - font_metrics.rb
85
+ - font_metrics.rb~
78
86
  homepage: http://www.mbcraft.it/products/chunky_text.php
79
87
  licenses:
80
88
  - MIT