Skip to content

Commit

Permalink
Better PDF compression with Ghostcript 9
Browse files Browse the repository at this point in the history
  • Loading branch information
alin23 committed Dec 21, 2023
1 parent 86de022 commit 04d2980
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 88 deletions.
32 changes: 16 additions & 16 deletions Clop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEVELOPMENT_TEAM = RDDXV84A73;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -898,7 +898,7 @@
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
PRODUCT_BUNDLE_IDENTIFIER = com.lowtechguys.Clop.FinderOptimiser;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -917,7 +917,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEVELOPMENT_TEAM = RDDXV84A73;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -933,7 +933,7 @@
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
PRODUCT_BUNDLE_IDENTIFIER = com.lowtechguys.Clop.FinderOptimiser;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -952,7 +952,7 @@
CODE_SIGN_ENTITLEMENTS = Setapp/Setapp.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Clop/Preview Content\"";
DEVELOPMENT_TEAM = RDDXV84A73;
Expand All @@ -974,7 +974,7 @@
);
LLVM_LTO = YES_THIN;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
OTHER_LDFLAGS = (
"-force_load",
"$(BUILT_PRODUCTS_DIR)/libSetapp.a",
Expand All @@ -996,7 +996,7 @@
CODE_SIGN_ENTITLEMENTS = Setapp/Setapp.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Clop/Preview Content\"";
DEVELOPMENT_TEAM = RDDXV84A73;
Expand All @@ -1018,7 +1018,7 @@
);
LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
OTHER_LDFLAGS = (
"-force_load",
"$(BUILT_PRODUCTS_DIR)/libSetapp.a",
Expand All @@ -1038,7 +1038,7 @@
CODE_SIGN_ENTITLEMENTS = "Setapp/FinderOptimiser-setapp.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEVELOPMENT_TEAM = RDDXV84A73;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -1053,7 +1053,7 @@
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.lowtechguys.Clop-setapp.FinderOptimiser";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -1070,7 +1070,7 @@
CODE_SIGN_ENTITLEMENTS = "Setapp/FinderOptimiser-setapp.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEVELOPMENT_TEAM = RDDXV84A73;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -1085,7 +1085,7 @@
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.lowtechguys.Clop-setapp.FinderOptimiser";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1321,7 +1321,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Clop/Preview Content\"";
DEVELOPMENT_TEAM = RDDXV84A73;
Expand All @@ -1342,7 +1342,7 @@
);
LLVM_LTO = YES_THIN;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
PRODUCT_BUNDLE_IDENTIFIER = com.lowtechguys.Clop;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1361,7 +1361,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 2.5.1;
CURRENT_PROJECT_VERSION = 2.5.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"Clop/Preview Content\"";
DEVELOPMENT_TEAM = RDDXV84A73;
Expand All @@ -1382,7 +1382,7 @@
);
LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 2.5.1;
MARKETING_VERSION = 2.5.2;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.lowtechguys.Clop;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@
<key>FinderOptimiser-setapp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>3</integer>
<integer>5</integer>
</dict>
<key>FinderOptimiser.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
<integer>3</integer>
</dict>
<key>Setapp.xcscheme_^#shared#^_</key>
<dict>
Expand Down
11 changes: 5 additions & 6 deletions Clop/Optimisable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ class Optimisable {
return nil
}
let outfile: Self? =
if let size = shortcutOutFile.fileSize(), size < 4096, let path = (try? String(contentsOfFile: shortcutOutFile.string))?.existingFilePath, self.path != path
{
Self(path, id: id)
} else {
Self(shortcutOutFile, id: id)
}
if let size = shortcutOutFile.fileSize(), size < 4096, let path = (try? String(contentsOfFile: shortcutOutFile.string))?.existingFilePath, self.path != path {
Self(path, id: id)
} else {
Self(shortcutOutFile, id: id)
}

guard let outfile, outfile.hash != hash else {
return nil
Expand Down
48 changes: 24 additions & 24 deletions Clop/OptimisationUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ final class QuickLooker: QLPreviewPanelDataSource {
let _ = try? await optimiseVideo(video, id: id, allowLarger: allowLarger, hideFloatingResult: hideFloatingResult, aggressiveOptimisation: shouldUseAggressiveOptimisation)
}
}
if type.isPDF, path.exists, let pdf {
Task.init { try? await optimisePDF(pdf, id: id, allowLarger: allowLarger, hideFloatingResult: hideFloatingResult, aggressiveOptimisation: shouldUseAggressiveOptimisation) }
}
}

