-
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kn: Add support for experimental writer api (#764)
* kn: Allow reading barcode without instantiate a BarcodeReader object Example: ```kotlin val barcode = BarcodeReader.read(iv) ``` ```kotlin val barcode = BarcodeReader.read(iv, opts) ``` * kn: Correct the arrangement of parameter for assert functions * kn: Add support for experimental barcode writer * kn: Add documentation for experimental writer api * kn: Mark Barcode constructors as ExperimentalWriterApi
- Loading branch information
Showing
9 changed files
with
235 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
wrappers/kn/src/nativeMain/kotlin/zxingcpp/BarcodeWriter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2024 ISNing | ||
*/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package zxingcpp | ||
|
||
import cnames.structs.ZXing_CreatorOptions | ||
import cnames.structs.ZXing_WriterOptions | ||
import kotlinx.cinterop.* | ||
import zxingcpp.cinterop.* | ||
import kotlin.experimental.ExperimentalNativeApi | ||
import kotlin.native.ref.createCleaner | ||
|
||
// TODO: Remove this annotation when the API is stable | ||
@RequiresOptIn(level = RequiresOptIn.Level.ERROR, message = "The Writer API is experimental and may change in the future.") | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class ExperimentalWriterApi | ||
|
||
class BarcodeWritingException(message: String?) : Exception("Failed to write barcode: $message") | ||
|
||
@ExperimentalWriterApi | ||
@OptIn(ExperimentalForeignApi::class) | ||
open class CreatorOptions(format: BarcodeFormat) { | ||
var format: BarcodeFormat | ||
get() = ZXing_CreatorOptions_getFormat(cValue).parseIntoBarcodeFormat().first() | ||
set(value) = ZXing_CreatorOptions_setFormat(cValue, value.rawValue) | ||
var readerInit: Boolean | ||
get() = ZXing_CreatorOptions_getReaderInit(cValue) | ||
set(value) = ZXing_CreatorOptions_setReaderInit(cValue, value) | ||
var forceSquareDataMatrix: Boolean | ||
get() = ZXing_CreatorOptions_getForceSquareDataMatrix(cValue) | ||
set(value) = ZXing_CreatorOptions_setForceSquareDataMatrix(cValue, value) | ||
var ecLevel: String | ||
get() = ZXing_CreatorOptions_getEcLevel(cValue)?.toKStringNullPtrHandledAndFree() ?: "" | ||
set(value) = ZXing_CreatorOptions_setEcLevel(cValue, value) | ||
|
||
val cValue: CValuesRef<ZXing_CreatorOptions>? = ZXing_CreatorOptions_new(format.rawValue) | ||
|
||
@Suppress("unused") | ||
@OptIn(ExperimentalNativeApi::class) | ||
private val cleaner = createCleaner(cValue) { ZXing_CreatorOptions_delete(it) } | ||
} | ||
|
||
@ExperimentalWriterApi | ||
@OptIn(ExperimentalForeignApi::class) | ||
open class WriterOptions { | ||
var scale: Int | ||
get() = ZXing_WriterOptions_getScale(cValue) | ||
set(value) = ZXing_WriterOptions_setScale(cValue, value) | ||
var sizeHint: Int | ||
get() = ZXing_WriterOptions_getSizeHint(cValue) | ||
set(value) = ZXing_WriterOptions_setSizeHint(cValue, value) | ||
var rotate: Int | ||
get() = ZXing_WriterOptions_getRotate(cValue) | ||
set(value) = ZXing_WriterOptions_setRotate(cValue, value) | ||
var withHRT: Boolean | ||
get() = ZXing_WriterOptions_getWithHRT(cValue) | ||
set(value) = ZXing_WriterOptions_setWithHRT(cValue, value) | ||
var withQuietZones: Boolean | ||
get() = ZXing_WriterOptions_getWithQuietZones(cValue) | ||
set(value) = ZXing_WriterOptions_setWithQuietZones(cValue, value) | ||
|
||
val cValue: CValuesRef<ZXing_WriterOptions>? = ZXing_WriterOptions_new() | ||
|
||
@Suppress("unused") | ||
@OptIn(ExperimentalNativeApi::class) | ||
private val cleaner = createCleaner(cValue) { ZXing_WriterOptions_delete(it) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters