text2svg 0.4.0 → 0.4.1
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 +4 -4
- data/lib/text2svg/typography.rb +31 -9
- data/lib/text2svg/typography_test.rb +1 -1
- data/lib/text2svg/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc9791dd9a1ca2e7c574f2d925ee0b60c54b6d6e
|
4
|
+
data.tar.gz: 558e0e2c3812fa6442d88740cf85edfd7a07f6b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 251968686481b39e1158be711a606bb9db0981310341f0840ec71535992fdcb79a47f919bd70ea60cf35e3b910449d02b5e10670a97a622570e90856a757206b
|
7
|
+
data.tar.gz: 01d3f3a4cf6201c176d3e4640247e7de661a4cb633e8db8e2e4514533a3be53dea485475c2cc98a92650a636a767e198e0a3aee929e2077de3dbacee808c13b7
|
data/lib/text2svg/typography.rb
CHANGED
@@ -81,19 +81,32 @@ module Text2svg
|
|
81
81
|
|
82
82
|
metrics = FreeType::C::FT_Glyph_Metrics.new
|
83
83
|
is_draw = if IDEOGRAPHIC_SPACE.match char
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
metrics[:width] = space_width * 2r
|
85
|
+
metrics[:height] = 0
|
86
|
+
metrics[:horiBearingX] = space_width * 2r
|
87
|
+
metrics[:horiBearingY] = 0
|
88
|
+
metrics[:horiAdvance] = space_width * 2r
|
89
|
+
metrics[:vertBearingX] = 0
|
90
|
+
metrics[:vertBearingY] = 0
|
91
|
+
metrics[:vertAdvance] = 0
|
92
|
+
|
87
93
|
false
|
88
94
|
elsif WHITESPACE.match char
|
89
|
-
|
90
|
-
|
91
|
-
|
95
|
+
metrics[:width] = space_width
|
96
|
+
metrics[:height] = 0
|
97
|
+
metrics[:horiBearingX] = space_width
|
98
|
+
metrics[:horiBearingY] = 0
|
99
|
+
metrics[:horiAdvance] = space_width
|
100
|
+
metrics[:vertBearingX] = 0
|
101
|
+
metrics[:vertBearingY] = 0
|
102
|
+
metrics[:vertAdvance] = 0
|
103
|
+
|
92
104
|
false
|
93
105
|
else
|
94
106
|
FreeType::C::FT_Glyph_Metrics.members.each do |m|
|
95
107
|
metrics[m] = glyph.metrics[m]
|
96
108
|
end
|
109
|
+
|
97
110
|
true
|
98
111
|
end
|
99
112
|
line << CharSet.new(char, metrics, is_draw, glyph.outline.svg_path_data)
|
@@ -127,9 +140,13 @@ module Text2svg
|
|
127
140
|
|
128
141
|
output << %(<g #{option.attribute}>\n) if option.attribute
|
129
142
|
|
130
|
-
lines.zip(width_by_line).
|
143
|
+
lines.zip(width_by_line).each_with_index do |(line, line_width), index|
|
131
144
|
x = 0r
|
132
|
-
y +=
|
145
|
+
y += if index == 0
|
146
|
+
line.map { |cs| cs.metrics[:horiBearingY] }.max || 0
|
147
|
+
else
|
148
|
+
line_height
|
149
|
+
end
|
133
150
|
before_char = nil
|
134
151
|
|
135
152
|
case option.text_align.to_sym
|
@@ -161,7 +178,12 @@ module Text2svg
|
|
161
178
|
|
162
179
|
option_width = 0
|
163
180
|
option_width += space_width / 1.5 if option.italic
|
164
|
-
Content.new(
|
181
|
+
Content.new(
|
182
|
+
output,
|
183
|
+
(max_width + option_width).to_i,
|
184
|
+
(y + (lines.last.map { |cs| cs.metrics[:height] - cs.metrics[:horiBearingY] }.max || 0)).to_i,
|
185
|
+
notdef_indexes
|
186
|
+
)
|
165
187
|
end
|
166
188
|
end
|
167
189
|
|
@@ -30,7 +30,7 @@ module Text2svgTypographyTest
|
|
30
30
|
opt.italic = italic
|
31
31
|
opt.char_size = char_size
|
32
32
|
|
33
|
-
['ABC', "\n", "\n\nA", "", "A\nB\n\n", "A\n\n\nC", "<", ">", "&", "=", "@", "%", "#", "("].each do |text|
|
33
|
+
['ABC', "\n", "\n\nA", "", "A\nB\n\n", "A\n \n\nC", "<", ">", "&", "=", "@", "%", "#", "("].each do |text|
|
34
34
|
begin
|
35
35
|
c = Text2svg::Typography.build(text, opt)
|
36
36
|
rescue => e
|
data/lib/text2svg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text2svg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: freetype
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.2
|
117
|
+
rubygems_version: 2.6.2
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Build svg path data from font file
|