@papyrus-sdk/engine-native 0.2.21 → 0.2.22-beta.1

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.
@@ -0,0 +1,56 @@
1
+ #import <React/RCTViewManager.h>
2
+
3
+ #import "PapyrusPdfDocumentView.h"
4
+
5
+ @interface PapyrusPdfDocumentViewManager : RCTViewManager
6
+ @end
7
+
8
+ @implementation PapyrusPdfDocumentViewManager
9
+
10
+ RCT_EXPORT_MODULE(PapyrusPdfDocumentView)
11
+ RCT_EXPORT_VIEW_PROPERTY(engineId, NSString)
12
+ RCT_EXPORT_VIEW_PROPERTY(pageTheme, NSString)
13
+ RCT_EXPORT_VIEW_PROPERTY(zoom, CGFloat)
14
+ RCT_EXPORT_VIEW_PROPERTY(currentPage, NSInteger)
15
+ RCT_EXPORT_VIEW_PROPERTY(viewMode, NSString)
16
+ RCT_EXPORT_VIEW_PROPERTY(searchResults, NSArray)
17
+ RCT_EXPORT_VIEW_PROPERTY(activeSearchIndex, NSInteger)
18
+ RCT_EXPORT_VIEW_PROPERTY(annotations, NSArray)
19
+ RCT_EXPORT_VIEW_PROPERTY(activeTool, NSString)
20
+ RCT_EXPORT_VIEW_PROPERTY(activeDrawToolPreset, NSString)
21
+ RCT_EXPORT_VIEW_PROPERTY(inkStrokeWidth, CGFloat)
22
+ RCT_EXPORT_VIEW_PROPERTY(annotationColor, NSString)
23
+ RCT_EXPORT_VIEW_PROPERTY(annotationSelectionColor, NSString)
24
+ RCT_EXPORT_VIEW_PROPERTY(annotationOpacity, CGFloat)
25
+ RCT_EXPORT_VIEW_PROPERTY(selectedAnnotationId, NSString)
26
+ RCT_EXPORT_VIEW_PROPERTY(selectionActive, BOOL)
27
+ RCT_EXPORT_VIEW_PROPERTY(defineLabel, NSString)
28
+ RCT_EXPORT_VIEW_PROPERTY(annotateLabel, NSString)
29
+ RCT_EXPORT_VIEW_PROPERTY(annotationHighlightLabel, NSString)
30
+ RCT_EXPORT_VIEW_PROPERTY(annotationUnderlineLabel, NSString)
31
+ RCT_EXPORT_VIEW_PROPERTY(annotationStrikeoutLabel, NSString)
32
+ RCT_EXPORT_VIEW_PROPERTY(annotationSquigglyLabel, NSString)
33
+ RCT_EXPORT_VIEW_PROPERTY(annotationNoteLabel, NSString)
34
+ RCT_EXPORT_VIEW_PROPERTY(annotationDeleteLabel, NSString)
35
+ RCT_EXPORT_VIEW_PROPERTY(onPageChange, RCTBubblingEventBlock)
36
+ RCT_EXPORT_VIEW_PROPERTY(onZoomChange, RCTBubblingEventBlock)
37
+ RCT_EXPORT_VIEW_PROPERTY(onVisiblePagesChange, RCTBubblingEventBlock)
38
+ RCT_EXPORT_VIEW_PROPERTY(onTextSelected, RCTBubblingEventBlock)
39
+ RCT_EXPORT_VIEW_PROPERTY(onDefineSelection, RCTBubblingEventBlock)
40
+ RCT_EXPORT_VIEW_PROPERTY(onAnnotationCreated, RCTBubblingEventBlock)
41
+ RCT_EXPORT_VIEW_PROPERTY(onAnnotationTap, RCTBubblingEventBlock)
42
+ RCT_EXPORT_VIEW_PROPERTY(onAnnotationDelete, RCTBubblingEventBlock)
43
+ RCT_EXPORT_VIEW_PROPERTY(onAnnotationDeselected, RCTBubblingEventBlock)
44
+ RCT_EXPORT_VIEW_PROPERTY(onInkDrawingCommitted, RCTBubblingEventBlock)
45
+ RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
46
+ RCT_EXPORT_VIEW_PROPERTY(onTap, RCTBubblingEventBlock)
47
+
48
+ + (BOOL)requiresMainQueueSetup {
49
+ return YES;
50
+ }
51
+
52
+ - (UIView *)view {
53
+ return [[PapyrusPdfDocumentView alloc] initWithFrame:CGRectZero];
54
+ }
55
+
56
+ @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papyrus-sdk/engine-native",
3
- "version": "0.2.21",
3
+ "version": "0.2.22-beta.1",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "papyrus",
@@ -46,17 +46,17 @@
46
46
  "bugs": {
47
47
  "url": "https://github.com/solrachix/Papyrus/issues"
48
48
  },
