prawn_hebrew 0.2.0 → 0.2.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/prawn_hebrew.rb +43 -3
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 223562a63ced0cedfc7d8b64ddae8408b3302a57676fa97ef100bf7266cf7203
4
- data.tar.gz: ec4ee45cf9a40979dcbc63d37ee914ef34520a80604b62a984b0eabc4556b535
3
+ metadata.gz: 07fed241f2c5f202aad8246a171d2c25d47912b0b1c99e5617e1d97228f057cc
4
+ data.tar.gz: 6780ab88428065941b1a9b07e9396bc26e186fb7f2d06a9c907a0402e7061162
5
5
  SHA512:
6
- metadata.gz: d99416beb3197fe6ab2955447f9319c41a5d074bc230ec7e56acdb30fcb6701d27cd5c850308c1c24c1e48e1c649af947dba886a68c1db68913aec12bfcbb07e
7
- data.tar.gz: e4edc4bf10ff2395ae65b2f07269ab5e53c7d42adb9080ba62b0fa7f64567c6e176f3b050a0b429072d0734b6e52c4ca1727a8694c5b5c802c46220022d3060a
6
+ metadata.gz: 31a99ee31175fa68e986105b6324157e9457b9ed6bf8dad99ba3a65f9177c888b4c9284a70c7b7fe3052df041dc0c122552786ed8ea328ef44f79e2d85e243c1
7
+ data.tar.gz: 1d89b7a87a803d949209e0b058c49152d4b3f62eb82220a5191b08729a9206bee5b4303d886b484ce78b424aed76180563e411e35d9764d3633a721425556cdb
data/lib/prawn_hebrew.rb CHANGED
@@ -79,6 +79,15 @@ module PrawnHebrew
79
79
  def hebrew_formatted_text(text, size: 12, style: :normal, hebrew_font: DEFAULT_HEBREW_FONT, english_font: DEFAULT_ENGLISH_FONT)
80
80
  text = sanitize_text(text)
81
81
 
82
+ # Check if text is pure Hebrew (no English characters)
83
+ is_pure_hebrew = text.to_s =~ /\p{Hebrew}/ && text.to_s !~ /[a-zA-Z]/
84
+
85
+ # If pure Hebrew, render it directly without word reversal
86
+ if is_pure_hebrew
87
+ return render_pure_hebrew(text, size, style, hebrew_font)
88
+ end
89
+
90
+ # Otherwise, use the mixed text logic with word reversal
82
91
  # Split by newlines first to process each line independently
83
92
  lines = text.to_s.split("\n")
84
93
  all_fragments = []
@@ -122,6 +131,26 @@ module PrawnHebrew
122
131
  all_fragments
123
132
  end
124
133
 
134
+ # Render pure Hebrew text as RTL without word reversal
135
+ def render_pure_hebrew(text, size, style, hebrew_font)
136
+ lines = text.to_s.split("\n")
137
+ all_fragments = []
138
+
139
+ styles = style.is_a?(Array) ? style : [style].compact
140
+
141
+ lines.each_with_index do |line, line_idx|
142
+ # For pure Hebrew, just add the line as-is with RTL direction
143
+ all_fragments << { text: line, font: hebrew_font, size: size, direction: :rtl, styles: styles }
144
+
145
+ # Add newline between lines (except after the last line)
146
+ if line_idx < lines.length - 1
147
+ all_fragments << { text: "\n", font: hebrew_font, size: size, direction: :rtl, styles: styles }
148
+ end
149
+ end
150
+
151
+ all_fragments
152
+ end
153
+
125
154
  # Process a run of Hebrew words, handling punctuation correctly
126
155
  def process_hebrew_run(hebrew_run, all_fragments, hebrew_font, english_font, size, styles)
127
156
  # Check if the last word in the run has trailing punctuation
@@ -168,7 +197,18 @@ module PrawnHebrew
168
197
  # Process each row: sanitize and render Hebrew cells using formatted text
169
198
  processed_data = data.map do |row|
170
199
  row.map do |cell_content|
171
- sanitize_text(cell_content.to_s)
200
+ # Handle hash cells (e.g., {content: "text", font_style: :bold})
201
+ if cell_content.is_a?(Hash)
202
+ cell_hash = cell_content.dup
203
+ # Sanitize the content if it exists
204
+ if cell_hash[:content]
205
+ cell_hash[:content] = sanitize_text(cell_hash[:content].to_s)
206
+ end
207
+ cell_hash
208
+ else
209
+ # Handle simple string cells
210
+ sanitize_text(cell_content.to_s)
211
+ end
172
212
  end
173
213
  end
174
214
 
@@ -180,12 +220,12 @@ module PrawnHebrew
180
220
  if cell_text =~ /\p{Hebrew}/
181
221
  # Use text_color and font to support Hebrew
182
222
  cell.font = hebrew_font
183
- cell.size = size
223
+ cell.size = size unless cell.size # Don't override if already set
184
224
  cell.text_color = table_opts[:text_color] || "000000"
185
225
  else
186
226
  # English cells
187
227
  cell.font = english_font
188
- cell.size = size
228
+ cell.size = size unless cell.size # Don't override if already set
189
229
  end
190
230
  end
191
231
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PrawnHebrew
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn_hebrew
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Lite