appearance method

PdfGraphics appearance(
  1. PdfDocument pdfDocument,
  2. PdfAnnotAppearance type, {
  3. String? name,
  4. Matrix4? matrix,
  5. PdfRect? boundingBox,
  6. bool selected = false,
})

Implementation

PdfGraphics appearance(
  PdfDocument pdfDocument,
  PdfAnnotAppearance type, {
  String? name,
  Matrix4? matrix,
  PdfRect? boundingBox,
  bool selected = false,
}) {
  final s = PdfGraphicXObject(pdfDocument, '/Form');
  String? n;
  switch (type) {
    case PdfAnnotAppearance.normal:
      n = '/N';
      break;
    case PdfAnnotAppearance.rollover:
      n = '/R';
      break;
    case PdfAnnotAppearance.down:
      n = '/D';
      break;
  }
  if (name == null) {
    _appearances[n] = s.ref();
  } else {
    if (_appearances[n] is! PdfDict) {
      _appearances[n] = PdfDict();
    }
    final d = _appearances[n];
    if (d is PdfDict) {
      d[name] = s.ref();
    }
  }

  if (matrix != null) {
    s.params['/Matrix'] = PdfArray.fromNum(
        [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]]);
  }

  final bBox = boundingBox ?? PdfRect.fromPoints(PdfPoint.zero, rect.size);
  s.params['/BBox'] =
      PdfArray.fromNum([bBox.x, bBox.y, bBox.width, bBox.height]);
  final g = PdfGraphics(s, s.buf);

  if (selected && name != null) {
    _as = PdfName(name);
  }
  return g;
}