Guest User

Untitled

a guest
Jan 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. #!/usr/local/bin/dscsh
  2.  
  3. @implementation NSObject(mapping)
  4.  
  5. -map:dict
  6. {
  7. return [dict objectForKey:self];
  8. }
  9.  
  10. -roundedTo100
  11. {
  12. id temp=[self floatValue]*100;
  13. temp=temp+0.5;
  14. temp=[temp intValue];
  15. temp=temp / 100.0;
  16. return temp;
  17. }
  18. @end
  19.  
  20. @implementation MPWColor(namedColorMapping)
  21.  
  22. -mappedWithName:aName
  23. {
  24. return [NSString stringWithFormat:@"\t[ %@ %@ %@ %@ ] (%@)\n",
  25. [[self componentAtIndex:0] roundedTo100],
  26. [[self componentAtIndex:1] roundedTo100],
  27. [[self componentAtIndex:2] roundedTo100],
  28. [[self componentAtIndex:3] roundedTo100],
  29. aName];
  30. }
  31.  
  32. @end
  33.  
  34. @implementation NSArray(color)
  35.  
  36. -asMPWColor
  37. {
  38. return [MPWColor colorWithValues:[[MPWRealArray arrayWithArray:self] operator_asterisk:0.01]];
  39. }
  40.  
  41. -asSet
  42. {
  43. return [NSSet setWithArray:self];
  44. }
  45.  
  46. @end
  47.  
  48. @implementation MPWGraphicDumper(interpreterClass)
  49.  
  50. -extractorClass
  51. {
  52. return [MPWPSInterpreterWithGraphics class];
  53. }
  54.  
  55. @end
  56.  
  57. @implementation NSData(ripping)
  58.  
  59. -parseColors
  60. {
  61. id dict=[[self stringValue] propertyList];
  62. id colorNames=[dict allKeys];
  63. id colorValues=[dict objectsForKeys:colorNames notFoundMarker:nil];
  64. colorValues=[[colorValues collect] asMPWColor];
  65. return [NSDictionary dictionaryWithObjects:colorValues forKeys:colorNames];
  66. }
  67.  
  68.  
  69.  
  70. @end
  71. @interface Cmyk2SpotConverter : NSObject
  72. @end
  73.  
  74.  
  75. @implementation Cmyk2SpotConverter
  76.  
  77. -colorKey2NameDict:colorDict
  78. {
  79. id colorNames=[colorDict allKeys];
  80. id colors=[colorDict objectsForKeys:colorNames notFoundMarker:nil];
  81. colors = [[colors collect] keyColor];
  82. return [NSDictionary dictionaryWithObjects:colorNames forKeys:colors];
  83. }
  84.  
  85. -checkColors:dsc
  86. {
  87. id target;
  88.  
  89. target = [[MPWPSColorChecker alloc] initWithTarget:nil];
  90. [target processSourceObjects:dsc];
  91. return [[target colors] allObjects];
  92. }
  93.  
  94. -insertProcsetAndColors:colors into:dsc
  95. {
  96. id i;
  97. for (i=0;i<[dsc count];i++) {
  98. id obj=[dsc objectAtIndex:i];
  99. if ( ![obj isKindOfClass:[MPWDSCComment class]] && ![obj hasPrefix:@"%%+"] ) {
  100. [dsc insertObject:colors atIndex:i];
  101. [dsc insertObject:[MPWDownsamplingDumper frameworkResource:@"cmyk2spot" category:@"procset"] atIndex:i+1];
  102. break;
  103. }
  104. }
  105. return dsc;
  106. }
  107.  
  108. -colorsForNames:colorNames withMap:colorMap
  109. {
  110. id colorValues = [[colorNames collect] map:colorMap];
  111. id psValues = [[[colorValues collect] mappedWithName:[colorNames each]] componentsJoinedByString:@"\n"];
  112. return [NSString stringWithFormat:@"/_mwcustomcolors <<\n%@ >> def\n",psValues];
  113. }
  114.  
  115. - convertCmyk2Spot :filename
  116. {
  117. id file;
  118. id out = [MPWDSCByteStream Stdout];
  119. id colors;
  120. id uniqueColors;
  121. id uniqueColorSet;
  122. id colorList;
  123. id colorMap;
  124. id colorNames;
  125. id dsc;
  126. id foundColorMap;
  127.  
  128. [self logWithFormat:@"checking cmyk -> spot for file: %@",filename];
  129. file=[NSData dataWithContentsOfMappedFile:filename];
  130. file=[MPWEPSFile getEPSPartOfDOSEps: file];
  131. dsc=[MPWDSCScanner scan:file];
  132. colorList = [[NSData dataWithContentsOfFile:@"color-list"] parseColors];
  133. colorMap=[self colorKey2NameDict:colorList];
  134. colors = [self checkColors:file];
  135. uniqueColors=[[[[colors collect] keyColor] asSet] allObjects];
  136. colorNames=[[uniqueColors collect] map:colorMap];
  137. {
  138. id mappableColors = [[uniqueColors select] map:colorMap];
  139. id unmappableColors = [[uniqueColors asSet] mutableCopy];
  140. [unmappableColors minusSet:[mappableColors asSet]];
  141. [self logWithFormat:@"found following spot colors: %@ and following process-color (keys) with no spoteqivalent: %@",colorNames,[unmappableColors allObjects]];
  142. }
  143.  
  144.  
  145. // [self logWithFormat:@"spot colors: %@",colorNames];
  146. }
  147.  
  148.  
  149. - main: args
  150. {
  151. id result1,outname;
  152.  
  153. [self convertCmyk2Spot:[args objectAtIndex:1]];
  154. return 0;
  155. }
  156. @end
Add Comment
Please, Sign In to add comment