react-native-rectangle-doc-scanner 7.63.0 → 7.65.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.
@@ -669,79 +669,44 @@ class CameraController(
669
669
  val centerX = viewRect.centerX()
670
670
  val centerY = viewRect.centerY()
671
671
 
672
- fun buildTransform(appliedRotation: Int): Pair<Matrix, FloatArray> {
673
- val candidate = Matrix()
674
- val swap = appliedRotation == 90 || appliedRotation == 270
675
- val bufferWidth = if (swap) preview.height.toFloat() else preview.width.toFloat()
676
- val bufferHeight = if (swap) preview.width.toFloat() else preview.height.toFloat()
677
- val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
678
- bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
679
-
680
- candidate.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
681
- val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
682
- candidate.postScale(scale, scale, centerX, centerY)
683
- if (appliedRotation != 0) {
684
- candidate.postRotate(appliedRotation.toFloat(), centerX, centerY)
685
- }
686
-
687
- val pts = floatArrayOf(
688
- 0f, 0f,
689
- bufferWidth, 0f,
690
- 0f, bufferHeight,
691
- bufferWidth, bufferHeight
692
- )
693
- candidate.mapPoints(pts)
694
- return Pair(candidate, pts)
695
- }
672
+ // Portrait-only mode: swap buffer dimensions based on sensor orientation
673
+ // sensorOrientation=90 means camera is rotated 90° from device natural orientation
674
+ val swap = sensorOrientation == 90 || sensorOrientation == 270
675
+ val bufferWidth = if (swap) preview.height.toFloat() else preview.width.toFloat()
676
+ val bufferHeight = if (swap) preview.width.toFloat() else preview.height.toFloat()
677
+ val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
678
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
696
679
 
697
- fun scoreCoverage(pts: FloatArray): Float {
698
- val minX = min(min(pts[0], pts[2]), min(pts[4], pts[6]))
699
- val maxX = max(max(pts[0], pts[2]), max(pts[4], pts[6]))
700
- val minY = min(min(pts[1], pts[3]), min(pts[5], pts[7]))
701
- val maxY = max(max(pts[1], pts[3]), max(pts[5], pts[7]))
702
-
703
- val left = max(viewRect.left, minX)
704
- val top = max(viewRect.top, minY)
705
- val right = min(viewRect.right, maxX)
706
- val bottom = min(viewRect.bottom, maxY)
707
- val intersection = if (right > left && bottom > top) (right - left) * (bottom - top) else 0f
708
- val viewArea = viewRect.width() * viewRect.height()
709
- return if (viewArea > 0f) intersection / viewArea else 0f
710
- }
711
-
712
- val positive = rotationDegrees
713
- val negative = if (rotationDegrees == 0) 0 else (360 - rotationDegrees) % 360
714
- val (matrixPos, ptsPos) = buildTransform(positive)
715
- val (matrixNeg, ptsNeg) = buildTransform(negative)
716
- val scorePos = scoreCoverage(ptsPos)
717
- val scoreNeg = scoreCoverage(ptsNeg)
680
+ val matrix = Matrix()
681
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
682
+ val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
683
+ matrix.postScale(scale, scale, centerX, centerY)
684
+ // Portrait-only: no additional rotation needed, sensor orientation is already handled by buffer swap
718
685
 
719
- val appliedRotation = if (scoreNeg > scorePos) negative else positive
720
- val appliedMatrix = if (appliedRotation == positive) matrixPos else matrixNeg
721
- val appliedPts = if (appliedRotation == positive) ptsPos else ptsNeg
686
+ val pts = floatArrayOf(
687
+ 0f, 0f,
688
+ bufferWidth, 0f,
689
+ 0f, bufferHeight,
690
+ bufferWidth, bufferHeight
691
+ )
692
+ matrix.mapPoints(pts)
722
693
 
723
694
  Log.d(
724
695
  TAG,
725
- "[TRANSFORM] rotations sensor=$sensorOrientation display=$displayRotation computed=$rotationDegrees applied=$appliedRotation " +
726
- "view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
696
+ "[TRANSFORM] sensor=$sensorOrientation display=$displayRotation swap=$swap " +
697
+ "view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height} buffer=${bufferWidth}x${bufferHeight}"
727
698
  )
728
699
 
729
- previewView.setTransform(appliedMatrix)
730
- latestTransform = Matrix(appliedMatrix)
700
+ previewView.setTransform(matrix)
701
+ latestTransform = Matrix(matrix)
731
702
  latestBufferWidth = preview.width
732
703
  latestBufferHeight = preview.height
733
- latestTransformRotation = appliedRotation
704
+ latestTransformRotation = 0 // Portrait-only mode, no rotation applied
734
705
 
735
706
  Log.d(
736
707
  TAG,
737
- "[TRANSFORM] appliedRotation=$appliedRotation scores pos=$scorePos neg=$scoreNeg viewClass=${previewView.javaClass.name} " +
738
- "isTextureView=${previewView is TextureView} matrix=$appliedMatrix " +
739
- "pts=[${appliedPts[0]},${appliedPts[1]} ${appliedPts[2]},${appliedPts[3]} ${appliedPts[4]},${appliedPts[5]} ${appliedPts[6]},${appliedPts[7]}]"
708
+ "[TRANSFORM] scale=$scale matrix=$matrix"
740
709
  )
741
- val recomputed = computeRotationDegrees()
742
- if (rotationDegrees != recomputed) {
743
- Log.e(TAG, "[TRANSFORM] rotation mismatch computed=$rotationDegrees recomputed=$recomputed")
744
- }
745
710
  Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
746
711
  }
747
712
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.63.0",
3
+ "version": "7.65.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",