David PHAM-VAN

Fix Page orientation

... ... @@ -10,6 +10,7 @@
- Format Java code
- Add optional clipping on Page
- Add Footer Widget
- Fix Page orientation
## 1.3.23
... ...
... ... @@ -90,8 +90,10 @@ class MultiPage extends Page {
..saveContext()
..setTransform(Matrix4.identity()
..rotateZ(-math.pi / 2)
..translate(x - pageHeight + _margin.top - _margin.left,
y + _margin.left - _margin.bottom));
..translate(
x - pageHeight + _margin.top - _margin.left,
y + _margin.left - _margin.bottom,
));
child.paint(context);
context.canvas.restoreContext();
... ...
... ... @@ -170,14 +170,14 @@ class Page {
if (mustRotate) {
final EdgeInsets _margin = margin;
final Matrix4 mat = Matrix4.identity();
mat
..rotateZ(-math.pi / 2)
..translate(-pageFormat.height - _margin.left + _margin.top,
child.box.height - child.box.width + _margin.left - _margin.bottom);
context.canvas
..saveContext()
..setTransform(mat);
..setTransform(Matrix4.identity()
..rotateZ(-math.pi / 2)
..translate(
-pageFormat.height - _margin.left + _margin.top,
-pageFormat.height + pageFormat.width + _margin.top - _margin.right,
));
child.paint(context);
context.canvas.restoreContext();
} else {
... ...
... ... @@ -24,6 +24,7 @@ import 'isolate_test.dart' as isolate;
import 'jpeg_test.dart' as jpeg;
import 'metrics_test.dart' as metrics;
import 'minimal_test.dart' as minimal;
import 'orientation_test.dart' as orientation;
import 'ttf_test.dart' as ttf;
import 'type1_test.dart' as type1;
import 'widget_basic_test.dart' as widget_basic;
... ... @@ -47,6 +48,7 @@ void main() {
jpeg.main();
metrics.main();
minimal.main();
orientation.main();
ttf.main();
type1.main();
widget_basic.main();
... ...
/*
* Copyright (C) 2017, David PHAM-VAN <dev.nfet.net@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import 'dart:io';
import 'package:test/test.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart';
Document pdf;
Widget content(Context context) {
return ListView(children: contentMultiPage(context));
}
Widget footer(Context context) {
return Footer(
trailing: Text('Page ${context.pageNumber}'),
);
}
Widget header(Context context) {
return Footer(
title: Text('Test document'),
);
}
List<Widget> contentMultiPage(Context context) {
return List<Widget>.generate(
150,
(int n) => Container(
height: 20,
child: Text(
'Hello World $n!',
style: TextStyle(fontSize: 15),
)),
);
}
void main() {
setUpAll(() {
Document.debug = true;
pdf = Document();
});
test('Orientation normal', () {
pdf.addPage(Page(
clip: true,
build: content,
));
});
test('Orientation landscape', () {
pdf.addPage(Page(
clip: true,
pageFormat: PdfPageFormat.standard.portrait,
orientation: PageOrientation.landscape,
build: content,
));
pdf.addPage(Page(
clip: true,
pageFormat: PdfPageFormat.standard.landscape,
orientation: PageOrientation.landscape,
build: content,
));
});
test('Orientation portrait', () {
pdf.addPage(Page(
clip: true,
pageFormat: PdfPageFormat.standard.portrait,
orientation: PageOrientation.portrait,
build: content,
));
pdf.addPage(Page(
clip: true,
pageFormat: PdfPageFormat.standard.landscape,
orientation: PageOrientation.portrait,
build: content,
));
});
test('Orientation MultiPage normal', () {
pdf.addPage(MultiPage(
build: contentMultiPage,
header: header,
footer: footer,
));
});
test('Orientation MultiPage landscape', () {
pdf.addPage(MultiPage(
pageFormat: PdfPageFormat.standard.portrait,
orientation: PageOrientation.landscape,
build: contentMultiPage,
header: header,
footer: footer,
));
pdf.addPage(MultiPage(
pageFormat: PdfPageFormat.standard.landscape,
orientation: PageOrientation.landscape,
build: contentMultiPage,
header: header,
footer: footer,
));
});
test('Orientation MultiPage portrait', () {
pdf.addPage(MultiPage(
pageFormat: PdfPageFormat.standard.portrait,
orientation: PageOrientation.portrait,
build: contentMultiPage,
header: header,
footer: footer,
));
pdf.addPage(MultiPage(
pageFormat: PdfPageFormat.standard.landscape,
orientation: PageOrientation.portrait,
build: contentMultiPage,
header: header,
footer: footer,
));
});
tearDownAll(() {
final File file = File('orientation.pdf');
file.writeAsBytesSync(pdf.save());
});
}
... ...