diff --git a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCode.kt b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCode.kt index eeeceb0..69830a7 100644 --- a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCode.kt +++ b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCode.kt @@ -5,7 +5,7 @@ import com.soywiz.korim.bitmap.Bitmap32 open class EpcQrCode( bitmap: Bitmap32, - heightAndWidth: Int = DefaultHeightAndWidth + heightAndWidth: Int ) { companion object { @@ -15,30 +15,15 @@ open class EpcQrCode( } - open var bitmap: Bitmap32 = bitmap // declare before init() method, otherwise application will crash + open var bitmap: Bitmap32 = bitmap protected set open val bytes: ByteArray get() = bitmap.extractBytes() - open val height: Int - get() = bitmap.height + open val height: Int = heightAndWidth - open val width: Int - get() = bitmap.width - - - - constructor(bitmap: Bitmap32) : this(bitmap, DefaultHeightAndWidth) // convenience constructor for languages that don't support default parameters - - init { - scale(heightAndWidth) - } - - - open fun scale(heightAndWidth: Int) { - this.bitmap = bitmap.scaled(heightAndWidth, heightAndWidth, true) - } + open val width: Int = heightAndWidth open fun qrCodeAsString(border: Int = 0, invertColors: Boolean = false): String { diff --git a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeConfig.kt b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeConfig.kt index 20e40ca..bebbecd 100644 --- a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeConfig.kt +++ b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeConfig.kt @@ -15,6 +15,8 @@ open class EpcQrCodeConfig( open val noteToUser: String? = null, + open val qrCodeHeightAndWidth: Int = EpcQrCode.DefaultHeightAndWidth, + open val encoding: EpcQrCodeCharacterSet = EpcQrCodeCharacterSet.UTF_8 ) { diff --git a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeGenerator.kt b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeGenerator.kt index 65b344a..f8e9424 100644 --- a/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeGenerator.kt +++ b/EpcQrCode/src/commonMain/kotlin/net/codinux/banking/epcqrcode/EpcQrCodeGenerator.kt @@ -6,15 +6,15 @@ import com.soywiz.korim.qr.QRErrorCorrectLevel open class EpcQrCodeGenerator { + protected open val qrCode = QR(correctLevel = QRErrorCorrectLevel.M) + open fun generateEpcQrCode(config: EpcQrCodeConfig): EpcQrCode { - return generateEpcQrCode(config, EpcQrCode.DefaultHeightAndWidth) - } + val heightAndWidth = config.qrCodeHeightAndWidth + val epcQrCodeContent = generateAsString(config) - open fun generateEpcQrCode(config: EpcQrCodeConfig, heightAndWidth: Int = EpcQrCode.DefaultHeightAndWidth): EpcQrCode { - val qrCode = QR(correctLevel = QRErrorCorrectLevel.M) - - val qrCodeBitmap = qrCode.msg(generateAsString(config)) + val qrCodeBitmap = qrCode.msg(epcQrCodeContent) + .scaled(heightAndWidth, heightAndWidth, true) return EpcQrCode(qrCodeBitmap, heightAndWidth) } diff --git a/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/service/EpcQrCodeService.kt b/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/service/EpcQrCodeService.kt index 61fe02c..fd6f613 100644 --- a/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/service/EpcQrCodeService.kt +++ b/EpcQrCodeRest/src/main/kotlin/net/codinux/banking/epcqrcode/rest/service/EpcQrCodeService.kt @@ -1,5 +1,6 @@ package net.codinux.banking.epcqrcode.rest.service +import net.codinux.banking.epcqrcode.EpcQrCode import net.codinux.banking.epcqrcode.EpcQrCodeConfig import net.codinux.banking.epcqrcode.EpcQrCodeGenerator import net.codinux.banking.epcqrcode.rest.dto.GenerateEpcQrCodeRequest @@ -14,11 +15,15 @@ class EpcQrCodeService { private val base64Encoder = Base64.getEncoder() fun generateEpcQrCodeBase64Encoded(request: GenerateEpcQrCodeRequest): ByteArray { - val epcQrCode = epcQrCodeGenerator.generateEpcQrCode(mapToEpcQrCodeConfig(request), request.imageHeightAndWidth) + val epcQrCode = generateEpcQrCode(request) return base64Encoder.encode(epcQrCode.bytes) } + private fun generateEpcQrCode(request: GenerateEpcQrCodeRequest): EpcQrCode { + return epcQrCodeGenerator.generateEpcQrCode(mapToEpcQrCodeConfig(request)) + } + private fun mapToEpcQrCodeConfig(dto: GenerateEpcQrCodeRequest): EpcQrCodeConfig { return EpcQrCodeConfig( dto.receiverName, @@ -26,7 +31,8 @@ class EpcQrCodeService { dto.bic, dto.amount, dto.reference, - dto.noteToUser + dto.noteToUser, + dto.imageHeightAndWidth ) } } \ No newline at end of file