David PHAM-VAN

Add Circular Progress Indicator

... ... @@ -3,6 +3,7 @@
* Remove color constants from PdfColor, use PdfColors
* Add TTF Font SubSetting
* Add Unicode support for TTF Fonts
* Add Circular Progress Indicator
# 1.3.4
* Add available dimensions for PdfPageFormat
... ...
... ... @@ -397,7 +397,7 @@ class PdfGraphics {
/// The center (cx, cy) of the ellipse is calculated automatically to satisfy
/// the constraints imposed by the other parameters. large and sweep flags
/// contribute to the automatic calculations and help determine how the arc is drawn.
void _bezierArc(
void bezierArc(
double x1, double y1, double rx, double ry, double x2, double y2,
{bool large = false, bool sweep = false, double phi = 0.0}) {
if (x1 == x2 && y1 == y2) {
... ... @@ -555,7 +555,7 @@ class PdfGraphics {
case 'A': // elliptical arc, absolute
int len = 0;
while (len < points.length) {
_bezierArc(lastPoint.x, lastPoint.y, points[len + 0],
bezierArc(lastPoint.x, lastPoint.y, points[len + 0],
points[len + 1], points[len + 5], points[len + 6],
phi: points[len + 2] * math.pi / 180.0,
large: points[len + 3] != 0.0,
... ... @@ -569,7 +569,7 @@ class PdfGraphics {
while (len < points.length) {
points[len + 5] += lastPoint.x;
points[len + 6] += lastPoint.y;
_bezierArc(lastPoint.x, lastPoint.y, points[len + 0],
bezierArc(lastPoint.x, lastPoint.y, points[len + 0],
points[len + 1], points[len + 5], points[len + 6],
phi: points[len + 2] * math.pi / 180.0,
large: points[len + 3] != 0.0,
... ...
... ... @@ -36,6 +36,7 @@ part 'widgets/grid_view.dart';
part 'widgets/image.dart';
part 'widgets/multi_page.dart';
part 'widgets/placeholders.dart';
part 'widgets/progress.dart';
part 'widgets/stack.dart';
part 'widgets/table.dart';
part 'widgets/text.dart';
... ...
/*
* 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.
*/
part of widget;
class CircularProgressIndicator extends Widget {
CircularProgressIndicator(
{@required this.value,
this.color,
this.strokeWidth = 4.0,
this.backgroundColor})
: assert(value != null),
assert(strokeWidth != null);
final double value;
final PdfColor color;
final PdfColor backgroundColor;
final double strokeWidth;
@override
void layout(Context context, BoxConstraints constraints,
{bool parentUsesSize = false}) {
box = PdfRect.fromPoints(PdfPoint.zero, constraints.biggest);
}
@override
void paint(Context context) {
super.paint(context);
final double adjustedValue = value.clamp(0.00001, .99999);
final double rx = box.width / 2;
final double ry = box.height / 2;
const double angleStart = math.pi / 2;
final double angleEnd = angleStart - math.pi * 2 * adjustedValue;
final PdfPoint startTop = PdfPoint(
box.x + rx + math.cos(angleStart) * rx,
box.y + ry + math.sin(angleStart) * ry,
);
final PdfPoint endTop = PdfPoint(
box.x + rx + math.cos(angleEnd) * rx,
box.y + ry + math.sin(angleEnd) * ry,
);
final PdfPoint startBottom = PdfPoint(
box.x + rx + math.cos(angleStart) * (rx - strokeWidth),
box.y + ry + math.sin(angleStart) * (ry - strokeWidth),
);
final PdfPoint endBottom = PdfPoint(
box.x + rx + math.cos(angleEnd) * (rx - strokeWidth),
box.y + ry + math.sin(angleEnd) * (ry - strokeWidth),
);
if (backgroundColor != null && value < 1) {
context.canvas
..moveTo(startTop.x, startTop.y)
..bezierArc(startTop.x, startTop.y, rx, ry, endTop.x, endTop.y,
large: adjustedValue < .5, sweep: true)
..lineTo(endBottom.x, endBottom.y)
..bezierArc(endBottom.x, endBottom.y, rx - strokeWidth,
ry - strokeWidth, startBottom.x, startBottom.y,
large: adjustedValue < .5)
..lineTo(startTop.x, startTop.y)
..setFillColor(backgroundColor)
..fillPath();
}
if (value > 0) {
context.canvas
..moveTo(startTop.x, startTop.y)
..bezierArc(startTop.x, startTop.y, rx, ry, endTop.x, endTop.y,
large: adjustedValue > .5)
..lineTo(endBottom.x, endBottom.y)
..bezierArc(endBottom.x, endBottom.y, rx - strokeWidth,
ry - strokeWidth, startBottom.x, startBottom.y,
large: adjustedValue > .5, sweep: true)
..lineTo(startTop.x, startTop.y)
..setFillColor(color ?? PdfColors.indigo)
..fillPath();
}
}
}
... ...
... ... @@ -182,7 +182,24 @@ void main() {
bottom: 10,
child: UrlLink(
child: Text('dart_pdf'),
destination: 'https://github.com/DavBfr/dart_pdf/'))
destination: 'https://github.com/DavBfr/dart_pdf/')),
Positioned(
left: 10,
top: 10,
child: Container(
width: 100,
height: 100,
child: Stack(
alignment: Alignment.center,
fit: StackFit.expand,
children: <Widget>[
Center(
child: Text('30%', textScaleFactor: 1.5)),
CircularProgressIndicator(
value: .3,
backgroundColor: PdfColors.grey300,
strokeWidth: 15),
])))
])));
final File file = File('widgets.pdf');
... ...