Skip to content
Snippets Groups Projects
Unverified Commit 2ff12981 authored by Mohamed's avatar Mohamed Committed by GitHub
Browse files

Device agnostic PDF size (EXPOSUREAPP-6696) (#3095)

* Resize PDF

* Update QrCodePosterViewModel.kt

* lint

* Scale canvas down for better quality

* Update QrCodePosterViewModel.kt
parent 2ec92a09
No related branches found
No related tags found
No related merge requests found
...@@ -151,7 +151,7 @@ class QrCodePosterFragment : Fragment(R.layout.qr_code_poster_fragment), AutoInj ...@@ -151,7 +151,7 @@ class QrCodePosterFragment : Fragment(R.layout.qr_code_poster_fragment), AutoInj
getString(R.string.app_name), getString(R.string.app_name),
PrintingAdapter(file), PrintingAdapter(file),
PrintAttributes.Builder() PrintAttributes.Builder()
.setMediaSize(PrintAttributes.MediaSize.ISO_A3) .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
.build() .build()
) )
......
...@@ -53,10 +53,12 @@ class QrCodePosterViewModel @AssistedInject constructor( ...@@ -53,10 +53,12 @@ class QrCodePosterViewModel @AssistedInject constructor(
val file = File(directory, "cwa-qr-code.pdf") val file = File(directory, "cwa-qr-code.pdf")
val weakView = weakViewRef.get() ?: return@launch // View is not existing anymore val weakView = weakViewRef.get() ?: return@launch // View is not existing anymore
val pageInfo = PdfDocument.PageInfo.Builder(weakView.width, weakView.height, 1).create() val pageInfo = PdfDocument.PageInfo.Builder(A4_WIDTH, A4_HEIGHT, 1).create()
PdfDocument().apply { PdfDocument().apply {
startPage(pageInfo).apply { startPage(pageInfo).apply {
val sx = A4_WIDTH.toFloat() / weakView.width
val sy = A4_HEIGHT.toFloat() / weakView.height
canvas.scale(sx, sy)
weakView.draw(canvas) weakView.draw(canvas)
finishPage(this) finishPage(this)
} }
...@@ -70,7 +72,7 @@ class QrCodePosterViewModel @AssistedInject constructor( ...@@ -70,7 +72,7 @@ class QrCodePosterViewModel @AssistedInject constructor(
sharingIntent.postValue(fileSharing.getFileIntentProvider(file, traceLocation().description)) sharingIntent.postValue(fileSharing.getFileIntentProvider(file, traceLocation().description))
} catch (e: Exception) { } catch (e: Exception) {
Timber.d(e, "Creating pdf failed") Timber.d(e, "Creating pdf failed")
e.report(ExceptionCategory.INTERNAL) e.report(ExceptionCategory.UI)
} }
} }
...@@ -96,7 +98,7 @@ class QrCodePosterViewModel @AssistedInject constructor( ...@@ -96,7 +98,7 @@ class QrCodePosterViewModel @AssistedInject constructor(
} catch (e: Exception) { } catch (e: Exception) {
Timber.d(e, "Generating poster failed") Timber.d(e, "Generating poster failed")
posterLiveData.postValue(Poster()) posterLiveData.postValue(Poster())
e.report(ExceptionCategory.INTERNAL) e.report(ExceptionCategory.UI)
} }
} }
...@@ -108,6 +110,15 @@ class QrCodePosterViewModel @AssistedInject constructor( ...@@ -108,6 +110,15 @@ class QrCodePosterViewModel @AssistedInject constructor(
traceLocationId: Long traceLocationId: Long
): QrCodePosterViewModel ): QrCodePosterViewModel
} }
companion object {
/**
* A4 size in PostScript
* @see <a href="https://www.cl.cam.ac.uk/~mgk25/iso-paper-ps.txt">Iso-paper-ps</a>
*/
private const val A4_WIDTH = 595 // PostScript
private const val A4_HEIGHT = 842 // PostScript
}
} }
data class Poster( data class Poster(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment