prawn_hebrew 0.0.6 → 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.
- checksums.yaml +4 -4
- data/lib/prawn_hebrew.rb +74 -12
- data/lib/version.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d1ef260d0ff7646b39769526d9c62e7b218213c0984566510a98255d9457939
|
|
4
|
+
data.tar.gz: 9ed590c393eeb60137e41a0d2f354513f001f07049d27964c2708acd8c0aa437
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad3ab20f48d5d3240b53772ef58da9753ea42f1efa30fba7bee40dcfe23ad1988d4d913160385a7f09097eeae45710d2cb6ef85278586e060bfea2c3aa709539
|
|
7
|
+
data.tar.gz: 83933c5108021e9c0d3c8b3c483220ab31640401b49af8332803bfac48d184ac0612251ef8c5638dc8f0620ec99c50fa6a31d8ab291860dafea4bd4943fd80c2
|
data/lib/prawn_hebrew.rb
CHANGED
|
@@ -4,16 +4,21 @@ require_relative 'version'
|
|
|
4
4
|
module PrawnHebrew
|
|
5
5
|
module Text
|
|
6
6
|
DEFAULT_HEBREW_FONT = 'GveretLevinHebrew'.freeze
|
|
7
|
-
DEFAULT_ENGLISH_FONT = '
|
|
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
12
|
def hebrew_formatted_text(text, size: 12, style: :normal, hebrew_font: DEFAULT_HEBREW_FONT, english_font: DEFAULT_ENGLISH_FONT)
|
|
10
13
|
words = text.to_s.split(/(\s+|\n)/)
|
|
11
14
|
hebrew_run = []
|
|
12
15
|
fragments = []
|
|
16
|
+
|
|
17
|
+
styles = style.is_a?(Array) ? style : [style].compact
|
|
13
18
|
|
|
14
19
|
words.each do |word|
|
|
15
20
|
if word.strip.empty?
|
|
16
|
-
fragments << { text: word, font: english_font, size: size, styles:
|
|
21
|
+
fragments << { text: word, font: english_font, size: size, styles: styles } if word != ' '
|
|
17
22
|
next
|
|
18
23
|
end
|
|
19
24
|
|
|
@@ -22,20 +27,20 @@ module PrawnHebrew
|
|
|
22
27
|
else
|
|
23
28
|
unless hebrew_run.empty?
|
|
24
29
|
hebrew_run.reverse.each_with_index do |hw, idx|
|
|
25
|
-
fragments << { text: hw, font: hebrew_font, size: size, direction: :rtl, styles:
|
|
26
|
-
fragments << { text: ' ', font: hebrew_font, size: size, direction: :rtl, styles:
|
|
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
|
|
27
32
|
end
|
|
28
33
|
fragments << { text: ' ' }
|
|
29
34
|
hebrew_run.clear
|
|
30
35
|
end
|
|
31
|
-
fragments << { text: "#{word} ", font: english_font, size: size, styles:
|
|
36
|
+
fragments << { text: "#{word} ", font: english_font, size: size, styles: styles }
|
|
32
37
|
end
|
|
33
38
|
end
|
|
34
39
|
|
|
35
40
|
unless hebrew_run.empty?
|
|
36
41
|
hebrew_run.reverse.each_with_index do |hw, idx|
|
|
37
|
-
fragments << { text: hw, font: hebrew_font, size: size, direction: :rtl, styles:
|
|
38
|
-
fragments << { text: ' ', font: hebrew_font, size: size, direction: :rtl, styles:
|
|
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
|
|
39
44
|
end
|
|
40
45
|
end
|
|
41
46
|
fragments
|
|
@@ -43,11 +48,68 @@ module PrawnHebrew
|
|
|
43
48
|
|
|
44
49
|
def hebrew_text_box(text, size: 12, style: :normal,
|
|
45
50
|
hebrew_font: DEFAULT_HEBREW_FONT,
|
|
46
|
-
english_font: DEFAULT_ENGLISH_FONT,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
|
51
113
|
end
|
|
52
114
|
end
|
|
53
115
|
end
|
data/lib/version.rb
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module PrawnHebrew
|
|
2
|
-
VERSION = "0.0.
|
|
3
|
-
end
|
|
1
|
+
module PrawnHebrew
|
|
2
|
+
VERSION = "0.0.7"
|
|
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.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Lite
|
|
@@ -10,7 +10,8 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: Working with hebrew words in prawn
|
|
13
|
-
email:
|
|
13
|
+
email:
|
|
14
|
+
- benlite96@gmail.com
|
|
14
15
|
executables: []
|
|
15
16
|
extensions: []
|
|
16
17
|
extra_rdoc_files: []
|