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 +4 -4
- data/lib/thumb_gen/generator.rb +41 -13
- 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
@@ -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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
105
|
-
|
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)
|
data/lib/thumb_gen/version.rb
CHANGED