class String
Public Instance Methods
determine_format(before_c, after_c)
click to toggle source
# File lib/prawn-arabic.rb, line 422 def determine_format(before_c, after_c) charmap = ArabicCharacterInfo.get_arabic_characters_map previous_is_character = charmap.key?(before_c) after_is_character = charmap.key?(after_c) if !after_is_character and (!previous_is_character or !charmap[before_c].is_connected) return CharacterFormat::Isolated end if !after_is_character return CharacterFormat::Final end if !previous_is_character or !charmap[before_c].is_connected return CharacterFormat::Initial end return CharacterFormat::Medial end
fix_arabic_glyphs()
click to toggle source
# File lib/prawn-arabic.rb, line 495 def fix_arabic_glyphs words = self.split(" ") result = "" #assuming default is rtl ltr_buffer = "" words.each { |word| fixed_word = word.fix_word if(fixed_word == word) #a non-arabic word (ltr) so we will buffer to see if more ltr words will follow ltr_buffer = ltr_buffer + " " + fixed_word else if(ltr_buffer.empty?) result = fixed_word + " " + result else result = ltr_buffer + " " + result result = fixed_word + " " + result ltr_buffer = "" end end } if(!(ltr_buffer.empty?)) result = ltr_buffer + " " + result end return result end
fix_word()
click to toggle source
# File lib/prawn-arabic.rb, line 454 def fix_word is_arabic = false connected_arabic = "" previous_letter = '' before_previous_letter = '' self.chars {|c| if previous_letter != '' format = determine_format(before_previous_letter, c) fixed_character = get_letter_in_format(format, previous_letter) connected_arabic += fixed_character if fixed_character != previous_letter is_arabic = true end end before_previous_letter = previous_letter previous_letter = c } if previous_letter != '' format = determine_format(before_previous_letter, '') fixed_character = get_letter_in_format(format, previous_letter) connected_arabic += fixed_character if fixed_character != previous_letter is_arabic = true end end if is_arabic return connected_arabic.reverse else return connected_arabic end end
get_letter_in_format(format, c)
click to toggle source
# File lib/prawn-arabic.rb, line 445 def get_letter_in_format(format, c) charmap = ArabicCharacterInfo.get_arabic_characters_map character = charmap[c] if character.nil? return c end return character.format_encodings[format] end