From 2e3b99b22c50e855331d64f347c10133230111ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Fri, 3 Dec 2021 15:06:41 +0100 Subject: [PATCH] Fix the rendering of PDF covers in some edge cases --- CHANGELOG.md | 4 ++++ .../readium/r2/streamer/parser/pdf/PdfiumDocument.kt | 12 +++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd77898213..df1627354d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,10 @@ All notable changes to this project will be documented in this file. Take a look * Fix building with Kotlin 1.6. +#### Streamer + +* Fixed the rendering of PDF covers in some edge cases. + #### Navigator * Fixed turning pages of an EPUB reflowable resource with an odd number of columns. A virtual blank trailing column is appended to the resource when displayed as two columns. diff --git a/readium/streamer/src/main/java/org/readium/r2/streamer/parser/pdf/PdfiumDocument.kt b/readium/streamer/src/main/java/org/readium/r2/streamer/parser/pdf/PdfiumDocument.kt index 25275770d9..67cb459e76 100644 --- a/readium/streamer/src/main/java/org/readium/r2/streamer/parser/pdf/PdfiumDocument.kt +++ b/readium/streamer/src/main/java/org/readium/r2/streamer/parser/pdf/PdfiumDocument.kt @@ -54,22 +54,20 @@ internal class PdfiumDocument( } private fun PdfiumCore.renderCover(document: _PdfiumDocument): Bitmap? { - try { - val pointer = openPage(document, 0) - if (pointer <= 0) return null - + return try { + openPage(document, 0) val width = getPageWidth(document, 0) val height = getPageHeight(document, 0) val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) renderPageBitmap(document, bitmap, 0, 0, 0, width, height, false) - return bitmap + bitmap } catch (e: Exception) { Timber.e(e) - return null + null } catch (e: OutOfMemoryError) { // We don't want to catch any Error, only OOM. Timber.e(e) - return null + null } }