func restoreOriginal() {
Expand Down Expand Up @@ -1813,14 +1816,13 @@ var manualOptimisationCount = 0
let downloadPath = FilePath.downloads.appending("\(name).\(ext)")

let outFilePath: FilePath =
if let path = output?.filePath, path.string.contains("/")
{
path.isDir ? path / "\(name).\(ext)" : path.dir / generateFileName(template: path.name.string, for: downloadPath, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else if let output {
downloadPath.dir / generateFileName(template: output, for: downloadPath, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else {
downloadPath
}
if let path = output?.filePath, path.string.contains("/") {
path.isDir ? path / "\(name).\(ext)" : path.dir / generateFileName(template: path.name.string, for: downloadPath, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else if let output {
downloadPath.dir / generateFileName(template: output, for: downloadPath, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else {
downloadPath
}
try fileURL.filePath!.move(to: outFilePath, force: true)

guard optimiser.running, !optimiser.inRemoval else {
Expand Down Expand Up @@ -1902,23 +1904,21 @@ var THUMBNAIL_URLS: ThreadSafeDictionary<URL, URL> = .init()
.replacingOccurrences(of: "%z", with: cropSizeStr(cropSize))
.replacingOccurrences(of: "%x", with: factorStr(changePlaybackSpeedFactor))
let outFilePath: FilePath? =
if let path = output?.filePath, path.string.contains("/"), path.string.starts(with: "/")
{
path.isDir ? path.appending(item.path.name) : path.dir / generateFileName(template: path.name.string, for: item.path, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else if let output {
item.path.dir / generateFileName(template: output, for: item.path, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else {
nil
}
if let path = output?.filePath, path.string.contains("/"), path.string.starts(with: "/") {
path.isDir ? path.appending(item.path.name) : path.dir / generateFileName(template: path.name.string, for: item.path, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else if let output {
item.path.dir / generateFileName(template: output, for: item.path, autoIncrementingNumber: &Defaults[.lastAutoIncrementingNumber])
} else {
nil
}
let item: ClipboardType =
if let outFilePath, item.path.exists, case let .image(img) = item
{
try .image(img.copyWithPath(item.path.copy(to: outFilePath, force: true)))
} else if let outFilePath, item.path.exists {
try .file(item.path.copy(to: outFilePath, force: true))
} else {
item
}
if let outFilePath, item.path.exists, case let .image(img) = item {
try .image(img.copyWithPath(item.path.copy(to: outFilePath, force: true)))
} else if let outFilePath, item.path.exists {
try .file(item.path.copy(to: outFilePath, force: true))
} else {
item
}

switch item {
case let .image(img):
Expand Down
2 changes: 1 addition & 1 deletion Clop/PDF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class PDF: Optimisable {
return true
}

let GHOSTSCRIPT_ENV = ["GS_LIB": BIN_DIR.appending(path: "share/ghostscript/10.02.0/Resource/Init").path]
let GHOSTSCRIPT_ENV = ["GS_LIB": BIN_DIR.appending(path: "share/ghostscript/9.56.1/Resource/Init").path]

@discardableResult
@MainActor func optimisePDF(
Expand Down
4 changes: 2 additions & 2 deletions Clop/bin.tar.xz
Git LFS file not shown
2 changes: 1 addition & 1 deletion Clop/bin.tar.xz.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1e179aa19c0808fc4eb7a6164d9139d3cc79f9e5ce8603cb7a079d09c5bb5a26
21d622d0d0e7d6153bb7aca29273eeb9a304e6fd91e9706f5231548beb94d1ad
38 changes: 18 additions & 20 deletions ClopCLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,15 @@ struct Clop: ParsableCommand {
pdf.uncrop()

let outFilePath: FilePath =
if let path = output?.filePath, path.string.contains("/"), path.string.starts(with: "/")
{
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let path = output?.filePath, path.string.contains("/"), let path = FileManager.default.currentDirectoryPath.filePath?.appending(path.string) {
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let output {
pdfPath.dir / generateFileName(template: output, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else {
pdfPath
}
if let path = output?.filePath, path.string.contains("/"), path.string.starts(with: "/") {
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let path = output?.filePath, path.string.contains("/"), let path = FileManager.default.currentDirectoryPath.filePath?.appending(path.string) {
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let output {
pdfPath.dir / generateFileName(template: output, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else {
pdfPath
}

print(" -> saved to \(outFilePath.string)")
pdf.write(to: outFilePath.url)
Expand Down Expand Up @@ -588,16 +587,15 @@ struct Clop: ParsableCommand {
pdf.cropTo(aspectRatio: ratio, alwaysPortrait: pageLayout == .portrait, alwaysLandscape: pageLayout == .landscape)

let outFilePath: FilePath =
if let path = output?.filePath, path.string.contains("/"), path.string.starts(with: "/")
{
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let path = output?.filePath, path.string.contains("/"), let path = FileManager.default.currentDirectoryPath.filePath?.appending(path.string) {
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let output {
pdfPath.dir / generateFileName(template: output, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else {
pdfPath
}
if let path = output?.filePath, path.string.contains("/"), path.string.starts(with: "/") {
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let path = output?.filePath, path.string.contains("/"), let path = FileManager.default.currentDirectoryPath.filePath?.appending(path.string) {
path.isDir ? path.appending(pdfPath.name) : path.dir / generateFileName(template: path.name.string, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else if let output {
pdfPath.dir / generateFileName(template: output, for: pdfPath, autoIncrementingNumber: &UserDefaults.standard.lastAutoIncrementingNumber)
} else {
pdfPath
}

print(" -> saved to \(outFilePath.string)")
pdf.write(to: outFilePath.url)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ else
endif

Clop/bin.tar.xz: $(wildcard Clop/bin/*) $(wildcard Clop/bin/*/*)
fd -t file . Clop/bin -x sh -c 'codesign -v "{}" || codesign -fs "$$CODESIGN_CERT" --options runtime --entitlements Clop/bin.entitlements --timestamp "{}"'
fd -uu -t file . Clop/bin -x sh -c 'codesign -v "{}" || codesign -fs "$$CODESIGN_CERT" --options runtime --entitlements Clop/bin.entitlements --timestamp "{}"'
rm Clop/bin.tar.xz; cd Clop/bin/; tar acvf ../bin.tar.xz *
sha256sum Clop/bin.tar.xz | cut -d' ' -f1 > Clop/bin.tar.xz.sha256
bin: Clop/bin.tar.xz
3 changes: 3 additions & 0 deletions ReleaseNotes/2.5.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Improvements

- Compress more types of PDFs *(even without aggressive optimisation needed)*
26 changes: 11 additions & 15 deletions Releases/appcast.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?xml version="1.0" standalone="yes"?>
<rss xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" version="2.0">
<channel>
<item>
<title>2.5.2</title>
<pubDate>Thu, 21 Dec 2023 18:43:54 +0200</pubDate>
<link>https://lowtechguys.com/clop</link>
<sparkle:fullReleaseNotesLink>https://github.com/FuzzyIdeas/Clop/releases</sparkle:fullReleaseNotesLink>
<sparkle:version>2.5.2</sparkle:version>
<sparkle:shortVersionString>2.5.2</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>13.0</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://files.lowtechguys.com/ReleaseNotes/Clop-2.5.2.html</sparkle:releaseNotesLink>
<enclosure url="https://files.lowtechguys.com/releases/Clop-2.5.2.dmg" length="92180718" type="application/octet-stream" sparkle:edSignature="42/oIxu2YT/wlpdQAoNNwCf0NBTPZB8GJjA3RuU0Ujc2ZTdufib2vRXRcmHDaCLFlujVIHMggYKtis6war0pBw=="/>
</item>
<item>
<title>2.5.1</title>
<pubDate>Wed, 20 Dec 2023 18:22:48 +0200</pubDate>
Expand Down Expand Up @@ -135,20 +146,5 @@
<sparkle:releaseNotesLink>https://files.lowtechguys.com/ReleaseNotes/Clop-2.2.4.html</sparkle:releaseNotesLink>
<enclosure url="https://files.lowtechguys.com/releases/Clop-2.2.4.dmg" length="83673298" type="application/octet-stream" sparkle:edSignature="oDVXttBwW9y0bArM6gxixhT1pHbkQBMe61l7aeJWgv7lNYRNqVR373wplcpyhWpX9AW7iOyu1wxToFHqWWvtAw=="/>
</item>
<item>
<title>2.2.3</title>
<pubDate>Thu, 12 Oct 2023 08:34:48 +0300</pubDate>
<link>https://lowtechguys.com/clop</link>
<sparkle:fullReleaseNotesLink>https://github.com/FuzzyIdeas/Clop/releases</sparkle:fullReleaseNotesLink>
<sparkle:version>2.2.3</sparkle:version>
<sparkle:shortVersionString>2.2.3</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>13.0</sparkle:minimumSystemVersion>
<sparkle:releaseNotesLink>https://files.lowtechguys.com/ReleaseNotes/Clop-2.2.3.html</sparkle:releaseNotesLink>
<enclosure url="https://files.lowtechguys.com/releases/Clop-2.2.3.dmg" length="92915603" type="application/octet-stream" sparkle:edSignature="pvQUKvZ0niNWHJHeOK758wD/7IzUArIRIVR8DQ/3YSKOCC9Ct9DUEX9cN+8J8RaqbOm2lxsHuqkgh/cQeKSkBw=="/>
<sparkle:deltas>
<enclosure url="https://files.lowtechguys.com/releases/Clop2.2.3-2.2.2.delta" sparkle:deltaFrom="2.2.2" length="272194" type="application/octet-stream" sparkle:deltaFromSparkleExecutableSize="865120" sparkle:deltaFromSparkleLocales="de,he,ar,el,ja,fa,en" sparkle:edSignature="+vJJSU7GT0IThWEB39ExgEJdVWlJYfs9Xnx+b3GzEsU1M/JHZ9CcMbUmCYmSrTJ4OYI99bext6GF0Cl+r9WBBQ=="/>
<enclosure url="https://files.lowtechguys.com/releases/Clop2.2.3-2.2.1.delta" sparkle:deltaFrom="2.2.1" length="11359430" type="application/octet-stream" sparkle:deltaFromSparkleExecutableSize="865120" sparkle:deltaFromSparkleLocales="de,he,ar,el,ja,fa,en" sparkle:edSignature="ZNHuKdIfDAXaGa2djcavs1FFOvCCcFjUiJXRWfwhOkVBWOgadFi1nzjcAvos8xNEZTe80v3ErMRCC10iEZGMBA=="/>
</sparkle:deltas>
</item>
</channel>
</rss>

0 comments on commit 04d2980

Please sign in to comment.