Skip to content

Instantly share code, notes, and snippets.

@wooster
Last active August 29, 2015 14:01
Show Gist options
  • Save wooster/e6b1d1afa7d0d91da311 to your computer and use it in GitHub Desktop.
Save wooster/e6b1d1afa7d0d91da311 to your computer and use it in GitHub Desktop.
Strange CGPDFBoolean Stuff
// Simple object, not an array or dictionary.
- (void)pushObject:(NSObject *)object withKey:(NSString *)key {
NSObject *last = [stack lastObject];
if ([last isKindOfClass:[NSMutableDictionary class]]) {
NSMutableDictionary *dictionary = (NSMutableDictionary *)last;
// Exception raised here.
// *** setObjectForKey: object cannot be nil (key: BaseFont)
[dictionary setObject:object forKey:key];
} else if ([last isKindOfClass:[NSMutableArray class]]) {
NSMutableArray *array = (NSMutableArray *)last;
[array addObject:object];
}
}
- (void)scanPDFNode:(const char *)cStringKey context:(MMPDFScannerContext *)context object:(CGPDFObjectRef)object dictionary:(CGPDFDictionaryRef)dictionaryRef isArray:(BOOL)isArray {
NSString *key = [NSString stringWithUTF8String:cStringKey];
CGPDFObjectType type = CGPDFObjectGetType(object);
switch (type) {
case kCGPDFObjectTypeNull:
[self pushObject:[NSNull null] withKey:key];
break;
case kCGPDFObjectTypeBoolean:
{
CGPDFBoolean pdfBoolean;
if (CGPDFObjectGetValue(object, type, &pdfBoolean)) {
// Exception raised inside -pushObject:withKey: from this path.
[self pushObject:[NSNumber numberWithBool:(BOOL)pdfBoolean] withKey:key];
}
break;
}
...
@wooster
Copy link
Author

wooster commented May 21, 2014

All of this happening inside a CGPDFDictionaryApplyFunction applier function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment