Skip to content

Commit 3f57f4a

Browse files
committed
moving page border size to parameter, also making it optional
1 parent 4a0c587 commit 3f57f4a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

pdfview-library/src/main/java/com/pdfview/PDFRegionDecoder.kt

+11-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import java.io.File
1313
internal class PDFRegionDecoder(private val view: PDFView,
1414
private val file: File,
1515
private val scale: Float,
16+
private val borderSize: Float = 0.0f, // size in mm, zero to skip drawing
1617
@param:ColorInt private val backgroundColorPdf: Int = Color.WHITE) : ImageRegionDecoder {
1718

1819
private lateinit var descriptor: ParcelFileDescriptor
@@ -41,12 +42,6 @@ internal class PDFRegionDecoder(private val view: PDFView,
4142
val numPageAtEnd = Math.ceil(rect.bottom.toDouble() / pageHeight).toInt() - 1
4243
val bitmap = Bitmap.createBitmap(rect.width() / sampleSize, rect.height() / sampleSize, Bitmap.Config.ARGB_8888)
4344
val canvas = Canvas(bitmap)
44-
val pageBorderPaint = Paint().apply() {
45-
color = Color.BLACK
46-
style = Paint.Style.STROKE
47-
isAntiAlias = true // for lines thinner than 1
48-
strokeWidth = 0.5f * 160f / 25.4f / sampleSize // = 0.5 mm
49-
}
5045
canvas.drawColor(backgroundColorPdf)
5146
canvas.drawBitmap(bitmap, 0f, 0f, null)
5247
for ((iteration, pageIndex) in (numPageAtStart..numPageAtEnd).withIndex()) {
@@ -58,9 +53,16 @@ internal class PDFRegionDecoder(private val view: PDFView,
5853
(-rect.left / sampleSize).toFloat(), -((rect.top - pageHeight * numPageAtStart) / sampleSize).toFloat() + (pageHeight.toFloat() / sampleSize) * iteration)
5954
page.render(bitmap,null, matrix, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY)
6055
page.close()
61-
val pageBorderRect = RectF(0f, 0f, page.width.toFloat(), page.height.toFloat())
62-
matrix.mapRect(pageBorderRect)
63-
canvas.drawRect(pageBorderRect, pageBorderPaint)
56+
if (borderSize > 0) {
57+
val pageBorderRect = RectF(0f, 0f, page.width.toFloat(), page.height.toFloat())
58+
matrix.mapRect(pageBorderRect)
59+
canvas.drawRect(pageBorderRect, Paint().apply() {
60+
color = Color.BLACK
61+
style = Paint.Style.STROKE
62+
isAntiAlias = true // for lines thinner than 1
63+
strokeWidth = borderSize * 160f / 25.4f / sampleSize // = 0.5 mm
64+
})
65+
}
6466
}
6567
}
6668
return bitmap

pdfview-library/src/main/java/com/pdfview/PDFView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class PDFView @JvmOverloads constructor(context: Context, attrs: AttributeSet? =
3838

3939
fun show() {
4040
val source = ImageSource.uri(mfile!!.path)
41-
setRegionDecoderFactory { PDFRegionDecoder(view = this, file = mfile!!, scale = mScale) }
41+
setRegionDecoderFactory { PDFRegionDecoder(view = this, file = mfile!!, scale = mScale, borderSize = 0.5f) }
4242
setImage(source)
4343
}
4444

0 commit comments

Comments
 (0)