Created
January 21, 2019 20:32
-
-
Save mpw/160a208db84c54f7e91070671ce236b3 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/dscsh | |
@implementation NSObject(mapping) | |
-map:dict | |
{ | |
return [dict objectForKey:self]; | |
} | |
-roundedTo100 | |
{ | |
id temp=[self floatValue]*100; | |
temp=temp+0.5; | |
temp=[temp intValue]; | |
temp=temp / 100.0; | |
return temp; | |
} | |
@end | |
@implementation MPWColor(namedColorMapping) | |
-mappedWithName:aName | |
{ | |
return [NSString stringWithFormat:@"\t[ %@ %@ %@ %@ ] (%@)\n", | |
[[self componentAtIndex:0] roundedTo100], | |
[[self componentAtIndex:1] roundedTo100], | |
[[self componentAtIndex:2] roundedTo100], | |
[[self componentAtIndex:3] roundedTo100], | |
aName]; | |
} | |
@end | |
@implementation NSArray(color) | |
-asMPWColor | |
{ | |
return [MPWColor colorWithValues:[[MPWRealArray arrayWithArray:self] operator_asterisk:0.01]]; | |
} | |
-asSet | |
{ | |
return [NSSet setWithArray:self]; | |
} | |
@end | |
@implementation MPWGraphicDumper(interpreterClass) | |
-extractorClass | |
{ | |
return [MPWPSInterpreterWithGraphics class]; | |
} | |
@end | |
@implementation NSData(ripping) | |
-parseColors | |
{ | |
id dict=[[self stringValue] propertyList]; | |
id colorNames=[dict allKeys]; | |
id colorValues=[dict objectsForKeys:colorNames notFoundMarker:nil]; | |
colorValues=[[colorValues collect] asMPWColor]; | |
return [NSDictionary dictionaryWithObjects:colorValues forKeys:colorNames]; | |
} | |
@end | |
@interface Cmyk2SpotConverter : NSObject | |
@end | |
@implementation Cmyk2SpotConverter | |
-colorKey2NameDict:colorDict | |
{ | |
id colorNames=[colorDict allKeys]; | |
id colors=[colorDict objectsForKeys:colorNames notFoundMarker:nil]; | |
colors = [[colors collect] keyColor]; | |
return [NSDictionary dictionaryWithObjects:colorNames forKeys:colors]; | |
} | |
-checkColors:dsc | |
{ | |
id target; | |
target = [[MPWPSColorChecker alloc] initWithTarget:nil]; | |
[target processSourceObjects:dsc]; | |
return [[target colors] allObjects]; | |
} | |
-insertProcsetAndColors:colors into:dsc | |
{ | |
id i; | |
for (i=0;i<[dsc count];i++) { | |
id obj=[dsc objectAtIndex:i]; | |
if ( ![obj isKindOfClass:[MPWDSCComment class]] && ![obj hasPrefix:@"%%+"] ) { | |
[dsc insertObject:colors atIndex:i]; | |
[dsc insertObject:[MPWDownsamplingDumper frameworkResource:@"cmyk2spot" category:@"procset"] atIndex:i+1]; | |
break; | |
} | |
} | |
return dsc; | |
} | |
-colorsForNames:colorNames withMap:colorMap | |
{ | |
id colorValues = [[colorNames collect] map:colorMap]; | |
id psValues = [[[colorValues collect] mappedWithName:[colorNames each]] componentsJoinedByString:@"\n"]; | |
return [NSString stringWithFormat:@"/_mwcustomcolors <<\n%@ >> def\n",psValues]; | |
} | |
- convertCmyk2Spot :filename | |
{ | |
id file; | |
id out = [MPWDSCByteStream Stdout]; | |
id colors; | |
id uniqueColors; | |
id uniqueColorSet; | |
id colorList; | |
id colorMap; | |
id colorNames; | |
id dsc; | |
id foundColorMap; | |
[self logWithFormat:@"checking cmyk -> spot for file: %@",filename]; | |
file=[NSData dataWithContentsOfMappedFile:filename]; | |
file=[MPWEPSFile getEPSPartOfDOSEps: file]; | |
dsc=[MPWDSCScanner scan:file]; | |
colorList = [[NSData dataWithContentsOfFile:@"color-list"] parseColors]; | |
colorMap=[self colorKey2NameDict:colorList]; | |
colors = [self checkColors:file]; | |
uniqueColors=[[[[colors collect] keyColor] asSet] allObjects]; | |
colorNames=[[uniqueColors collect] map:colorMap]; | |
{ | |
id mappableColors = [[uniqueColors select] map:colorMap]; | |
id unmappableColors = [[uniqueColors asSet] mutableCopy]; | |
[unmappableColors minusSet:[mappableColors asSet]]; | |
[self logWithFormat:@"found following spot colors: %@ and following process-color (keys) with no spoteqivalent: %@",colorNames,[unmappableColors allObjects]]; | |
} | |
// [self logWithFormat:@"spot colors: %@",colorNames]; | |
} | |
- main: args | |
{ | |
id result1,outname; | |
[self convertCmyk2Spot:[args objectAtIndex:1]]; | |
return 0; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment