thumb_gen 0.2.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 171cd85f8638b80c939cf1f4623ee4bfa578e2cd9adcd32828b6257f01bf0e11
4
- data.tar.gz: 489dd00512f4a53dfe9d1b1050a51ecde9609ed438ad7e0addceab33105b5894
3
+ metadata.gz: bb27f036fb53827c3fa86a2c875dbc7c2c7afb8476dfada4d48e103b6d038fc4
4
+ data.tar.gz: bf08d3c0f317f62473b233d567066903a682f408ecebe9971c82797a1a0606a3
5
5
  SHA512:
6
- metadata.gz: 83a20a5809ed73e8a9d26465a3ec959012ab99fe28f08585b1c24bf3b714a65516e43635104463555f6dcc4478b3f66aedd6c9faa319902345cfc2143cc1c22a
7
- data.tar.gz: 62d8fe868ba9373bd7dbe9ff17c044400d0a009ad0e08fa9871fb3c93850f7bb52fc5ec6cd7718fbbe6bbe04b9dc16c1595dc044b5c2a4e86f69cd91271d8bda
6
+ metadata.gz: 5c089a80b59f0075168aed1cfe032d8c1d40e60d19a22cfbc13f316068305c5aacaec05a10110ea1d98593b262be5c2305b0cbe2e06a1bfba463b133e83e2f91
7
+ data.tar.gz: 7a8f55f853b8fec7652db0254e810b77c414d950ff94c66a78bd0cda7c32040f989b6bbc28b6cc4ae731f25f34d93a10f4cf86a53464f7266b19c82b46d55f16
@@ -81,28 +81,56 @@ 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 contains_cjk?(text)
91
+ # 🇯🇵 CJK text wrap by character
92
+ chars = text.scan(/.{1}/m)
93
+ lines = []
94
+ line = ''
95
+
96
+ chars.each do |char|
97
+ test_line = line + char
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 = char
104
+ end
101
105
  end
106
+
107
+ lines << line unless line.empty?
108
+ lines.join("\n")
109
+ else
110
+ # 🌍 Non-CJK text → wrap by word
111
+ words = text.split(/\s+/)
112
+ lines = []
113
+ line = ''
114
+
115
+ words.each do |word|
116
+ test_line = line.empty? ? word : "#{line} #{word}"
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 = word
123
+ end
124
+ end
125
+
126
+ lines << line unless line.empty?
127
+ lines.join("\n")
102
128
  end
129
+ end
103
130
 
104
- lines << line unless line.empty?
105
- lines.join("\n")
131
+ def contains_cjk?(text)
132
+ # Checks for any CJK character (Japanese, Chinese, Korean)
133
+ !!(text =~ /[\p{Han}\p{Katakana}\p{Hiragana}\p{Hangul}]/)
106
134
  end
107
135
 
108
136
  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.4'
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - YutoYasunaga