49
+ "scripts": {
50
+ "build": "tsup"
51
+ },
49
52
  "peerDependencies": {
50
- "@papyrus-sdk/core": ">=0.2.18",
51
- "@papyrus-sdk/types": ">=0.2.11",
53
+ "@papyrus-sdk/core": ">=0.2.18 || 0.2.23-beta.1",
54
+ "@papyrus-sdk/types": ">=0.2.11 || 0.2.16-beta.1",
52
55
  "react-native": ">=0.81.0"
53
56
  },
54
57
  "devDependencies": {
55
58
  "@papyrus-sdk/core": "0.2.19",
56
59
  "@papyrus-sdk/types": "0.2.12",
57
60
  "react-native": "^0.81.0"
58
- },
59
- "scripts": {
60
- "build": "tsup"
61
61
  }
62
- }
62
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Papyrus Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,240 +0,0 @@
1
- #include "papyrus_outline_loader.h"
2
-
3
- #include <cstdlib>
4
- #include <cstring>
5
- #include <iostream>
6
- #include <string>
7
- #include <unordered_map>
8
-
9
- namespace {
10
-
11
- using PdfiumSymbol = OutlineLoaderDeps::PdfiumSymbol;
12
-
13
- struct FakeLoaderEnv {
14
- void *library_handle = reinterpret_cast<void *>(0x1);
15
- int dlopen_calls = 0;
16
- int dlsym_calls = 0;
17
- int dlclose_calls = 0;
18
- std::unordered_map<std::string, PdfiumSymbol> symbols;
19
- };
20
-
21
- FPDF_DOCUMENT FakeLoadDocument(const char *, const char *) {
22
- return nullptr;
23
- }
24
-
25
- void FakeCloseDocument(FPDF_DOCUMENT) {}
26
-
27
- FPDF_BOOKMARK FakeBookmarkGetFirstChild(FPDF_DOCUMENT, FPDF_BOOKMARK) {
28
- return nullptr;
29
- }
30
-
31
- FPDF_BOOKMARK FakeBookmarkGetNextSibling(FPDF_DOCUMENT, FPDF_BOOKMARK) {
32
- return nullptr;
33
- }
34
-
35
- unsigned long FakeBookmarkGetTitle(FPDF_BOOKMARK, void *, unsigned long) {
36
- return 0;
37
- }
38
-
39
- FPDF_DEST FakeBookmarkGetDest(FPDF_DOCUMENT, FPDF_BOOKMARK) {
40
- return nullptr;
41
- }
42
-
43
- int FakeDestGetPageIndex(FPDF_DOCUMENT, FPDF_DEST) {
44
- return -1;
45
- }
46
-
47
- template <typename FnType>
48
- PdfiumSymbol ToPdfiumSymbol(FnType fn) {
49
- PdfiumSymbol symbol = nullptr;
50
- static_assert(sizeof(symbol) == sizeof(fn),
51
- "Expected function pointers to share the same size");
52
- std::memcpy(&symbol, &fn, sizeof(symbol));
53
- return symbol;
54
- }
55
-
56
- PdfiumOutlineFns MakeCompleteOutlineFns() {
57
- PdfiumOutlineFns fns = {};
58
- fns.loadDocument = &FakeLoadDocument;
59
- fns.closeDocument = &FakeCloseDocument;
60
- fns.bookmarkGetFirstChild = &FakeBookmarkGetFirstChild;
61
- fns.bookmarkGetNextSibling = &FakeBookmarkGetNextSibling;
62
- fns.bookmarkGetTitle = &FakeBookmarkGetTitle;
63
- fns.bookmarkGetDest = &FakeBookmarkGetDest;
64
- fns.destGetPageIndex = &FakeDestGetPageIndex;
65
- return fns;
66
- }
67
-
68
- FakeLoaderEnv *GetEnv(void *user_data) {
69
- return static_cast<FakeLoaderEnv *>(user_data);
70
- }
71
-
72
- void *FakeDlopen(void *user_data, const char *, int) {
73
- FakeLoaderEnv *env = GetEnv(user_data);
74
- env->dlopen_calls += 1;
75
- return env->library_handle;
76
- }
77
-
78
- PdfiumSymbol FakeDlsym(void *user_data, void *, const char *symbol_name) {
79
- FakeLoaderEnv *env = GetEnv(user_data);
80
- env->dlsym_calls += 1;
81
-
82
- const auto it = env->symbols.find(symbol_name);
83
- if (it == env->symbols.end()) {
84
- return nullptr;
85
- }
86
-
87
- return it->second;
88
- }
89
-
90
- int FakeDlclose(void *user_data, void *) {
91
- FakeLoaderEnv *env = GetEnv(user_data);
92
- env->dlclose_calls += 1;
93
- return 0;
94
- }
95
-
96
- OutlineLoaderDeps MakeDeps(FakeLoaderEnv *env) {
97
- OutlineLoaderDeps deps = {};
98
- deps.user_data = env;
99
- deps.dlopen_fn = &FakeDlopen;
100
- deps.dlsym_fn = &FakeDlsym;
101
- deps.dlclose_fn = &FakeDlclose;
102
- deps.library_name = "libmodpdfium.so";
103
- deps.dlopen_flags = 0;
104
- return deps;
105
- }
106
-
107
- void InstallSymbols(FakeLoaderEnv *env, const PdfiumOutlineFns &fns) {
108
- env->symbols["FPDF_LoadDocument"] = ToPdfiumSymbol(fns.loadDocument);
109
- env->symbols["FPDF_CloseDocument"] = ToPdfiumSymbol(fns.closeDocument);
110
- env->symbols["FPDFBookmark_GetFirstChild"] = ToPdfiumSymbol(fns.bookmarkGetFirstChild);
111
- env->symbols["FPDFBookmark_GetNextSibling"] = ToPdfiumSymbol(fns.bookmarkGetNextSibling);
112
- env->symbols["FPDFBookmark_GetTitle"] = ToPdfiumSymbol(fns.bookmarkGetTitle);
113
- env->symbols["FPDFBookmark_GetDest"] = ToPdfiumSymbol(fns.bookmarkGetDest);
114
- env->symbols["FPDFDest_GetPageIndex"] = ToPdfiumSymbol(fns.destGetPageIndex);
115
- }
116
-
117
- [[noreturn]] void Fail(const char *expression, const char *file, int line) {
118
- std::cerr << file << ":" << line << ": assertion failed: " << expression << std::endl;
119
- std::exit(1);
120
- }
121
-
122
- #define EXPECT_TRUE(condition) \
123
- do { \
124
- if (!(condition)) { \
125
- Fail(#condition, __FILE__, __LINE__); \
126
- } \
127
- } while (false)
128
-
129
- #define EXPECT_FALSE(condition) EXPECT_TRUE(!(condition))
130
-
131
- #define EXPECT_EQ(expected, actual) \
132
- do { \
133
- const auto expected_value = (expected); \
134
- const auto actual_value = (actual); \
135
- if (!(expected_value == actual_value)) { \
136
- std::cerr << __FILE__ << ":" << __LINE__ \
137
- << ": expected equality for " << #expected << " and " << #actual << std::endl; \
138
- std::exit(1); \
139
- } \
140
- } while (false)
141
-
142
- void TestFullSymbolTableReturnsSupported() {
143
- FakeLoaderEnv env = {};
144
- const PdfiumOutlineFns complete_fns = MakeCompleteOutlineFns();
145
- InstallSymbols(&env, complete_fns);
146
-
147
- OutlineLoaderState state = {};
148
- const OutlineLoaderDeps deps = MakeDeps(&env);
149
-
150
- const OutlineLoadAttemptResult result = EnsureOutlinePdfiumLoaded(&state, &deps);
151
-
152
- EXPECT_TRUE(result.loaded);
153
- EXPECT_FALSE(result.transitioned_to_unsupported);
154
- EXPECT_EQ(OutlineLoadState::kSupported, state.load_state);
155
- EXPECT_TRUE(state.handle != nullptr);
156
- EXPECT_TRUE(HasCompleteOutlineFns(state.fns));
157
- EXPECT_EQ(1, env.dlopen_calls);
158
- EXPECT_EQ(7, env.dlsym_calls);
159
- EXPECT_EQ(0, env.dlclose_calls);
160
- }
161
-
162
- void TestMissingLibraryReturnsUnsupported() {
163
- FakeLoaderEnv env = {};
164
- env.library_handle = nullptr;
165
-
166
- OutlineLoaderState state = {};
167
- const OutlineLoaderDeps deps = MakeDeps(&env);
168
-
169
- const OutlineLoadAttemptResult result = EnsureOutlinePdfiumLoaded(&state, &deps);
170
-
171
- EXPECT_FALSE(result.loaded);
172
- EXPECT_TRUE(result.transitioned_to_unsupported);
173
- EXPECT_EQ(OutlineLoadState::kUnsupported, state.load_state);
174
- EXPECT_TRUE(state.handle == nullptr);
175
- EXPECT_FALSE(HasCompleteOutlineFns(state.fns));
176
- EXPECT_EQ(1, env.dlopen_calls);
177
- EXPECT_EQ(0, env.dlsym_calls);
178
- EXPECT_EQ(0, env.dlclose_calls);
179
- }
180
-
181
- void TestMissingSymbolReturnsUnsupportedAndClosesHandle() {
182
- FakeLoaderEnv env = {};
183
- const PdfiumOutlineFns partial_fns = MakeCompleteOutlineFns();
184
- InstallSymbols(&env, partial_fns);
185
- env.symbols.erase("FPDFBookmark_GetDest");
186
-
187
- OutlineLoaderState state = {};
188
- const OutlineLoaderDeps deps = MakeDeps(&env);
189
-
190
- const OutlineLoadAttemptResult result = EnsureOutlinePdfiumLoaded(&state, &deps);
191
-
192
- EXPECT_FALSE(result.loaded);
193
- EXPECT_TRUE(result.transitioned_to_unsupported);
194
- EXPECT_EQ(OutlineLoadState::kUnsupported, state.load_state);
195
- EXPECT_TRUE(state.handle == nullptr);
196
- EXPECT_FALSE(HasCompleteOutlineFns(state.fns));
197
- EXPECT_EQ(1, env.dlopen_calls);
198
- EXPECT_EQ(7, env.dlsym_calls);
199
- EXPECT_EQ(1, env.dlclose_calls);
200
- }
201
-
202
- void TestRepeatedCallsAfterFailureStayUnsupported() {
203
- FakeLoaderEnv env = {};
204
- const PdfiumOutlineFns partial_fns = MakeCompleteOutlineFns();
205
- InstallSymbols(&env, partial_fns);
206
- env.symbols.erase("FPDFDest_GetPageIndex");
207
-
208
- OutlineLoaderState state = {};
209
- const OutlineLoaderDeps deps = MakeDeps(&env);
210
-
211
- const OutlineLoadAttemptResult first = EnsureOutlinePdfiumLoaded(&state, &deps);
212
- EXPECT_FALSE(first.loaded);
213
- EXPECT_TRUE(first.transitioned_to_unsupported);
214
- EXPECT_EQ(OutlineLoadState::kUnsupported, state.load_state);
215
- EXPECT_TRUE(state.handle == nullptr);
216
- EXPECT_FALSE(HasCompleteOutlineFns(state.fns));
217
- EXPECT_EQ(1, env.dlopen_calls);
218
- EXPECT_EQ(7, env.dlsym_calls);
219
- EXPECT_EQ(1, env.dlclose_calls);
220
-
221
- const OutlineLoadAttemptResult second = EnsureOutlinePdfiumLoaded(&state, &deps);
222
- EXPECT_FALSE(second.loaded);
223
- EXPECT_FALSE(second.transitioned_to_unsupported);
224
- EXPECT_EQ(OutlineLoadState::kUnsupported, state.load_state);
225
- EXPECT_TRUE(state.handle == nullptr);
226
- EXPECT_FALSE(HasCompleteOutlineFns(state.fns));
227
- EXPECT_EQ(1, env.dlopen_calls);
228
- EXPECT_EQ(7, env.dlsym_calls);
229
- EXPECT_EQ(1, env.dlclose_calls);
230
- }
231
-
232
- } // namespace
233
-
234
- int main() {
235
- TestFullSymbolTableReturnsSupported();
236
- TestMissingLibraryReturnsUnsupported();
237
- TestMissingSymbolReturnsUnsupportedAndClosesHandle();
238
- TestRepeatedCallsAfterFailureStayUnsupported();
239
- return 0;
240
- }
@@ -1,72 +0,0 @@
1
- #include "papyrus_text_word.h"
2
-
3
- #include <iostream>
4
- #include <vector>
5
-
6
- namespace {
7
-
8
- int failures = 0;
9
-
10
- void ExpectTrue(bool value, const char *name) {
11
- if (!value) {
12
- std::cerr << "FAIL: " << name << std::endl;
13
- failures += 1;
14
- }
15
- }
16
-
17
- void ExpectRange(const std::vector<char16_t> &text, int index, int expectedStart,
18
- int expectedEnd, const char *name) {
19
- const auto range = papyrus::ResolveWordRange(text, index);
20
- if (range.first != expectedStart || range.second != expectedEnd) {
21
- std::cerr << "FAIL: " << name << " expected [" << expectedStart << ", "
22
- << expectedEnd << ") got [" << range.first << ", " << range.second
23
- << ")" << std::endl;
24
- failures += 1;
25
- }
26
- }
27
-
28
- } // namespace
29
-
30
- int main() {
31
- ExpectTrue(papyrus::IsWordCharacter(u'a'), "ascii letter");
32
- ExpectTrue(papyrus::IsWordCharacter(u'Z'), "ascii upper");
33
- ExpectTrue(papyrus::IsWordCharacter(u'7'), "digit");
34
- ExpectTrue(papyrus::IsWordCharacter(0x00E7), "c-cedilla");
35
- ExpectTrue(papyrus::IsWordCharacter(0x00E3), "a-tilde");
36
- ExpectTrue(papyrus::IsWordCharacter(u'\''), "apostrophe");
37
- ExpectTrue(papyrus::IsWordCharacter(0x2019), "curly apostrophe");
38
- ExpectTrue(papyrus::IsWordCharacter(u'-'), "hyphen");
39
- ExpectTrue(!papyrus::IsWordCharacter(u' '), "space is not a word char");
40
- ExpectTrue(!papyrus::IsWordCharacter(u'.'), "dot is not a word char");
41
- ExpectTrue(!papyrus::IsWordCharacter(u'\n'), "newline is not a word char");
42
-
43
- const std::vector<char16_t> simple = {u'd', u'i', u'n', u'a'};
44
- ExpectRange(simple, 0, 0, 4, "word from first char");
45
- ExpectRange(simple, 3, 0, 4, "word from last char");
46
- ExpectRange(simple, -1, -1, -1, "out of bounds start");
47
- ExpectRange(simple, 4, 4, 4, "out of bounds end");
48
-
49
- const std::vector<char16_t> accented = {u'c', u'o', u'm', u'p', u'i',
50
- u'l', u'a', 0x00E7, 0x00E3, u'o'};
51
- ExpectRange(accented, 7, 0, 10, "accented word");
52
-
53
- const std::vector<char16_t> hyphenated = {u'j', u'u', u's', u't', u'-',
54
- u'i', u'n', u'-', u't', u'i',
55
- u'm', u'e'};
56
- ExpectRange(hyphenated, 5, 0, 12, "hyphenated word");
57
- ExpectRange(hyphenated, 4, 0, 12, "hyphen is word char");
58
-
59
- const std::vector<char16_t> apostrophe = {u'l', u'\'', 0x00E9, u't'};
60
- ExpectRange(apostrophe, 1, 0, 4, "apostrophe joins the word");
61
-
62
- const std::vector<char16_t> sentence = {u'a', u' ', u'b', u'.', u'c'};
63
- ExpectRange(sentence, 1, 1, 1, "space yields empty range");
64
- ExpectRange(sentence, 3, 3, 3, "dot yields empty range");
65
-
66
- if (failures > 0) {
67
- std::cerr << failures << " failure(s)" << std::endl;
68
- return 1;
69
- }
70
- std::cout << "papyrus_text_word_test: OK" << std::endl;
71
- return 0;
72
- }