Skip to content

Commit

Permalink
Add TextAlign.start and TextAlign.end and fix Line.realign accordingly
Browse files Browse the repository at this point in the history
change widgets geometry to directional geometry
  • Loading branch information
Milad-Akarie authored and DavBfr committed Jul 24, 2023
1 parent 297aa68 commit 97490bd
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 375 deletions.
201 changes: 70 additions & 131 deletions pdf/lib/src/widgets/basic.dart

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pdf/lib/src/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ class Footer extends StatelessWidget {

final Widget? trailing;

final EdgeInsets? margin;
final EdgeInsetsGeometry? margin;

final EdgeInsets? padding;
final EdgeInsetsGeometry? padding;

final BoxDecoration? decoration;

Expand Down
20 changes: 10 additions & 10 deletions pdf/lib/src/widgets/decoration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ class LinearGradient extends Gradient {
}) : super(colors: colors, stops: stops);

/// The offset at which stop 0.0 of the gradient is placed.
final Alignment begin;
final AlignmentGeometry begin;

/// The offset at which stop 1.0 of the gradient is placed.
final Alignment end;
final AlignmentGeometry end;

/// How this gradient should tile the plane beyond in the region before
final TileMode tileMode;
Expand All @@ -134,7 +134,7 @@ class LinearGradient extends Gradient {
}

assert(stops == null || stops!.length == colors.length);

final textDirection = Directionality.of(context);
context.canvas
..saveContext()
..clipPath()
Expand All @@ -148,8 +148,8 @@ class LinearGradient extends Gradient {
colors,
stops,
),
start: begin.withinRect(box),
end: end.withinRect(box),
start: begin.resolve(textDirection).withinRect(box),
end: end.resolve(textDirection).withinRect(box),
extendStart: true,
extendEnd: true,
),
Expand All @@ -175,7 +175,7 @@ class RadialGradient extends Gradient {
}) : super(colors: colors, stops: stops);

/// The center of the gradient
final Alignment center;
final AlignmentGeometry center;

/// The radius of the gradient
final double radius;
Expand All @@ -185,7 +185,7 @@ class RadialGradient extends Gradient {
final TileMode tileMode;

/// The focal point of the gradient.
final Alignment? focal;
final AlignmentGeometry? focal;

/// The radius of the focal point of the gradient.
final double focalRadius;
Expand All @@ -207,7 +207,7 @@ class RadialGradient extends Gradient {
final _focal = focal ?? center;

final _radius = math.min(box.width, box.height);

final textDirection = Directionality.of(context);
context.canvas
..saveContext()
..clipPath()
Expand All @@ -221,8 +221,8 @@ class RadialGradient extends Gradient {
colors,
stops,
),
start: _focal.withinRect(box),
end: center.withinRect(box),
start: _focal.resolve(textDirection).withinRect(box),
end: center.resolve(textDirection).withinRect(box),
radius0: focalRadius * _radius,
radius1: radius * _radius,
extendStart: true,
Expand Down
2 changes: 1 addition & 1 deletion pdf/lib/src/widgets/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class FlatButton extends SingleChildWidget with AnnotationAppearance {
PdfColor color = PdfColors.blue,
PdfColor colorDown = PdfColors.red,
PdfColor colorRollover = PdfColors.blueAccent,
EdgeInsets? padding,
EdgeInsetsGeometry? padding,
BoxDecoration? decoration,
this.flags,
required Widget child,
Expand Down
10 changes: 5 additions & 5 deletions pdf/lib/src/widgets/page_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ class PageTheme {

EdgeInsetsGeometry? get margin {
if (_margin != null) {
final effectiveMargin = _margin!.resolve(textDirection);
final resolvedMargin = _margin!.resolve(textDirection);
if (mustRotate) {
return EdgeInsets.fromLTRB(
effectiveMargin.bottom,
effectiveMargin.left,
effectiveMargin.top,
effectiveMargin.right,
resolvedMargin.bottom,
resolvedMargin.left,
resolvedMargin.top,
resolvedMargin.right,
);
} else {
return _margin;
Expand Down
14 changes: 7 additions & 7 deletions pdf/lib/src/widgets/table_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ mixin TableHelper {
required List<List<dynamic>> data,
EdgeInsetsGeometry cellPadding = const EdgeInsets.all(5),
double cellHeight = 0,
Alignment cellAlignment = Alignment.topLeft,
Map<int, Alignment>? cellAlignments,
AlignmentGeometry cellAlignment = Alignment.topLeft,
Map<int, AlignmentGeometry>? cellAlignments,
TextStyle? cellStyle,
TextStyle? oddCellStyle,
OnCellFormat? cellFormat,
Expand All @@ -50,8 +50,8 @@ mixin TableHelper {
List<dynamic>? headers,
EdgeInsetsGeometry? headerPadding,
double? headerHeight,
Alignment headerAlignment = Alignment.center,
Map<int, Alignment>? headerAlignments,
AlignmentGeometry headerAlignment = Alignment.center,
Map<int, AlignmentGeometry>? headerAlignments,
TextStyle? headerStyle,
OnCellFormat? headerFormat,
TableBorder? border = const TableBorder(
Expand Down Expand Up @@ -120,14 +120,14 @@ mixin TableHelper {
rowNum++;
}

final textDirection = context == null ? TextDirection.ltr : Directionality.of(context);
for (final row in data) {
final tableRow = <Widget>[];
final isOdd = (rowNum - headerCount) % 2 != 0;

if (rowNum < headerCount) {
for (final dynamic cell in row) {
final align = headerAlignments[tableRow.length] ?? headerAlignment;
final textAlign = _textAlign(align);
final textAlign = _textAlign(align.resolve(textDirection));

tableRow.add(
Container(
Expand Down Expand Up @@ -165,7 +165,7 @@ mixin TableHelper {
? cell.toString()
: cellFormat(tableRow.length, cell),
style: isOdd ? oddCellStyle : cellStyle,
textAlign: _textAlign(align),
textAlign: _textAlign(align.resolve(textDirection)),
textDirection: tableDirection,
),
),
Expand Down
Loading

0 comments on commit 97490bd

Please sign in to comment.