prawn_hebrew 0.1.4 → 0.1.6
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/prawn_hebrew.rb +28 -18
- data/lib/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: 1c923e10c8587bf590c02c70f3ef62dd6d2e95c6fb5c338c453e41db11fce73a
|
|
4
|
+
data.tar.gz: 15fee6431648b088fd6b6e824db4a00f43880eb7a30cc208a0ecbc0b59ffeaf6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6ed446d3c436f65630bfb528b79735e6c2d9cc4120b68e70c7c173047868081068a3eb22689d79ac472d2db7306cf3373feb8998b520b613f9fa466f69a27f3
|
|
7
|
+
data.tar.gz: a4ae2aaa3b7b7e8990df02a953345010e66aaa41b167ba3dea0e44011d1719081397fcc2fea5a2c5e12e2ae0c04eb2ca94e84d464e4b23fcc4045e87e7673370
|
data/lib/prawn_hebrew.rb
CHANGED
|
@@ -159,43 +159,53 @@ module PrawnHebrew
|
|
|
159
159
|
def shrink_hebrew_text_to_fit(text, initial_size, style, hebrew_font, english_font,
|
|
160
160
|
char_spacing, leading, min_font_size, rotation, box_opts)
|
|
161
161
|
min_size = min_font_size || 5
|
|
162
|
+
|
|
163
|
+
# Get box dimensions
|
|
164
|
+
box_width = box_opts[:width]
|
|
165
|
+
box_height = box_opts[:height]
|
|
166
|
+
|
|
167
|
+
return render_hebrew_text_content(text, true, :rtl, initial_size, style,
|
|
168
|
+
hebrew_font, english_font, char_spacing, leading, box_opts) unless box_width && box_height
|
|
169
|
+
|
|
162
170
|
current_size = initial_size
|
|
163
171
|
fitting_size = nil
|
|
164
172
|
|
|
165
|
-
#
|
|
173
|
+
# Try progressively smaller sizes
|
|
166
174
|
while current_size >= min_size
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
# Calculate approximate text dimensions at this size
|
|
176
|
+
test_fragments = hebrew_formatted_text(text, size: current_size, style: style,
|
|
177
|
+
hebrew_font: hebrew_font,
|
|
178
|
+
english_font: english_font)
|
|
170
179
|
|
|
171
|
-
|
|
172
|
-
|
|
180
|
+
# Calculate total text width by measuring each fragment
|
|
181
|
+
total_width = 0
|
|
182
|
+
total_height = current_size * 1.2 # Approximate line height
|
|
173
183
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
end
|
|
180
|
-
else
|
|
181
|
-
formatted_text_box(fragments, test_opts.merge(dry_run: true))
|
|
184
|
+
test_fragments.each do |fragment|
|
|
185
|
+
next if fragment[:text] == "\n"
|
|
186
|
+
fragment_font = fragment[:font] || hebrew_font
|
|
187
|
+
font(fragment_font) do
|
|
188
|
+
total_width += width_of(fragment[:text], size: current_size)
|
|
182
189
|
end
|
|
183
190
|
end
|
|
184
191
|
|
|
185
|
-
#
|
|
186
|
-
|
|
192
|
+
# Count newlines to estimate height
|
|
193
|
+
line_count = text.count("\n") + 1
|
|
194
|
+
total_height = (current_size * 1.2 * line_count) + (leading * (line_count - 1))
|
|
195
|
+
|
|
196
|
+
# Check if it would fit (with some padding)
|
|
197
|
+
if total_width <= (box_width * 0.95) && total_height <= (box_height * 0.95)
|
|
187
198
|
fitting_size = current_size
|
|
188
199
|
break
|
|
189
200
|
end
|
|
190
201
|
|
|
191
|
-
# Reduce font size and try again
|
|
192
202
|
current_size -= 0.5
|
|
193
203
|
end
|
|
194
204
|
|
|
195
205
|
# Use the fitting size, or min_size if nothing fit
|
|
196
206
|
final_size = fitting_size || min_size
|
|
197
207
|
|
|
198
|
-
#
|
|
208
|
+
# Render with the final size
|
|
199
209
|
fragments = hebrew_formatted_text(text, size: final_size, style: style,
|
|
200
210
|
hebrew_font: hebrew_font,
|
|
201
211
|
english_font: english_font)
|
data/lib/version.rb
CHANGED