color property

PdfColor? get color

The /C color of the annotation, or null when absent or transparent.

An array of one number is gray, of three is RGB and of four is CMYK; the empty array means transparent, and becomes null.

Implementation

PdfColor? get color {
  final value = _store.resolveArray(dictionary[PdfNameTokens.c]);
  if (value == null) return null;

  final components = <double>[];
  for (final item in value.values) {
    if (item is! PdfNum) return null;
    components.add(item.value.toDouble().clamp(0.0, 1.0));
  }

  switch (components.length) {
    case 1:
      return PdfColor(components[0], components[0], components[0]);
    case 3:
      return PdfColor(components[0], components[1], components[2]);
    case 4:
      return PdfColorCmyk(
          components[0], components[1], components[2], components[3]);
    default:
      return null;
  }
}
set color (PdfColor? value)

Writes /C; null removes the key.

Implementation

set color(PdfColor? value) {
  final target = writableDictionary();
  if (target == null) return;
  if (value == null) {
    target.values.remove(PdfNameTokens.c);
  } else {
    target[PdfNameTokens.c] = PdfArray.fromColor(value);
  }
}