Giter VIP home page Giter VIP logo

ruby-bidi's Introduction

Ruby BiDi

Ruby gem to help working with bidirectional (left-to-right and right-to-left) text.

Install

gem install bidi

Use

Require the bidi module and use to_visual:

require "bidi"

bidi = Bidi.new
bidi_string = bidi.to_visual "משפט עם עברית ו-English. מספרים: 12345 (וגם כל מיני סימני פיסוק) וגם סימן קריאה!"

When rendering right-to-left text, some writers require reversing the string before passing it to them. Prawn is one such example. The render_visual function does this for you:

require "prawn"
require "bidi"

Prawn::Document.generate("hello.pdf") do
  self.text_direction = :rtl

  bidi = Bidi.new
  text bidi.render_visual "משפט עם עברית ו-English. מספרים: 12345 (וגם כל מיני סימני פיסוק) וגם סימן קריאה!"
end

Note: Hebrew (or any language, really) characters must be present in the font used by Prawn for them to appear. If you don't see the characters you expect, try explicitly setting the font inside the Prawn block. For example, if you have the Unicode Arial font in Arial.ttf, you should add:

font_families.update("Arial" => {
  :normal => "Arial.ttf",
});
font("Arial")

License

Copyright (c) 2014 Amit Yaron <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ruby-bidi's People

Contributors

elad avatar high5apps avatar mkdynamic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ruby-bidi's Issues

Annoying gem bugs

From this commit message:

  • When installing the gem I get warnings like:

    unable to convert "\xAB" from ASCII-8BIT to UTF-8 for lib/data/BidiMirroring.dat, skipping
    unable to convert "\x87" from ASCII-8BIT to UTF-8 for lib/data/UnicodeData.idx, skipping
    

    This might be an issue with the Mac OS X terminal and in any case it seems harmless.

  • Gem installation freezes (or lags horribly) when printing this line:

    Installing ri documentation for bidi-0.0.1
    

    I have no idea why, and if I ^C and install again it doesn't happen, and it seems like a relatively common problem, so whatever.

  • This gem requires weakref. Unfortunately, when I add it as a dependency
    using

    s.add_dependency rubysl-weakref
    

    It gets added to the $LOAD_PATH which makes it not work for some reason. If I remove the dependency it works... but requires that it be installed manually.

Help appreciated!

Bidi works exactly once

I've tried the provided example and it doesn't seem to change anything after first try.

2.2.10 :001 > bidi = Bidi.new
 => #<Bidi:0x007f9912ce0b78 @dataPath="/Users/rails/.rvm/gems/ruby-2.2.10/gems/bidi-0.0.2/lib/data/", @idxFile=#<File:/Users/rails/.rvm/gems/ruby-2.2.10/gems/bidi-0.0.2/lib/data/UnicodeData.idx>, @dataFile=#<File:/Users/rails/.rvm/gems/ruby-2.2.10/gems/bidi-0.0.2/lib/data/UnicodeData.txt>, @mirrorFile=#<File:/Users/rails/.rvm/gems/ruby-2.2.10/gems/bidi-0.0.2/lib/data/BidiMirroring.dat>, @num_of_indexes=24428, @mirror_record_len=6, @num_of_mirror_chars=364>
2.2.10 :002 > bidi_string = bidi.to_visual(text = "משפט עם עברית ו-English. מספרים: 12345 (וגם כל מיני סימני פיסוק) וגם סימן קריאה!")
 => "!האירק ןמיס םגו (קוסיפ ינמיס ינימ לכ םגו) 12345 :םירפסמ .English-ו תירבע םע טפשמ"
2.2.10 :003 > bidi_string = bidi.to_visual(text = "משפט עם עברית ו-English. מספרים: 12345 (וגם כל מיני סימני פיסוק) וגם סימן קריאה!")
 => "משפט עם עברית ו-English. מספרים: 12345 (וגם כל מיני סימני פיסוק) וגם סימן קריאה!"
2.2.10 :014 > bidi_string2 = bidi.to_visual(text = "משפט עם עברית ו-English. מספרים: 12345 (וגם כל מיני סימני פיסוק) וגם סימן קריאה!")
 => "משפט עם עברית ו-English. מספרים: 12345 (וגם כל מיני סימני פיסוק) וגם סימן קריאה!"

ruby 2.2.10p489 (2018-03-28 revision 63023) [x86_64-darwin18]

It works correctly exactly once. Creating new Bidi instance does not help, but then used enough times leads to Errno::EMFILE: Too many open files @ rb_sysopen - /Users/rails/.rvm/gems/ruby-2.2.10/gems/bidi-0.0.2/lib/data/UnicodeData.idx instead

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.