David PHAM-VAN

Add Directionality Widget

# Changelog
## 1.10.2
## 1.11.0
- Fix mixing Arabic with English [Anas Altair]
- Support Dagger alif in Arabic [Anas Altair]
- Support ARABIC TATWEEL [Anas Altair]
- Update Arabic tests [Anas Altair]
- Add Directionality Widget
## 1.10.1
... ...
... ... @@ -445,14 +445,13 @@ class RichText extends Widget {
RichText(
{@required this.text,
TextAlign textAlign,
TextDirection textDirection,
this.textDirection,
bool softWrap,
this.tightBounds = false,
this.textScaleFactor = 1.0,
int maxLines})
: assert(text != null),
_textAlign = textAlign,
textDirection = textDirection ?? TextDirection.ltr,
_softWrap = softWrap,
_maxLines = maxLines;
... ... @@ -486,6 +485,7 @@ class RichText extends Widget {
double wordsWidth,
bool last,
double baseline,
TextDirection textDirection,
) {
double delta = 0;
switch (textAlign) {
... ... @@ -553,6 +553,8 @@ class RichText extends Widget {
_softWrap ??= theme.softWrap;
_maxLines ??= theme.maxLines;
_textAlign ??= theme.textAlign;
final TextDirection _textDirection =
textDirection ?? Directionality.of(context);
final double constraintWidth = constraints.hasBoundedWidth
? constraints.maxWidth
... ... @@ -583,7 +585,7 @@ class RichText extends Widget {
final PdfFontMetrics space =
font.stringMetrics(' ') * (style.fontSize * textScaleFactor);
final List<String> spanLines = (textDirection == TextDirection.rtl
final List<String> spanLines = (_textDirection == TextDirection.rtl
? PdfArabic.convert(span.text)
: span.text)
.split('\n');
... ... @@ -613,6 +615,7 @@ class RichText extends Widget {
style.letterSpacing,
false,
bottom,
_textDirection,
));
spanStart += spanCount;
... ... @@ -676,6 +679,7 @@ class RichText extends Widget {
style.letterSpacing,
true,
bottom,
_textDirection,
));
spanStart += spanCount;
... ... @@ -725,6 +729,7 @@ class RichText extends Widget {
offsetX,
false,
bottom,
_textDirection,
));
spanStart += spanCount;
... ... @@ -782,6 +787,7 @@ class RichText extends Widget {
offsetX,
true,
bottom,
_textDirection,
));
bottom ??= 0.0;
... ...
... ... @@ -380,3 +380,45 @@ class TextStyle {
String toString() =>
'TextStyle(color:$color font:$font size:$fontSize weight:$fontWeight style:$fontStyle letterSpacing:$letterSpacing wordSpacing:$wordSpacing lineSpacing:$lineSpacing height:$height background:$background decoration:$decoration decorationColor:$decorationColor decorationStyle:$decorationStyle decorationThickness:$decorationThickness, renderingMode:$renderingMode)';
}
class Directionality extends StatelessWidget implements Inherited {
/// Creates a widget that determines the directionality of text and
/// text-direction-sensitive render objects.
///
/// The [textDirection] and [child] arguments must not be null.
Directionality({
@required this.textDirection,
@required this.child,
}) : assert(textDirection != null),
assert(child != null);
/// The subtree
final Widget child;
/// The text direction for this subtree.
final TextDirection textDirection;
/// The text direction from the closest instance of this class that encloses
/// the given context.
///
/// If there is no [Directionality] ancestor widget in the tree at the given
/// context, then this will return TextDirection.ltr.
///
/// Typical usage is as follows:
///
/// ```dart
/// TextDirection textDirection = Directionality.of(context);
/// ```
static TextDirection of(Context context) {
final Directionality widget = context.inherited[Directionality];
return widget?.textDirection ?? TextDirection.ltr;
}
@override
Widget build(Context context) {
return InheritedWidget(
build: (context) => child,
inherited: this,
);
}
}
... ...
... ... @@ -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.2
version: 1.11.0
environment:
sdk: ">=2.3.0 <3.0.0"
... ...
... ... @@ -24,6 +24,8 @@ import 'package:test/test.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
import 'utils.dart';
Document pdf;
List<TableRow> buildTable(
... ... @@ -232,6 +234,25 @@ void main() {
));
});
test('Table fromTextArray with directionality', () {
pdf.addPage(Page(
theme: ThemeData.withFont(
base: loadFont('hacen-tunisia.ttf'),
),
build: (Context context) => Directionality(
textDirection: TextDirection.rtl,
child: Table.fromTextArray(
headers: <dynamic>['ثلاثة', 'اثنان', 'واحد'],
cellAlignment: Alignment.centerRight,
data: <List<dynamic>>[
<dynamic>['الكلب', 'قط', 'ذئب'],
<dynamic>['فأر', 'بقرة', 'طائر'],
],
),
),
));
});
tearDownAll(() {
final File file = File('widgets-table.pdf');
file.writeAsBytesSync(pdf.save());
... ...