summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-09-29 00:08:20 -0700
committerMinh Nguyễn <mxn@1ec5.org>2017-09-29 00:08:20 -0700
commit1684b0c768592b41c04987da1e8e2c3492a0f66e (patch)
tree3e5d380d6ea6956be88ae9a5e93972eec50cf159
parent5213133dc74267bc04d312e5127336b24459b346 (diff)
downloadqtlocation-mapboxgl-1684b0c768592b41c04987da1e8e2c3492a0f66e.tar.gz
[macos] Save snapshots in correct format
-rw-r--r--platform/macos/app/MapDocument.m48
1 files changed, 19 insertions, 29 deletions
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index d466d2ef4b..feef53062b 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -162,58 +162,48 @@ NS_ARRAY_OF(id <MGLAnnotation>) *MBXFlattenedShapes(NS_ARRAY_OF(id <MGLAnnotatio
- (IBAction)takeSnapshot:(id)sender {
MGLMapCamera *camera = self.mapView.camera;
- MGLMapSnapshotOptions* options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:self.mapView.styleURL camera:camera size:self.mapView.bounds.size];
+ MGLMapSnapshotOptions *options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:self.mapView.styleURL camera:camera size:self.mapView.bounds.size];
options.zoomLevel = self.mapView.zoomLevel;
// Create and start the snapshotter
snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options];
- [snapshotter startWithCompletionHandler: ^(NSImage *image, NSError *error) {
+ [snapshotter startWithCompletionHandler:^(NSImage *image, NSError *error) {
if (error) {
- NSLog(@"Could not load snapshot: %@", [error localizedDescription]);
+ NSLog(@"Could not load snapshot: %@", error.localizedDescription);
} else {
- NSWindow* window = [[[self windowControllers] objectAtIndex:0] window];
-
- NSString* newName = [[@"snapshot" stringByDeletingPathExtension] stringByAppendingPathExtension:@"png"];
-
// Set the default name for the file and show the panel.
- NSSavePanel* panel = [NSSavePanel savePanel];
+ NSSavePanel *panel = [NSSavePanel savePanel];
+ panel.nameFieldStringValue = [self.mapView.styleURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension:@"png"];
+ panel.allowedFileTypes = [@[(NSString *)kUTTypePNG] arrayByAddingObjectsFromArray:[NSBitmapImageRep imageUnfilteredTypes]];
- [panel setNameFieldStringValue:newName];
- [panel beginSheetModalForWindow:window completionHandler:^(NSInteger result){
+ [panel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton) {
// Write the contents in the new format.
- NSURL* fileURL = [panel URL];
+ NSURL *fileURL = panel.URL;
- NSBitmapImageRep *bitmapRep = nil;
- for (NSImageRep *imageRep in [image representations]) {
- if ([imageRep isKindOfClass:[NSBitmapImageRep class]]){
+ NSBitmapImageRep *bitmapRep;
+ for (NSImageRep *imageRep in image.representations) {
+ if ([imageRep isKindOfClass:[NSBitmapImageRep class]]) {
bitmapRep = (NSBitmapImageRep *)imageRep;
break; // stop on first bitmap rep we find
}
}
if (!bitmapRep) {
- bitmapRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
-
+ bitmapRep = [NSBitmapImageRep imageRepWithData:image.TIFFRepresentation];
}
- NSString *uti;
- [fileURL getResourceValue:&uti forKey:NSURLTypeIdentifierKey error:nil];
+ CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileURL.pathExtension, NULL /* inConformingToUTI */);
NSBitmapImageFileType fileType = NSTIFFFileType;
-
- if (UTTypeConformsTo((__bridge CFStringRef)uti, kUTTypePNG)) {
+ if (UTTypeConformsTo(uti, kUTTypePNG)) {
fileType = NSPNGFileType;
- }
- if (UTTypeConformsTo((__bridge CFStringRef)uti, kUTTypeGIF)) {
+ } else if (UTTypeConformsTo(uti, kUTTypeGIF)) {
fileType = NSGIFFileType;
- }
- if (UTTypeConformsTo((__bridge CFStringRef)uti, kUTTypeJPEG)) {
- fileType = NSJPEGFileType;
- }
- if (UTTypeConformsTo((__bridge CFStringRef)uti, kUTTypeJPEG2000)) {
+ } else if (UTTypeConformsTo(uti, kUTTypeJPEG2000)) {
+ fileType = NSJPEG2000FileType;
+ } else if (UTTypeConformsTo(uti, kUTTypeJPEG)) {
fileType = NSJPEGFileType;
- }
- if (UTTypeConformsTo((__bridge CFStringRef)uti, kUTTypeBMP)) {
+ } else if (UTTypeConformsTo(uti, kUTTypeBMP)) {
fileType = NSBitmapImageFileTypeBMP;
}