David PHAM-VAN

Fix raster quality on Android

@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 4
5 - Fix dispose state issue 5 - Fix dispose state issue
6 - Add onPageFormatChanged event 6 - Add onPageFormatChanged event
  7 +- Fix raster quality on Android
7 8
8 ## 5.7.1 9 ## 5.7.1
9 10
@@ -248,7 +248,8 @@ class PrintingPlugin extends PrintingPlatform { @@ -248,7 +248,8 @@ class PrintingPlugin extends PrintingPlatform {
248 248
249 for (final i in _pages) { 249 for (final i in _pages) {
250 final page = await promiseToFuture<PdfJsPage>(d.getPage(i + 1)); 250 final page = await promiseToFuture<PdfJsPage>(d.getPage(i + 1));
251 - final viewport = page.getViewport(Settings()..scale = 1.5); 251 + final viewport =
  252 + page.getViewport(Settings()..scale = dpi / PdfPageFormat.inch);
252 253
253 canvas.height = viewport.height.toInt(); 254 canvas.height = viewport.height.toInt();
254 canvas.width = viewport.width.toInt(); 255 canvas.width = viewport.width.toInt();
@@ -174,12 +174,12 @@ class _PdfPreviewState extends State<PdfPreview> { @@ -174,12 +174,12 @@ class _PdfPreviewState extends State<PdfPreview> {
174 PdfPageFormat computeActualPageFormat() { 174 PdfPageFormat computeActualPageFormat() {
175 var format = previewData.pageFormat; 175 var format = previewData.pageFormat;
176 final pages = previewWidget.currentState?.pages ?? const []; 176 final pages = previewWidget.currentState?.pages ?? const [];
177 - final dpi = previewWidget.currentState?.dpi ?? 72; 177 + final dpi = previewWidget.currentState?.dpi ?? PdfPageFormat.inch;
178 178
179 if (!widget.canChangePageFormat && pages.isNotEmpty) { 179 if (!widget.canChangePageFormat && pages.isNotEmpty) {
180 format = PdfPageFormat( 180 format = PdfPageFormat(
181 - pages.first.page!.width * 72 / dpi,  
182 - pages.first.page!.height * 72 / dpi, 181 + pages.first.page!.width * PdfPageFormat.inch / dpi,
  182 + pages.first.page!.height * PdfPageFormat.inch / dpi,
183 marginAll: 5 * PdfPageFormat.mm, 183 marginAll: 5 * PdfPageFormat.mm,
184 ); 184 );
185 } 185 }
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 */ 15 */
16 16
17 import 'dart:async'; 17 import 'dart:async';
  18 +import 'dart:io';
18 import 'dart:math'; 19 import 'dart:math';
19 import 'dart:typed_data'; 20 import 'dart:typed_data';
20 21
@@ -62,10 +63,12 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> { @@ -62,10 +63,12 @@ mixin PdfPreviewRaster on State<PdfPreviewCustom> {
62 _previewUpdate?.cancel(); 63 _previewUpdate?.cancel();
63 _previewUpdate = Timer(_updateTime, () { 64 _previewUpdate = Timer(_updateTime, () {
64 final mq = MediaQuery.of(context); 65 final mq = MediaQuery.of(context);
  66 + final maxDPR = !kIsWeb && Platform.isAndroid ? 2.0 : 1.0;
  67 + final dpr = max(maxDPR, mq.devicePixelRatio);
65 dpi = (min(mq.size.width - 16, widget.maxPageWidth ?? double.infinity)) * 68 dpi = (min(mq.size.width - 16, widget.maxPageWidth ?? double.infinity)) *
66 - mq.devicePixelRatio / 69 + dpr /
67 pageFormat.width * 70 pageFormat.width *
68 - 72; 71 + PdfPageFormat.inch;
69 72
70 _raster(); 73 _raster();
71 }); 74 });