Files
lottie-flutter/lib/src/parser/document_data_parser.dart
Xavier H bc3eb4621b Add latest feature/fixes from Lottie-Android (#209)
- Added support for rounded corners on shapes and rects
- Add support for text in dynamic properties (ValueDelegate)
- Improve stroke with offset
- Add support for reversed polystar paths
- Enforce order of operations to avoid rounding errors
2022-04-14 22:20:22 +02:00

95 lines
2.2 KiB
Dart

import 'dart:ui';
import '../model/document_data.dart';
import 'json_utils.dart';
import 'moshi/json_reader.dart';
final JsonReaderOptions _names = JsonReaderOptions.of([
't', // 0
'f', // 1
's', // 2
'j', // 3
'tr', // 4
'lh', // 5
'ls', // 6
'fc', // 7
'sc', // 8
'sw', // 9
'of', // 10
]);
DocumentData documentDataParser(JsonReader reader, {required double scale}) {
String? text;
String? fontName;
var size = 0.0;
var justification = Justification.center;
var tracking = 0;
var lineHeight = 0.0;
var baselineShift = 0.0;
var fillColor = const Color(0x00000000);
var strokeColor = const Color(0x00000000);
var strokeWidth = 0.0;
var strokeOverFill = true;
reader.beginObject();
while (reader.hasNext()) {
switch (reader.selectName(_names)) {
case 0:
text = reader.nextString();
break;
case 1:
fontName = reader.nextString();
break;
case 2:
size = reader.nextDouble();
break;
case 3:
var justificationInt = reader.nextInt();
if (justificationInt > Justification.center.index ||
justificationInt < 0) {
justification = Justification.center;
} else {
justification = Justification.values[justificationInt];
}
break;
case 4:
tracking = reader.nextInt();
break;
case 5:
lineHeight = reader.nextDouble();
break;
case 6:
baselineShift = reader.nextDouble();
break;
case 7:
fillColor = JsonUtils.jsonToColor(reader);
break;
case 8:
strokeColor = JsonUtils.jsonToColor(reader);
break;
case 9:
strokeWidth = reader.nextDouble();
break;
case 10:
strokeOverFill = reader.nextBoolean();
break;
default:
reader.skipName();
reader.skipValue();
}
}
reader.endObject();
return DocumentData(
text: text ?? '',
fontName: fontName,
size: size,
justification: justification,
tracking: tracking,
lineHeight: lineHeight,
baselineShift: baselineShift,
color: fillColor,
strokeColor: strokeColor,
strokeWidth: strokeWidth,
strokeOverFill: strokeOverFill);
}