react-native-rectangle-doc-scanner 7.16.0 → 7.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -486,7 +486,13 @@ class CameraController(
486
486
  ?: throw IllegalStateException("Failed to decode JPEG")
487
487
 
488
488
  val rotation = if (exifRotation != 0) exifRotation else computeRotationDegrees()
489
- val rotated = rotateAndMirror(bitmap, rotation, useFrontCamera)
489
+ val shouldRotate = if (rotation == 90 || rotation == 270) {
490
+ bitmap.width > bitmap.height
491
+ } else {
492
+ bitmap.height > bitmap.width
493
+ }
494
+ val appliedRotation = if (shouldRotate) rotation else 0
495
+ val rotated = rotateAndMirror(bitmap, appliedRotation, useFrontCamera)
490
496
  val photoFile = File(pending.outputDirectory, "doc_scan_${System.currentTimeMillis()}.jpg")
491
497
  FileOutputStream(photoFile).use { out ->
492
498
  rotated.compress(Bitmap.CompressFormat.JPEG, 95, out)
@@ -559,14 +565,11 @@ class CameraController(
559
565
  val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
560
566
  val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
561
567
  val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
562
- val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
563
- val scaledWidth = bufferWidth * scale
564
- val scaledHeight = bufferHeight * scale
565
- val dx = (viewWidth - scaledWidth) / 2f
566
- val dy = (viewHeight - scaledHeight) / 2f
567
-
568
- matrix.setScale(scale, scale)
569
- matrix.postTranslate(dx, dy)
568
+ val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
569
+ val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
570
+
571
+ // Scale to fill while preserving aspect ratio; avoid double-scaling.
572
+ matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.FILL)
570
573
 
571
574
  if (rotation != Surface.ROTATION_0) {
572
575
  val rotateDegrees = when (rotation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.16.0",
3
+ "version": "7.18.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",