prawn-rtl-support 0.1.6 → 0.1.8
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/CHANGELOG.md +43 -0
- data/CLAUDE.md +56 -0
- data/Gemfile +15 -0
- data/README.md +27 -10
- data/Rakefile +5 -3
- data/lib/prawn/rtl/connector/logic.rb +72 -14
- data/lib/prawn/rtl/connector.rb +44 -1
- data/lib/prawn/rtl/support/version.rb +1 -1
- data/lib/prawn/rtl/support.rb +20 -6
- data/prawn-rtl-support.gemspec +33 -24
- metadata +23 -103
- data/.gitignore +0 -14
- data/.rspec +0 -2
- data/.travis.yml +0 -7
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1424d40245ffbe3f42623e759747cdf847a9ca998df21164a2e08c800417fe1e
|
4
|
+
data.tar.gz: abad0e4cc7958ef0f3fd4213eb50ecb02bfa121312a1cab18b2418c568ec4427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bef93dc5aa91ba1869881d51a109f305f1e9c4567be688333503c10714efdb448deba04634053c23351e9f8c5b8f85e87df08c6f702ba2e4347b15bd13ab5ca
|
7
|
+
data.tar.gz: fbd89cc337db56fd6c3f369c745f125b95fbaa099ab6e1783a354cb5cb90d5d3b8024692fc74a5debc3ad45e881bbf6e92e83d2716522d872a559e1ea9e4d8c3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [0.1.8] - 2025-09-04
|
9
|
+
|
10
|
+
### Customer-Impacting Changes
|
11
|
+
|
12
|
+
#### Added
|
13
|
+
- **Ruby 2.7+ requirement**: Gem now explicitly requires Ruby 2.7 or higher
|
14
|
+
- **Better documentation**: All public APIs now have YARD documentation with examples
|
15
|
+
|
16
|
+
### Internal Changes
|
17
|
+
|
18
|
+
#### Development & CI
|
19
|
+
- Migrated from Travis CI to GitHub Actions
|
20
|
+
- Added testing matrix for Ruby 2.7, 3.0, 3.1, 3.2, 3.3, and 3.4
|
21
|
+
- Added RuboCop linting to CI workflow
|
22
|
+
- Added Dependabot for automated dependency updates
|
23
|
+
- Added CLAUDE.md for AI-assisted development guidance
|
24
|
+
- Multi-factor authentication (MFA) is now required for gem publishers
|
25
|
+
|
26
|
+
#### Code Quality
|
27
|
+
- Added YARD documentation to all modules and classes
|
28
|
+
- Fixed some RuboCop violations
|
29
|
+
- Fixed typos
|
30
|
+
- Improved gemspec metadata (added source_code_uri, changelog_uri, bug_tracker_uri, documentation_uri)
|
31
|
+
- Moved development dependencies from gemspec to Gemfile
|
32
|
+
- Removed unnecessary `$LOAD_PATH` manipulation
|
33
|
+
- Internal file requires now use `require_relative` for faster loading
|
34
|
+
- Gemspec file inclusion no longer depends on git, works in any environment
|
35
|
+
|
36
|
+
#### Documentation
|
37
|
+
- Updated README with "Supported Languages" section
|
38
|
+
- Updated gemspec description to accurately reflect RTL language support
|
39
|
+
- Added comprehensive code examples in YARD documentation
|
40
|
+
|
41
|
+
## [0.1.7] - 2020-05-10
|
42
|
+
|
43
|
+
For changes in previous versions, see the git commit history.
|
data/CLAUDE.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# CLAUDE.md
|
2
|
+
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
4
|
+
|
5
|
+
## Project Overview
|
6
|
+
|
7
|
+
This is prawn-rtl-support, a Ruby gem that provides bidirectional text (RTL/LTR) support for the Prawn PDF generation library. It enables proper rendering of Arabic and other right-to-left languages in PDFs by:
|
8
|
+
- Using Unicode Bidirectional Algorithm via TwitterCldr for text reordering
|
9
|
+
- Connecting Arabic letters properly for visual display
|
10
|
+
- Minimally patching Prawn's text rendering pipeline
|
11
|
+
|
12
|
+
## Development Commands
|
13
|
+
|
14
|
+
```bash
|
15
|
+
# Install dependencies
|
16
|
+
bundle install
|
17
|
+
|
18
|
+
# Run test suite
|
19
|
+
bundle exec rake spec
|
20
|
+
# or just
|
21
|
+
rake spec
|
22
|
+
|
23
|
+
# Run linting (RuboCop)
|
24
|
+
bundle exec rubocop
|
25
|
+
|
26
|
+
# Open console for experimentation
|
27
|
+
bin/console
|
28
|
+
|
29
|
+
# Build gem locally
|
30
|
+
bundle exec rake build
|
31
|
+
|
32
|
+
# Install gem to local machine
|
33
|
+
bundle exec rake install
|
34
|
+
```
|
35
|
+
|
36
|
+
## Architecture
|
37
|
+
|
38
|
+
The gem patches Prawn by prepending a module to `Prawn::Text::Formatted::Box#original_text`. The core functionality:
|
39
|
+
|
40
|
+
1. **lib/prawn/rtl/support.rb**: Main entry point that patches Prawn::Text::Formatted::Box
|
41
|
+
2. **lib/prawn/rtl/connector.rb**: Core RTL fixing logic with three main methods:
|
42
|
+
- `fix_rtl(string)`: Main public API that detects RTL text and processes it
|
43
|
+
- `connect(string)`: Applies Arabic letter connection rules
|
44
|
+
- `reorder(string)`: Uses TwitterCldr's Bidi algorithm to reorder text visually
|
45
|
+
3. **lib/prawn/rtl/connector/logic.rb**: Arabic letter connection logic with character mapping tables for different forms (isolated, initial, medial, final)
|
46
|
+
|
47
|
+
The gem automatically activates when required - no configuration needed. It detects RTL text and only processes strings that contain RTL characters.
|
48
|
+
|
49
|
+
## Key Dependencies
|
50
|
+
|
51
|
+
- **prawn ~> 2.2**: The PDF generation library being patched
|
52
|
+
- **twitter_cldr >= 4.0, < 7.0**: Provides Unicode Bidirectional Algorithm implementation
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
- Run tests `bundle exec rake` and RuboCop linting `bundle exec rubocop` before committing.
|
data/Gemfile
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in prawn-rtl-support.gemspec
|
4
6
|
gemspec
|
7
|
+
|
8
|
+
# Development dependencies
|
9
|
+
group :development, :test do
|
10
|
+
gem 'pry', '~> 0.12'
|
11
|
+
gem 'rake', '~> 13.0'
|
12
|
+
gem 'rspec', '~> 3.9'
|
13
|
+
gem 'rubocop', '1.80.2'
|
14
|
+
gem 'rubocop-performance', '1.25.0'
|
15
|
+
gem 'rubocop-rake', '0.7.1'
|
16
|
+
gem 'rubocop-rspec', '3.7.0'
|
17
|
+
gem 'rubocop-rubycw', '0.2.2'
|
18
|
+
gem 'rubocop-thread_safety', '0.7.3'
|
19
|
+
end
|
data/README.md
CHANGED
@@ -1,15 +1,26 @@
|
|
1
1
|
# Prawn::Rtl::Support
|
2
2
|
|
3
|
-
[](https://github.com/prawn-rtl-support/prawn-rtl-support/actions/workflows/ci.yml)
|
4
4
|
|
5
|
-
This gem
|
5
|
+
This gem provides bidirectional text support for Prawn PDF generator. It uses the Unicode Bidirectional Algorithm from [TwitterCldr::Shared::Bidi](https://github.com/twitter/twitter-cldr-rb) for text reordering and implements Arabic letter shaping similar to [Arabic Letter Connector](https://github.com/staii/arabic-letter-connector). Prawn patching is minimal - we only patch [`Prawn::Text::Formatted::Box#original_text`](https://github.com/prawnpdf/prawn/blob/master/lib/prawn/text/formatted/box.rb#L367).
|
6
6
|
|
7
|
-
##
|
7
|
+
## Supported Languages
|
8
8
|
|
9
|
-
|
9
|
+
- **Full support** (with contextual letter shaping):
|
10
|
+
- Arabic
|
11
|
+
- Persian/Farsi
|
12
|
+
- Urdu
|
13
|
+
- Other Arabic script languages
|
14
|
+
|
15
|
+
- **RTL support** (bidirectional text reordering):
|
16
|
+
- Hebrew
|
17
|
+
- Syriac
|
18
|
+
- Thaana
|
19
|
+
- Mixed LTR/RTL text
|
10
20
|
|
11
|
-
##
|
12
|
-
|
21
|
+
## Motivation
|
22
|
+
|
23
|
+
Ruby and Rails internally provide Unicode string normalization. However, Prawn doesn't connect Arabic letters into their contextual forms and doesn't support mixed LTR and RTL strings. This gem adds this support.
|
13
24
|
|
14
25
|
## Installation
|
15
26
|
|
@@ -23,24 +34,30 @@ And that's all. Your Prawn is patched!
|
|
23
34
|
|
24
35
|
Or install it yourself as:
|
25
36
|
|
26
|
-
|
37
|
+
```shell
|
38
|
+
gem install prawn-rtl-support
|
39
|
+
```
|
27
40
|
|
28
41
|
## Usage
|
29
42
|
|
30
|
-
`prawn-rtl-support` provide method [`Prawn::Rtl::Connector#fix_rtl(string)`](https://github.com/
|
43
|
+
`prawn-rtl-support` provide method [`Prawn::Rtl::Connector#fix_rtl(string)`](https://github.com/prawn-rtl-support/prawn-rtl-support/blob/master/lib/prawn/rtl/connector.rb#L13) which reverse string and connect arabic letters.
|
44
|
+
|
31
45
|
Prawn patching is minimal, we patch only [`Prawn::Text::Formatted::Box#original_text`](https://github.com/prawnpdf/prawn/blob/master/lib/prawn/text/formatted/box.rb#L367).
|
32
46
|
|
33
47
|
## Development
|
34
48
|
|
49
|
+
Check [CLAUDE.md](CLAUDE.md) for more details about the architecture and development commands.
|
50
|
+
|
35
51
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
52
|
|
37
53
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
54
|
|
39
55
|
## Contributing
|
40
56
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
42
|
-
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/prawn-rtl-support/prawn-rtl-support. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
43
58
|
|
59
|
+
## Acknowledgment
|
60
|
+
This gem uses the same code as [Arabic Letter Connector](https://github.com/staii/arabic-letter-connector) by [@staii](https://github.com/staii) and therefore is based on [Arabic-Prawn](https://rubygems.org/gems/Arabic-Prawn/versions/0.0.1) by Dynamix Solutions (Ahmed Nasser).
|
44
61
|
|
45
62
|
## License
|
46
63
|
|
data/Rakefile
CHANGED
@@ -3,48 +3,82 @@
|
|
3
3
|
module Prawn
|
4
4
|
module Rtl
|
5
5
|
module Connector
|
6
|
+
# Handles the logic for Arabic letter connection and contextual form selection.
|
7
|
+
#
|
8
|
+
# This module implements the core algorithm for determining which form
|
9
|
+
# (isolated, initial, medial, or final) an Arabic character should take
|
10
|
+
# based on its surrounding characters. It maintains a mapping of Arabic
|
11
|
+
# Unicode characters to their various contextual forms.
|
6
12
|
module Logic
|
7
|
-
|
8
13
|
@@charinfos = nil
|
9
14
|
|
15
|
+
# Represents information about an Arabic character and its contextual forms.
|
16
|
+
#
|
17
|
+
# Each Arabic letter can have up to four different forms depending on
|
18
|
+
# its position within a word and connection to surrounding letters.
|
10
19
|
class CharacterInfo
|
11
|
-
|
20
|
+
# @return [String] the base Unicode character
|
21
|
+
attr_accessor :common
|
22
|
+
|
23
|
+
# @return [Hash] the character's forms (:isolated, :final, :initial, :medial)
|
24
|
+
attr_accessor :formatted
|
12
25
|
|
26
|
+
# Initializes a new CharacterInfo instance.
|
27
|
+
#
|
28
|
+
# @param common [String] the base Unicode character
|
29
|
+
# @param isolated [String] the isolated form of the character
|
30
|
+
# @param final [String] the final form of the character
|
31
|
+
# @param initial [String] the initial form of the character
|
32
|
+
# @param medial [String] the medial form of the character
|
33
|
+
# @param connects [Boolean] whether this character connects to the next
|
34
|
+
# @param diacritic [Boolean] whether this character is a diacritic mark
|
13
35
|
def initialize(common, isolated, final, initial, medial, connects, diacritic)
|
14
36
|
@common = common
|
15
37
|
@formatted = {
|
16
38
|
isolated: isolated,
|
17
39
|
final: final,
|
18
40
|
initial: initial,
|
19
|
-
medial: medial
|
41
|
+
medial: medial
|
20
42
|
}
|
21
43
|
@connects = connects
|
22
44
|
@diacritic = diacritic
|
23
45
|
end
|
24
46
|
|
47
|
+
# Checks if this character connects to the following character.
|
48
|
+
#
|
49
|
+
# @return [Boolean] true if the character connects forward
|
25
50
|
def connects?
|
26
51
|
@connects
|
27
52
|
end
|
28
53
|
|
54
|
+
# Checks if this character is a diacritic mark.
|
55
|
+
#
|
56
|
+
# @return [Boolean] true if the character is a diacritic
|
29
57
|
def diacritic?
|
30
58
|
@diacritic
|
31
59
|
end
|
32
|
-
|
33
60
|
end
|
34
61
|
|
35
|
-
#
|
62
|
+
# Determines the contextual form of an Arabic character.
|
63
|
+
#
|
64
|
+
# Determines the form of the current character (:isolated, :initial, :medial,
|
36
65
|
# or :final), given the previous character and the next one. In Arabic, all
|
37
66
|
# characters can connect with a previous character, but not all letters can
|
38
|
-
# connect with the next character (this is determined by
|
39
|
-
#
|
67
|
+
# connect with the next character (this is determined by CharacterInfo#connects?).
|
68
|
+
#
|
69
|
+
# @param previous_previous_char [String, nil] the character two positions before
|
70
|
+
# @param previous_char [String, nil] the character immediately before
|
71
|
+
# @param next_char [String, nil] the character immediately after
|
72
|
+
# @param next_next_char [String, nil] the character two positions after
|
73
|
+
# @return [Symbol] the contextual form (:isolated, :initial, :medial, or :final)
|
40
74
|
def self.determine_form(previous_previous_char, previous_char, next_char, next_next_char)
|
41
75
|
charinfos = self.charinfos
|
42
76
|
next_char = next_next_char if charinfos[next_char] && charinfos[next_char].diacritic?
|
43
77
|
previous_char = previous_previous_char if charinfos[previous_char] && charinfos[previous_char].diacritic?
|
44
78
|
if charinfos[previous_char] && charinfos[next_char]
|
45
79
|
charinfos[previous_char].connects? ? :medial : :initial # If the current character does not connect,
|
46
|
-
|
47
|
-
|
80
|
+
# its medial form will map to its final form,
|
81
|
+
# and its initial form will map to its isolated form.
|
48
82
|
elsif charinfos[previous_char] # The next character is not an arabic character.
|
49
83
|
charinfos[previous_char].connects? ? :final : :isolated
|
50
84
|
elsif charinfos[next_char] # The previous character is not an arabic character.
|
@@ -54,6 +88,14 @@ module Prawn
|
|
54
88
|
end
|
55
89
|
end
|
56
90
|
|
91
|
+
# Transforms Arabic text by applying contextual letter forms.
|
92
|
+
#
|
93
|
+
# Processes a string character by character, determining the appropriate
|
94
|
+
# contextual form for each Arabic letter based on its surrounding characters.
|
95
|
+
# Non-Arabic characters pass through unchanged.
|
96
|
+
#
|
97
|
+
# @param str [String] the text to transform
|
98
|
+
# @return [String] the transformed text with Arabic letters in their contextual forms
|
57
99
|
def self.transform(str)
|
58
100
|
res = ''
|
59
101
|
charinfos = self.charinfos
|
@@ -69,7 +111,8 @@ module Prawn
|
|
69
111
|
next_char = next_next_char
|
70
112
|
next_next_char = char
|
71
113
|
return unless current_char
|
72
|
-
|
114
|
+
|
115
|
+
if charinfos.key?(current_char)
|
73
116
|
form = determine_form(previous_previous_char, previous_char, next_char, next_next_char)
|
74
117
|
res += charinfos[current_char].formatted[form]
|
75
118
|
else
|
@@ -78,13 +121,19 @@ module Prawn
|
|
78
121
|
end
|
79
122
|
str.each_char { |char| consume_character.call(char) }
|
80
123
|
2.times { consume_character.call(nil) }
|
81
|
-
|
124
|
+
res
|
82
125
|
end
|
83
126
|
|
84
|
-
|
85
|
-
|
127
|
+
# Returns the character information mapping for Arabic characters.
|
128
|
+
#
|
129
|
+
# Lazily initializes and returns a hash mapping Arabic Unicode characters
|
130
|
+
# to their CharacterInfo objects containing contextual forms.
|
131
|
+
#
|
132
|
+
# @return [Hash{String => CharacterInfo}] the character information mapping
|
133
|
+
# @api private
|
86
134
|
def self.charinfos
|
87
135
|
return @@charinfos unless @@charinfos.nil?
|
136
|
+
|
88
137
|
@@charinfos = {}
|
89
138
|
add('0627', 'fe8d', 'fe8e', 'fe8d', 'fe8e', false) # Alef
|
90
139
|
add('0628', 'fe8f', 'fe90', 'fe91', 'fe92', true) # Ba2
|
@@ -135,6 +184,16 @@ module Prawn
|
|
135
184
|
@@charinfos
|
136
185
|
end
|
137
186
|
|
187
|
+
# Adds a character and its contextual forms to the character mapping.
|
188
|
+
#
|
189
|
+
# @param common [String] hex code of the base Unicode character
|
190
|
+
# @param isolated [String] hex code of the isolated form
|
191
|
+
# @param final [String] hex code of the final form
|
192
|
+
# @param initial [String] hex code of the initial form
|
193
|
+
# @param medial [String] hex code of the medial form
|
194
|
+
# @param connects [Boolean] whether this character connects to the next
|
195
|
+
# @param diacritic [Boolean] whether this character is a diacritic mark
|
196
|
+
# @api private
|
138
197
|
def self.add(common, isolated, final, initial, medial, connects, diacritic = false)
|
139
198
|
charinfo = CharacterInfo.new(
|
140
199
|
[common.hex].pack('U'),
|
@@ -147,7 +206,6 @@ module Prawn
|
|
147
206
|
)
|
148
207
|
@@charinfos[charinfo.common] = charinfo
|
149
208
|
end
|
150
|
-
|
151
209
|
end
|
152
210
|
end
|
153
211
|
end
|
data/lib/prawn/rtl/connector.rb
CHANGED
@@ -1,20 +1,59 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'connector/logic'
|
4
4
|
require 'twitter_cldr'
|
5
5
|
|
6
6
|
module Prawn
|
7
7
|
module Rtl
|
8
|
+
# Provides bidirectional text support and Arabic letter connection for Prawn PDF generation.
|
9
|
+
#
|
10
|
+
# This module handles RTL (Right-to-Left) text processing by:
|
11
|
+
# - Connecting Arabic script letters according to their contextual forms
|
12
|
+
# - Reordering text using the Unicode Bidirectional Algorithm
|
13
|
+
# - Supporting multiple RTL languages (Arabic, Hebrew, Persian, Urdu, etc.)
|
14
|
+
# - Handling mixed LTR/RTL text properly
|
15
|
+
#
|
16
|
+
# @example Fix Arabic text for PDF rendering
|
17
|
+
# text = "مرحبا بالعالم"
|
18
|
+
# fixed_text = Prawn::Rtl::Connector.fix_rtl(text)
|
19
|
+
#
|
20
|
+
# @example Fix Hebrew text for PDF rendering
|
21
|
+
# text = "שלום עולם"
|
22
|
+
# fixed_text = Prawn::Rtl::Connector.fix_rtl(text)
|
23
|
+
#
|
24
|
+
# @example Fix mixed LTR/RTL text
|
25
|
+
# text = "Hello مرحبا World"
|
26
|
+
# fixed_text = Prawn::Rtl::Connector.fix_rtl(text)
|
8
27
|
module Connector
|
28
|
+
# Connects Arabic letters according to their contextual forms.
|
29
|
+
#
|
30
|
+
# @param string [String] the text containing Arabic letters to connect
|
31
|
+
# @return [String] the text with properly connected Arabic letters
|
9
32
|
def self.connect(string)
|
10
33
|
Prawn::Rtl::Connector::Logic.transform(string)
|
11
34
|
end
|
12
35
|
|
36
|
+
# Fixes RTL text by connecting Arabic letters and reordering for visual display.
|
37
|
+
#
|
38
|
+
# This is the main entry point for processing RTL text. It detects if the text
|
39
|
+
# contains RTL characters and applies both letter connection and bidirectional
|
40
|
+
# reordering if needed.
|
41
|
+
#
|
42
|
+
# @param string [String] the text to process
|
43
|
+
# @return [String] the processed text ready for PDF rendering
|
13
44
|
def self.fix_rtl(string)
|
14
45
|
return string unless include_rtl?(string)
|
46
|
+
|
15
47
|
reorder(connect(string))
|
16
48
|
end
|
17
49
|
|
50
|
+
# Reorders text according to the Unicode Bidirectional Algorithm.
|
51
|
+
#
|
52
|
+
# Uses TwitterCldr's Bidi implementation to visually reorder mixed
|
53
|
+
# LTR/RTL text for correct display.
|
54
|
+
#
|
55
|
+
# @param string [String] the text to reorder
|
56
|
+
# @return [String] the visually reordered text
|
18
57
|
def self.reorder(string)
|
19
58
|
TwitterCldr::Shared::Bidi
|
20
59
|
.from_string(string, direction: :RTL)
|
@@ -22,6 +61,10 @@ module Prawn
|
|
22
61
|
.to_s
|
23
62
|
end
|
24
63
|
|
64
|
+
# Checks if a string contains RTL (Right-to-Left) characters.
|
65
|
+
#
|
66
|
+
# @param string [String] the text to check
|
67
|
+
# @return [Boolean] true if the text contains RTL characters, false otherwise
|
25
68
|
def self.include_rtl?(string)
|
26
69
|
TwitterCldr::Shared::Bidi
|
27
70
|
.from_string(string)
|
data/lib/prawn/rtl/support.rb
CHANGED
@@ -1,18 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'pdf/core/text'
|
4
|
-
|
5
|
-
|
4
|
+
require_relative 'support/version'
|
5
|
+
require_relative 'connector'
|
6
6
|
|
7
7
|
module Prawn
|
8
8
|
module Rtl
|
9
|
+
# Main module for RTL support functionality.
|
9
10
|
module Support
|
11
|
+
# Patch module that intercepts Prawn's text rendering to apply RTL transformations.
|
12
|
+
#
|
13
|
+
# This module is prepended to Prawn::Text::Formatted::Box to automatically
|
14
|
+
# process RTL text before rendering. It intercepts the original_text method
|
15
|
+
# and applies Arabic letter connection and bidirectional text reordering
|
16
|
+
# to any text fragments that contain RTL characters.
|
17
|
+
#
|
18
|
+
# @example How it works internally
|
19
|
+
# # When Prawn renders text, this patch:
|
20
|
+
# # 1. Intercepts the text fragments
|
21
|
+
# # 2. Applies RTL fixes to each fragment
|
22
|
+
# # 3. Returns the processed fragments for rendering
|
10
23
|
module PrawnTextPatch
|
24
|
+
# Overrides the original_text method to apply RTL transformations.
|
25
|
+
#
|
26
|
+
# @return [Array<Hash>] array of text fragments with RTL text properly formatted
|
11
27
|
def original_text
|
12
28
|
super.map do |h|
|
13
|
-
if h.key?(:text)
|
14
|
-
h[:text] = Prawn::Rtl::Connector.fix_rtl(h[:text])
|
15
|
-
end
|
29
|
+
h[:text] = Prawn::Rtl::Connector.fix_rtl(h[:text]) if h.key?(:text)
|
16
30
|
h
|
17
31
|
end
|
18
32
|
end
|
@@ -25,7 +39,7 @@ module Prawn
|
|
25
39
|
module Text
|
26
40
|
module Formatted
|
27
41
|
class Box
|
28
|
-
prepend
|
42
|
+
prepend Prawn::Rtl::Support::PrawnTextPatch
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
data/prawn-rtl-support.gemspec
CHANGED
@@ -1,33 +1,42 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
require 'prawn/rtl/support/version'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/prawn/rtl/support/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'prawn-rtl-support'
|
8
7
|
spec.version = Prawn::Rtl::Support::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['Oleksandr Lapchenko']
|
9
|
+
spec.email = ['ozeron@me.com']
|
11
10
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = '
|
14
|
-
|
15
|
-
|
11
|
+
spec.summary = 'Bidirectional text support for Prawn PDF generator'
|
12
|
+
spec.description = 'Adds right-to-left (RTL) text support to Prawn PDF generator. ' \
|
13
|
+
'Fully supports Arabic script languages (Arabic, Persian, Urdu) with ' \
|
14
|
+
'contextual letter shaping and ligatures. Also supports Hebrew and other ' \
|
15
|
+
'RTL languages with bidirectional text reordering. Handles mixed LTR/RTL text properly.'
|
16
|
+
spec.homepage = 'https://github.com/prawn-rtl-support/prawn-rtl-support'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
spec.required_ruby_version = '>= 2.7.0'
|
16
19
|
|
17
|
-
spec.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
spec.metadata = {
|
21
|
+
'rubygems_mfa_required' => 'true',
|
22
|
+
'source_code_uri' => 'https://github.com/prawn-rtl-support/prawn-rtl-support',
|
23
|
+
'changelog_uri' => 'https://github.com/prawn-rtl-support/prawn-rtl-support/blob/main/CHANGELOG.md',
|
24
|
+
'bug_tracker_uri' => 'https://github.com/prawn-rtl-support/prawn-rtl-support/issues',
|
25
|
+
'documentation_uri' => 'https://rubydoc.info/gems/prawn-rtl-support'
|
26
|
+
}
|
23
27
|
|
24
|
-
|
25
|
-
spec.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
# Specify which files should be included in the gem
|
29
|
+
spec.files = (Dir['{lib,exe}/**/*'] +
|
30
|
+
Dir['*.{md,txt,gemspec}'] +
|
31
|
+
%w[Gemfile Rakefile LICENSE.txt README.md CODE_OF_CONDUCT.md].select { |f| File.exist?(f) })
|
32
|
+
.reject { |f| File.directory?(f) }
|
33
|
+
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
spec.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
30
38
|
|
39
|
+
# Runtime dependencies
|
31
40
|
spec.add_dependency 'prawn', '~> 2.2'
|
32
|
-
spec.add_dependency 'twitter_cldr', '>= 4.0', '<
|
41
|
+
spec.add_dependency 'twitter_cldr', '>= 4.0', '< 7.0'
|
33
42
|
end
|
metadata
CHANGED
@@ -1,99 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-rtl-support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleksandr Lapchenko
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '13.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '13.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.9'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.9'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: pry
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.12'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.12'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.77'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.77'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-performance
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.5'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.5'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.37'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.37'
|
97
12
|
- !ruby/object:Gem::Dependency
|
98
13
|
name: prawn
|
99
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,7 +32,7 @@ dependencies:
|
|
117
32
|
version: '4.0'
|
118
33
|
- - "<"
|
119
34
|
- !ruby/object:Gem::Version
|
120
|
-
version: '
|
35
|
+
version: '7.0'
|
121
36
|
type: :runtime
|
122
37
|
prerelease: false
|
123
38
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -127,34 +42,40 @@ dependencies:
|
|
127
42
|
version: '4.0'
|
128
43
|
- - "<"
|
129
44
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
131
|
-
description:
|
45
|
+
version: '7.0'
|
46
|
+
description: Adds right-to-left (RTL) text support to Prawn PDF generator. Fully supports
|
47
|
+
Arabic script languages (Arabic, Persian, Urdu) with contextual letter shaping and
|
48
|
+
ligatures. Also supports Hebrew and other RTL languages with bidirectional text
|
49
|
+
reordering. Handles mixed LTR/RTL text properly.
|
132
50
|
email:
|
133
51
|
- ozeron@me.com
|
134
52
|
executables: []
|
135
53
|
extensions: []
|
136
|
-
extra_rdoc_files:
|
54
|
+
extra_rdoc_files:
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
137
57
|
files:
|
138
|
-
-
|
139
|
-
-
|
140
|
-
- ".travis.yml"
|
58
|
+
- CHANGELOG.md
|
59
|
+
- CLAUDE.md
|
141
60
|
- CODE_OF_CONDUCT.md
|
142
61
|
- Gemfile
|
143
62
|
- LICENSE.txt
|
144
63
|
- README.md
|
145
64
|
- Rakefile
|
146
|
-
- bin/console
|
147
|
-
- bin/setup
|
148
65
|
- lib/prawn/rtl/connector.rb
|
149
66
|
- lib/prawn/rtl/connector/logic.rb
|
150
67
|
- lib/prawn/rtl/support.rb
|
151
68
|
- lib/prawn/rtl/support/version.rb
|
152
69
|
- prawn-rtl-support.gemspec
|
153
|
-
homepage: https://github.com/
|
70
|
+
homepage: https://github.com/prawn-rtl-support/prawn-rtl-support
|
154
71
|
licenses:
|
155
72
|
- MIT
|
156
|
-
metadata:
|
157
|
-
|
73
|
+
metadata:
|
74
|
+
rubygems_mfa_required: 'true'
|
75
|
+
source_code_uri: https://github.com/prawn-rtl-support/prawn-rtl-support
|
76
|
+
changelog_uri: https://github.com/prawn-rtl-support/prawn-rtl-support/blob/main/CHANGELOG.md
|
77
|
+
bug_tracker_uri: https://github.com/prawn-rtl-support/prawn-rtl-support/issues
|
78
|
+
documentation_uri: https://rubydoc.info/gems/prawn-rtl-support
|
158
79
|
rdoc_options: []
|
159
80
|
require_paths:
|
160
81
|
- lib
|
@@ -162,15 +83,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
83
|
requirements:
|
163
84
|
- - ">="
|
164
85
|
- !ruby/object:Gem::Version
|
165
|
-
version:
|
86
|
+
version: 2.7.0
|
166
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
88
|
requirements:
|
168
89
|
- - ">="
|
169
90
|
- !ruby/object:Gem::Version
|
170
91
|
version: '0'
|
171
92
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
173
|
-
signing_key:
|
93
|
+
rubygems_version: 3.6.7
|
174
94
|
specification_version: 4
|
175
|
-
summary:
|
95
|
+
summary: Bidirectional text support for Prawn PDF generator
|
176
96
|
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "prawn/rtl/support"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "pry"
|
14
|
-
Pry.start(__FILE__)
|