thumb_gen 0.2.3 → 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: 96583f8cea87b49a125c5f5d6499b9b9c1f17b4cf0876e1e69c83f4d3d842f6b
4
- data.tar.gz: 19f73d44d5d410f5cf63c742962e9bc66231e82b56df70115bae652526c87c79
3
+ metadata.gz: bb27f036fb53827c3fa86a2c875dbc7c2c7afb8476dfada4d48e103b6d038fc4
4
+ data.tar.gz: bf08d3c0f317f62473b233d567066903a682f408ecebe9971c82797a1a0606a3
5
5
  SHA512:
6
- metadata.gz: b694d60b9ebb8746f68f1e5a3604027a7b6748d7b5e758268b978f844eadfecd4b355a6625cf46c617bb1d1b4efbe325a8a18f9fef6061d700d7a9655ccd8461
7
- data.tar.gz: 85f0e68efa2e949980550f5fa47b4605bc1a4070e06925cb680d11580d2b20e69fb68326b68a21c25414578f30ed577450847c619c58f63cfffaea576f0c686a
6
+ metadata.gz: 5c089a80b59f0075168aed1cfe032d8c1d40e60d19a22cfbc13f316068305c5aacaec05a10110ea1d98593b262be5c2305b0cbe2e06a1bfba463b133e83e2f91
7
+ data.tar.gz: 7a8f55f853b8fec7652db0254e810b77c414d950ff94c66a78bd0cda7c32040f989b6bbc28b6cc4ae731f25f34d93a10f4cf86a53464f7266b19c82b46d55f16
@@ -87,39 +87,39 @@ module ThumbGen
87
87
  draw.font_weight = opts[:font_weight]
88
88
  draw.font_style = opts[:font_style]
89
89
 
90
- if text.include?(' ')
91
- # 📝 For languages with spaces (e.g. English) → wrap by words
92
- words = text.split(/\s+/)
90
+ if contains_cjk?(text)
91
+ # 🇯🇵 CJK text → wrap by character
92
+ chars = text.scan(/.{1}/m)
93
93
  lines = []
94
94
  line = ''
95
95
 
96
- words.each do |word|
97
- test_line = line.empty? ? word : "#{line} #{word}"
96
+ chars.each do |char|
97
+ test_line = line + char
98
98
  width = draw.get_type_metrics(background, test_line).width
99
99
  if width <= max_width
100
100
  line = test_line
101
101
  else
102
102
  lines << line unless line.empty?
103
- line = word
103
+ line = char
104
104
  end
105
105
  end
106
106
 
107
107
  lines << line unless line.empty?
108
108
  lines.join("\n")
109
109
  else
110
- # 🇯🇵 For languages without spaces (e.g. Japanese, Chinese) → wrap by character
111
- chars = text.scan(/.{1}/m)
110
+ # 🌍 Non-CJK text → wrap by word
111
+ words = text.split(/\s+/)
112
112
  lines = []
113
113
  line = ''
114
114
 
115
- chars.each do |char|
116
- test_line = line + char
115
+ words.each do |word|
116
+ test_line = line.empty? ? word : "#{line} #{word}"
117
117
  width = draw.get_type_metrics(background, test_line).width
118
118
  if width <= max_width
119
119
  line = test_line
120
120
  else
121
121
  lines << line unless line.empty?
122
- line = char
122
+ line = word
123
123
  end
124
124
  end
125
125
 
@@ -128,6 +128,11 @@ module ThumbGen
128
128
  end
129
129
  end
130
130
 
131
+ def contains_cjk?(text)
132
+ # Checks for any CJK character (Japanese, Chinese, Korean)
133
+ !!(text =~ /[\p{Han}\p{Katakana}\p{Hiragana}\p{Hangul}]/)
134
+ end
135
+
131
136
  def text_options(text)
132
137
  font_family = text[:font] || 'PublicSans-Regular'
133
138
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ThumbGen
4
- VERSION = '0.2.3'
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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - YutoYasunaga