David PHAM-VAN

Fix raster quality on Android

... ... @@ -4,6 +4,7 @@
- Fix dispose state issue
- Add onPageFormatChanged event
- Fix raster quality on Android
## 5.7.1
... ...
... ... @@ -248,7 +248,8 @@ class PrintingPlugin extends PrintingPlatform {
for (final i in _pages) {
final page = await promiseToFuture<PdfJsPage>(d.getPage(i + 1));
final viewport = page.getViewport(Settings()..scale = 1.5);
final viewport =
page.getViewport(Settings()..scale = dpi / PdfPageFormat.inch);
canvas.height = viewport.height.toInt();
canvas.width = viewport.width.toInt();
... ...
... ... @@ -174,12 +174,12 @@ class _PdfPreviewState extends State<PdfPreview> {
PdfPageFormat computeActualPageFormat() {
var format = previewData.pageFormat;
final pages = previewWidget.currentState?.pages ?? const [];
final dpi = previewWidget.currentState?.dpi ?? 72;
final dpi = previewWidget.currentState?.dpi ?? PdfPageFormat.inch;
if (!widget.canChangePageFormat && pages.isNotEmpty) {
format = PdfPageFormat(
pages.first.page!.width * 72 / dpi,
pages.first.page!.height * 72 / dpi,
pages.first.page!.width * PdfPageFormat.inch / dpi,
pages.first.page!.height * PdfPageFormat.inch / dpi,
marginAll: 5 * PdfPageFormat.mm,
);
}
... ...
... ... @@ -15,6 +15,7 @@
*/
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
... ... @@ -62,10 +63,12 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
_previewUpdate?.cancel();
_previewUpdate = Timer(_updateTime, () {
final mq = MediaQuery.of(context);
final maxDPR = !kIsWeb && Platform.isAndroid ? 2.0 : 1.0;
final dpr = max(maxDPR, mq.devicePixelRatio);
dpi = (min(mq.size.width - 16, widget.maxPageWidth ?? double.infinity)) *
mq.devicePixelRatio /
dpr /
pageFormat.width *
72;
PdfPageFormat.inch;
_raster();
});
... ...