Committed by
David PHAM-VAN
fix mixing Arabic with English.
Signed-off-by: Anas Altair <anastr244@gmail.com>
Showing
3 changed files
with
48 additions
and
23 deletions
| @@ -25,8 +25,6 @@ class PdfArabic { | @@ -25,8 +25,6 @@ class PdfArabic { | ||
| 25 | /// Arabic shape substitutions: char code => (isolated, final, initial, medial). | 25 | /// Arabic shape substitutions: char code => (isolated, final, initial, medial). |
| 26 | /// Arabic Substition A | 26 | /// Arabic Substition A |
| 27 | static const Map<int, dynamic> _arabicSubstitionA = <int, dynamic>{ | 27 | static const Map<int, dynamic> _arabicSubstitionA = <int, dynamic>{ |
| 28 | -// 0x0652: <int>[0xFE7E, 0xFE7F], | ||
| 29 | - | ||
| 30 | 0x0621: <int>[0xFE80], // ARABIC LETTER HAMZA | 28 | 0x0621: <int>[0xFE80], // ARABIC LETTER HAMZA |
| 31 | 0x0622: <int>[0xFE81, 0xFE82], // ARABIC LETTER ALEF WITH MADDA ABOVE | 29 | 0x0622: <int>[0xFE81, 0xFE82], // ARABIC LETTER ALEF WITH MADDA ABOVE |
| 32 | 0x0623: <int>[0xFE83, 0xFE84], // ARABIC LETTER ALEF WITH HAMZA ABOVE | 30 | 0x0623: <int>[0xFE83, 0xFE84], // ARABIC LETTER ALEF WITH HAMZA ABOVE |
| @@ -128,6 +126,7 @@ class PdfArabic { | @@ -128,6 +126,7 @@ class PdfArabic { | ||
| 128 | 0x064E: 0xFC60, // Shadda + Fatha | 126 | 0x064E: 0xFC60, // Shadda + Fatha |
| 129 | 0x064F: 0xFC61, // Shadda + Damma | 127 | 0x064F: 0xFC61, // Shadda + Damma |
| 130 | 0x0650: 0xFC62, // Shadda + Kasra | 128 | 0x0650: 0xFC62, // Shadda + Kasra |
| 129 | + 0x0670: 0xFC63, // Shadda + Dagger alif | ||
| 131 | }, | 130 | }, |
| 132 | }; | 131 | }; |
| 133 | 132 | ||
| @@ -160,20 +159,23 @@ class PdfArabic { | @@ -160,20 +159,23 @@ class PdfArabic { | ||
| 160 | static const List<int> _alfletter = <int>[1570, 1571, 1573, 1575]; | 159 | static const List<int> _alfletter = <int>[1570, 1571, 1573, 1575]; |
| 161 | 160 | ||
| 162 | static const Map<int, int> _arabicDiacritics = <int, int>{ | 161 | static const Map<int, int> _arabicDiacritics = <int, int>{ |
| 163 | - 1611: 1611, // Fathatan | ||
| 164 | - 1612: 1612, // Dammatan | ||
| 165 | - 1613: 1613, // Kasratan | ||
| 166 | - 1614: 1614, // Fatha | ||
| 167 | - 1615: 1615, // Damma | ||
| 168 | - 1616: 1616, // Kasra | ||
| 169 | - 1617: 1617, | ||
| 170 | - 1618: 1618, | ||
| 171 | - | ||
| 172 | - 64606: 64606, // Shadda + Dammatan | ||
| 173 | - 64607: 64607, // Shadda + Kasratan | ||
| 174 | - 64608: 64608, // Shadda + Fatha | ||
| 175 | - 64609: 64609, // Shadda + Damma | ||
| 176 | - 64610: 64610, // Shadda + Kasra | 162 | + 0x064B: 0x064B, // Fathatan |
| 163 | + 0x064C: 0x064C, // Dammatan | ||
| 164 | + 0x064D: 0x064D, // Kasratan | ||
| 165 | + 0x064E: 0x064E, // Fatha | ||
| 166 | + 0x064F: 0x064F, // Damma | ||
| 167 | + 0x0650: 0x0650, // Kasra | ||
| 168 | + 0x0651: 0x0651, // Shadda | ||
| 169 | + 0x0652: 0x0652, // Sukun | ||
| 170 | + | ||
| 171 | + 0x0670: 0x0670, // Dagger alif | ||
| 172 | + | ||
| 173 | + 0xFC5E: 0xFC5E, // Shadda + Dammatan | ||
| 174 | + 0xFC5F: 0xFC5F, // Shadda + Kasratan | ||
| 175 | + 0xFC60: 0xFC60, // Shadda + Fatha | ||
| 176 | + 0xFC61: 0xFC61, // Shadda + Damma | ||
| 177 | + 0xFC62: 0xFC62, // Shadda + Kasra | ||
| 178 | + 0xFC63: 0xFC63, // Shadda + Dagger alif | ||
| 177 | // 1548: 1548, | 179 | // 1548: 1548, |
| 178 | }; | 180 | }; |
| 179 | 181 | ||
| @@ -324,10 +326,12 @@ class PdfArabic { | @@ -324,10 +326,12 @@ class PdfArabic { | ||
| 324 | static Iterable<String> _parse(String text) sync* { | 326 | static Iterable<String> _parse(String text) sync* { |
| 325 | final List<String> words = text.split(' '); | 327 | final List<String> words = text.split(' '); |
| 326 | 328 | ||
| 329 | + final List<List<int>> notArabicWords = <List<int>>[]; | ||
| 330 | + | ||
| 327 | bool first = true; | 331 | bool first = true; |
| 328 | for (String word in words) { | 332 | for (String word in words) { |
| 329 | final List<int> newWord = <int>[]; | 333 | final List<int> newWord = <int>[]; |
| 330 | - bool isArabic = false; | 334 | + bool isNewWordArabic = false; |
| 331 | 335 | ||
| 332 | int prevLetter = 0; | 336 | int prevLetter = 0; |
| 333 | 337 | ||
| @@ -348,31 +352,48 @@ class PdfArabic { | @@ -348,31 +352,48 @@ class PdfArabic { | ||
| 348 | ); | 352 | ); |
| 349 | 353 | ||
| 350 | if (_isArabicLetter(currentLetter)) { | 354 | if (_isArabicLetter(currentLetter)) { |
| 351 | - isArabic = true; | 355 | + isNewWordArabic = true; |
| 352 | 356 | ||
| 353 | final int position = | 357 | final int position = |
| 354 | _getCorrectForm(currentLetter, prevLetter, nextLetter); | 358 | _getCorrectForm(currentLetter, prevLetter, nextLetter); |
| 359 | + prevLetter = currentLetter; | ||
| 355 | if (position != -1) { | 360 | if (position != -1) { |
| 356 | newWord.insert(0, _arabicSubstitionA[currentLetter][position]); | 361 | newWord.insert(0, _arabicSubstitionA[currentLetter][position]); |
| 357 | } else { | 362 | } else { |
| 358 | newWord.add(currentLetter); | 363 | newWord.add(currentLetter); |
| 359 | } | 364 | } |
| 360 | } else { | 365 | } else { |
| 361 | - if (isArabic && currentLetter > 32) { | 366 | + prevLetter = 0; |
| 367 | + if (isNewWordArabic && currentLetter > 32) { | ||
| 362 | newWord.insert(0, currentLetter); | 368 | newWord.insert(0, currentLetter); |
| 363 | } else { | 369 | } else { |
| 364 | newWord.add(currentLetter); | 370 | newWord.add(currentLetter); |
| 365 | } | 371 | } |
| 366 | } | 372 | } |
| 367 | - prevLetter = currentLetter; | ||
| 368 | } | 373 | } |
| 369 | 374 | ||
| 370 | - if (!first) { | 375 | + if (!first && isNewWordArabic) { |
| 371 | yield ' '; | 376 | yield ' '; |
| 372 | } | 377 | } |
| 373 | first = false; | 378 | first = false; |
| 374 | 379 | ||
| 375 | - yield String.fromCharCodes(_resolveLigatures(newWord)); | 380 | + if (isNewWordArabic) { |
| 381 | + isNewWordArabic = false; | ||
| 382 | + for (List<int> notArabicNewWord in notArabicWords) { | ||
| 383 | + yield '${String.fromCharCodes(notArabicNewWord)} '; | ||
| 384 | + } | ||
| 385 | + notArabicWords.clear(); | ||
| 386 | + yield String.fromCharCodes(_resolveLigatures(newWord)); | ||
| 387 | + } else { | ||
| 388 | + notArabicWords.insert(0, newWord); | ||
| 389 | + } | ||
| 390 | + } | ||
| 391 | + // if notArabicWords.length != 0, that means all sentence doesn't contain Arabic. | ||
| 392 | + for (int i = 0; i < notArabicWords.length; i++) { | ||
| 393 | + yield String.fromCharCodes(notArabicWords[i]); | ||
| 394 | + if (i != notArabicWords.length - 1) { | ||
| 395 | + yield ' '; | ||
| 396 | + } | ||
| 376 | } | 397 | } |
| 377 | } | 398 | } |
| 378 | 399 |
| @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | @@ -4,7 +4,7 @@ description: A pdf producer for Dart. It can create pdf files for both web or fl | ||
| 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf | 4 | homepage: https://github.com/DavBfr/dart_pdf/tree/master/pdf |
| 5 | repository: https://github.com/DavBfr/dart_pdf | 5 | repository: https://github.com/DavBfr/dart_pdf |
| 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues | 6 | issue_tracker: https://github.com/DavBfr/dart_pdf/issues |
| 7 | -version: 1.10.1 | 7 | +version: 1.10.2 |
| 8 | 8 | ||
| 9 | environment: | 9 | environment: |
| 10 | sdk: ">=2.3.0 <3.0.0" | 10 | sdk: ">=2.3.0 <3.0.0" |
-
Please register or login to post a comment