Milad Akarie
Committed by GitHub

Fix Arabic fonts missing isolated form ( mostly Arabic Google fonts ) (#1451)

* Add RTL support to Flex widget

* Add RTL support to Wrap widget

* Add RTL support to EdgeInsets widget
Add RTL support Page and MultiPage

* Add RTL support to BorderRadius widget
Add RTL support Alignment

* Add RTL support to GridView

* Add test annotations

* Add TextAlign.start and TextAlign.end and fix Line.realign accordingly
change widgets geometry to directional geometry

* support multi page slots alignments

* support stack's Positioned directional

* Fix: some Arabic fonts do not render the isolated from because it doesn't have a corresponding glyph

* format code
@@ -38,6 +38,46 @@ bool isArabicDiacriticValue(int letter) { @@ -38,6 +38,46 @@ bool isArabicDiacriticValue(int letter) {
38 return _arabicDiacritics.containsValue(letter); 38 return _arabicDiacritics.containsValue(letter);
39 } 39 }
40 40
  41 +/// Arabic characters that have different unicode values
  42 +/// but should point to the same glyph.
  43 +const Map<int, int> basicToIsolatedMappings = {
  44 + 0x0627: 0xFE8D, // ا
  45 + 0x0628: 0xFE8F, // ب
  46 + 0x062A: 0xFE95, // ت
  47 + 0x062B: 0xFE99, // ث
  48 + 0x062C: 0xFE9D, // ج
  49 + 0x062D: 0xFEA1, // ح
  50 + 0x062E: 0xFEA5, // خ
  51 + 0x062F: 0xFEA9, // د
  52 + 0x0630: 0xFEAB, // ذ
  53 + 0x0631: 0xFEAD, // ر
  54 + 0x0632: 0xFEAF, // ز
  55 + 0x0633: 0xFEB1, // س
  56 + 0x0634: 0xFEB5, // ش
  57 + 0x0635: 0xFEB9, // ص
  58 + 0x0636: 0xFEBD, // ض
  59 + 0x0637: 0xFEC1, // ط
  60 + 0x0638: 0xFEC5, // ظ
  61 + 0x0639: 0xFEC9, // ع
  62 + 0x063A: 0xFECD, // غ
  63 + 0x0641: 0xFED1, // ف
  64 + 0x0642: 0xFED5, // ق
  65 + 0x0643: 0xFED9, // ك
  66 + 0x0644: 0xFEDD, // ل
  67 + 0x0645: 0xFEE1, // م
  68 + 0x0646: 0xFEE5, // ن
  69 + 0x0647: 0xFEE9, // ه
  70 + 0x0648: 0xFEED, // و
  71 + 0x064A: 0xFEEF, // ي
  72 + 0x0621: 0xFE80, // ء
  73 + 0x0622: 0xFE81, // آ
  74 + 0x0623: 0xFE83, // أ
  75 + 0x0624: 0xFE85, // ؤ
  76 + 0x0625: 0xFE87, // إ
  77 + 0x0626: 0xFE89, // ئ
  78 + 0x0629: 0xFE93, // ة
  79 +};
  80 +
41 /// Applies THE BIDIRECTIONAL ALGORITHM using (https://pub.dev/packages/bidi) 81 /// Applies THE BIDIRECTIONAL ALGORITHM using (https://pub.dev/packages/bidi)
42 String logicalToVisual(String input) { 82 String logicalToVisual(String input) {
43 final buffer = StringBuffer(); 83 final buffer = StringBuffer();
@@ -19,8 +19,8 @@ @@ -19,8 +19,8 @@
19 import 'dart:convert'; 19 import 'dart:convert';
20 import 'dart:math' as math; 20 import 'dart:math' as math;
21 import 'dart:typed_data'; 21 import 'dart:typed_data';
22 -  
23 import 'package:meta/meta.dart'; 22 import 'package:meta/meta.dart';
  23 +import 'bidi_utils.dart' as bidi;
24 24
25 import 'font_metrics.dart'; 25 import 'font_metrics.dart';
26 26
@@ -316,6 +316,13 @@ class TtfParser { @@ -316,6 +316,13 @@ class TtfParser {
316 glyphIndex = bytes.getUint16(glyphIndexAddress); 316 glyphIndex = bytes.getUint16(glyphIndexAddress);
317 } 317 }
318 charToGlyphIndexMap[c] = glyphIndex; 318 charToGlyphIndexMap[c] = glyphIndex;
  319 +
  320 + /// Having both the unicode and the isolated form code
  321 + /// point to the same glyph index because some fonts
  322 + /// do not have a glyph for the isolated form.\
  323 + if (bidi.basicToIsolatedMappings.containsKey(c)) {
  324 + charToGlyphIndexMap[bidi.basicToIsolatedMappings[c]!] = glyphIndex;
  325 + }
319 } 326 }
320 } 327 }
321 } 328 }