Showing
7 changed files
with
61 additions
and
23 deletions
@@ -88,16 +88,19 @@ class MultiPage extends Page { | @@ -88,16 +88,19 @@ class MultiPage extends Page { | ||
88 | this.maxPages = 20, | 88 | this.maxPages = 20, |
89 | PageOrientation orientation, | 89 | PageOrientation orientation, |
90 | EdgeInsets margin, | 90 | EdgeInsets margin, |
91 | + TextDirection textDirection, | ||
91 | }) : _buildList = build, | 92 | }) : _buildList = build, |
92 | assert(mainAxisAlignment != null), | 93 | assert(mainAxisAlignment != null), |
93 | assert(crossAxisAlignment != null), | 94 | assert(crossAxisAlignment != null), |
94 | assert(maxPages != null && maxPages > 0), | 95 | assert(maxPages != null && maxPages > 0), |
95 | super( | 96 | super( |
96 | - pageTheme: pageTheme, | ||
97 | - pageFormat: pageFormat, | ||
98 | - margin: margin, | ||
99 | - theme: theme, | ||
100 | - orientation: orientation); | 97 | + pageTheme: pageTheme, |
98 | + pageFormat: pageFormat, | ||
99 | + margin: margin, | ||
100 | + theme: theme, | ||
101 | + orientation: orientation, | ||
102 | + textDirection: textDirection, | ||
103 | + ); | ||
101 | 104 | ||
102 | final BuildListCallback _buildList; | 105 | final BuildListCallback _buildList; |
103 | 106 | ||
@@ -168,7 +171,11 @@ class MultiPage extends Page { | @@ -168,7 +171,11 @@ class MultiPage extends Page { | ||
168 | int index = 0; | 171 | int index = 0; |
169 | int sameCount = 0; | 172 | int sameCount = 0; |
170 | final Context baseContext = | 173 | final Context baseContext = |
171 | - Context(document: document.document).inheritFrom(calculatedTheme); | 174 | + Context(document: document.document).inheritFromAll(<Inherited>[ |
175 | + calculatedTheme, | ||
176 | + if (pageTheme.textDirection != null) | ||
177 | + InheritedDirectionality(pageTheme.textDirection), | ||
178 | + ]); | ||
172 | final List<Widget> children = _buildList(baseContext); | 179 | final List<Widget> children = _buildList(baseContext); |
173 | WidgetContext widgetContext; | 180 | WidgetContext widgetContext; |
174 | 181 |
@@ -24,21 +24,23 @@ typedef BuildListCallback = List<Widget> Function(Context context); | @@ -24,21 +24,23 @@ typedef BuildListCallback = List<Widget> Function(Context context); | ||
24 | enum PageOrientation { natural, landscape, portrait } | 24 | enum PageOrientation { natural, landscape, portrait } |
25 | 25 | ||
26 | class Page { | 26 | class Page { |
27 | - Page( | ||
28 | - {PageTheme pageTheme, | ||
29 | - PdfPageFormat pageFormat, | ||
30 | - BuildCallback build, | ||
31 | - ThemeData theme, | ||
32 | - PageOrientation orientation, | ||
33 | - EdgeInsets margin, | ||
34 | - bool clip = false}) | ||
35 | - : assert( | 27 | + Page({ |
28 | + PageTheme pageTheme, | ||
29 | + PdfPageFormat pageFormat, | ||
30 | + BuildCallback build, | ||
31 | + ThemeData theme, | ||
32 | + PageOrientation orientation, | ||
33 | + EdgeInsets margin, | ||
34 | + bool clip = false, | ||
35 | + TextDirection textDirection, | ||
36 | + }) : assert( | ||
36 | pageTheme == null || | 37 | pageTheme == null || |
37 | (pageFormat == null && | 38 | (pageFormat == null && |
38 | theme == null && | 39 | theme == null && |
39 | orientation == null && | 40 | orientation == null && |
40 | margin == null && | 41 | margin == null && |
41 | - clip == false), | 42 | + clip == false && |
43 | + textDirection == null), | ||
42 | 'Don\'t set both pageTheme and other settings'), | 44 | 'Don\'t set both pageTheme and other settings'), |
43 | pageTheme = pageTheme ?? | 45 | pageTheme = pageTheme ?? |
44 | PageTheme( | 46 | PageTheme( |
@@ -47,6 +49,7 @@ class Page { | @@ -47,6 +49,7 @@ class Page { | ||
47 | margin: margin, | 49 | margin: margin, |
48 | theme: theme, | 50 | theme: theme, |
49 | clip: clip, | 51 | clip: clip, |
52 | + textDirection: textDirection, | ||
50 | ), | 53 | ), |
51 | _build = build; | 54 | _build = build; |
52 | 55 | ||
@@ -106,7 +109,11 @@ class Page { | @@ -106,7 +109,11 @@ class Page { | ||
106 | document: document.document, | 109 | document: document.document, |
107 | page: _pdfPage, | 110 | page: _pdfPage, |
108 | canvas: canvas, | 111 | canvas: canvas, |
109 | - ).inheritFrom(calculatedTheme); | 112 | + ).inheritFromAll(<Inherited>[ |
113 | + calculatedTheme, | ||
114 | + if (pageTheme.textDirection != null) | ||
115 | + InheritedDirectionality(pageTheme.textDirection), | ||
116 | + ]); | ||
110 | 117 | ||
111 | Widget background; | 118 | Widget background; |
112 | Widget content; | 119 | Widget content; |
@@ -26,6 +26,7 @@ class PageTheme { | @@ -26,6 +26,7 @@ class PageTheme { | ||
26 | PageOrientation orientation, | 26 | PageOrientation orientation, |
27 | EdgeInsets margin, | 27 | EdgeInsets margin, |
28 | this.clip = false, | 28 | this.clip = false, |
29 | + this.textDirection, | ||
29 | }) : pageFormat = pageFormat ?? PdfPageFormat.standard, | 30 | }) : pageFormat = pageFormat ?? PdfPageFormat.standard, |
30 | orientation = orientation ?? PageOrientation.natural, | 31 | orientation = orientation ?? PageOrientation.natural, |
31 | _margin = margin; | 32 | _margin = margin; |
@@ -44,6 +45,8 @@ class PageTheme { | @@ -44,6 +45,8 @@ class PageTheme { | ||
44 | 45 | ||
45 | final bool clip; | 46 | final bool clip; |
46 | 47 | ||
48 | + final TextDirection textDirection; | ||
49 | + | ||
47 | bool get mustRotate => | 50 | bool get mustRotate => |
48 | (orientation == PageOrientation.landscape && | 51 | (orientation == PageOrientation.landscape && |
49 | pageFormat.height > pageFormat.width) || | 52 | pageFormat.height > pageFormat.width) || |
@@ -77,6 +80,7 @@ class PageTheme { | @@ -77,6 +80,7 @@ class PageTheme { | ||
77 | PageOrientation orientation, | 80 | PageOrientation orientation, |
78 | EdgeInsets margin, | 81 | EdgeInsets margin, |
79 | bool clip, | 82 | bool clip, |
83 | + TextDirection textDirection, | ||
80 | }) => | 84 | }) => |
81 | PageTheme( | 85 | PageTheme( |
82 | pageFormat: pageFormat ?? this.pageFormat, | 86 | pageFormat: pageFormat ?? this.pageFormat, |
@@ -86,5 +90,6 @@ class PageTheme { | @@ -86,5 +90,6 @@ class PageTheme { | ||
86 | orientation: orientation ?? this.orientation, | 90 | orientation: orientation ?? this.orientation, |
87 | margin: margin ?? this.margin, | 91 | margin: margin ?? this.margin, |
88 | clip: clip ?? this.clip, | 92 | clip: clip ?? this.clip, |
93 | + textDirection: textDirection ?? this.textDirection, | ||
89 | ); | 94 | ); |
90 | } | 95 | } |
@@ -381,7 +381,14 @@ class TextStyle { | @@ -381,7 +381,14 @@ class TextStyle { | ||
381 | '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)'; | 381 | '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)'; |
382 | } | 382 | } |
383 | 383 | ||
384 | -class Directionality extends StatelessWidget implements Inherited { | 384 | +class InheritedDirectionality extends Inherited { |
385 | + const InheritedDirectionality(this.textDirection); | ||
386 | + | ||
387 | + /// The text direction for this subtree. | ||
388 | + final TextDirection textDirection; | ||
389 | +} | ||
390 | + | ||
391 | +class Directionality extends StatelessWidget { | ||
385 | /// Creates a widget that determines the directionality of text and | 392 | /// Creates a widget that determines the directionality of text and |
386 | /// text-direction-sensitive render objects. | 393 | /// text-direction-sensitive render objects. |
387 | /// | 394 | /// |
@@ -410,15 +417,16 @@ class Directionality extends StatelessWidget implements Inherited { | @@ -410,15 +417,16 @@ class Directionality extends StatelessWidget implements Inherited { | ||
410 | /// TextDirection textDirection = Directionality.of(context); | 417 | /// TextDirection textDirection = Directionality.of(context); |
411 | /// ``` | 418 | /// ``` |
412 | static TextDirection of(Context context) { | 419 | static TextDirection of(Context context) { |
413 | - final Directionality widget = context.inherited[Directionality]; | ||
414 | - return widget?.textDirection ?? TextDirection.ltr; | 420 | + final InheritedDirectionality inherited = |
421 | + context.inherited[InheritedDirectionality]; | ||
422 | + return inherited?.textDirection ?? TextDirection.ltr; | ||
415 | } | 423 | } |
416 | 424 | ||
417 | @override | 425 | @override |
418 | Widget build(Context context) { | 426 | Widget build(Context context) { |
419 | return InheritedWidget( | 427 | return InheritedWidget( |
420 | build: (Context context) => child, | 428 | build: (Context context) => child, |
421 | - inherited: this, | 429 | + inherited: InheritedDirectionality(textDirection), |
422 | ); | 430 | ); |
423 | } | 431 | } |
424 | } | 432 | } |
@@ -68,9 +68,15 @@ class Context { | @@ -68,9 +68,15 @@ class Context { | ||
68 | } | 68 | } |
69 | 69 | ||
70 | Context inheritFrom(Inherited object) { | 70 | Context inheritFrom(Inherited object) { |
71 | + return inheritFromAll(<Inherited>[object]); | ||
72 | + } | ||
73 | + | ||
74 | + Context inheritFromAll(Iterable<Inherited> objects) { | ||
71 | final HashMap<Type, Inherited> inherited = | 75 | final HashMap<Type, Inherited> inherited = |
72 | HashMap<Type, Inherited>.of(this.inherited); | 76 | HashMap<Type, Inherited>.of(this.inherited); |
73 | - inherited[object.runtimeType] = object; | 77 | + for (final Inherited object in objects) { |
78 | + inherited[object.runtimeType] = object; | ||
79 | + } | ||
74 | return copyWith(inherited: inherited); | 80 | return copyWith(inherited: inherited); |
75 | } | 81 | } |
76 | } | 82 | } |
@@ -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.11.2 | 7 | +version: 1.12.0 |
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