react-native-rectangle-doc-scanner 7.31.0 → 7.32.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.
@@ -558,36 +558,27 @@ class CameraController(
558
558
  val viewHeight = previewView.height.toFloat()
559
559
  val preview = previewSize ?: return
560
560
  if (viewWidth == 0f || viewHeight == 0f) return
561
- val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
561
+ val rotationDegrees = computeRotationDegrees()
562
562
  Log.d(
563
563
  TAG,
564
564
  "[TRANSFORM] rotation=${displayRotationDegrees()} view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
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)
568
+ val bufferWidth = preview.width.toFloat()
569
+ val bufferHeight = preview.height.toFloat()
570
+ val rotateDegrees = rotationDegrees.toFloat()
571
+
572
+ // Move buffer center to origin, rotate, scale uniformly to fill view, then move to view center.
573
+ matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
574
+ if (rotateDegrees != 0f) {
575
+ matrix.postRotate(rotateDegrees)
590
576
  }
577
+ val rotatedWidth = if (rotationDegrees == 90 || rotationDegrees == 270) bufferHeight else bufferWidth
578
+ val rotatedHeight = if (rotationDegrees == 90 || rotationDegrees == 270) bufferWidth else bufferHeight
579
+ val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
580
+ matrix.postScale(scale, scale)
581
+ matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
591
582
 
592
583
  previewView.setTransform(matrix)
593
584
  Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
@@ -621,23 +612,15 @@ class CameraController(
621
612
  }
622
613
 
623
614
  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
628
-
629
- // Debug: log aspect ratio diff for each size
630
- pool.forEach { size ->
615
+ // Prefer aspect ratio match first, then pick the highest resolution among matches.
616
+ capped.forEach { size ->
631
617
  val diff = aspectDiff(size)
632
618
  Log.d(TAG, "[SIZE_SELECTION] ${size.width}x${size.height} aspect=${size.width.toDouble()/size.height} diff=$diff")
633
619
  }
634
620
 
635
- val bestDiff = pool.minOf { aspectDiff(it) }
636
- // Use very tight tolerance (0.001) to get only the best aspect ratio matches
637
- val close = pool.filter { aspectDiff(it) <= bestDiff + 0.001 }
638
-
639
- // Among best aspect ratio matches, prefer higher resolution
640
- val selected = close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
621
+ val bestDiff = capped.minOf { aspectDiff(it) }
622
+ val close = capped.filter { aspectDiff(it) <= bestDiff + 0.001 }
623
+ val selected = close.maxByOrNull { it.width * it.height } ?: capped.maxByOrNull { it.width * it.height }
641
624
  Log.d(TAG, "[SIZE_SELECTION] Best aspect diff: $bestDiff, candidates: ${close.size}, selected: ${selected?.width}x${selected?.height}")
642
625
  return selected
643
626
  }
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.32.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",