mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-29 09:52:03 +00:00
CPImage: Preserve theme values across archiving
System images defined by a theme failed to propagate into built theme blends. Because the blend task archives each themed object and records the decoded copy, CPImage's coder—which omitted theme values—stripped them during serialization, leaving the compiled Aristo3 theme without image attributes. CPImage now encodes its theme values when present and decodes them when available in the archive, matching the behavior of CPColor and CPFont. Images without theme values serialize unchanged, preserving backward compatibility with existing archives.
This commit is contained in:
1 parent
25527b47b7
commit
45765ebe55
2 files changed
+34
No files matched your search
@@ -522,3 +522,11 @@ var NULL_THEME = {};
|
||||
|
||||
|
||||
@end
|
||||
|
||||
/*
|
||||
Returns YES when aCoder holds the theme objects that -_encodeThemeObjectsWithCoder: writes.
|
||||
*/
|
||||
function _CPCoderContainsThemeObjects(aCoder)
|
||||
{
|
||||
return [aCoder containsValueForKey:CPViewThemeClassKey];
|
||||
}
|
||||
@@ -17,4 +17,30 @@
|
||||
[self assert:nil equals:image message:@"- CPImage initWithContentsOfFile:nil should return nil"];
|
||||
}
|
||||
|
||||
// MARK: Archiving
|
||||
|
||||
/*
|
||||
A theme records its system images on a CPImage, and the blend task archives that image
|
||||
before it records it. The theme values therefore survive archiving.
|
||||
*/
|
||||
- (void)testAnImageKeepsItsThemeValuesThroughArchiving
|
||||
{
|
||||
var image = [[CPImage alloc] init],
|
||||
value = [CPImage imageWithCSSDictionary:@{ "background-color": "red" } size:CGSizeMake(24.0, 24.0)];
|
||||
|
||||
[image setValue:value forThemeAttribute:@"font-panel"];
|
||||
|
||||
var decoded = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:image]];
|
||||
|
||||
[self assert:[value cssDictionary] equals:[[decoded valueForThemeAttribute:@"font-panel"] cssDictionary]];
|
||||
}
|
||||
|
||||
- (void)testAnImageWithoutThemeValuesArchivesNoThemeObjects
|
||||
{
|
||||
var image = [CPImage imageWithCSSDictionary:@{ "background-color": "red" } size:CGSizeMake(24.0, 24.0)],
|
||||
data = [CPKeyedArchiver archivedDataWithRootObject:image];
|
||||
|
||||
[self assertFalse:[[data rawString] containsString:@"CPViewThemeClassKey"]];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user