prawn_hebrew 0.0.5 → 0.0.7

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 +74 -17
  3. data/lib/version.rb +3 -3
  4. metadata +5 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad2256a5c7e53cc0b335bce5f5284ad3d33372d8580239c83283a4ab2542796c
4
- data.tar.gz: 4464fb1beb01533773a6eb1969455c539af02619fb6e4153d93a3682ca988121
3
+ metadata.gz: 2d1ef260d0ff7646b39769526d9c62e7b218213c0984566510a98255d9457939
4
+ data.tar.gz: 9ed590c393eeb60137e41a0d2f354513f001f07049d27964c2708acd8c0aa437
5
5
  SHA512:
6
- metadata.gz: fd4e466a35cdfa7d047419c0b49e08b6fb0b16dce0a1e36649f9245ed645ce81bbfefd5fb6783e7a0c0d5497d3af4086c7488c6925ffabd73db7524156d9c21f
7
- data.tar.gz: 7268788094ed4044b2b4621bfa3598a0bf3eb6fd5e8bfa8105b752fa41a9be764625dee7be864407db8f4444fc36633188e80cbe2873f016ca2bb0ac5e06238f
6
+ metadata.gz: ad3ab20f48d5d3240b53772ef58da9753ea42f1efa30fba7bee40dcfe23ad1988d4d913160385a7f09097eeae45710d2cb6ef85278586e060bfea2c3aa709539
7
+ data.tar.gz: 83933c5108021e9c0d3c8b3c483220ab31640401b49af8332803bfac48d184ac0612251ef8c5638dc8f0620ec99c50fa6a31d8ab291860dafea4bd4943fd80c2
data/lib/prawn_hebrew.rb CHANGED
@@ -4,19 +4,21 @@ require_relative 'version'
4
4
  module PrawnHebrew
5
5
  module Text
6
6
  DEFAULT_HEBREW_FONT = 'GveretLevinHebrew'.freeze
7
- DEFAULT_ENGLISH_FONT = 'Arial'.freeze
7
+ DEFAULT_ENGLISH_FONT = 'Helvetica'.freeze
8
+
9
+ # Set to true for debugging which text rendering path is used
10
+ DEBUG_MODE = false
8
11
 
9
- # Returns array of text fragments for Prawn's formatted_text methods
10
- # Example:
11
- # formatted_text_box hebrew_formatted_text('שלום world'), at: [0,100]
12
12
  def hebrew_formatted_text(text, size: 12, style: :normal, hebrew_font: DEFAULT_HEBREW_FONT, english_font: DEFAULT_ENGLISH_FONT)
13
13
  words = text.to_s.split(/(\s+|\n)/)
14
14
  hebrew_run = []
15
15
  fragments = []
16
+
17
+ styles = style.is_a?(Array) ? style : [style].compact
16
18
 
17
19
  words.each do |word|
18
20
  if word.strip.empty?
19
- fragments << { text: word, font: english_font, size: size, style: style } if word != ' '
21
+ fragments << { text: word, font: english_font, size: size, styles: styles } if word != ' '
20
22
  next
21
23
  end
22
24
 
@@ -25,34 +27,89 @@ module PrawnHebrew
25
27
  else
26
28
  unless hebrew_run.empty?
27
29
  hebrew_run.reverse.each_with_index do |hw, idx|
28
- fragments << { text: hw, font: hebrew_font, size: size, direction: :rtl, style: style }
29
- fragments << { text: ' ', font: hebrew_font, size: size, direction: :rtl, style: style } if idx < hebrew_run.length - 1
30
+ fragments << { text: hw, font: hebrew_font, size: size, direction: :rtl, styles: styles }
31
+ fragments << { text: ' ', font: hebrew_font, size: size, direction: :rtl, styles: styles } if idx < hebrew_run.length - 1
30
32
  end
31
33
  fragments << { text: ' ' }
32
34
  hebrew_run.clear
33
35
  end
34
- fragments << { text: "#{word} ", font: english_font, size: size, style: style }
36
+ fragments << { text: "#{word} ", font: english_font, size: size, styles: styles }
35
37
  end
36
38
  end
37
39
 
38
40
  unless hebrew_run.empty?
39
41
  hebrew_run.reverse.each_with_index do |hw, idx|
40
- fragments << { text: hw, font: hebrew_font, size: size, direction: :rtl, style: style }
41
- fragments << { text: ' ', font: hebrew_font, size: size, direction: :rtl, style: style } if idx < hebrew_run.length - 1
42
+ fragments << { text: hw, font: hebrew_font, size: size, direction: :rtl, styles: styles }
43
+ fragments << { text: ' ', font: hebrew_font, size: size, direction: :rtl, styles: styles } if idx < hebrew_run.length - 1
42
44
  end
