mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 19:10:37 +00:00
* Source/GSGhostscriptImageRep.m: Remove hardcoded path to gs
executable. First try GSGhostscriptExecutablePath default, then try running "$SHELL -c which gs" to get the path. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33505 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
34266c025a
commit
74e522c0c2
2 changed files with 84 additions and 23 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2011-07-10 Eric Wasylishen <ewasylishen@gmail.com>
|
||||||
|
|
||||||
|
* Source/GSGhostscriptImageRep.m: Remove hardcoded path to gs
|
||||||
|
executable. First try GSGhostscriptExecutablePath default, then
|
||||||
|
try running "$SHELL -c which gs" to get the path.
|
||||||
|
|
||||||
2011-07-08 Eric Wasylishen <ewasylishen@gmail.com>
|
2011-07-08 Eric Wasylishen <ewasylishen@gmail.com>
|
||||||
|
|
||||||
* Source/NSView.m (-resizeWithOldSuperviewSize:): Factor out
|
* Source/NSView.m (-resizeWithOldSuperviewSize:): Factor out
|
||||||
|
|
|
@ -28,9 +28,14 @@
|
||||||
|
|
||||||
#import <Foundation/NSArray.h>
|
#import <Foundation/NSArray.h>
|
||||||
#import <Foundation/NSAffineTransform.h>
|
#import <Foundation/NSAffineTransform.h>
|
||||||
|
#import <Foundation/NSCharacterSet.h>
|
||||||
#import <Foundation/NSCoder.h>
|
#import <Foundation/NSCoder.h>
|
||||||
#import <Foundation/NSData.h>
|
#import <Foundation/NSData.h>
|
||||||
|
#import <Foundation/NSException.h>
|
||||||
|
#import <Foundation/NSProcessInfo.h>
|
||||||
|
#import <Foundation/NSString.h>
|
||||||
#import <Foundation/NSTask.h>
|
#import <Foundation/NSTask.h>
|
||||||
|
#import <Foundation/NSUserDefaults.h>
|
||||||
#import "AppKit/NSImageRep.h"
|
#import "AppKit/NSImageRep.h"
|
||||||
#import "AppKit/NSPasteboard.h"
|
#import "AppKit/NSPasteboard.h"
|
||||||
#import "AppKit/NSGraphicsContext.h"
|
#import "AppKit/NSGraphicsContext.h"
|
||||||
|
@ -89,6 +94,49 @@
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString *) _ghostscriptExecutablePath
|
||||||
|
{
|
||||||
|
NSString *result = nil;
|
||||||
|
|
||||||
|
result = [[NSUserDefaults standardUserDefaults] stringForKey: @"GSGhostscriptExecutablePath"];
|
||||||
|
if (result == nil)
|
||||||
|
{
|
||||||
|
NS_DURING
|
||||||
|
{
|
||||||
|
NSTask *task = [[[NSTask alloc] init] autorelease];
|
||||||
|
NSPipe *outputPipe = [NSPipe pipe];
|
||||||
|
NSFileHandle *outputHandle = [outputPipe fileHandleForReading];
|
||||||
|
NSString *shellLaunchPath = [[[NSProcessInfo processInfo] environment] objectForKey: @"SHELL"];
|
||||||
|
NSData *resultData;
|
||||||
|
|
||||||
|
[task setLaunchPath: shellLaunchPath];
|
||||||
|
[task setArguments: [NSArray arrayWithObjects: @"-c", @"which gs", nil]];
|
||||||
|
[task setStandardOutput: outputPipe];
|
||||||
|
[task launch];
|
||||||
|
|
||||||
|
resultData = [outputHandle readDataToEndOfFile];
|
||||||
|
[outputHandle closeFile];
|
||||||
|
|
||||||
|
if (resultData != nil && [resultData length] > 0)
|
||||||
|
{
|
||||||
|
// FIXME: How do we know which encoding the data will be in?
|
||||||
|
result = [[[NSString alloc] initWithBytes: [resultData bytes]
|
||||||
|
length: [resultData length]
|
||||||
|
encoding: NSUTF8StringEncoding] autorelease];
|
||||||
|
|
||||||
|
result = [result stringByTrimmingCharactersInSet:
|
||||||
|
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NS_HANDLER
|
||||||
|
{
|
||||||
|
}
|
||||||
|
NS_ENDHANDLER
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSData *) _pngWithGhostscriptData: (NSData *)psData atResolution: (CGFloat)res
|
- (NSData *) _pngWithGhostscriptData: (NSData *)psData atResolution: (CGFloat)res
|
||||||
{
|
{
|
||||||
NSTask *task = [[[NSTask alloc] init] autorelease];
|
NSTask *task = [[[NSTask alloc] init] autorelease];
|
||||||
|
@ -96,30 +144,37 @@
|
||||||
NSPipe *outputPipe = [NSPipe pipe];
|
NSPipe *outputPipe = [NSPipe pipe];
|
||||||
NSFileHandle *inputHandle = [inputPipe fileHandleForWriting];
|
NSFileHandle *inputHandle = [inputPipe fileHandleForWriting];
|
||||||
NSFileHandle *outputHandle = [outputPipe fileHandleForReading];
|
NSFileHandle *outputHandle = [outputPipe fileHandleForReading];
|
||||||
NSData *result;
|
NSData *result = nil;
|
||||||
|
NSString *launchPath = [self _ghostscriptExecutablePath];
|
||||||
|
|
||||||
// FIXME: Parameterize
|
NS_DURING
|
||||||
[task setLaunchPath: @"/usr/bin/gs"];
|
{
|
||||||
[task setArguments: [NSArray arrayWithObjects: @"-dSAFER",
|
[task setLaunchPath: launchPath];
|
||||||
@"-q",
|
[task setArguments: [NSArray arrayWithObjects: @"-dSAFER",
|
||||||
@"-o",
|
@"-q",
|
||||||
@"-", // Write output image to stdout
|
@"-o",
|
||||||
@"-sDEVICE=pngalpha",
|
@"-", // Write output image to stdout
|
||||||
[NSString stringWithFormat: @"-r%d", (int)res],
|
@"-sDEVICE=pngalpha",
|
||||||
@"-dTextAlphaBits=4",
|
[NSString stringWithFormat: @"-r%d", (int)res],
|
||||||
@"-dGraphicsAlphaBits=4",
|
@"-dTextAlphaBits=4",
|
||||||
@"-dDOINTERPOLATE",
|
@"-dGraphicsAlphaBits=4",
|
||||||
@"-", // Read input from stdin
|
@"-dDOINTERPOLATE",
|
||||||
nil]];
|
@"-", // Read input from stdin
|
||||||
[task setStandardInput: inputPipe];
|
nil]];
|
||||||
[task setStandardOutput: outputPipe];
|
[task setStandardInput: inputPipe];
|
||||||
[task launch];
|
[task setStandardOutput: outputPipe];
|
||||||
|
[task launch];
|
||||||
[inputHandle writeData: psData];
|
|
||||||
[inputHandle closeFile];
|
[inputHandle writeData: psData];
|
||||||
|
[inputHandle closeFile];
|
||||||
result = [outputHandle readDataToEndOfFile];
|
|
||||||
[outputHandle closeFile];
|
result = [outputHandle readDataToEndOfFile];
|
||||||
|
[outputHandle closeFile];
|
||||||
|
}
|
||||||
|
NS_HANDLER
|
||||||
|
{
|
||||||
|
}
|
||||||
|
NS_ENDHANDLER
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue