diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e0b144..7489b99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,17 @@ open: **a second build under the same version goes under the already cut heading, not back under `Unreleased`.** Date the heading and add its compare link once the version tag exists. +## [Unreleased] + +### Changed + +- PDFs are rendered by odrcore instead of being handed to the web view, and a + password protected one takes the prompt the other formats use. Their text is + in the page, so they become searchable once odrcore writes the search script + for a pdf page as it does for a document. +- The search button leaves the tool bar when the page cannot be searched, + rather than greying out - the same as the edit button. + ## [1.40] ### Changed diff --git a/OpenDocumentReader.xcodeproj/project.pbxproj b/OpenDocumentReader.xcodeproj/project.pbxproj index 8ee56b2..bb657a4 100644 --- a/OpenDocumentReader.xcodeproj/project.pbxproj +++ b/OpenDocumentReader.xcodeproj/project.pbxproj @@ -29,6 +29,8 @@ E2A17B1000000000000000B0 /* test.ods in Resources */ = {isa = PBXBuildFile; fileRef = E2A17B1200000000000000B2 /* test.ods */; }; E2A17B1100000000000000B1 /* test.odp in Resources */ = {isa = PBXBuildFile; fileRef = E2A17B1300000000000000B3 /* test.odp */; }; E2A17B1400000000000000B4 /* test.csv in Resources */ = {isa = PBXBuildFile; fileRef = E2A17B1500000000000000B5 /* test.csv */; }; + E2A17B1600000000000000B6 /* test.pdf in Resources */ = {isa = PBXBuildFile; fileRef = E2A17B1700000000000000B7 /* test.pdf */; }; + E2A17B1800000000000000B8 /* test-encrypted.pdf in Resources */ = {isa = PBXBuildFile; fileRef = E2A17B1900000000000000B9 /* test-encrypted.pdf */; }; E2A17B2000000000000000C0 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2A17B2200000000000000C2 /* CoreFoundation.framework */; }; E2A17B2100000000000000C1 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2A17B2300000000000000C3 /* CFNetwork.framework */; }; FB494C85E264BD924C1EA54E /* OdrCore in Frameworks */ = {isa = PBXBuildFile; productRef = E381918B979121CD165C966A /* OdrCore */; }; @@ -65,6 +67,8 @@ E2A17B1200000000000000B2 /* test.ods */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.ods; sourceTree = ""; }; E2A17B1300000000000000B3 /* test.odp */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.odp; sourceTree = ""; }; E2A17B1500000000000000B5 /* test.csv */ = {isa = PBXFileReference; lastKnownFileType = text; path = test.csv; sourceTree = ""; }; + E2A17B1700000000000000B7 /* test.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = test.pdf; sourceTree = ""; }; + E2A17B1900000000000000B9 /* test-encrypted.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = "test-encrypted.pdf"; sourceTree = ""; }; E2A17B2200000000000000C2 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; E2A17B2300000000000000C3 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -163,6 +167,8 @@ E2A17B1200000000000000B2 /* test.ods */, E2A17B1300000000000000B3 /* test.odp */, E2A17B1500000000000000B5 /* test.csv */, + E2A17B1700000000000000B7 /* test.pdf */, + E2A17B1900000000000000B9 /* test-encrypted.pdf */, E22B252E2557F0E2001D0C52 /* OpenDocumentReaderTests.swift */, E2A17B0300000000000000A3 /* PageTabBarTests.swift */, E22B25302557F0E2001D0C52 /* Info.plist */, @@ -353,6 +359,8 @@ E2A17B1000000000000000B0 /* test.ods in Resources */, E2A17B1100000000000000B1 /* test.odp in Resources */, E2A17B1400000000000000B4 /* test.csv in Resources */, + E2A17B1600000000000000B6 /* test.pdf in Resources */, + E2A17B1800000000000000B8 /* test-encrypted.pdf in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/OpenDocumentReader/CoreWrapper.swift b/OpenDocumentReader/CoreWrapper.swift index 331c06f..42f6d3c 100644 --- a/OpenDocumentReader/CoreWrapper.swift +++ b/OpenDocumentReader/CoreWrapper.swift @@ -7,7 +7,7 @@ let CoreWrapperErrorDomain = "app.opendocument.CoreWrapperErrorDomain" @objc enum CoreWrapperError: Int { case unknown = 1 case wrongPassword = 2 - /// Not a document odrcore can translate. PDFs land here on purpose. + /// Not something odrcore renders for us — see the guard in `translate`. case unsupportedFileType = 3 } @@ -107,11 +107,6 @@ private func isCsv(_ file: DecodedFile) -> Bool { file.fileType == .commaSeparat guard !fileTypes.isEmpty else { throw coreWrapperError(.unsupportedFileType, "odrcore does not recognise this file type") } - // PDFs are handed to WKWebView instead, which renders them natively - guard !fileTypes.contains(NSNumber(value: FileType.portableDocumentFormat.rawValue)) else { - throw coreWrapperError( - .unsupportedFileType, "PDF is rendered by the web view, not by odrcore") - } var file = try DecodedFile.decode(path: inputPath) if file.isPasswordEncrypted { @@ -124,8 +119,11 @@ private func isCsv(_ file: DecodedFile) -> Bool { file.fileType == .commaSeparat } } - guard file.isDocumentFile || isCsv(file) else { - throw coreWrapperError(.unsupportedFileType, "not a document file") + // odrcore also translates images, media and fonts, but only into an + // `` or a `