43
45
  end
44
-
45
46
  fragments
46
47
  end
47
48
 
48
- # Helper combining hebrew_formatted_text with formatted_text_box
49
49
  def hebrew_text_box(text, size: 12, style: :normal,
50
50
  hebrew_font: DEFAULT_HEBREW_FONT,
51
- english_font: DEFAULT_ENGLISH_FONT, **box_opts)
52
- fragments = hebrew_formatted_text(text, size: size, style: style,
53
- hebrew_font: hebrew_font,
54
- english_font: english_font)
55
- formatted_text_box(fragments, box_opts)
51
+ english_font: DEFAULT_ENGLISH_FONT,
52
+ direction: :auto, **box_opts)
53
+
54
+ # Handle font specification in box_opts or use defaults
55
+ final_hebrew_font = box_opts.delete(:hebrew_font) || hebrew_font
56
+ final_english_font = box_opts.delete(:english_font) || english_font
57
+ final_size = box_opts.delete(:size) || size
58
+ rotation = box_opts.delete(:rotate) || 0
59
+ char_spacing = box_opts.delete(:character_spacing) || 0
60
+ leading = box_opts.delete(:leading) || 0
61
+
62
+ # Check if text contains Hebrew characters
63
+ contains_hebrew = text.to_s =~ /\p{Hebrew}/
64
+
65
+ # If direction is auto, determine based on content
66
+ if direction == :auto
67
+ direction = contains_hebrew ? :rtl : :ltr
68
+ end
69
+
70
+ # For completely English text (no Hebrew characters and LTR direction),
71
+ # use standard Prawn text_box for better performance and compatibility
72
+ if !contains_hebrew && direction == :ltr
73
+ render_english_only_text(text, final_size, style, final_english_font,
74
+ rotation, char_spacing, leading, box_opts)
75
+ else
76
+ # For Hebrew text or RTL direction, use formatted text approach
77
+ if rotation != 0
78
+ rotate(rotation, origin: box_opts[:at] || [0, 0]) do
79
+ render_hebrew_text_content(text, contains_hebrew, direction, final_size, style,
80
+ final_hebrew_font, final_english_font, char_spacing, leading, box_opts)
81
+ end
82
+ else
83
+ render_hebrew_text_content(text, contains_hebrew, direction, final_size, style,
84
+ final_hebrew_font, final_english_font, char_spacing, leading, box_opts)
85
+ end
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ # Render pure English text using standard Prawn text_box for optimal performance
92
+ def render_english_only_text(text, final_size, style, final_english_font,
93
+ rotation, char_spacing, leading, box_opts)
94
+ font(final_english_font) do
95
+ text_box(text.to_s, { size: final_size, style: style }.merge(box_opts))
96
+ end
97
+ end
98
+
99
+ # Render Hebrew text or mixed text using formatted text approach
100
+ def render_hebrew_text_content(text, contains_hebrew, direction, final_size, style,
101
+ final_hebrew_font, final_english_font, char_spacing, leading, box_opts)
102
+ # Apply character spacing and leading if specified
103
+ character_spacing(char_spacing) do
104
+ fragments = hebrew_formatted_text(text, size: final_size, style: style,
105
+ hebrew_font: final_hebrew_font,
106
+ english_font: final_english_font)
107
+
108
+ # Add leading to box_opts if specified
109
+ box_opts[:leading] = leading if leading > 0
110
+
111
+ formatted_text_box(fragments, box_opts)
112
+ end
56
113
  end
57
114
  end
58
115
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module PrawnHebrew
2
- VERSION = "0.0.1"
3
- end
1
+ module PrawnHebrew
2
+ VERSION = "0.0.7"
3
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn_hebrew
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Lite
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-06-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Working with hebrew words in prawn
14
- email: benlite96@gmail.com
13
+ email:
14
+ - benlite96@gmail.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
@@ -22,7 +22,6 @@ homepage: https://rubygems.org/gems/prawn_hebrew
22
22
  licenses:
23
23
  - MIT
24
24
  metadata: {}
25
- post_install_message:
26
25
  rdoc_options: []
27
26
  require_paths:
28
27
  - lib
@@ -37,8 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
38
  requirements: []
40
- rubygems_version: 3.0.3
41
- signing_key:
39
+ rubygems_version: 3.6.7
42
40
  specification_version: 4
43
41
  summary: Hebrew Text in Prawn
44
42
  test_files: []