plist <data> support. NSColor unarchiving for nib2cib.

This commit is contained in:
Tom Robinson
2008-12-19 00:48:13 -08:00
parent f7571f83c8
commit 059456571d
5 changed files with 116 additions and 12 deletions
+17 -1
View File
@@ -316,7 +316,7 @@ var _CPKeyedUnarchiverArrayClass = Ni
if ([object isKindOfClass:_CPKeyedUnarchiverDictionaryClass])
return _CPKeyedUnarchiverDecodeObjectAtIndex(self, [object objectForKey:_CPKeyedArchiverUIDKey]);
else if ([object isKindOfClass:[CPNumber class]])
else if ([object isKindOfClass:[CPNumber class]] || [object isKindOfClass:[CPData class]])
return object;
/* else
alert([object className] + " " + object + " " + aKey + " " + [_plistObject description]);*/
@@ -324,6 +324,22 @@ var _CPKeyedUnarchiverArrayClass = Ni
return nil;
}
/*
Decodes bytes from the archive.
@param aKey the object's associated key
@return array of bytes
*/
- (id)decodeBytesForKey:(CPString)aKey
{
// We get the CPData wrapper, then extract the bytes array
var data = [self decodeObjectForKey:aKey];
if ([data isKindOfClass:[CPData class]])
return data.bytes;
return nil;
}
/*
Notifies the delegates that decoding has finished.
*/
+2 -1
View File
@@ -360,7 +360,8 @@ function CPPropertyListCreateFromXMLData(XMLNodeOrData)
case PLIST_BOOLEAN_FALSE: object = false;
break;
case PLIST_DATA: object = FIRST_CHILD(XMLNode) ? CHILD_VALUE(XMLNode) : ""; // FIXME: temporary fix for NIBs with <data> tags
case PLIST_DATA: object = new objj_data();
object.bytes = FIRST_CHILD(XMLNode) ? base64_decode_to_array(CHILD_VALUE(XMLNode), true) : [];
break;
default: objj_exception_throw(new objj_exception(OBJJPlistParseException, "*** " + NODE_NAME(XMLNode) + " tag not recognized in Plist."));
+7 -1
View File
@@ -254,7 +254,13 @@ function base64_encode_array(input)
function base64_decode_to_string(input, strip)
{
return String.fromCharCode.apply(null, base64_decode_to_array(input, strip));
return bytes_to_string(base64_decode_to_array(input, strip));
}
function bytes_to_string(bytes)
{
// This is relatively efficient, I think:
return String.fromCharCode.apply(null, bytes);
}
function base64_encode_string(input)
+7 -7
View File
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">352.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="1" id="9"/>
<integer value="106"/>
<integer value="13"/>
<integer value="15"/>
</object>
@@ -146,7 +146,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="12" id="779933340"/>
<reference ref="779933340"/>
<reference ref="9"/>
<integer value="1" id="9"/>
</object>
</object>
</object>
@@ -380,7 +380,7 @@
<bool key="NSIsNotContinuous">YES</bool>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4wNTgxMzA0OTkgMC4wNTU1NDE4OTkgMQA</bytes>
<bytes key="NSRGB">MC4zNzUyMzAzNyAwLjQ1NjE5NzE0IDEAA</bytes>
</object>
</object>
<object class="NSColorWell" id="426656007">
@@ -398,7 +398,7 @@
<bool key="NSEnabled">YES</bool>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4wNTgxMzA0OTkgMC4wNTU1NDE4OTkgMQA</bytes>
<bytes key="NSRGB">MSAwLjE3MjgzOTUyIDAuMTcyODM5NTIAA</bytes>
</object>
</object>
<object class="NSButton" id="684874808">
@@ -3327,7 +3327,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{199, 438}, {480, 303}}</string>
<string>{{438, 741}, {480, 303}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{628, 654}</string>
<string>{{257, 484}, {480, 272}}</string>
@@ -3352,7 +3352,7 @@
<string>{{56, 843}, {299, 193}}</string>
<reference ref="9"/>
<string>{{115, 207}, {299, 193}}</string>
<integer value="0"/>
<integer value="0" id="8"/>
<reference ref="9"/>
<string>{299, 193}</string>
<string>{299, 193}</string>
@@ -3373,7 +3373,7 @@
<string>{{0, 822}, {276, 323}}</string>
<reference ref="9"/>
<string>{{118, 105}, {276, 323}}</string>
<integer value="0"/>
<reference ref="8"/>
<string>{3.40282e+38, 3.40282e+38}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+83 -2
View File
@@ -2,6 +2,9 @@
* NSColor.j
* nib2cib
*
* Portions based on NSColor.m (12/18/2008) in Cocotron (http://www.cocotron.org/)
* Copyright (c) 2006-2007 Christopher J. W. Lloyd
*
* Created by Thomas Robinson.
* Copyright 2008, 280 North, Inc.
*
@@ -35,8 +38,86 @@ var NSUnknownColorSpaceModel = -1,
- (id)NS_initWithCoder:(CPCoder)aCoder
{
//var colorSpace = [aCoder decodeIntForKey:@"NSColorSpace"];
return self = [CPColor blueColor];
var colorSpace = [aCoder decodeIntForKey:@"NSColorSpace"],
result;
switch (colorSpace)
{
case 1: // [NSColor colorWithCalibratedRed:values[0] green:values[1] blue:values[2] alpha:values[3]];
case 2: // [NSColor colorWithDeviceRed:values[0] green:values[1] blue:values[2] alpha:values[3]];
// NSComponents data
// NSCustomColorSpace NSColorSpace
var rgb = [aCoder decodeBytesForKey:@"NSRGB"],
string = bytes_to_string(rgb),
components = [string componentsSeparatedByString:@" "],
values = [0,0,0,1];
for (var i = 0; i < components.length && i < 4; i++)
values[i] = [components[i] floatValue];
CPLog.warn("rgb="+rgb+" string=" + string + " values=" + values);
result = [CPColor colorWithCalibratedRed:values[0] green:values[1] blue:values[2] alpha:values[3]];
break;
case 3: // [NSColor colorWithCalibratedWhite:values[0] alpha:values[1]];
case 4: // [NSColor colorWithDeviceWhite:values[0] alpha:values[1]];
var bytes = [aCoder decodeBytesForKey:@"NSWhite"],
string = bytes_to_string(rgb),
components = [string componentsSeparatedByString:@" "],
values = [0,1];
for (var i = 0; i < components.length && i < 2; i++)
values[i] = [components[i] floatValue];
result = [CPColor colorWithCalibratedWhite:values[0] alpha:values[1]];
break;
/*
case 5:
var cmyk = [aCoder decodeBytesForKey:@"NSCMYK"],
string = bytes_to_string(rgb),
components = [string componentsSeparatedByString:@" "],
values = [0,0,0,0,1];
for (var i = 0; i < components.length && i < 5; i++)
values[i] = [components[i] floatValue];
result = [CPColor colorWithDeviceCyan:values[0] magenta:values[1] yellow:values[2] black:values[3] alpha:values[4]];
break;
*/
case 6:
var catalogName = [aCoder decodeObjectForKey:@"NSCatalogName"],
colorName = [aCoder decodeObjectForKey:@"NSColorName"],
color = [aCoder decodeObjectForKey:@"NSColor"];
// We don't having color mappings implemented, so just use the cached NSColor
if (catalogName === @"System")
{
var //display = [NSDisplay currentDisplay],
result = null;//[display colorWithName: colorName];
if (!result)
{
result = color;
//[display _addSystemColor: result forName: colorName];
}
}
else
{
result = null;//[CPColor colorWithCatalogName: catalogName colorName: colorName];
if (!result)
result = color;
}
break;
default:
CPLog(@"-[%@ %s] unknown color space %d", isa, _cmd, colorSpace);
result = [CPColor blackColor];
break;
}
return result;
}
@end