text2svg 0.4.0 → 0.4.1

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: 9bfacdff9cb34a8770ff99e984013f4ff9a4f837
4
- data.tar.gz: 0909e9114da286c14ec1bb577c7ac2c858902ddd
3
+ metadata.gz: bc9791dd9a1ca2e7c574f2d925ee0b60c54b6d6e
4
+ data.tar.gz: 558e0e2c3812fa6442d88740cf85edfd7a07f6b5
5
5
  SHA512:
6
- metadata.gz: aa3d335335590c1c9a76cdd12a2bdd758e14651c76eb5b42c5f8fe064789a3ad5a3daee73e76ae7ff00ee507b496be9639cf9b08ae53e5954b36fb1af02d0879
7
- data.tar.gz: 137eb22ad7a9be9a9f742d3158d69f78dda6f7bf844bdb38add81e32aff7a4037be6d25ce2e3de7d52d26b696f6057398127d1031dd67d7c3429b323939bfeb2
6
+ metadata.gz: 251968686481b39e1158be711a606bb9db0981310341f0840ec71535992fdcb79a47f919bd70ea60cf35e3b910449d02b5e10670a97a622570e90856a757206b
7
+ data.tar.gz: 01d3f3a4cf6201c176d3e4640247e7de661a4cb633e8db8e2e4514533a3be53dea485475c2cc98a92650a636a767e198e0a3aee929e2077de3dbacee808c13b7
@@ -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
- FreeType::C::FT_Glyph_Metrics.members.each do |m|
85
- metrics[m] = space_width * 2r
86
- end
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
- FreeType::C::FT_Glyph_Metrics.members.each do |m|
90
- metrics[m] = space_width
91
- end
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).each do |(line, line_width)|
143
+ lines.zip(width_by_line).each_with_index do |(line, line_width), index|
131
144
  x = 0r
132
- y += line_height
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(output, (max_width + option_width).to_i, (y + line_height / 4).to_i, notdef_indexes)
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
@@ -1,3 +1,3 @@
1
1
  module Text2svg
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
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.0
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 00:00:00.000000000 Z
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.5
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