Anas Altair
Committed by David PHAM-VAN

fix mixing Arabic with English.

Signed-off-by: Anas Altair <anastr244@gmail.com>
# Changelog
## 1.10.2
- Fix mixing Arabic with English [Anas Altair]
- Support Dagger alif in Arabic [Anas Altair]
## 1.10.1
... ...
... ... @@ -25,8 +25,6 @@ class PdfArabic {
/// Arabic shape substitutions: char code => (isolated, final, initial, medial).
/// Arabic Substition A
static const Map<int, dynamic> _arabicSubstitionA = <int, dynamic>{
// 0x0652: <int>[0xFE7E, 0xFE7F],
0x0621: <int>[0xFE80], // ARABIC LETTER HAMZA
0x0622: <int>[0xFE81, 0xFE82], // ARABIC LETTER ALEF WITH MADDA ABOVE
0x0623: <int>[0xFE83, 0xFE84], // ARABIC LETTER ALEF WITH HAMZA ABOVE
... ... @@ -128,6 +126,7 @@ class PdfArabic {
0x064E: 0xFC60, // Shadda + Fatha
0x064F: 0xFC61, // Shadda + Damma
0x0650: 0xFC62, // Shadda + Kasra
0x0670: 0xFC63, // Shadda + Dagger alif
},
};
... ... @@ -160,20 +159,23 @@ class PdfArabic {
static const List<int> _alfletter = <int>[1570, 1571, 1573, 1575];
static const Map<int, int> _arabicDiacritics = <int, int>{
1611: 1611, // Fathatan
1612: 1612, // Dammatan
1613: 1613, // Kasratan
1614: 1614, // Fatha
1615: 1615, // Damma
1616: 1616, // Kasra
1617: 1617,
1618: 1618,
64606: 64606, // Shadda + Dammatan
64607: 64607, // Shadda + Kasratan
64608: 64608, // Shadda + Fatha
64609: 64609, // Shadda + Damma
64610: 64610, // Shadda + Kasra
0x064B: 0x064B, // Fathatan
0x064C: 0x064C, // Dammatan
0x064D: 0x064D, // Kasratan
0x064E: 0x064E, // Fatha
0x064F: 0x064F, // Damma
0x0650: 0x0650, // Kasra
0x0651: 0x0651, // Shadda
0x0652: 0x0652, // Sukun
0x0670: 0x0670, // Dagger alif
0xFC5E: 0xFC5E, // Shadda + Dammatan
0xFC5F: 0xFC5F, // Shadda + Kasratan
0xFC60: 0xFC60, // Shadda + Fatha
0xFC61: 0xFC61, // Shadda + Damma
0xFC62: 0xFC62, // Shadda + Kasra
0xFC63: 0xFC63, // Shadda + Dagger alif
// 1548: 1548,
};
... ... @@ -324,10 +326,12 @@ class PdfArabic {
static Iterable<String> _parse(String text) sync* {
final List<String> words = text.split(' ');
final List<List<int>> notArabicWords = <List<int>>[];
bool first = true;
for (String word in words) {
final List<int> newWord = <int>[];
bool isArabic = false;
bool isNewWordArabic = false;
int prevLetter = 0;
... ... @@ -348,31 +352,48 @@ class PdfArabic {
);
if (_isArabicLetter(currentLetter)) {
isArabic = true;
isNewWordArabic = true;
final int position =
_getCorrectForm(currentLetter, prevLetter, nextLetter);
prevLetter = currentLetter;
if (position != -1) {
newWord.insert(0, _arabicSubstitionA[currentLetter][position]);
} else {
newWord.add(currentLetter);
}
} else {
if (isArabic && currentLetter > 32) {
prevLetter = 0;
if (isNewWordArabic && currentLetter > 32) {
newWord.insert(0, currentLetter);
} else {
newWord.add(currentLetter);
}
}
prevLetter = currentLetter;
}
if (!first) {
if (!first && isNewWordArabic) {
yield ' ';
}
first = false;
yield String.fromCharCodes(_resolveLigatures(newWord));
if (isNewWordArabic) {
isNewWordArabic = false;
for (List<int> notArabicNewWord in notArabicWords) {
yield '${String.fromCharCodes(notArabicNewWord)} ';
}
notArabicWords.clear();
yield String.fromCharCodes(_resolveLigatures(newWord));
} else {
notArabicWords.insert(0, newWord);
}
}
// if notArabicWords.length != 0, that means all sentence doesn't contain Arabic.
for (int i = 0; i < notArabicWords.length; i++) {
yield String.fromCharCodes(notArabicWords[i]);
if (i != notArabicWords.length - 1) {
yield ' ';
}
}
}
... ...
... ... @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl
homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf
repository: https://github.com/DavBfr/dart_pdf
issue_tracker: https://github.com/DavBfr/dart_pdf/issues
version: 1.10.1
version: 1.10.2
environment:
sdk: ">=2.3.0 <3.0.0"
... ...