resolve method

PdfImage resolve(
  1. Context context,
  2. PdfPoint size, {
  3. double? dpi,
})

Resolves this image provider using the given context, returning a PdfImage The image is automatically added to the document

Implementation

PdfImage resolve(Context context, PdfPoint size, {double? dpi}) {
  final effectiveDpi = dpi ?? this.dpi;

  if (effectiveDpi == null || _cache[0] != null) {
    _cache[0] ??= buildImage(context);

    if (_cache[0]!.pdfDocument != context.document) {
      _cache[0] = buildImage(context);
    }

    return _cache[0]!;
  }

  final width = (size.x / PdfPageFormat.inch * effectiveDpi).toInt();
  final height = (size.y / PdfPageFormat.inch * effectiveDpi).toInt();

  if (!_cache.containsKey(width)) {
    _cache[width] ??= buildImage(context, width: width, height: height);
  }

  if (_cache[width]!.pdfDocument != context.document) {
    _cache[width] = buildImage(context, width: width, height: height);
  }

  return _cache[width]!;
}