persian-bechasboon 0.0.0 → 0.0.1

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: d39ba4730ca49a3236330e0545c5f36ea4d223de
4
- data.tar.gz: 53e5c38d80cc215577fe2875f4980cd025071b90
3
+ metadata.gz: dfffba769b563cf415e2a90b68c877c6f078be34
4
+ data.tar.gz: dd9a739f574d5ae6bb153b7ffb3b2ffca0536638
5
5
  SHA512:
6
- metadata.gz: 3f7969288d045cb7f6bb01e9ee0c20acd4b7a566d859967925ce7eb090dd0abd405ea35fca0593dc3d32b70360146eb93ce9a145c0c633e831efb1900732f302
7
- data.tar.gz: b6da92ece6bfc8f39931e321c3bd5c559596dfac430c67a290568c9f5688c0ede736491bee1f1deeb39dbea13cc2be960e024910a21b58b7d958d6ccfa4c25d1
6
+ metadata.gz: 86aec7a0cf1c6a5e5b52b7a5fdd3d54fafe9d085b221d82bd4fc78417d460ed85217892c6e5c6960bb11b51842c8c958b81466eef76569b3b7cd8dbef86c24f1
7
+ data.tar.gz: 7eefbcc318a3a406ee5283008754d7f90d63bc01e84ffb6301ab54fe50f2969f3a6840d713375a630813e623ddb10601401c452f9d6dfa86b716e21b32470fc6
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
@@ -0,0 +1,36 @@
1
+ Persian Bechasboon
2
+ ==================
3
+
4
+ Languages which have connecting characters are not well-supported by many programming libraries.
5
+ Persian language is one of them. I try to use prawn as a PDF generator to create a report in pdf format.
6
+ But because of above mentioned problem it's failed. So I found arabic-letter-connector
7
+ which solve this problem for arabic language. I use this gem and provide Persian bechasboonn gem to add Persian
8
+ support when using ruby's libraries like prawn.
9
+
10
+ Acknowledgment
11
+ --------------
12
+
13
+ Thanks to arabic-letter-connector by (Ahmed Nasser).
14
+
15
+ Installation
16
+ ------------
17
+
18
+ Run:
19
+
20
+ gem install persian-bechasboon
21
+
22
+ Then require it with:
23
+
24
+ require 'persian-bechasboon'
25
+
26
+ Usage
27
+ -----
28
+
29
+ require 'prawn'
30
+ require 'persian-bechasboon'
31
+ Prawn::Document.generate("persian.pdf") do
32
+ text_direction :rtl
33
+ font("/path/to/persian/font.ttf") do # For example: B Nazanin
34
+ text "درود دنیا".connect_persian_letters
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ require 'persian-bechasboon/version'
2
+ require 'persian-bechasboon/core'
3
+ require 'persian-bechasboon/string'
@@ -0,0 +1,134 @@
1
+ module PersianBechasboon
2
+
3
+ @@charinfos = nil
4
+
5
+ class CharacterInfo
6
+
7
+ attr_accessor :common , :formatted
8
+
9
+ def initialize(common, isolated, final, initial, medial, connects)
10
+ @common = common
11
+ @formatted = {
12
+ :isolated => isolated,
13
+ :final => final,
14
+ :initial => initial,
15
+ :medial => medial,
16
+ }
17
+ @connects = connects
18
+ end
19
+
20
+ def connects?
21
+ @connects
22
+ end
23
+
24
+ end
25
+
26
+ # Determine the form of the current character (:isolated, :initial, :medial,
27
+ # or :final), given the previous character and the next one. In Persian, all
28
+ # characters can connect with a previous character, but not all letters can
29
+ # connect with the next character (this is determined by
30
+ # CharacterInfo#connects?).
31
+ def self.determine_form(previous_char, next_char)
32
+ charinfos = self.charinfos
33
+ if charinfos[previous_char] && charinfos[next_char]
34
+ charinfos[previous_char].connects? ? :medial : :initial # If the current character does not connect,
35
+ # its medial form will map to its final form,
36
+ # and its initial form will map to its isolated form.
37
+ elsif charinfos[previous_char] # The next character is not an persian character.
38
+ charinfos[previous_char].connects? ? :final : :isolated
39
+ elsif charinfos[next_char] # The previous character is not an persian character.
40
+ :initial # If the current character does not connect, its initial form will map to its isolated form.
41
+ else # Neither of the surrounding characters are persian characters.
42
+ :isolated
43
+ end
44
+ end
45
+
46
+ def self.transform(str)
47
+ res = ""
48
+ charinfos = self.charinfos
49
+ previous_char = nil
50
+ current_char = nil
51
+ next_char = nil
52
+ consume_character = lambda do |char|
53
+ previous_char = current_char
54
+ current_char = next_char
55
+ next_char = char
56
+ return unless current_char
57
+ if charinfos.keys.include?(current_char)
58
+ form = determine_form(previous_char, next_char)
59
+ res += charinfos[current_char].formatted[form]
60
+ else
61
+ res += current_char
62
+ end
63
+ end
64
+ str.each_char { |char| consume_character.call(char) }
65
+ consume_character.call(nil)
66
+ res.gsub!(/\d+/) {|m| m.reverse}
67
+ return res
68
+ end
69
+
70
+ private
71
+
72
+ def self.charinfos
73
+ return @@charinfos unless @@charinfos.nil?
74
+ @@charinfos = {}
75
+ add("0627", "fe8d", "fe8e", "fe8d", "fe8e", false) # Alef
76
+ add("0628", "fe8f", "fe90", "fe91", "fe92", true) # Ba2
77
+ add("067e", "fb56", "fb57", "fb58", "fb59", true) # pe
78
+ add("062a", "fe95", "fe96", "fe97", "fe98", true) # Ta2
79
+ add("062b", "fe99", "fe9a", "fe9b", "fe9c", true) # Tha2
80
+ add("062c", "fe9d", "fe9e", "fe9f", "fea0", true) # Jeem
81
+ add("fb7a", "0868", "fb7b", "fb7c", "fb7d", true) # che
82
+ add("062d", "fea1", "fea2", "fea3", "fea4", true) # 7a2
83
+ add("062e", "fea5", "fea6", "fea7", "fea8", true) # 7'a2
84
+ add("062f", "fea9", "feaa", "fea9", "feaa", false) # Dal
85
+ add("0630", "feab", "feac", "feab", "feac", false) # Thal
86
+ add("0631", "fead", "feae", "fead", "feae", false) # Ra2
87
+ add("0632", "feaf", "feb0", "feaf", "feb0", false) # Zain
88
+ add("0633", "feb1", "feb2", "feb3", "feb4", true) # Seen
89
+ add("0634", "feb5", "feb6", "feb7", "feb8", true) # Sheen
90
+ add("0635", "feb9", "feba", "febb", "febc", true) # 9ad
91
+ add("0636", "febd", "febe", "febf", "fec0", true) # 9'ad
92
+ add("0637", "fec1", "fec2", "fec3", "fec4", true) # 6a2
93
+ add("0638", "fec5", "fec6", "fec7", "fec8", true) # 6'a2
94
+ add("0639", "fec9", "feca", "fecb", "fecc", true) # 3ain
95
+ add("063a", "fecd", "fece", "fecf", "fed0", true) # 3'ain
96
+ add("0641", "fed1", "fed2", "fed3", "fed4", true) # Fa2
97
+ add("0642", "fed5", "fed6", "fed7", "fed8", true) # Qaf
98
+ add("0643", "fed9", "feda", "fedb", "fedc", true) # Kaf
99
+ add("06a9", "fb8e", "fb8f", "fb90", "fb91", true) # Ke
100
+ add("06af", "fb92", "fb93", "fb94", "fb95", true) # Gaf
101
+ add("0644", "fedd", "fede", "fedf", "fee0", true) # Lam
102
+ add("0645", "fee1", "fee2", "fee3", "fee4", true) # Meem
103
+ add("0646", "fee5", "fee6", "fee7", "fee8", true) # Noon
104
+ add("0647", "fee9", "feea", "feeb", "feec", true) # Ha2
105
+ add("0648", "feed", "feee", "feed", "feee", false) # Waw
106
+ add("064a", "fef1", "fef2", "fef3", "fef4", true) # Ya2
107
+ add("0621", "fe80", "fe80", "fe80", "fe80", false) # Hamza
108
+ add("0622", "fe81", "fe82", "fe81", "fe82", false) # Alef Madda
109
+ add("0623", "fe83", "fe84", "fe83", "fe84", false) # Alef Hamza Above
110
+ add("0624", "fe85", "fe86", "fe85", "fe86", false) # Waw Hamza
111
+ add("0625", "fe87", "fe88", "fe87", "fe88", false) # Alef Hamza Below
112
+ add("0626", "fe89", "fe8a", "fe8b", "fe8c", true) # Ya2 Hamza
113
+ add("06cc", "fbfc", "fbfd", "fbfe", "fbff", true) # Ye
114
+ add("0629", "fe93", "fe94", "fe93", "fe94", false) # Ta2 Marbu6a
115
+ add("0640", "0640", "0640", "0640", "0640", true) # Tatweel
116
+ add("0649", "feef", "fef0", "feef", "fef0", false) # Alef Layyina
117
+ #add("068e", "fb86", "fb87", "fb86", "fb87", false) # zhe
118
+ add("0698", "fb8a", "fb8b", "fb8a", "fb8b", false) # zhe
119
+ @@charinfos
120
+ end
121
+
122
+ def self.add(common, isolated, final, initial, medial, connects)
123
+ charinfo = CharacterInfo.new(
124
+ [common.hex].pack("U"),
125
+ [isolated.hex].pack("U"),
126
+ [final.hex].pack("U"),
127
+ [initial.hex].pack("U"),
128
+ [medial.hex].pack("U"),
129
+ connects
130
+ )
131
+ @@charinfos[charinfo.common] = charinfo
132
+ end
133
+
134
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def connect_persian_letters
3
+ PersianBechasboon.transform(self)
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module PersianBechasboon
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+ require 'persian-bechasboon/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'persian-bechasboon'
6
+ s.version = PersianBechasboon::VERSION
7
+ s.date = '2015-05-06'
8
+ s.summary = 'Persian Characters Connector (Bechasboon)'
9
+ s.description = 'A tool to replace generic disconnected Persian letters with their connected counterparts, for the Ruby programming language.'
10
+ s.authors = ["Hazhir Derakhshi"]
11
+ s.email = 'hajear@gmail.com'
12
+ s.homepage = 'https://github.com/volfgox/persian-bechasboon'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.require_paths = ['lib']
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: persian-bechasboon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hazhir Derakhshi
@@ -10,18 +10,22 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-05-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Generated persian pdf files by other gems have a big problem. Characters
14
- in the words are separated. using this gem help you to connect characters before
15
- place them in the pdf file.
13
+ description: A tool to replace generic disconnected Persian letters with their connected
14
+ counterparts, for the Ruby programming language.
16
15
  email: hajear@gmail.com
17
16
  executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
20
19
  files:
20
+ - ".gitignore"
21
+ - README.md
21
22
  - lib/persian-bechasboon.rb
23
+ - lib/persian-bechasboon/core.rb
24
+ - lib/persian-bechasboon/string.rb
25
+ - lib/persian-bechasboon/version.rb
26
+ - persian-bechasboon.gemspec
22
27
  homepage: https://github.com/volfgox/persian-bechasboon
23
- licenses:
24
- - MIT
28
+ licenses: []
25
29
  metadata: {}
26
30
  post_install_message:
27
31
  rdoc_options: []
@@ -42,7 +46,6 @@ rubyforge_project:
42
46
  rubygems_version: 2.4.6
43
47
  signing_key:
44
48
  specification_version: 4
45
- summary: The problem of separated persian characters in generated pdf is solved by
46
- using this gem.
49
+ summary: Persian Characters Connector (Bechasboon)
47
50
  test_files: []
48
51
  has_rdoc: