Git Product home page Git Product logo

arabic-letter-connector's Introduction

Arabic Letter Connector

Motivation

Arabic is not always well-supported in all libraries. There are two problems that often occur when attempting to present Arabic text:

  1. The letters appear in reverse order (often because there is no right-to-left support).
  2. The letters appear disconnected.

This gem deals with the second problem. If you are this problem, it normally means your string use the generic form of every Arabic letter (that is, without any attributed form, for example a Qaf not a Qaf at the beginning of a word), and the library you are using to present this string doesn't do anything about it.

What this gem does is replace each such generic character to a character with form.

Acknowledgment

This gem is a refactored version of Arabic-Prawn by Dynamix Solutions (Ahmed Nasser).

Installation

Simply run:

gem install arabic-letter-connector

Then require it with:

require 'arabic-letter-connector'

Usage

The gem provides a ArabicLetterConnector.transform(string) method, and also monkey-patches String to include a connect_arabic_letters method.

Below is an example. In the browser, it might appear that this library is doing nothing (since the browser does the work of converting the characters from their generic form considering their correct form). Try it in IRB to get a sense of what is happening.

x = "مرحبا يا العالم"
x[0].unpack("C*")            # [217, 133] 
y = x.connect_arabic_letters # "ﻣﺮﺣﺒﺎ ﻳﺎ ﺍﻟﻌﺎﻟﻢ"
y[0].unpack("C*")            # [239, 187, 163]

This gem is particular useful if you are using prawn to generate PDF files.

require 'prawn'
require 'arabic-letter-connector'
Prawn::Document.generate("arabic.pdf") do
  text_direction :rtl
  font("/path/to/arabic/font.ttf") do # For example: http://www.amirifont.org/
    text "مرحبا يا العالم".connect_arabic_letters
  end
end

arabic-letter-connector's People

Contributors

sinantaifour avatar husam212 avatar

Watchers

James Cloos avatar

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.