Showing
5 changed files
with
155 additions
and
8 deletions
| @@ -90,8 +90,10 @@ class MultiPage extends Page { | @@ -90,8 +90,10 @@ class MultiPage extends Page { | ||
| 90 | ..saveContext() | 90 | ..saveContext() |
| 91 | ..setTransform(Matrix4.identity() | 91 | ..setTransform(Matrix4.identity() |
| 92 | ..rotateZ(-math.pi / 2) | 92 | ..rotateZ(-math.pi / 2) |
| 93 | - ..translate(x - pageHeight + _margin.top - _margin.left, | ||
| 94 | - y + _margin.left - _margin.bottom)); | 93 | + ..translate( |
| 94 | + x - pageHeight + _margin.top - _margin.left, | ||
| 95 | + y + _margin.left - _margin.bottom, | ||
| 96 | + )); | ||
| 95 | 97 | ||
| 96 | child.paint(context); | 98 | child.paint(context); |
| 97 | context.canvas.restoreContext(); | 99 | context.canvas.restoreContext(); |
| @@ -170,14 +170,14 @@ class Page { | @@ -170,14 +170,14 @@ class Page { | ||
| 170 | 170 | ||
| 171 | if (mustRotate) { | 171 | if (mustRotate) { |
| 172 | final EdgeInsets _margin = margin; | 172 | final EdgeInsets _margin = margin; |
| 173 | - final Matrix4 mat = Matrix4.identity(); | ||
| 174 | - mat | ||
| 175 | - ..rotateZ(-math.pi / 2) | ||
| 176 | - ..translate(-pageFormat.height - _margin.left + _margin.top, | ||
| 177 | - child.box.height - child.box.width + _margin.left - _margin.bottom); | ||
| 178 | context.canvas | 173 | context.canvas |
| 179 | ..saveContext() | 174 | ..saveContext() |
| 180 | - ..setTransform(mat); | 175 | + ..setTransform(Matrix4.identity() |
| 176 | + ..rotateZ(-math.pi / 2) | ||
| 177 | + ..translate( | ||
| 178 | + -pageFormat.height - _margin.left + _margin.top, | ||
| 179 | + -pageFormat.height + pageFormat.width + _margin.top - _margin.right, | ||
| 180 | + )); | ||
| 181 | child.paint(context); | 181 | child.paint(context); |
| 182 | context.canvas.restoreContext(); | 182 | context.canvas.restoreContext(); |
| 183 | } else { | 183 | } else { |
| @@ -24,6 +24,7 @@ import 'isolate_test.dart' as isolate; | @@ -24,6 +24,7 @@ import 'isolate_test.dart' as isolate; | ||
| 24 | import 'jpeg_test.dart' as jpeg; | 24 | import 'jpeg_test.dart' as jpeg; |
| 25 | import 'metrics_test.dart' as metrics; | 25 | import 'metrics_test.dart' as metrics; |
| 26 | import 'minimal_test.dart' as minimal; | 26 | import 'minimal_test.dart' as minimal; |
| 27 | +import 'orientation_test.dart' as orientation; | ||
| 27 | import 'ttf_test.dart' as ttf; | 28 | import 'ttf_test.dart' as ttf; |
| 28 | import 'type1_test.dart' as type1; | 29 | import 'type1_test.dart' as type1; |
| 29 | import 'widget_basic_test.dart' as widget_basic; | 30 | import 'widget_basic_test.dart' as widget_basic; |
| @@ -47,6 +48,7 @@ void main() { | @@ -47,6 +48,7 @@ void main() { | ||
| 47 | jpeg.main(); | 48 | jpeg.main(); |
| 48 | metrics.main(); | 49 | metrics.main(); |
| 49 | minimal.main(); | 50 | minimal.main(); |
| 51 | + orientation.main(); | ||
| 50 | ttf.main(); | 52 | ttf.main(); |
| 51 | type1.main(); | 53 | type1.main(); |
| 52 | widget_basic.main(); | 54 | widget_basic.main(); |
pdf/test/orientation_test.dart
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com> | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +import 'dart:io'; | ||
| 18 | + | ||
| 19 | +import 'package:test/test.dart'; | ||
| 20 | +import 'package:pdf/pdf.dart'; | ||
| 21 | +import 'package:pdf/widgets.dart'; | ||
| 22 | + | ||
| 23 | +Document pdf; | ||
| 24 | + | ||
| 25 | +Widget content(Context context) { | ||
| 26 | + return ListView(children: contentMultiPage(context)); | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +Widget footer(Context context) { | ||
| 30 | + return Footer( | ||
| 31 | + trailing: Text('Page ${context.pageNumber}'), | ||
| 32 | + ); | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +Widget header(Context context) { | ||
| 36 | + return Footer( | ||
| 37 | + title: Text('Test document'), | ||
| 38 | + ); | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +List<Widget> contentMultiPage(Context context) { | ||
| 42 | + return List<Widget>.generate( | ||
| 43 | + 150, | ||
| 44 | + (int n) => Container( | ||
| 45 | + height: 20, | ||
| 46 | + child: Text( | ||
| 47 | + 'Hello World $n!', | ||
| 48 | + style: TextStyle(fontSize: 15), | ||
| 49 | + )), | ||
| 50 | + ); | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +void main() { | ||
| 54 | + setUpAll(() { | ||
| 55 | + Document.debug = true; | ||
| 56 | + pdf = Document(); | ||
| 57 | + }); | ||
| 58 | + | ||
| 59 | + test('Orientation normal', () { | ||
| 60 | + pdf.addPage(Page( | ||
| 61 | + clip: true, | ||
| 62 | + build: content, | ||
| 63 | + )); | ||
| 64 | + }); | ||
| 65 | + | ||
| 66 | + test('Orientation landscape', () { | ||
| 67 | + pdf.addPage(Page( | ||
| 68 | + clip: true, | ||
| 69 | + pageFormat: PdfPageFormat.standard.portrait, | ||
| 70 | + orientation: PageOrientation.landscape, | ||
| 71 | + build: content, | ||
| 72 | + )); | ||
| 73 | + pdf.addPage(Page( | ||
| 74 | + clip: true, | ||
| 75 | + pageFormat: PdfPageFormat.standard.landscape, | ||
| 76 | + orientation: PageOrientation.landscape, | ||
| 77 | + build: content, | ||
| 78 | + )); | ||
| 79 | + }); | ||
| 80 | + | ||
| 81 | + test('Orientation portrait', () { | ||
| 82 | + pdf.addPage(Page( | ||
| 83 | + clip: true, | ||
| 84 | + pageFormat: PdfPageFormat.standard.portrait, | ||
| 85 | + orientation: PageOrientation.portrait, | ||
| 86 | + build: content, | ||
| 87 | + )); | ||
| 88 | + pdf.addPage(Page( | ||
| 89 | + clip: true, | ||
| 90 | + pageFormat: PdfPageFormat.standard.landscape, | ||
| 91 | + orientation: PageOrientation.portrait, | ||
| 92 | + build: content, | ||
| 93 | + )); | ||
| 94 | + }); | ||
| 95 | + | ||
| 96 | + test('Orientation MultiPage normal', () { | ||
| 97 | + pdf.addPage(MultiPage( | ||
| 98 | + build: contentMultiPage, | ||
| 99 | + header: header, | ||
| 100 | + footer: footer, | ||
| 101 | + )); | ||
| 102 | + }); | ||
| 103 | + | ||
| 104 | + test('Orientation MultiPage landscape', () { | ||
| 105 | + pdf.addPage(MultiPage( | ||
| 106 | + pageFormat: PdfPageFormat.standard.portrait, | ||
| 107 | + orientation: PageOrientation.landscape, | ||
| 108 | + build: contentMultiPage, | ||
| 109 | + header: header, | ||
| 110 | + footer: footer, | ||
| 111 | + )); | ||
| 112 | + pdf.addPage(MultiPage( | ||
| 113 | + pageFormat: PdfPageFormat.standard.landscape, | ||
| 114 | + orientation: PageOrientation.landscape, | ||
| 115 | + build: contentMultiPage, | ||
| 116 | + header: header, | ||
| 117 | + footer: footer, | ||
| 118 | + )); | ||
| 119 | + }); | ||
| 120 | + | ||
| 121 | + test('Orientation MultiPage portrait', () { | ||
| 122 | + pdf.addPage(MultiPage( | ||
| 123 | + pageFormat: PdfPageFormat.standard.portrait, | ||
| 124 | + orientation: PageOrientation.portrait, | ||
| 125 | + build: contentMultiPage, | ||
| 126 | + header: header, | ||
| 127 | + footer: footer, | ||
| 128 | + )); | ||
| 129 | + pdf.addPage(MultiPage( | ||
| 130 | + pageFormat: PdfPageFormat.standard.landscape, | ||
| 131 | + orientation: PageOrientation.portrait, | ||
| 132 | + build: contentMultiPage, | ||
| 133 | + header: header, | ||
| 134 | + footer: footer, | ||
| 135 | + )); | ||
| 136 | + }); | ||
| 137 | + | ||
| 138 | + tearDownAll(() { | ||
| 139 | + final File file = File('orientation.pdf'); | ||
| 140 | + file.writeAsBytesSync(pdf.save()); | ||
| 141 | + }); | ||
| 142 | +} |
-
Please register or login to post a comment