-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from vincentneo/thumbnails
Quick Look Thumbnails + Document Icon support
- Loading branch information
Showing
30 changed files
with
369 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
Avenue Thumbnails/Assets.xcassets/avenue-pin.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "V2.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+588 Bytes
Avenue Thumbnails/Assets.xcassets/avenue-pin.imageset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>NSExtension</key> | ||
<dict> | ||
<key>NSExtensionAttributes</key> | ||
<dict> | ||
<key>QLSupportedContentTypes</key> | ||
<array> | ||
<string>com.topografix.gpx</string> | ||
<string>com.apple.dt.document.gpx</string> | ||
<string>com.glacierpeakstudios.gpx</string> | ||
<string>com.berbie.documenttypes.gpx</string> | ||
<string>com.topographix.gpx</string> | ||
<string>public.gpx</string> | ||
<string>public.xml</string> | ||
</array> | ||
<key>QLThumbnailMinimumDimension</key> | ||
<integer>0</integer> | ||
</dict> | ||
<key>NSExtensionPointIdentifier</key> | ||
<string>com.apple.quicklook.thumbnail</string> | ||
<key>NSExtensionPrincipalClass</key> | ||
<string>$(PRODUCT_MODULE_NAME).ThumbnailProvider</string> | ||
</dict> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// ThumbnailProvider.swift | ||
// Avenue Thumbnails | ||
// | ||
// Created by Vincent Neo on 13/1/23. | ||
// Copyright © 2023 Vincent. All rights reserved. | ||
// | ||
|
||
import QuickLookThumbnailing | ||
import MapKit | ||
import CoreGPX | ||
|
||
class ThumbnailProvider: QLThumbnailProvider { | ||
|
||
func prepareExtent(from gpx: GPXRoot) -> GPXExtentCoordinates { | ||
let extent = GPXExtentCoordinates() | ||
for route in gpx.routes { | ||
for point in route.points { | ||
extent.extendAreaToIncludeLocation(point.coordinate) | ||
} | ||
} | ||
|
||
for track in gpx.tracks { | ||
for segment in track.segments { | ||
for point in segment.points { | ||
extent.extendAreaToIncludeLocation(point.coordinate) | ||
} | ||
} | ||
} | ||
|
||
for waypoint in gpx.waypoints { | ||
extent.extendAreaToIncludeLocation(waypoint.coordinate) | ||
} | ||
return extent | ||
} | ||
|
||
override func provideThumbnail(for request: QLFileThumbnailRequest, _ handler: @escaping (QLThumbnailReply?, Error?) -> Void) { | ||
|
||
// There are three ways to provide a thumbnail through a QLThumbnailReply. Only one of them should be used. | ||
|
||
// First way: Draw the thumbnail into the current context, set up with UIKit's coordinate system. | ||
guard let parser = GPXParser(withURL: request.fileURL), let gpx = parser.parsedData() else { | ||
handler(nil, GPXError.parser.fileIsEmpty) | ||
return | ||
} | ||
|
||
let extent = self.prepareExtent(from: gpx) | ||
|
||
let options = MKMapSnapshotter.Options() | ||
options.region = extent.region | ||
options.size = request.maximumSize | ||
|
||
let snapshotter = MKMapSnapshotter(options: options) | ||
snapshotter.start { snapshot, error in | ||
let drawer = MKSnapshotDrawer(snapshot!, gpx: gpx) | ||
let newImage = drawer.processImage() | ||
|
||
handler(QLThumbnailReply(contextSize: request.maximumSize, currentContextDrawing: { () -> Bool in | ||
// Draw the thumbnail here. | ||
newImage.draw(in: NSRect(origin: .zero, size: request.maximumSize)) | ||
// Return true if the thumbnail was successfully drawn inside this block. | ||
return true | ||
}), nil) | ||
} | ||
|
||
/* | ||
|
||
// Second way: Draw the thumbnail into a context passed to your block, set up with Core Graphics's coordinate system. | ||
handler(QLThumbnailReply(contextSize: request.maximumSize, drawing: { (context) -> Bool in | ||
// Draw the thumbnail here. | ||
|
||
// Return true if the thumbnail was successfully drawn inside this block. | ||
return true | ||
}), nil) | ||
|
||
// Third way: Set an image file URL. | ||
handler(QLThumbnailReply(imageFileURL: Bundle.main.url(forResource: "fileThumbnail", withExtension: "jpg")!), nil) | ||
|
||
*/ | ||
} | ||
} |
Oops, something went wrong.