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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7377ed9d1fc3efd5e3379b5c032e0b7418c7d1c8
4
- data.tar.gz: 8b88073aa4b6b0cdd29a0a4accb208614163dfbe
3
+ metadata.gz: be6a2b42d40aa2ffbf6bd2a754f19ab1de3d896c
4
+ data.tar.gz: 85bbe0586f15909958aff1dbdd85839cc640e5b4
5
5
  SHA512:
6
- metadata.gz: 763b806afc19cdc81b79e52c7fd6afe4831a1193d502aa5607daed85b16d759ef8a9e26d2e66e01b4fa57d4ac01a3041e4cab17d7df8bef4c084c77217ffe7b5
7
- data.tar.gz: e888d74ffd0e16e0a679cd853cfa6f997a6b70b32faf353e568543bb444a020bedcb37605259e4fe525e20a37daaf0e0c9c201a4fce473ae8abf1a25d0ba78f0
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/prawn/rtl/support`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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 then execute:
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
- TODO: Write usage instructions here
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/[USERNAME]/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.
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
-
@@ -1,25 +1,20 @@
1
1
  # frozen_string_literal: true
2
- require 'prawn'
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 Text
19
- module Formatted
20
- class Parser
21
- class << self
22
- prepend PrawnPatch
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
- def text(string, options = {})
32
- return false if string.nil?
33
- # we modify the options. don't change the user's hash
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
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prawn
2
4
  module Rtl
3
5
  module Support
4
- VERSION = "0.1.1"
6
+ VERSION = '0.1.5'
5
7
  end
6
8
  end
7
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn-rtl-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksandr Lapchenko