prawn-rtl-support 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -8
- data/lib/prawn/rtl/support.rb +15 -37
- data/lib/prawn/rtl/support/version.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be6a2b42d40aa2ffbf6bd2a754f19ab1de3d896c
|
4
|
+
data.tar.gz: 85bbe0586f15909958aff1dbdd85839cc640e5b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d40f065944778d9ba6374ae87e9329c8b58e0af2d683f9c1da0fe8344f1d57cfd02ad7689ae5928a2e9d8ffb6bd161f12429bc7590ed6ff4f9712948d49f69e3
|
7
|
+
data.tar.gz: bcf30e9272b51dc311f14374b390b6dc9b539c796ba594fac661328ecc56a98c9fae1fa0e3a5d5183ecb9dc05b78b7ffbc6b7222ead0511fc5e31ec07707e56d
|
data/README.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
# Prawn::Rtl::Support
|
2
2
|
|
3
|
-
|
3
|
+
This gem provide bidirectional text support for Prawn. It uses Unicode Bidirectional Algorithm for displaying text from [TwitterCldr::Shared::Bidi](https://github.com/twitter/twitter-cldr-rb) and connect arabic letters using [Arabic Letter Connector](https://github.com/staii/arabic-letter-connector). 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).
|
4
4
|
|
5
|
-
|
5
|
+
## Motivation
|
6
|
+
|
7
|
+
Ruby and Rails internally provide unicode string normalization and store normalized letters inside. But Prawn don't connect arabic glyphs back and don't suport mixet LTR and RTL string. This gem add this suport.
|
8
|
+
|
9
|
+
## Acknowledgment
|
10
|
+
This gem use same code as [Arabic Letter Connector](https://github.com/staii/arabic-letter-connector) by [@staii](https://github.com/staii) and therefore based on [Arabic-Prawn](https://rubygems.org/gems/Arabic-Prawn/versions/0.0.1) by Dynamix Solutions (Ahmed Nasser)
|
6
11
|
|
7
12
|
## Installation
|
8
13
|
|
@@ -12,9 +17,7 @@ Add this line to your application's Gemfile:
|
|
12
17
|
gem 'prawn-rtl-support'
|
13
18
|
```
|
14
19
|
|
15
|
-
And
|
16
|
-
|
17
|
-
$ bundle
|
20
|
+
And that's all. Your Prawn is patched!
|
18
21
|
|
19
22
|
Or install it yourself as:
|
20
23
|
|
@@ -22,7 +25,8 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
`prawn-rtl-support` provide method `Prawn::Rtl::Connector#fix_rtl(string)` which reverse string and connect arabic letters.
|
29
|
+
Prawn patching is minimal, we patch only [Prawn::Text::Formatted::Box#original_text]
|
26
30
|
|
27
31
|
## Development
|
28
32
|
|
@@ -32,10 +36,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
36
|
|
33
37
|
## Contributing
|
34
38
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cropio/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.
|
40
|
+
|
36
41
|
|
37
42
|
|
38
43
|
## License
|
39
44
|
|
40
45
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/lib/prawn/rtl/support.rb
CHANGED
@@ -1,25 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
|
3
|
+
require 'pdf/core/text'
|
3
4
|
require 'prawn/rtl/support/version'
|
4
5
|
require 'prawn/rtl/connector'
|
5
6
|
|
6
|
-
module PrawnPatch
|
7
|
-
def array_from_tokens(tokens)
|
8
|
-
super.map do |record|
|
9
|
-
if record.include?(:text)
|
10
|
-
record[:text] = Prawn::Rtl::Connector.fix_rtl(record[:text])
|
11
|
-
end
|
12
|
-
record
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
7
|
module Prawn
|
18
|
-
module
|
19
|
-
module
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
module Rtl
|
9
|
+
module Support
|
10
|
+
module PrawnTextPatch
|
11
|
+
def original_text
|
12
|
+
super.map do |h|
|
13
|
+
if h.key?(:text)
|
14
|
+
h[:text] = Prawn::Rtl::Connector.fix_rtl(h[:text])
|
15
|
+
end
|
16
|
+
h
|
17
|
+
end
|
23
18
|
end
|
24
19
|
end
|
25
20
|
end
|
@@ -28,26 +23,9 @@ end
|
|
28
23
|
|
29
24
|
module Prawn
|
30
25
|
module Text
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
options = options.dup
|
35
|
-
|
36
|
-
p = options[:inline_format]
|
37
|
-
if p
|
38
|
-
p = [] unless p.is_a?(Array)
|
39
|
-
options.delete(:inline_format)
|
40
|
-
array = text_formatter.format(string, *p)
|
41
|
-
else
|
42
|
-
array = [{ text: Prawn::Rtl::Connector.fix_rtl(string) }]
|
43
|
-
end
|
44
|
-
|
45
|
-
formatted_text(array, options)
|
46
|
-
end
|
47
|
-
|
48
|
-
class Box
|
49
|
-
def initialize(string, options = {})
|
50
|
-
super([{ text: Prawn::Rtl::Connector.fix_rtl(string) }], options)
|
26
|
+
module Formatted
|
27
|
+
class Box
|
28
|
+
prepend Prawn::Rtl::Support::PrawnTextPatch
|
51
29
|
end
|
52
30
|
end
|
53
31
|
end
|