@papyrus-sdk/engine-native 0.2.10 → 0.2.12-beta.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.
Files changed (41) hide show
  1. package/README.md +38 -38
  2. package/android/build.gradle +1 -1
  3. package/android/consumer-rules.pro +1 -1
  4. package/android/src/main/AndroidManifest.xml +1 -1
  5. package/android/src/main/cpp/CMakeLists.txt +1 -1
  6. package/android/src/main/cpp/papyrus_outline.cpp +1 -1
  7. package/android/src/main/cpp/papyrus_outline_loader.cpp +1 -1
  8. package/android/src/main/cpp/papyrus_outline_loader.h +1 -1
  9. package/android/src/main/cpp/papyrus_outline_loader_test.cpp +1 -1
  10. package/android/src/main/cpp/papyrus_text_search.cpp +408 -408
  11. package/android/src/main/java/android/support/v4/util/ArrayMap.java +18 -18
  12. package/android/src/main/java/com/papyrus/engine/PapyrusEngineStore.java +71 -71
  13. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +557 -553
  14. package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.kt +561 -561
  15. package/android/src/main/java/com/papyrus/engine/PapyrusOutline.java +1 -1
  16. package/android/src/main/java/com/papyrus/engine/PapyrusOutlineItem.java +13 -13
  17. package/android/src/main/java/com/papyrus/engine/PapyrusPackage.java +24 -24
  18. package/android/src/main/java/com/papyrus/engine/PapyrusPageView.java +197 -86
  19. package/android/src/main/java/com/papyrus/engine/PapyrusPageViewManager.java +22 -16
  20. package/android/src/main/java/com/papyrus/engine/PapyrusPageViewModule.kt +15 -12
  21. package/android/src/main/java/com/papyrus/engine/PapyrusTextHit.java +15 -15
  22. package/android/src/main/java/com/papyrus/engine/PapyrusTextSearch.java +20 -20
  23. package/android/src/main/java/com/papyrus/engine/PapyrusTextSelect.java +20 -20
  24. package/android/src/main/java/com/papyrus/engine/PapyrusTextSelection.java +11 -11
  25. package/android/src/test/java/com/papyrus/engine/PapyrusOutlineTest.java +1 -1
  26. package/android/src/test/java/com/papyrus/engine/PapyrusPageViewTest.java +30 -0
  27. package/dist/index.d.mts +2 -1
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.js +32 -44
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.mjs +30 -41
  32. package/dist/index.mjs.map +1 -1
  33. package/ios/PapyrusEngineStore.h +16 -16
  34. package/ios/PapyrusEngineStore.m +48 -48
  35. package/ios/PapyrusNativeEngine.m +447 -447
  36. package/ios/PapyrusNativeEngine.podspec +15 -15
  37. package/ios/PapyrusPageView.h +21 -19
  38. package/ios/PapyrusPageView.m +194 -63
  39. package/ios/PapyrusPageViewManager.m +20 -19
  40. package/package.json +62 -60
  41. package/react-native.config.js +10 -10
