resolve method
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) {
final width = (size.x / PdfPageFormat.inch * effectiveDpi).toInt();
final height = (size.y / PdfPageFormat.inch * effectiveDpi).toInt();
// Never resample above the source resolution: upscaling adds no detail
// but discards the original (possibly better compressed) image data.
// For rotated orientations the axis buildImage resizes depends on
// whether decoding bakes the rotation into the pixels, so only an
// upper bound is checked here; buildImage itself skips the resample
// when the target is at or above the decoded pixel width. An unknown
// source width keeps the original: it cannot be proven a downsample.
final sourceWidth = _width;
final resampleBound = sourceWidth == null
? null
: orientation.index >= 4
? (sourceWidth > _height ? sourceWidth : _height)
: sourceWidth;
if (resampleBound != null && width > 0 && width < resampleBound) {
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]!;
}
}
_cache[0] ??= buildImage(context);
if (_cache[0]!.pdfDocument != context.document) {
_cache[0] = buildImage(context);
}
return _cache[0]!;
}