Giter Site home page Giter Site logo

xclud / dart_bidi Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 3.0 427 KB

Implementation of the Unicode Bidirectional Algorithm (UBA) as described in https://unicode.org/reports/tr9/.

Home Page: https://pub.dev/packages/bidi

License: MIT License

Dart 99.81% Kotlin 0.01% Swift 0.04% Objective-C 0.01% HTML 0.14%
bidi unicode persian hebrew arabic dart flutter

dart_bidi's Introduction

pub package

Implementation of the Unicode Bidirectional Algorithm (UBA).

Reference: https://unicode.org/reports/tr9/.

Converts logical strings to their equivalent visual representation. Persian, Hebrew and Arabic languages (and any other RTL language) are supported.

Web Demo

Web Demo

Getting Started

In your pubspec.yaml file add:

dependencies:
  bidi: any

Then, in your code import and use the package:

import 'package:bidi/bidi.dart' as bidi;

final visual = bidi.logicalToVisual('نوشته پارسی اینجا گذارده شود.');
print(visual);

Other Implementations

This package is also written in Rust (apart from this package, which is written in Dart). If you are looking for a pure Rust implementation of this package, look at https://crates.io/crates/bidi/.

dart_bidi's People

Contributors

milad-akarie avatar xclud avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

dart_bidi's Issues

Using Arabic letters basic from in favor of isolated form

Hey, @xclud
context: There are two letter forms in Arabic that render exactly the same, the basic form and the isolated form.

Notices how the following Arabic letter LAM has the same glyph for both basic and isolated form.
image

currently, the algorithm maps to the isolated form which might be the right thing to do but unfortunately Arabic Google fonts seem to have a problem with this, this issue can be fixed by always mapping to the basic form when an isolated form is required.

even dart seems to work with the basic form in such cases

 final letter = 'ل';
 print(letter.codeUnits); // prints [1604]
 print(bidi.logicalToVisual(letter)); // prints [65245]

I'm willing the make a PR, but do you think we should introduce this change as an optional change or just hard-code it?

P.s I'll be changing the mappings inside of shapping_resolver._charForms

Null safety

Hi, any plans to convert this code to null-safe?

[Bug] When Arabic letter has a HAMZA-form reshaping throws an error

first of all, thank you for this great package.
I've noticed that when a letter of the sentence has a HAMZA an error occurs.
I think the problem is letters with Hamza should be reshaped not decomposed into a base letter and a diacritic.

All of these throw an out of range error

  bidi.logicalToVisual('أ');
  bidi.logicalToVisual('إ');
  bidi.logicalToVisual('ؤ');
  bidi.logicalToVisual('ئ');

stacktrace

RangeError (index): Invalid value: Only valid value is 0: 1
dart:core                               List.[]
package:bidi/src/paragraph.dart 752:24  Paragraph.internalCompose
package:bidi/src/paragraph.dart 113:5   Paragraph.normalizeText
package:bidi/src/paragraph.dart 42:5    Paragraph.text=
package:bidi/src/paragraph.dart 13:10   new Paragraph
package:bidi/src/bidi.dart 73:13        splitStringToParagraphs
package:bidi/src/bidi.dart 9:16         logicalToVisual
test/arabic_test.dart 40:8              main

these don't throw an error but the result is incorrect

  bidi.logicalToVisual('خطأ');
  bidi.logicalToVisual('كؤ');
  bidi.logicalToVisual('مئ');

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.