Skip to content

Commit 0031f11

Browse files
author
Thomas Taschauer
committed
first implementation of editing
ATTENTION: assumes local changes in core. to be committed as soon as we have a proper fix
1 parent b456498 commit 0031f11

9 files changed

Lines changed: 218 additions & 102 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 = 13;
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.9;
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 = 13;
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.9;
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
@property NSArray *pageNames;
1717
@property NSNumber *errorCode;
1818

19-
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath at:(NSNumber *)page with:(NSString *)password;
19+
- (void)close;
20+
21+
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath at:(NSNumber *)page with:(NSString *)password editable:(bool)editable;
22+
- (bool)backTranslate:(NSString *)inputPath into:(NSString *)outputPath;
2023
@end
2124

2225
#endif /* CoreWrapper_h */

OpenDocumentReader/CoreWrapper.mm

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,90 @@
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 {
17+
@implementation CoreWrapper {
18+
odr::TranslationHelper *translator;
19+
}
20+
21+
- (void)close {
22+
if (translator != nullptr) {
23+
delete translator;
24+
translator = nullptr;
25+
}
26+
}
27+
28+
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath at:(NSNumber *)page with:(NSString *)password editable:(bool)editable {
1929
try {
20-
odr::TranslationHelper translator;
21-
bool opened = translator.openOpenDocument([inputPath cStringUsingEncoding:NSUTF8StringEncoding]);
22-
if (!opened) {
23-
_errorCode = @(-1);
24-
return false;
25-
}
30+
_errorCode = 0;
2631

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);
36-
return false;
32+
if (translator == nullptr) {
33+
translator = new odr::TranslationHelper();
34+
35+
bool opened = translator->openOpenDocument([inputPath cStringUsingEncoding:NSUTF8StringEncoding]);
36+
if (!opened) {
37+
_errorCode = @(-1);
38+
return false;
39+
}
40+
41+
const auto meta = translator->getMeta();
42+
43+
bool decrypted = !meta->encrypted;
44+
if (password != nil) {
45+
decrypted = translator->decrypt([password cStringUsingEncoding:NSUTF8StringEncoding]);
46+
}
47+
48+
if (!decrypted) {
49+
[self close];
50+
51+
_errorCode = @(-2);
52+
return false;
53+
}
54+
55+
NSMutableArray *pageNames = [[NSMutableArray alloc] init];
56+
if (meta->type == odr::FileType::OPENDOCUMENT_TEXT) {
57+
[pageNames addObject:@"Text document"];
58+
} else {
59+
for (auto page = meta->entries.begin(); page != meta->entries.end(); page++) {
60+
auto pageName = page->name;
61+
62+
[pageNames addObject:[NSString stringWithCString:pageName.c_str() encoding:[NSString defaultCStringEncoding]]];
63+
}
64+
}
65+
_pageNames = pageNames;
3766
}
3867

3968
odr::TranslationConfig config = {};
69+
config.editable = editable;
4070
config.entryOffset = page.intValue;
4171
config.entryCount = 1;
4272

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]]];
51-
}
73+
bool translated = translator->translate([outputPath cStringUsingEncoding:NSUTF8StringEncoding], config);
74+
if (!translated) {
75+
_errorCode = @(-4);
76+
return false;
77+
}
78+
} catch (...) {
79+
_errorCode = @(-3);
80+
return false;
81+
}
82+
83+
return true;
84+
}
85+
86+
- (bool)backTranslate:(NSString *)inputPath into:(NSString *)outputPath {
87+
try {
88+
_errorCode = 0;
89+
90+
bool translated = translator->backTranslate([inputPath cStringUsingEncoding:NSUTF8StringEncoding], [outputPath cStringUsingEncoding:NSUTF8StringEncoding]);
91+
if (!translated) {
92+
_errorCode = @(-4);
93+
return false;
5294
}
53-
_pageNames = pageNames;
54-
55-
translator.translate([outputPath cStringUsingEncoding:NSUTF8StringEncoding], config);
5695
} catch (...) {
5796
_errorCode = @(-3);
5897
return false;
5998
}
6099

61100
return true;
62101
}
102+
63103
@end

0 commit comments

Comments
 (0)