react-native-rectangle-doc-scanner 3.3.0 → 3.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -79,7 +79,7 @@
79
79
  view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
80
80
  view.translatesAutoresizingMaskIntoConstraints = YES;
81
81
  view.context = self.context;
82
- view.contentScaleFactor = 1.0f;
82
+ view.contentScaleFactor = [UIScreen mainScreen].scale;
83
83
  view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
84
84
  [self insertSubview:view atIndex:0];
85
85
  _glkView = view;
@@ -265,7 +265,30 @@
265
265
 
266
266
  if (self.context && _coreImageContext)
267
267
  {
268
- [_coreImageContext drawImage:image inRect:self.bounds fromRect:image.extent];
268
+ // Calculate the rect to draw the image with aspect fill
269
+ CGRect drawRect = self.bounds;
270
+ CGRect imageExtent = image.extent;
271
+
272
+ // Calculate aspect ratios
273
+ CGFloat imageAspect = imageExtent.size.width / imageExtent.size.height;
274
+ CGFloat viewAspect = drawRect.size.width / drawRect.size.height;
275
+
276
+ CGRect fromRect = imageExtent;
277
+
278
+ // Aspect fill: crop the image to fill the view
279
+ if (imageAspect > viewAspect) {
280
+ // Image is wider, crop width
281
+ CGFloat newWidth = imageExtent.size.height * viewAspect;
282
+ CGFloat xOffset = (imageExtent.size.width - newWidth) / 2.0;
283
+ fromRect = CGRectMake(xOffset, 0, newWidth, imageExtent.size.height);
284
+ } else {
285
+ // Image is taller, crop height
286
+ CGFloat newHeight = imageExtent.size.width / viewAspect;
287
+ CGFloat yOffset = (imageExtent.size.height - newHeight) / 2.0;
288
+ fromRect = CGRectMake(0, yOffset, imageExtent.size.width, newHeight);
289
+ }
290
+
291
+ [_coreImageContext drawImage:image inRect:drawRect fromRect:fromRect];
269
292
  [self.context presentRenderbuffer:GL_RENDERBUFFER];
270
293
 
271
294
  [_glkView setNeedsDisplay];