Skip to content

Commit 9b4425e

Browse files
authored
Merge pull request #29 from TomTasche/feature/editing
editing
2 parents b456498 + 7646e1b commit 9b4425e

9 files changed

Lines changed: 224 additions & 114 deletions

File tree

OpenDocument.core

OpenDocumentReader.xcodeproj/project.pbxproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,28 +160,28 @@
160160
isa = PBXContainerItemProxy;
161161
containerPortal = E26C38EA2250D91C009C484A /* odr.xcodeproj */;
162162
proxyType = 1;
163-
remoteGlobalIDString = E8750BA65D65423EB75AC563;
163+
remoteGlobalIDString = 68722AEF2DC64BF8AB2DF7D5;
164164
remoteInfo = glog;
165165
};
166166
E26C39322250D976009C484A /* PBXContainerItemProxy */ = {
167167
isa = PBXContainerItemProxy;
168168
containerPortal = E26C38EA2250D91C009C484A /* odr.xcodeproj */;
169169
proxyType = 1;
170-
remoteGlobalIDString = B47238B8891F4586873EEF82;
170+
remoteGlobalIDString = DBADB6840206443A97F2A76D;
171171
remoteInfo = miniz;
172172
};
173173
E26C39342250D976009C484A /* PBXContainerItemProxy */ = {
174174
isa = PBXContainerItemProxy;
175175
containerPortal = E26C38EA2250D91C009C484A /* odr.xcodeproj */;
176176
proxyType = 1;
177-
remoteGlobalIDString = AE495395BBBE4F7B9CEF6C48;
177+
remoteGlobalIDString = CD40E84D34284EF7A80FB402;
178178
remoteInfo = odrlib;
179179
};
180180
E26C39362250D976009C484A /* PBXContainerItemProxy */ = {
181181
isa = PBXContainerItemProxy;
182182
containerPortal = E26C38EA2250D91C009C484A /* odr.xcodeproj */;
183183
proxyType = 1;
184-
remoteGlobalIDString = 3E01C15B40E6472FABEEAEAC;
184+
remoteGlobalIDString = B382587C51824ECE8AB80585;
185185
remoteInfo = tinyxml2;
186186
};
187187
E29A02212365EF7800BD6A96 /* PBXContainerItemProxy */ = {
@@ -251,7 +251,7 @@
251251
isa = PBXContainerItemProxy;
252252
containerPortal = E26C38EA2250D91C009C484A /* odr.xcodeproj */;
253253
proxyType = 1;
254-
remoteGlobalIDString = 58D71E509A434B40833DD053;
254+
remoteGlobalIDString = E08901684B824F61ACF4B07B;
255255
remoteInfo = "cryptopp-object";
256256
};
257257
/* End PBXContainerItemProxy section */
@@ -930,7 +930,7 @@
930930
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
931931
CLANG_ENABLE_MODULES = YES;
932932
CODE_SIGN_STYLE = Automatic;
933-
CURRENT_PROJECT_VERSION = 11;
933+
CURRENT_PROJECT_VERSION = 14;
934934
DEVELOPMENT_TEAM = 5LS6X97G6J;
935935
HEADER_SEARCH_PATHS = (
936936
"$(inherited)",
@@ -943,7 +943,7 @@
943943
"@executable_path/Frameworks",
944944
);
945945
LIBRARY_SEARCH_PATHS = "$(inherited)";
946-
MARKETING_VERSION = 1.8;
946+
MARKETING_VERSION = 1.10;
947947
PRODUCT_BUNDLE_IDENTIFIER = at.tomtasche.reader;
948948
PRODUCT_NAME = "$(TARGET_NAME)";
949949
SWIFT_OBJC_BRIDGING_HEADER = OpenDocumentReader/BridgingHeader.h;
@@ -960,7 +960,7 @@
960960
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
961961
CLANG_ENABLE_MODULES = YES;
962962
CODE_SIGN_STYLE = Automatic;
963-
CURRENT_PROJECT_VERSION = 11;
963+
CURRENT_PROJECT_VERSION = 14;
964964
DEVELOPMENT_TEAM = 5LS6X97G6J;
965965
HEADER_SEARCH_PATHS = (
966966
"$(inherited)",
@@ -973,7 +973,7 @@
973973
"@executable_path/Frameworks",
974974
);
975975
LIBRARY_SEARCH_PATHS = "$(inherited)";
976-
MARKETING_VERSION = 1.8;
976+
MARKETING_VERSION = 1.10;
977977
PRODUCT_BUNDLE_IDENTIFIER = at.tomtasche.reader;
978978
PRODUCT_NAME = "$(TARGET_NAME)";
979979
SWIFT_OBJC_BRIDGING_HEADER = OpenDocumentReader/BridgingHeader.h;

