bounds property

Rect get bounds

Gets or sets the bounds.

Implementation

Rect get bounds {
  if (_fieldHelper.isLoadedField) {
    final Rect rect = _fieldHelper.getBounds();
    double x = 0;
    double y = 0;
    if (page != null) {
      final PdfDictionary dictionary =
          PdfPageHelper.getHelper(page!).dictionary!;
      if (dictionary.containsKey(PdfDictionaryProperties.cropBox)) {
        PdfArray? cropBox;
        if (dictionary[PdfDictionaryProperties.cropBox] is PdfArray) {
          cropBox = dictionary[PdfDictionaryProperties.cropBox] as PdfArray?;
        } else {
          final PdfReferenceHolder cropBoxHolder =
              dictionary[PdfDictionaryProperties.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 (dictionary.containsKey(PdfDictionaryProperties.mediaBox)) {
        PdfArray? mediaBox;
        if (PdfCrossTable.dereference(
            dictionary[PdfDictionaryProperties.mediaBox]) is PdfArray) {
          mediaBox = PdfCrossTable.dereference(
              dictionary[PdfDictionaryProperties.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 {
        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 _fieldHelper.widget!.bounds;
  }
}
set bounds (Rect value)

Implementation

set bounds(Rect value) {
  if (value.isEmpty && this is! PdfSignatureField) {
    ArgumentError("bounds can't be empty.");
  }
  if (_fieldHelper.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 = _fieldHelper.dictionary!;
    if (!dic.containsKey(PdfDictionaryProperties.rect)) {
      dic = _fieldHelper.getWidgetAnnotation(
          _fieldHelper.dictionary!, _fieldHelper.crossTable);
    }
    dic.setArray(PdfDictionaryProperties.rect, values);
    _fieldHelper.changed = true;
  } else {
    _fieldHelper.widget!.bounds = value;
  }
}