bounds property Null safety

Rect bounds

Gets or sets the bounds.

Implementation

Rect get bounds {
  if (_isLoadedField) {
    final Rect rect = _getBounds();
    double x = 0;
    double y = 0;
    if (page != null &&
        page!._dictionary.containsKey(_DictionaryProperties.cropBox)) {
      _PdfArray? cropBox;
      if (page!._dictionary[_DictionaryProperties.cropBox] is _PdfArray) {
        cropBox =
            page!._dictionary[_DictionaryProperties.cropBox] as _PdfArray?;
      } else {
        final _PdfReferenceHolder cropBoxHolder =
            page!._dictionary[_DictionaryProperties.cropBox]!
                as _PdfReferenceHolder;
        cropBox = cropBoxHolder.object as _PdfArray?;
      }
      if ((cropBox![0]! as _PdfNumber).value != 0 ||
          (cropBox[1]! as _PdfNumber).value != 0 ||
          page!.size.width == (cropBox[2]! as _PdfNumber).value ||
          page!.size.height == (cropBox[3]! as _PdfNumber).value) {
        x = rect.left - (cropBox[0]! as _PdfNumber).value!;
        y = (cropBox[3]! as _PdfNumber).value! - (rect.top + rect.height);
      } else {
        y = page!.size.height - (rect.top + rect.height);
      }
    } else if (page != null &&
        page!._dictionary.containsKey(_DictionaryProperties.mediaBox)) {
      _PdfArray? mediaBox;
      if (_PdfCrossTable._dereference(
          page!._dictionary[_DictionaryProperties.mediaBox]) is _PdfArray) {
        mediaBox = _PdfCrossTable._dereference(
            page!._dictionary[_DictionaryProperties.mediaBox]) as _PdfArray?;
      }
      if ((mediaBox![0]! as _PdfNumber).value! > 0 ||
          (mediaBox[1]! as _PdfNumber).value! > 0 ||
          page!.size.width == (mediaBox[2]! as _PdfNumber).value ||
          page!.size.height == (mediaBox[3]! as _PdfNumber).value) {
        x = rect.left - (mediaBox[0]! as _PdfNumber).value!;
        y = (mediaBox[3]! as _PdfNumber).value! - (rect.top + rect.height);
      } else {
        y = page!.size.height - (rect.top + rect.height);
      }
    } else if (page != null) {
      y = page!.size.height - (rect.top + rect.height);
    } else {
      y = rect.top + rect.height;
    }
    return Rect.fromLTWH(x == 0 ? rect.left : x, y == 0 ? rect.top : y,
        rect.width, rect.height);
  } else {
    return _widget!.bounds;
  }
}
void bounds=(Rect value)

Implementation

set bounds(Rect value) {
  if (value.isEmpty && this is! PdfSignatureField) {
    ArgumentError('bounds can\'t be empty.');
  }
  if (_isLoadedField) {
    final Rect rect = value;
    final double height = page!.size.height;
    final List<_PdfNumber> values = <_PdfNumber>[
      _PdfNumber(rect.left),
      _PdfNumber(height - (rect.top + rect.height)),
      _PdfNumber(rect.left + rect.width),
      _PdfNumber(height - rect.top)
    ];
    _PdfDictionary dic = _dictionary;
    if (!dic.containsKey(_DictionaryProperties.rect)) {
      dic = _getWidgetAnnotation(_dictionary, _crossTable);
    }
    dic._setArray(_DictionaryProperties.rect, values);
    _changed = true;
  } else {
    _widget!.bounds = value;
  }
}