CPDFInkAnnotation.fromJson constructor

CPDFInkAnnotation.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory CPDFInkAnnotation.fromJson(Map<String, dynamic> json) {
  final common = CPDFAnnotation.fromJson(json);
  final List<List<List<double>>> strokes = [];
  final dynamic rawInkPath = json['inkPath'];
  if (rawInkPath != null && rawInkPath is List) {
    for (final stroke in rawInkPath) {
      final List<List<double>> points = [];
      if (stroke is List) {
        for (final point in stroke) {
          if (point is List && point.length >= 2) {
            final double x = _toDouble(point[0], fallback: 0.0);
            final double y = _toDouble(point[1], fallback: 0.0);
            points.add([x,y]);
          }
        }
      }
      strokes.add(points);
    }
  }

  return CPDFInkAnnotation(
      title: common.title,
      page: common.page,
      content: common.content,
      uuid: common.uuid,
      createDate: common.createDate,
      rect: common.rect,
      color: HexColor.fromHex(json['color'] ?? '#000000'),
      alpha: (json['alpha'] as num?)?.toDouble() ?? 255.0,
      borderWidth: (json['borderWidth'] as num?)?.toDouble() ?? 0,
      inkPath: strokes);
}