From d40d09dc0529ff77bade0401946c519ffc315fea Mon Sep 17 00:00:00 2001 From: Myst Date: Sun, 26 Oct 2014 05:13:03 +0100 Subject: [PATCH] RTL recognition fixed --- CHANGELOG.md | 4 +++- lib/combine_pdf/combine_pdf_basic_writer.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c768f..202dbfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ Change log v.0.1.6 -**Fix**: added Mutex to font library (which was shared by all PDFWriter objects) - now fonts are thread safe (PDF objects are NOT thread safe by design). +**fix**: added Mutex to font library (which was shared by all PDFWriter objects) - now fonts are thread safe (PDF objects are NOT thread safe by design). + +**fix**: RTL recognition did not reverse brackets, it should now correctly perform brackets reversal for any of the following: (,),[,],{,},<,>. **update**: updated license to MIT. diff --git a/lib/combine_pdf/combine_pdf_basic_writer.rb b/lib/combine_pdf/combine_pdf_basic_writer.rb index 622785e..449ff3d 100644 --- a/lib/combine_pdf/combine_pdf_basic_writer.rb +++ b/lib/combine_pdf/combine_pdf_basic_writer.rb @@ -403,6 +403,11 @@ def encode text, fonts # ...still, it works (I think). def reorder_rtl_content text rtl_characters = "\u05d0-\u05ea\u05f0-\u05f4\u0600-\u06ff\u0750-\u077f" + rtl_replaces = { '(' => ')', ')' => '(', + '[' => ']', ']'=>'[', + '{' => '}', '}'=>'{', + '<' => '>', '>'=>'<', + } return text unless text =~ /[#{rtl_characters}]/ out = [] @@ -415,6 +420,8 @@ def reorder_rtl_content text white_space_to_move = scanner.matched.match(/[\s]+$/).to_s out.unshift scanner.matched[0..-1-white_space_to_move.length] out.unshift white_space_to_move + elsif scanner.matched.match /^[\(\)\[\]\{\}\<\>]$/ + out.unshift rtl_replaces[scanner.matched] else out.unshift scanner.matched end