chunky_text 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +8 -0
- data/README.md +11 -0
- data/chunky_text.gemspec +20 -0
- data/chunky_text.rb +21 -0
- data/font/default_font.rb +132 -0
- data/font_metrics.rb +122 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3f050988611cd5e7a1c74aeb89a3b18921637cb9
|
4
|
+
data.tar.gz: bbf9d94e12ee97af725728b0c4614a032418e2ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 16a2bd601f20e9b9e188663e0ee28759a2181c504ef16462e79b9425636d1781caabca5480704b906eaae150cdd00ba873518de4a74145778f37c63b94b3664b
|
7
|
+
data.tar.gz: 39b4f1f88fc07fb5969eacafa133352d1535c44e3d091aebee9513be545b74d397e6577486b014e55a92162857ed8e8f9ee9c93ee8e0b463df50224f04936659
|
data/LICENSE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Copyright (c) 2015 - MBCRAFT di Marco Bagnaresi
|
2
|
+
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
==== chunky_text : a gem for writing vector text using chunky_png ====
|
2
|
+
|
3
|
+
This library is useful for :
|
4
|
+
|
5
|
+
- Writing vector text on png images (annotations)
|
6
|
+
|
7
|
+
|
8
|
+
I hope it can be useful. I'll add some more useful features in my spare time.
|
9
|
+
|
10
|
+
-Marco Bagnaresi
|
11
|
+
|
data/chunky_text.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "chunky_text"
|
3
|
+
s.summary = "Draw vector text on chunky_png images."
|
4
|
+
s.description = File.read(File.join(File.dirname(__FILE__), 'README.md'))
|
5
|
+
s.license = "MIT"
|
6
|
+
s.requirements= ['chunky_png gem must be installed.']
|
7
|
+
s.version = "0.1.4"
|
8
|
+
s.author = "Marco Bagnaresi"
|
9
|
+
s.email = "info@mbcraft.it"
|
10
|
+
s.homepage = "http://www.mbcraft.it/products/chunky_text.php"
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.required_ruby_version = '>=1.9'
|
13
|
+
s.files = Dir['font/**','test/**','**']
|
14
|
+
s.require_paths = ['.']
|
15
|
+
s.add_development_dependency 'rspec', '~>3'
|
16
|
+
s.add_development_dependency 'rake', '~>0'
|
17
|
+
s.add_runtime_dependency 'chunky_png','~> 1.3'
|
18
|
+
s.test_files = Dir["test/test*.rb"]
|
19
|
+
s.has_rdoc = false
|
20
|
+
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
|
@@ -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
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
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chunky_text
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marco Bagnaresi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: chunky_png
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
description: |+
|
56
|
+
==== chunky_text : a gem for writing vector text using chunky_png ====
|
57
|
+
|
58
|
+
This library is useful for :
|
59
|
+
|
60
|
+
- Writing vector text on png images (annotations)
|
61
|
+
|
62
|
+
|
63
|
+
I hope it can be useful. I'll add some more useful features in my spare time.
|
64
|
+
|
65
|
+
-Marco Bagnaresi
|
66
|
+
|
67
|
+
email: info@mbcraft.it
|
68
|
+
executables: []
|
69
|
+
extensions: []
|
70
|
+
extra_rdoc_files: []
|
71
|
+
files:
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- chunky_text.gemspec
|
75
|
+
- chunky_text.rb
|
76
|
+
- font/default_font.rb
|
77
|
+
- font_metrics.rb
|
78
|
+
homepage: http://www.mbcraft.it/products/chunky_text.php
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- "."
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.9'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements:
|
97
|
+
- chunky_png gem must be installed.
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.0
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Draw vector text on chunky_png images.
|
103
|
+
test_files: []
|