Milad
Committed by David PHAM-VAN

Fix bidirectional text incorrect render order

Properly handle line breakers (\\n) in bidirectional text
# Changelog
## 3.7.4
- Fix Bidirectional text (Arabic + Latin words) order and line breakers issue #990 [Milad]
## 3.7.3
- Fix missing endobj with compressed xref
... ...
... ... @@ -386,14 +386,22 @@ Iterable<String> _parse(String text) sync* {
}
// if notArabicWords.length != 0, that means all sentence doesn't contain Arabic.
for (var i = 0; i < notArabicWords.length; i++) {
yield String.fromCharCodes(notArabicWords[i]);
if (i != notArabicWords.length - 1) {
if (!first) {
yield ' ';
}
yield String.fromCharCodes(notArabicWords[i]);
}
}
/// Apply Arabic shape substitutions
String convert(String input) {
return List<String>.from(_parse(input)).join('');
final lines = input.split('\n');
final parsed = <String>[];
for (var i = 0; i < lines.length; i++) {
if (lines[i].isEmpty) {
continue;
}
parsed.addAll([..._parse(lines[i]), if (i != lines.length - 1) '\n']);
}
return parsed.join();
}
... ...
... ... @@ -3,7 +3,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: 3.7.3
version: 3.7.4
environment:
sdk: ">=2.12.0 <3.0.0"
... ...
... ... @@ -439,7 +439,7 @@ void main() {
65176,
65252,
65247,
1575
1575,
]),
];
... ... @@ -492,6 +492,38 @@ void main() {
));
});
test(
'Text Widgets, Mixed Arabic and Latin words should be rendered in order ',
() {
pdf.addPage(Page(
textDirection: TextDirection.rtl,
build: (Context context) => RichText(
text: TextSpan(
text: 'النصوص ثنائية الإتجاه Bidirectional Text\n',
style: TextStyle(
font: arabicFont,
fontSize: 30,
),
children: const <TextSpan>[
TextSpan(
text: r'''
الكلمات اللاتينية المضافة إلى نص عربي يجب أن توضع في الترتيب الصحيح Right Order مهما كان موضعها في النص.
At the Beginning of the sentence في بداية الجملة
أو في منتصفها In the middle of the sentence حيث يكون بعدها كلام عربي
أو في نهاية النص At the end of the sentence
أيضا ترتيب الأرقام والرموز يجب 1 أن 2 يكون 3 صحيحاً$.
ولا ننسى أيضا فواصل السطور Line breakers حيث وجودها في موضعها الصحيح مهم جدا في النصوص ثنائية الاتجاه Bidirectional
''',
style: TextStyle(
fontSize: 18,
),
),
],
),
),
));
});
tearDownAll(() async {
final file = File('arabic.pdf');
await file.writeAsBytes(await pdf.save());
... ...
No preview for this file type