thumb_gen 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 171cd85f8638b80c939cf1f4623ee4bfa578e2cd9adcd32828b6257f01bf0e11
4
- data.tar.gz: 489dd00512f4a53dfe9d1b1050a51ecde9609ed438ad7e0addceab33105b5894
3
+ metadata.gz: 96583f8cea87b49a125c5f5d6499b9b9c1f17b4cf0876e1e69c83f4d3d842f6b
4
+ data.tar.gz: 19f73d44d5d410f5cf63c742962e9bc66231e82b56df70115bae652526c87c79
5
5
  SHA512:
6
- metadata.gz: 83a20a5809ed73e8a9d26465a3ec959012ab99fe28f08585b1c24bf3b714a65516e43635104463555f6dcc4478b3f66aedd6c9faa319902345cfc2143cc1c22a
7
- data.tar.gz: 62d8fe868ba9373bd7dbe9ff17c044400d0a009ad0e08fa9871fb3c93850f7bb52fc5ec6cd7718fbbe6bbe04b9dc16c1595dc044b5c2a4e86f69cd91271d8bda
6
+ metadata.gz: b694d60b9ebb8746f68f1e5a3604027a7b6748d7b5e758268b978f844eadfecd4b355a6625cf46c617bb1d1b4efbe325a8a18f9fef6061d700d7a9655ccd8461
7
+ data.tar.gz: 85f0e68efa2e949980550f5fa47b4605bc1a4070e06925cb680d11580d2b20e69fb68326b68a21c25414578f30ed577450847c619c58f63cfffaea576f0c686a
@@ -81,28 +81,51 @@ module ThumbGen
81
81
  end
82
82
 
83
83
  def wrap_text(text, max_width, opts)
84
- words = text.split(/\s+/)
85
- lines = []
86
- line = ''
87
84
  draw = Magick::Draw.new
88
85
  draw.font = opts[:font]
89
86
  draw.pointsize = opts[:font_size]
90
87
  draw.font_weight = opts[:font_weight]
91
88
  draw.font_style = opts[:font_style]
92
89
 
93
- words.each do |word|
94
- test_line = line.empty? ? word : "#{line} #{word}"
95
- width = draw.get_type_metrics(background, test_line).width
96
- if width <= max_width
97
- line = test_line
98
- else
99
- lines << line unless line.empty?
100
- line = word
90
+ if text.include?(' ')
91
+ # 📝 For languages with spaces (e.g. English) wrap by words
92
+ words = text.split(/\s+/)
93
+ lines = []
94
+ line = ''
95
+
96
+ words.each do |word|
97
+ test_line = line.empty? ? word : "#{line} #{word}"
98
+ width = draw.get_type_metrics(background, test_line).width
99
+ if width <= max_width
100
+ line = test_line
101
+ else
102
+ lines << line unless line.empty?
103
+ line = word
104
+ end
105
+ end
106
+
107
+ lines << line unless line.empty?
108
+ lines.join("\n")
109
+ else
110
+ # 🇯🇵 For languages without spaces (e.g. Japanese, Chinese) → wrap by character
111
+ chars = text.scan(/.{1}/m)
112
+ lines = []
113
+ line = ''
114
+
115
+ chars.each do |char|
116
+ test_line = line + char
117
+ width = draw.get_type_metrics(background, test_line).width
118
+ if width <= max_width
119
+ line = test_line
120
+ else
121
+ lines << line unless line.empty?
122
+ line = char
123
+ end
101
124
  end
102
- end
103
125
 
104
- lines << line unless line.empty?
105
- lines.join("\n")
126
+ lines << line unless line.empty?
127
+ lines.join("\n")
128
+ end
106
129
  end
107
130
 
108
131
  def text_options(text)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ThumbGen
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thumb_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - YutoYasunaga