@@ -1,15 +1,15 @@
1
- Pod::Spec.new do |s|
2
- s.name = 'PapyrusNativeEngine'
3
- s.version = '0.1.1'
4
- s.summary = 'Papyrus Native Engine (PDFKit)'
5
- s.homepage = 'https://example.com/papyrus'
6
- s.license = { :type => 'MIT' }
7
- s.author = { 'Papyrus' => 'dev@papyrus.local' }
8
- s.platforms = { :ios => '13.0' }
9
- s.source = { :git => 'https://example.com/papyrus.git', :tag => s.version.to_s }
10
- s.source_files = '**/*.{h,m,mm,swift}'
11
- s.requires_arc = true
12
- s.swift_version = '5.0'
13
-
14
- s.dependency 'React-Core'
15
- end
1
+ Pod::Spec.new do |s|
2
+ s.name = 'PapyrusNativeEngine'
3
+ s.version = '0.1.1'
4
+ s.summary = 'Papyrus Native Engine (PDFKit)'
5
+ s.homepage = 'https://example.com/papyrus'
6
+ s.license = { :type => 'MIT' }
7
+ s.author = { 'Papyrus' => 'dev@papyrus.local' }
8
+ s.platforms = { :ios => '13.0' }
9
+ s.source = { :git => 'https://example.com/papyrus.git', :tag => s.version.to_s }
10
+ s.source_files = '**/*.{h,m,mm,swift}'
11
+ s.requires_arc = true
12
+ s.swift_version = '5.0'
13
+
14
+ s.dependency 'React-Core'
15
+ end
@@ -1,19 +1,21 @@
1
- #import <UIKit/UIKit.h>
2
- #import <PDFKit/PDFKit.h>
3
-
4
- NS_ASSUME_NONNULL_BEGIN
5
-
6
- @interface PapyrusPageView : UIView
7
-
8
- - (void)renderWithDocument:(PDFDocument *_Nullable)document
9
- pageIndex:(NSInteger)pageIndex
10
- scale:(CGFloat)scale
11
- zoom:(CGFloat)zoom
12
- rotation:(NSInteger)rotation;
13
-
14
- - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page;
15
- - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page;
16
-
17
- @end
18
-
19
- NS_ASSUME_NONNULL_END
1
+ #import <UIKit/UIKit.h>
2
+ #import <PDFKit/PDFKit.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface PapyrusPageView : UIView
7
+
8
+ @property (nonatomic, copy) NSString *pageTheme;
9
+
10
+ - (void)renderWithDocument:(PDFDocument *_Nullable)document
11
+ pageIndex:(NSInteger)pageIndex
12
+ scale:(CGFloat)scale
13
+ zoom:(CGFloat)zoom
14
+ rotation:(NSInteger)rotation;
15
+
16
+ - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page;
17
+ - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page;
18
+
19
+ @end
20
+
21
+ NS_ASSUME_NONNULL_END
@@ -1,63 +1,194 @@
1
- #import "PapyrusPageView.h"
2
-
3
- @interface PapyrusPageView ()
4
- @property (nonatomic, strong) PDFView *pdfView;
5
- @end
6
-
7
- @implementation PapyrusPageView
8
-
9
- - (instancetype)initWithFrame:(CGRect)frame {
10
- self = [super initWithFrame:frame];
11
- if (self) {
12
- _pdfView = [[PDFView alloc] initWithFrame:self.bounds];
13
- _pdfView.displayBox = kPDFDisplayBoxCropBox;
14
- _pdfView.autoScales = NO;
15
- _pdfView.displayMode = kPDFDisplaySinglePage;
16
- _pdfView.displayDirection = kPDFDisplayDirectionVertical;
17
- _pdfView.displaysPageBreaks = NO;
18
- _pdfView.userInteractionEnabled = NO;
19
- [self addSubview:_pdfView];
20
- }
21
- return self;
22
- }
23
-
24
- - (void)layoutSubviews {
25
- [super layoutSubviews];
26
- self.pdfView.frame = self.bounds;
27
- }
28
-
29
- - (void)renderWithDocument:(PDFDocument *_Nullable)document
30
- pageIndex:(NSInteger)pageIndex
31
- scale:(CGFloat)scale
32
- zoom:(CGFloat)zoom
33
- rotation:(NSInteger)rotation {
34
- if (!document) {
35
- self.pdfView.document = nil;
36
- return;
37
- }
38
-
39
- if (self.pdfView.document != document) {
40
- self.pdfView.document = document;
41
- }
42
-
43
- PDFPage *page = [document pageAtIndex:pageIndex];
44
- if (!page) return;
45
-
46
- page.rotation = (int)rotation;
47
- [self.pdfView goToPage:page];
48
-
49
- CGFloat clampedZoom = MAX(0.1, MIN(5.0, zoom));
50
- CGFloat baseScale = self.pdfView.scaleFactorForSizeToFit;
51
- CGFloat targetScale = baseScale * MAX(0.1, scale) * clampedZoom;
52
- self.pdfView.scaleFactor = targetScale;
53
- }
54
-
55
- - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page {
56
- return [self.pdfView convertRect:rect toPage:page];
57
- }
58
-
59
- - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page {
60
- return [self.pdfView convertRect:rect fromPage:page];
61
- }
62
-
63
- @end
1
+ #import "PapyrusPageView.h"
2
+
3
+ #import <CoreImage/CoreImage.h>
4
+
5
+ @interface PapyrusPageView ()
6
+ @property (nonatomic, strong) PDFView *pdfView;
7
+ @property (nonatomic, strong) UIImageView *imageView;
8
+ @property (nonatomic, strong) CIContext *ciContext;
9
+ @property (nonatomic, weak) PDFDocument *currentDocument;
10
+ @property (nonatomic, assign) NSInteger currentPageIndex;
11
+ @property (nonatomic, assign) NSInteger currentRotation;
12
+ @property (nonatomic, assign) CGFloat currentScale;
13
+ @property (nonatomic, assign) CGFloat currentZoom;
14
+ @end
15
+
16
+ @implementation PapyrusPageView
17
+
18
+ - (instancetype)initWithFrame:(CGRect)frame {
19
+ self = [super initWithFrame:frame];
20
+ if (self) {
21
+ _pageTheme = @"normal";
22
+ _currentPageIndex = NSNotFound;
23
+ _currentRotation = 0;
24
+ _currentScale = 1.0;
25
+ _currentZoom = 1.0;
26
+ _ciContext = [CIContext contextWithOptions:nil];
27
+
28
+ _pdfView = [[PDFView alloc] initWithFrame:self.bounds];
29
+ _pdfView.displayBox = kPDFDisplayBoxCropBox;
30
+ _pdfView.autoScales = NO;
31
+ _pdfView.displayMode = kPDFDisplaySinglePage;
32
+ _pdfView.displayDirection = kPDFDisplayDirectionVertical;
33
+ _pdfView.displaysPageBreaks = NO;
34
+ _pdfView.userInteractionEnabled = NO;
35
+ _pdfView.hidden = YES;
36
+ [self addSubview:_pdfView];
37
+
38
+ _imageView = [[UIImageView alloc] initWithFrame:self.bounds];
39
+ _imageView.contentMode = UIViewContentModeScaleAspectFit;
40
+ _imageView.clipsToBounds = YES;
41
+ [self addSubview:_imageView];
42
+ }
43
+ return self;
44
+ }
45
+
46
+ - (void)layoutSubviews {
47
+ [super layoutSubviews];
48
+ self.pdfView.frame = self.bounds;
49
+ self.imageView.frame = self.bounds;
50
+ [self rerenderCurrentPageIfNeeded];
51
+ }
52
+
53
+ - (void)setPageTheme:(NSString *)pageTheme {
54
+ NSString *normalized = pageTheme.length > 0 ? pageTheme : @"normal";
55
+ if ([_pageTheme isEqualToString:normalized]) return;
56
+ _pageTheme = [normalized copy];
57
+ [self rerenderCurrentPageIfNeeded];
58
+ }
59
+
60
+ - (void)renderWithDocument:(PDFDocument *_Nullable)document
61
+ pageIndex:(NSInteger)pageIndex
62
+ scale:(CGFloat)scale
63
+ zoom:(CGFloat)zoom
64
+ rotation:(NSInteger)rotation {
65
+ self.currentDocument = document;
66
+ self.currentPageIndex = pageIndex;
67
+ self.currentRotation = rotation;
68
+ self.currentScale = scale;
69
+ self.currentZoom = zoom;
70
+
71
+ if (!document) {
72
+ self.pdfView.document = nil;
73
+ self.imageView.image = nil;
74
+ return;
75
+ }
76
+
77
+ if (self.pdfView.document != document) {
78
+ self.pdfView.document = document;
79
+ }
80
+
81
+ PDFPage *page = [document pageAtIndex:pageIndex];
82
+ if (!page) return;
83
+
84
+ page.rotation = (int)rotation;
85
+ [self.pdfView goToPage:page];
86
+
87
+ CGFloat clampedZoom = MAX(0.1, MIN(5.0, zoom));
88
+ CGFloat baseScale = self.pdfView.scaleFactorForSizeToFit;
89
+ CGFloat targetScale = baseScale * MAX(0.1, scale) * clampedZoom;
90
+ self.pdfView.scaleFactor = targetScale;
91
+
92
+ [self rerenderCurrentPageIfNeeded];
93
+ }
94
+
95
+ - (CGRect)convertRectToPage:(CGRect)rect page:(PDFPage *)page {
96
+ return [self.pdfView convertRect:rect toPage:page];
97
+ }
98
+
99
+ - (CGRect)convertRectFromPage:(CGRect)rect page:(PDFPage *)page {
100
+ return [self.pdfView convertRect:rect fromPage:page];
101
+ }
102
+
103
+ - (void)rerenderCurrentPageIfNeeded {
104
+ if (!self.currentDocument) return;
105
+ if (self.currentPageIndex == NSNotFound) return;
106
+ if (CGRectGetWidth(self.bounds) <= 0 || CGRectGetHeight(self.bounds) <= 0) {
107
+ return;
108
+ }
109
+
110
+ PDFPage *page = [self.currentDocument pageAtIndex:self.currentPageIndex];
111
+ if (!page) return;
112
+
113
+ UIImage *baseImage = [self renderImageForPage:page];
114
+ self.imageView.image = [self themedImageFromImage:baseImage];
115
+ }
116
+
117
+ - (UIImage *)renderImageForPage:(PDFPage *)page {
118
+ CGSize targetSize = self.bounds.size;
119
+ UIGraphicsImageRendererFormat *format =
120
+ [UIGraphicsImageRendererFormat defaultFormat];
121
+ format.opaque = YES;
122
+ format.scale = UIScreen.mainScreen.scale;
123
+
124
+ UIGraphicsImageRenderer *renderer =
125
+ [[UIGraphicsImageRenderer alloc] initWithSize:targetSize format:format];
126
+
127
+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull context) {
128
+ CGContextRef cgContext = context.CGContext;
129
+ CGContextSetFillColorWithColor(cgContext, UIColor.whiteColor.CGColor);
130
+ CGContextFillRect(cgContext, (CGRect){CGPointZero, targetSize});
131
+
132
+ CGRect pageBounds = [page boundsForBox:kPDFDisplayBoxCropBox];
133
+ if (CGRectGetWidth(pageBounds) <= 0 || CGRectGetHeight(pageBounds) <= 0) {
134
+ return;
135
+ }
136
+
137
+ CGFloat scaleX = targetSize.width / CGRectGetWidth(pageBounds);
138
+ CGFloat scaleY = targetSize.height / CGRectGetHeight(pageBounds);
139
+ CGFloat fitScale = MIN(scaleX, scaleY);
140
+ CGFloat drawWidth = CGRectGetWidth(pageBounds) * fitScale;
141
+ CGFloat drawHeight = CGRectGetHeight(pageBounds) * fitScale;
142
+ CGFloat offsetX = (targetSize.width - drawWidth) / 2.0;
143
+ CGFloat offsetY = (targetSize.height - drawHeight) / 2.0;
144
+
145
+ CGContextSaveGState(cgContext);
146
+ CGContextTranslateCTM(cgContext, 0, targetSize.height);
147
+ CGContextScaleCTM(cgContext, 1, -1);
148
+ CGContextTranslateCTM(cgContext, offsetX, offsetY);
149
+ CGContextScaleCTM(cgContext, fitScale, fitScale);
150
+ [page drawWithBox:kPDFDisplayBoxCropBox toContext:cgContext];
151
+ CGContextRestoreGState(cgContext);
152
+ }];
153
+ }
154
+
155
+ - (UIImage *)themedImageFromImage:(UIImage *)image {
156
+ if (!image) return nil;
157
+ if ([self.pageTheme isEqualToString:@"normal"]) return image;
158
+
159
+ CIImage *input = [[CIImage alloc] initWithImage:image];
160
+ if (!input) return image;
161
+
162
+ CIImage *output = input;
163
+
164
+ if ([self.pageTheme isEqualToString:@"sepia"]) {
165
+ CIFilter *sepia = [CIFilter filterWithName:@"CISepiaTone"];
166
+ [sepia setValue:output forKey:kCIInputImageKey];
167
+ [sepia setValue:@0.85 forKey:kCIInputIntensityKey];
168
+ output = sepia.outputImage ?: output;
169
+ } else if ([self.pageTheme isEqualToString:@"dark"] ||
170
+ [self.pageTheme isEqualToString:@"high-contrast"]) {
171
+ CIFilter *invert = [CIFilter filterWithName:@"CIColorInvert"];
172
+ [invert setValue:output forKey:kCIInputImageKey];
173
+ output = invert.outputImage ?: output;
174
+
175
+ CIFilter *controls = [CIFilter filterWithName:@"CIColorControls"];
176
+ [controls setValue:output forKey:kCIInputImageKey];
177
+ [controls setValue:@0 forKey:kCIInputSaturationKey];
178
+ [controls setValue:([self.pageTheme isEqualToString:@"high-contrast"] ? @1.25 : @0.9)
179
+ forKey:kCIInputContrastKey];
180
+ [controls setValue:([self.pageTheme isEqualToString:@"high-contrast"] ? @0.02 : @-0.08)
181
+ forKey:kCIInputBrightnessKey];
182
+ output = controls.outputImage ?: output;
183
+ }
184
+
185
+ CGImageRef cgImage = [self.ciContext createCGImage:output fromRect:output.extent];
186
+ if (!cgImage) return image;
187
+ UIImage *result = [UIImage imageWithCGImage:cgImage
188
+ scale:image.scale
189
+ orientation:image.imageOrientation];
190
+ CGImageRelease(cgImage);
191
+ return result;
192
+ }
193
+
194
+ @end
@@ -1,19 +1,20 @@
1
- #import <React/RCTViewManager.h>
2
- #import "PapyrusPageView.h"
3
-
4
- @interface PapyrusPageViewManager : RCTViewManager
5
- @end
6
-
7
- @implementation PapyrusPageViewManager
8
-
9
- RCT_EXPORT_MODULE(PapyrusPageView)
10
-
11
- + (BOOL)requiresMainQueueSetup {
12
- return YES;
13
- }
14
-
15
- - (UIView *)view {
16
- return [[PapyrusPageView alloc] initWithFrame:CGRectZero];
17
- }
18
-
19
- @end
1
+ #import <React/RCTViewManager.h>
2
+ #import "PapyrusPageView.h"
3
+
4
+ @interface PapyrusPageViewManager : RCTViewManager
5
+ @end
6
+
7
+ @implementation PapyrusPageViewManager
8
+
9
+ RCT_EXPORT_MODULE(PapyrusPageView)
10
+ RCT_EXPORT_VIEW_PROPERTY(pageTheme, NSString)
11
+
12
+ + (BOOL)requiresMainQueueSetup {
13
+ return YES;
14
+ }
15
+
16
+ - (UIView *)view {
17
+ return [[PapyrusPageView alloc] initWithFrame:CGRectZero];
18
+ }
19
+
20
+ @end
package/package.json CHANGED
@@ -1,60 +1,62 @@
1
- {
2
- "name": "@papyrus-sdk/engine-native",
3
- "version": "0.2.10",
4
- "license": "MIT",
5
- "keywords": [
6
- "papyrus",
7
- "react-native",
8
- "pdf",
9
- "pdfium",
10
- "pdfkit",
11
- "document",
12
- "sdk",
13
- "viewer"
14
- ],
15
- "main": "dist/index.js",
16
- "module": "dist/index.mjs",
17
- "types": "dist/index.d.ts",
18
- "exports": {
19
- ".": {
20
- "types": "./dist/index.d.ts",
21
- "import": "./dist/index.mjs",
22
- "require": "./dist/index.js"
23
- }
24
- },
25
- "files": [
26
- "dist",
27
- "android/src",
28
- "android/build.gradle",
29
- "android/consumer-rules.pro",
30
- "ios/*.h",
31
- "ios/*.m",
32
- "ios/*.podspec",
33
- "react-native.config.js"
34
- ],
35
- "publishConfig": {
36
- "access": "public"
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/solrachix/Papyrus.git"
41
- },
42
- "homepage": "https://solrachix.github.io/Papyrus/",
43
- "bugs": {
44
- "url": "https://github.com/solrachix/Papyrus/issues"
45
- },
46
- "scripts": {
47
- "build": "tsup index.ts --dts --format cjs,esm --out-dir dist --clean --sourcemap",
48
- "prepublishOnly": "pnpm build"
49
- },
50
- "peerDependencies": {
51
- "@papyrus-sdk/core": ">=0.2.1",
52
- "@papyrus-sdk/types": ">=0.2.1",
53
- "react-native": ">=0.81.0"
54
- },
55
- "devDependencies": {
56
- "@papyrus-sdk/core": "0.2.1",
57
- "@papyrus-sdk/types": "0.2.1",
58
- "react-native": "^0.81.0"
59
- }
60
- }
1
+ {
2
+ "name": "@papyrus-sdk/engine-native",
3
+ "version": "0.2.12-beta.0",
4
+ "license": "MIT",
5
+ "keywords": [
6
+ "papyrus",
7
+ "react-native",
8
+ "pdf",
9
+ "pdfium",
10
+ "pdfkit",
11
+ "document",
12
+ "sdk",
13
+ "viewer"
14
+ ],
15
+ "main": "dist/index.js",
16
+ "react-native": "dist/index.js",
17
+ "module": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "react-native": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "android/src",
30
+ "android/build.gradle",
31
+ "android/consumer-rules.pro",
32
+ "ios/*.h",
33
+ "ios/*.m",
34
+ "ios/*.podspec",
35
+ "react-native.config.js"
36
+ ],
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/solrachix/Papyrus.git"
43
+ },
44
+ "homepage": "https://solrachix.github.io/Papyrus/",
45
+ "bugs": {
46
+ "url": "https://github.com/solrachix/Papyrus/issues"
47
+ },
48
+ "scripts": {
49
+ "build": "tsup index.ts --dts --format cjs,esm --out-dir dist --clean --sourcemap",
50
+ "prepublishOnly": "pnpm build"
51
+ },
52
+ "peerDependencies": {
53
+ "@papyrus-sdk/core": ">=0.2.15-beta.0",
54
+ "@papyrus-sdk/types": ">=0.2.8-beta.0",
55
+ "react-native": ">=0.81.0"
56
+ },
57
+ "devDependencies": {
58
+ "@papyrus-sdk/core": "0.2.15-beta.0",
59
+ "@papyrus-sdk/types": "0.2.8-beta.0",
60
+ "react-native": "^0.81.0"
61
+ }
62
+ }
@@ -1,10 +1,10 @@
1
- module.exports = {
2
- project: {
3
- ios: {
4
- podspecPath: 'ios/PapyrusNativeEngine.podspec',
5
- },
6
- android: {
7
- sourceDir: 'android',
8
- },
9
- },
10
- };
1
+ module.exports = {
2
+ project: {
3
+ ios: {
4
+ podspecPath: 'ios/PapyrusNativeEngine.podspec',
5
+ },
6
+ android: {
7
+ sourceDir: 'android',
8
+ },
9
+ },
10
+ };