OpenDocumentReader.xcodeproj/xcshareddata/xcschemes/OpenDocumentReader.xcscheme

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES">
30-
<Testables>
31-
</Testables>
3230
<MacroExpansion>
3331
<BuildableReference
3432
BuildableIdentifier = "primary"
@@ -38,11 +36,11 @@
3836
ReferencedContainer = "container:OpenDocumentReader.xcodeproj">
3937
</BuildableReference>
4038
</MacroExpansion>
41-
<AdditionalOptions>
42-
</AdditionalOptions>
39+
<Testables>
40+
</Testables>
4341
</TestAction>
4442
<LaunchAction
45-
buildConfiguration = "Release"
43+
buildConfiguration = "Debug"
4644
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4745
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4846
launchStyle = "0"
@@ -61,8 +59,6 @@
6159
ReferencedContainer = "container:OpenDocumentReader.xcodeproj">
6260
</BuildableReference>
6361
</BuildableProductRunnable>
64-
<AdditionalOptions>
65-
</AdditionalOptions>
6662
</LaunchAction>
6763
<ProfileAction
6864
buildConfiguration = "Release"

OpenDocumentReader/AppDelegate.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
4646

4747
func application(_ app: UIApplication, open inputURL: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
4848
guard let documentBrowserViewController = window?.rootViewController as? DocumentBrowserViewController else {
49-
print("*** The root view is not a document browser! ***")
49+
Crashlytics.sharedInstance().throwException()
50+
5051
return false
5152
}
5253

5354
documentBrowserViewController.revealDocument(at: inputURL, importIfNeeded: true) { (revealedDocumentURL, error) in
5455

5556
guard error == nil else {
56-
print("*** Failed to reveal the document at %@. Error: %@. ***")
57+
Crashlytics.sharedInstance().recordError(error!)
58+
Crashlytics.sharedInstance().throwException()
59+
5760
return
5861
}
5962

6063
guard let url = revealedDocumentURL else {
61-
print("*** No URL revealed. ***")
64+
Crashlytics.sharedInstance().throwException()
65+
6266
return
6367
}
64-
65-
print("==> Revealed URL")
66-
68+
6769
documentBrowserViewController.presentDocument(at: url)
6870
}
6971

OpenDocumentReader/CoreWrapper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
@property NSArray *pageNames;
1717
@property NSNumber *errorCode;
1818

19-
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath at:(NSNumber *)page with:(NSString *)password;
19+
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath at:(NSNumber *)page with:(NSString *)password editable:(bool)editable;
20+
- (bool)backTranslate:(NSString *)inputPath into:(NSString *)outputPath;
2021
@end
2122

2223
#endif /* CoreWrapper_h */

OpenDocumentReader/CoreWrapper.mm

Lines changed: 74 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,86 @@
1414
#include "TranslationConfig.h"
1515
#include "FileMeta.h"
1616

17-
@implementation CoreWrapper
18-
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath at:(NSNumber *)page with:(NSString *)password {
19-
try {
20-
odr::TranslationHelper translator;
21-
bool opened = translator.openOpenDocument([inputPath cStringUsingEncoding:NSUTF8StringEncoding]);
22-
if (!opened) {
23-
_errorCode = @(-1);
24-
return false;
25-
}
26-
27-
const auto meta = translator.getMeta();
28-
29-
bool decrypted = !meta->encrypted;
30-
if (password != nil) {
31-
decrypted = translator.decrypt([password cStringUsingEncoding:NSUTF8StringEncoding]);
32-
}
33-
34-
if (!decrypted) {
35-
_errorCode = @(-2);
17+
@implementation CoreWrapper {
18+
odr::TranslationHelper translator;
19+
bool initialized;
20+
}
21+
22+
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath at:(NSNumber *)page with:(NSString *)password editable:(bool)editable {
23+
@synchronized(self) {
24+
try {
25+
_errorCode = 0;
26+
27+
if (!initialized) {
28+
bool opened = translator.openOpenDocument([inputPath cStringUsingEncoding:NSUTF8StringEncoding]);
29+
if (!opened) {
30+
_errorCode = @(-1);
31+
return false;
32+
}
33+
34+
const auto meta = translator.getMeta();
35+
36+
bool decrypted = !meta->encrypted;
37+
if (password != nil) {
38+
decrypted = translator.decrypt([password cStringUsingEncoding:NSUTF8StringEncoding]);
39+
}
40+
41+
if (!decrypted) {
42+
_errorCode = @(-2);
43+
return false;
44+
}
45+
46+
NSMutableArray *pageNames = [[NSMutableArray alloc] init];
47+
if (meta->type == odr::FileType::OPENDOCUMENT_TEXT) {
48+
[pageNames addObject:@"Text document"];
49+
} else {
50+
for (auto page = meta->entries.begin(); page != meta->entries.end(); page++) {
51+
auto pageName = page->name;
52+
53+
[pageNames addObject:[NSString stringWithCString:pageName.c_str() encoding:[NSString defaultCStringEncoding]]];
54+
}
55+
}
56+
_pageNames = pageNames;
57+
58+
initialized = true;
59+
}
60+
61+
odr::TranslationConfig config = {};
62+
config.editable = editable;
63+
config.entryOffset = page.intValue;
64+
config.entryCount = 1;
65+
66+
bool translated = translator.translate([outputPath cStringUsingEncoding:NSUTF8StringEncoding], config);
67+
if (!translated) {
68+
_errorCode = @(-4);
69+
return false;
70+
}
71+
} catch (...) {
72+
_errorCode = @(-3);
3673
return false;
3774
}
3875

39-
odr::TranslationConfig config = {};
40-
config.entryOffset = page.intValue;
41-
config.entryCount = 1;
42-
43-
NSMutableArray *pageNames = [[NSMutableArray alloc] init];
44-
if (meta->type == odr::FileType::OPENDOCUMENT_TEXT) {
45-
[pageNames addObject:@"Text document"];
46-
} else {
47-
for (auto page = meta->entries.begin(); page != meta->entries.end(); page++) {
48-
auto pageName = page->name;
49-
50-
[pageNames addObject:[NSString stringWithCString:pageName.c_str() encoding:[NSString defaultCStringEncoding]]];
76+
return true;
77+
}
78+
}
79+
80+
- (bool)backTranslate:(NSString *)inputPath into:(NSString *)outputPath {
81+
@synchronized(self) {
82+
try {
83+
_errorCode = 0;
84+
85+
bool translated = translator.backTranslate([inputPath cStringUsingEncoding:NSUTF8StringEncoding], [outputPath cStringUsingEncoding:NSUTF8StringEncoding]);
86+
if (!translated) {
87+
_errorCode = @(-4);
88+
return false;
5189
}
90+
} catch (...) {
91+
_errorCode = @(-3);
92+
return false;
5293
}
53-
_pageNames = pageNames;
5494

55-
translator.translate([outputPath cStringUsingEncoding:NSUTF8StringEncoding], config);
56-
} catch (...) {
57-
_errorCode = @(-3);
58-
return false;
95+
return true;
5996
}
60-
61-
return true;
6297
}
98+
6399
@end

0 commit comments

Comments
 (0)