From d004b8bcde6a8f78b3b3f1508692fa3af301cb3d Mon Sep 17 00:00:00 2001 From: pyaephyoeaung Date: Thu, 11 Aug 2022 11:03:45 +0630 Subject: [PATCH] convert unicode to zawgyi for prawn documents - prawn text --- config/initializers/prawn_text.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 config/initializers/prawn_text.rb diff --git a/config/initializers/prawn_text.rb b/config/initializers/prawn_text.rb new file mode 100644 index 00000000..197d2ed4 --- /dev/null +++ b/config/initializers/prawn_text.rb @@ -0,0 +1,28 @@ +require 'myanmar-tools' +require 'rabbit' +Prawn::Text.module_eval do + + def text(string, options = {}) + return false if string.nil? + detector = MyanmarTools::ZawgyiDetector.new + score = detector.get_zawgyi_probability(string) + if score > 0 && score < 0.05 + rabbit = Rabbit::Converter.new + string = rabbit.uni2zg(string) # returns zg strings "မဂၤလာပါ" + end + # we modify the options. don't change the user's hash + options = options.dup + + p = options[:inline_format] + if p + p = [] unless p.is_a?(Array) + options.delete(:inline_format) + array = text_formatter.format(string, *p) + else + array = [{ text: string }] + end + + formatted_text(array, options) + end +end +