Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/wrappers/kn/README.md @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 # ZXing-C++ Kotlin/Native Library | |
| 2 | |
| 3 ## Install | |
| 4 | |
| 5 The easiest way to use the library is to fetch it from _mavenCentral_. Simply add | |
| 6 | |
| 7 ```gradle | |
| 8 implementation("io.github.zxing-cpp:kotlin-native:2.3.0-SNAPSHOT") | |
| 9 ``` | |
| 10 | |
| 11 to your `build.gradle.kts` file in the `dependencies` section of `nativeMain` source set. | |
| 12 To access the SNAPSHOT version, you also need to add a separate repositories entry in your build.cradle file: | |
| 13 | |
| 14 ```gradle | |
| 15 maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") } | |
| 16 ``` | |
| 17 | |
| 18 ## Use | |
| 19 | |
| 20 ### Reading | |
| 21 | |
| 22 A trivial use case looks like this: | |
| 23 | |
| 24 ```kotlin | |
| 25 import zxingcpp.BarcodeFormat | |
| 26 import zxingcpp.BarcodeReader | |
| 27 import zxingcpp.ImageFormat | |
| 28 import zxingcpp.ImageView | |
| 29 | |
| 30 val data: ByteArray = ... // the image data | |
| 31 val width: Int = ... // the image width | |
| 32 val height: Int = ... // the image height | |
| 33 val format: ImageFormat = ImageFormat.Lum // ImageFormat.Lum assumes grey scale image data | |
| 34 | |
| 35 val image: ImageView = ImageView(data, width, height, format) | |
| 36 val barcodeReader = BarcodeReader().apply { | |
| 37 formats = setOf(BarcodeFormat.EAN13, BarcodeFormat.QRCode) | |
| 38 tryHarder = true | |
| 39 maxNumberOfSymbols = 3 | |
| 40 // more options, see documentation | |
| 41 } | |
| 42 | |
| 43 barcodeReader.read(image).joinToString("\n") { barcode: Barcode -> | |
| 44 "${barcode.format} (${barcode.contentType}): ${barcode.text}" | |
| 45 } | |
| 46 ``` | |
| 47 | |
| 48 Here you have to load your image into memory by yourself and pass the decoded data to the constructor of `ImageView`. | |
| 49 | |
| 50 ### Writing | |
| 51 | |
| 52 A trivial use case looks like this: | |
| 53 | |
| 54 ```kotlin | |
| 55 import zxingcpp.* | |
| 56 | |
| 57 val text: String = "Hello, World!" | |
| 58 val format = BarcodeFormat.QRCode | |
| 59 | |
| 60 @OptIn(ExperimentalWriterApi::class) | |
| 61 val cOpts = CreatorOptions(format) // more options, see documentation | |
| 62 | |
| 63 @OptIn(ExperimentalWriterApi::class) | |
| 64 val barcode = Barcode(text, cOpts) | |
| 65 // or | |
| 66 @OptIn(ExperimentalWriterApi::class) | |
| 67 val barcode2 = Barcode(text.encodeToByteArray(), format) | |
| 68 | |
| 69 @OptIn(ExperimentalWriterApi::class) | |
| 70 val wOpts = WriterOptions().apply { | |
| 71 sizeHint = 400 | |
| 72 // more options, see documentation | |
| 73 } | |
| 74 | |
| 75 @OptIn(ExperimentalWriterApi::class) | |
| 76 val svg: String = barcode.toSVG(wOpts) | |
| 77 @OptIn(ExperimentalWriterApi::class) | |
| 78 val image: Image = barcode.toImage(wOpts) | |
| 79 ``` | |
| 80 | |
| 81 > Note: The Writer api is still experimental and may change in future versions. | |
| 82 > You will have to opt-in `zxingcpp.ExperimentalWriterApi` to use it. | |
| 83 | |
| 84 ## Build locally | |
| 85 | |
| 86 1. Install JDK, CMake and Android NDK(With `$ANDROID_NDK` correctly configured) and ensure their | |
| 87 executable binaries appear in `$PATH`. | |
| 88 2. Prepare kotlin/native toolchain (You can easily do this by cloning | |
| 89 [K/N Toolchain Initializer](https://github.com/ISNing/kn-toolchain-initializer) and executing `gradle build` | |
| 90 so that kotlin will download toolchains needed into user's home dir.). | |
| 91 3. Ensure there's `run_konan` available in `$PATH` or specify path of kotlin-native toolchain in `local.properties` | |
| 92 like `konan.dir=/home/user/.konan/kotlin-native-prebuilt-linux-x86_64-1.9.22`. | |
| 93 4. Ensure there's `llvm-ar` available in `$PATH` for mingwX64 target building. | |
| 94 | |
| 95 And then you can build the project from the command line: | |
| 96 | |
| 97 $ ./gradlew :assemble |
