react-native-rectangle-doc-scanner 7.31.0 → 7.33.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.
@@ -565,29 +565,25 @@ class CameraController(
565
565
  )
566
566
 
567
567
  val matrix = Matrix()
568
- val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
569
- val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
570
- val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
571
- val centerX = viewWidth / 2f
572
- val centerY = viewHeight / 2f
573
- val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
574
- val scaledWidth = bufferWidth * scale
575
- val scaledHeight = bufferHeight * scale
576
- val dx = (viewWidth - scaledWidth) / 2f
577
- val dy = (viewHeight - scaledHeight) / 2f
578
-
579
- matrix.setScale(scale, scale)
580
- matrix.postTranslate(dx, dy)
581
-
582
- if (rotation != Surface.ROTATION_0) {
583
- val rotateDegrees = when (rotation) {
584
- Surface.ROTATION_90 -> -90f
585
- Surface.ROTATION_180 -> 180f
586
- Surface.ROTATION_270 -> 90f
587
- else -> 0f
588
- }
589
- matrix.postRotate(rotateDegrees, centerX, centerY)
590
- }
568
+ val bufferWidth = preview.width.toFloat()
569
+ val bufferHeight = preview.height.toFloat()
570
+ val rotateDegrees = when (rotation) {
571
+ Surface.ROTATION_90 -> -90f
572
+ Surface.ROTATION_180 -> 180f
573
+ Surface.ROTATION_270 -> 90f
574
+ else -> 0f
575
+ }
576
+
577
+ // Move buffer center to origin, rotate, scale uniformly to fill view, then move to view center.
578
+ matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
579
+ if (rotateDegrees != 0f) {
580
+ matrix.postRotate(rotateDegrees)
581
+ }
582
+ val rotatedWidth = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) bufferHeight else bufferWidth
583
+ val rotatedHeight = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) bufferWidth else bufferHeight
584
+ val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
585
+ matrix.postScale(scale, scale)
586
+ matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
591
587
 
592
588
  previewView.setTransform(matrix)
593
589
  Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
@@ -621,22 +617,18 @@ class CameraController(
621
617
  }
622
618
 
623
619
  if (preferClosestAspect) {
624
- // Prefer high-resolution sizes: minimum 1080p (1920x1080 or 1080x1920)
625
- val minAcceptableArea = 1920 * 1080
626
- val highResSizes = capped.filter { it.width * it.height >= minAcceptableArea }
627
- val pool = if (highResSizes.isNotEmpty()) highResSizes else capped
620
+ // Avoid tiny preview sizes even if aspect matches; prefer reasonable resolution.
621
+ val minAcceptableArea = 640 * 480
622
+ val pool = capped.filter { it.width * it.height >= minAcceptableArea }.ifEmpty { capped }
628
623
 
629
- // Debug: log aspect ratio diff for each size
624
+ // Prefer aspect ratio match first, then pick the highest resolution among matches.
630
625
  pool.forEach { size ->
631
626
  val diff = aspectDiff(size)
632
627
  Log.d(TAG, "[SIZE_SELECTION] ${size.width}x${size.height} aspect=${size.width.toDouble()/size.height} diff=$diff")
633
628
  }
634
629
 
635
630
  val bestDiff = pool.minOf { aspectDiff(it) }
636
- // Use very tight tolerance (0.001) to get only the best aspect ratio matches
637
631
  val close = pool.filter { aspectDiff(it) <= bestDiff + 0.001 }
638
-
639
- // Among best aspect ratio matches, prefer higher resolution
640
632
  val selected = close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
641
633
  Log.d(TAG, "[SIZE_SELECTION] Best aspect diff: $bestDiff, candidates: ${close.size}, selected: ${selected?.width}x${selected?.height}")
642
634
  return selected
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.31.0",
3
+ "version": "7.33.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",