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 +4 -4
- data/lib/thumb_gen/generator.rb +16 -11
- data/lib/thumb_gen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb27f036fb53827c3fa86a2c875dbc7c2c7afb8476dfada4d48e103b6d038fc4
|
4
|
+
data.tar.gz: bf08d3c0f317f62473b233d567066903a682f408ecebe9971c82797a1a0606a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c089a80b59f0075168aed1cfe032d8c1d40e60d19a22cfbc13f316068305c5aacaec05a10110ea1d98593b262be5c2305b0cbe2e06a1bfba463b133e83e2f91
|
7
|
+
data.tar.gz: 7a8f55f853b8fec7652db0254e810b77c414d950ff94c66a78bd0cda7c32040f989b6bbc28b6cc4ae731f25f34d93a10f4cf86a53464f7266b19c82b46d55f16
|
data/lib/thumb_gen/generator.rb
CHANGED
@@ -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
|
91
|
-
#
|
92
|
-
|
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
|
-
|
97
|
-
test_line = line
|
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 =
|
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
|
-
#
|
111
|
-
|
110
|
+
# 🌍 Non-CJK text → wrap by word
|
111
|
+
words = text.split(/\s+/)
|
112
112
|
lines = []
|
113
113
|
line = ''
|
114
114
|
|
115
|
-
|
116
|
-
test_line = line
|
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 =
|
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
|
{
|
data/lib/thumb_gen/version.rb
CHANGED