Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines -58 to -59
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why I checked for the pointer to be above 0, but sometimes it is negative and still valid. This prevented a few PDF covers to be rendered on some devices.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is supposed to be an invalid pointer. I'm not sure the method can return it here though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's weird. Maybe the openPage() fails for some reason, but that doesn't prevent the rest of the code from working as we don't use the pointer directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose in case of failure you won't get the first page though...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice yes, but that's not guaranteed... I will look again on Friday to see if I can find a better way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qnga I investigated more and looking at the Java and C++ code of PdfiumAndroid, I don't think the returned long is the address of a C++ pointer. I also tried giving a non-existing page index and this function throws an exception, so the error handling is properly handled inside.

So I think this PR is safe to merge as is. We also used this code in production for the past two weeks without bug reports.


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
}
}

Expand Down