Showing
5 changed files
with
119 additions
and
4 deletions
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | * Remove color constants from PdfColor, use PdfColors | 3 | * Remove color constants from PdfColor, use PdfColors |
4 | * Add TTF Font SubSetting | 4 | * Add TTF Font SubSetting |
5 | * Add Unicode support for TTF Fonts | 5 | * Add Unicode support for TTF Fonts |
6 | +* Add Circular Progress Indicator | ||
6 | 7 | ||
7 | # 1.3.4 | 8 | # 1.3.4 |
8 | * Add available dimensions for PdfPageFormat | 9 | * Add available dimensions for PdfPageFormat |
@@ -397,7 +397,7 @@ class PdfGraphics { | @@ -397,7 +397,7 @@ class PdfGraphics { | ||
397 | /// The center (cx, cy) of the ellipse is calculated automatically to satisfy | 397 | /// The center (cx, cy) of the ellipse is calculated automatically to satisfy |
398 | /// the constraints imposed by the other parameters. large and sweep flags | 398 | /// the constraints imposed by the other parameters. large and sweep flags |
399 | /// contribute to the automatic calculations and help determine how the arc is drawn. | 399 | /// contribute to the automatic calculations and help determine how the arc is drawn. |
400 | - void _bezierArc( | 400 | + void bezierArc( |
401 | double x1, double y1, double rx, double ry, double x2, double y2, | 401 | double x1, double y1, double rx, double ry, double x2, double y2, |
402 | {bool large = false, bool sweep = false, double phi = 0.0}) { | 402 | {bool large = false, bool sweep = false, double phi = 0.0}) { |
403 | if (x1 == x2 && y1 == y2) { | 403 | if (x1 == x2 && y1 == y2) { |
@@ -555,7 +555,7 @@ class PdfGraphics { | @@ -555,7 +555,7 @@ class PdfGraphics { | ||
555 | case 'A': // elliptical arc, absolute | 555 | case 'A': // elliptical arc, absolute |
556 | int len = 0; | 556 | int len = 0; |
557 | while (len < points.length) { | 557 | while (len < points.length) { |
558 | - _bezierArc(lastPoint.x, lastPoint.y, points[len + 0], | 558 | + bezierArc(lastPoint.x, lastPoint.y, points[len + 0], |
559 | points[len + 1], points[len + 5], points[len + 6], | 559 | points[len + 1], points[len + 5], points[len + 6], |
560 | phi: points[len + 2] * math.pi / 180.0, | 560 | phi: points[len + 2] * math.pi / 180.0, |
561 | large: points[len + 3] != 0.0, | 561 | large: points[len + 3] != 0.0, |
@@ -569,7 +569,7 @@ class PdfGraphics { | @@ -569,7 +569,7 @@ class PdfGraphics { | ||
569 | while (len < points.length) { | 569 | while (len < points.length) { |
570 | points[len + 5] += lastPoint.x; | 570 | points[len + 5] += lastPoint.x; |
571 | points[len + 6] += lastPoint.y; | 571 | points[len + 6] += lastPoint.y; |
572 | - _bezierArc(lastPoint.x, lastPoint.y, points[len + 0], | 572 | + bezierArc(lastPoint.x, lastPoint.y, points[len + 0], |
573 | points[len + 1], points[len + 5], points[len + 6], | 573 | points[len + 1], points[len + 5], points[len + 6], |
574 | phi: points[len + 2] * math.pi / 180.0, | 574 | phi: points[len + 2] * math.pi / 180.0, |
575 | large: points[len + 3] != 0.0, | 575 | large: points[len + 3] != 0.0, |
@@ -36,6 +36,7 @@ part 'widgets/grid_view.dart'; | @@ -36,6 +36,7 @@ part 'widgets/grid_view.dart'; | ||
36 | part 'widgets/image.dart'; | 36 | part 'widgets/image.dart'; |
37 | part 'widgets/multi_page.dart'; | 37 | part 'widgets/multi_page.dart'; |
38 | part 'widgets/placeholders.dart'; | 38 | part 'widgets/placeholders.dart'; |
39 | +part 'widgets/progress.dart'; | ||
39 | part 'widgets/stack.dart'; | 40 | part 'widgets/stack.dart'; |
40 | part 'widgets/table.dart'; | 41 | part 'widgets/table.dart'; |
41 | part 'widgets/text.dart'; | 42 | part 'widgets/text.dart'; |
pdf/lib/widgets/progress.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 | +part of widget; | ||
18 | + | ||
19 | +class CircularProgressIndicator extends Widget { | ||
20 | + CircularProgressIndicator( | ||
21 | + {@required this.value, | ||
22 | + this.color, | ||
23 | + this.strokeWidth = 4.0, | ||
24 | + this.backgroundColor}) | ||
25 | + : assert(value != null), | ||
26 | + assert(strokeWidth != null); | ||
27 | + | ||
28 | + final double value; | ||
29 | + | ||
30 | + final PdfColor color; | ||
31 | + | ||
32 | + final PdfColor backgroundColor; | ||
33 | + | ||
34 | + final double strokeWidth; | ||
35 | + | ||
36 | + @override | ||
37 | + void layout(Context context, BoxConstraints constraints, | ||
38 | + {bool parentUsesSize = false}) { | ||
39 | + box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest); | ||
40 | + } | ||
41 | + | ||
42 | + @override | ||
43 | + void paint(Context context) { | ||
44 | + super.paint(context); | ||
45 | + | ||
46 | + final double adjustedValue = value.clamp(0.00001, .99999); | ||
47 | + final double rx = box.width / 2; | ||
48 | + final double ry = box.height / 2; | ||
49 | + const double angleStart = math.pi / 2; | ||
50 | + final double angleEnd = angleStart - math.pi * 2 * adjustedValue; | ||
51 | + final PdfPoint startTop = PdfPoint( | ||
52 | + box.x + rx + math.cos(angleStart) * rx, | ||
53 | + box.y + ry + math.sin(angleStart) * ry, | ||
54 | + ); | ||
55 | + final PdfPoint endTop = PdfPoint( | ||
56 | + box.x + rx + math.cos(angleEnd) * rx, | ||
57 | + box.y + ry + math.sin(angleEnd) * ry, | ||
58 | + ); | ||
59 | + final PdfPoint startBottom = PdfPoint( | ||
60 | + box.x + rx + math.cos(angleStart) * (rx - strokeWidth), | ||
61 | + box.y + ry + math.sin(angleStart) * (ry - strokeWidth), | ||
62 | + ); | ||
63 | + final PdfPoint endBottom = PdfPoint( | ||
64 | + box.x + rx + math.cos(angleEnd) * (rx - strokeWidth), | ||
65 | + box.y + ry + math.sin(angleEnd) * (ry - strokeWidth), | ||
66 | + ); | ||
67 | + | ||
68 | + if (backgroundColor != null && value < 1) { | ||
69 | + context.canvas | ||
70 | + ..moveTo(startTop.x, startTop.y) | ||
71 | + ..bezierArc(startTop.x, startTop.y, rx, ry, endTop.x, endTop.y, | ||
72 | + large: adjustedValue < .5, sweep: true) | ||
73 | + ..lineTo(endBottom.x, endBottom.y) | ||
74 | + ..bezierArc(endBottom.x, endBottom.y, rx - strokeWidth, | ||
75 | + ry - strokeWidth, startBottom.x, startBottom.y, | ||
76 | + large: adjustedValue < .5) | ||
77 | + ..lineTo(startTop.x, startTop.y) | ||
78 | + ..setFillColor(backgroundColor) | ||
79 | + ..fillPath(); | ||
80 | + } | ||
81 | + | ||
82 | + if (value > 0) { | ||
83 | + context.canvas | ||
84 | + ..moveTo(startTop.x, startTop.y) | ||
85 | + ..bezierArc(startTop.x, startTop.y, rx, ry, endTop.x, endTop.y, | ||
86 | + large: adjustedValue > .5) | ||
87 | + ..lineTo(endBottom.x, endBottom.y) | ||
88 | + ..bezierArc(endBottom.x, endBottom.y, rx - strokeWidth, | ||
89 | + ry - strokeWidth, startBottom.x, startBottom.y, | ||
90 | + large: adjustedValue > .5, sweep: true) | ||
91 | + ..lineTo(startTop.x, startTop.y) | ||
92 | + ..setFillColor(color ?? PdfColors.indigo) | ||
93 | + ..fillPath(); | ||
94 | + } | ||
95 | + } | ||
96 | +} |
@@ -182,7 +182,24 @@ void main() { | @@ -182,7 +182,24 @@ void main() { | ||
182 | bottom: 10, | 182 | bottom: 10, |
183 | child: UrlLink( | 183 | child: UrlLink( |
184 | child: Text('dart_pdf'), | 184 | child: Text('dart_pdf'), |
185 | - destination: 'https://github.com/DavBfr/dart_pdf/')) | 185 | + destination: 'https://github.com/DavBfr/dart_pdf/')), |
186 | + Positioned( | ||
187 | + left: 10, | ||
188 | + top: 10, | ||
189 | + child: Container( | ||
190 | + width: 100, | ||
191 | + height: 100, | ||
192 | + child: Stack( | ||
193 | + alignment: Alignment.center, | ||
194 | + fit: StackFit.expand, | ||
195 | + children: <Widget>[ | ||
196 | + Center( | ||
197 | + child: Text('30%', textScaleFactor: 1.5)), | ||
198 | + CircularProgressIndicator( | ||
199 | + value: .3, | ||
200 | + backgroundColor: PdfColors.grey300, | ||
201 | + strokeWidth: 15), | ||
202 | + ]))) | ||
186 | ]))); | 203 | ]))); |
187 | 204 | ||
188 | final File file = File('widgets.pdf'); | 205 | final File file = File('widgets.pdf'); |
-
Please register or login to post a comment