-
Notifications
You must be signed in to change notification settings - Fork 443
Add PDF extraction support #24
base: master
Are you sure you want to change the base?
Conversation
@interface CUICatalog : NSObject | ||
|
||
@property(readonly) bool isVectorBased; | ||
|
||
-(id)initWithURL:(id)arg1 error:(id*)arg2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This initializer replaces the need to use the CUIThemeFacet
(in my limited testing)
|
||
struct CGPDFDocument *pdfDocument = [catalog pdfDocumentWithName:key]; | ||
|
||
if (pdfDocument) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a PDF document, I'm skipping the extraction of the generated raster images and only extracting the PDF
return images; | ||
} | ||
|
||
void writePDFtoFile(struct CGPDFDocument *pdfDocument, NSString *path, NSString *key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super familiar with CGPDFDocument
, but I cobbled this together from a few answers on Stack Overflow and pastern and it hasn't failed me yet
/* Override CUICatalog to point to a file rather than a bundle */ | ||
[catalog setValue:facet forKey:@"_storageRef"]; | ||
|
||
carPath = [carPath stringByExpandingTildeInPath]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well expand this path too
@@ -185,8 +215,19 @@ void exportCarFileAtPath(NSString * carPath, NSString *outputDirectoryPath) | |||
NSMutableArray *images = getImagesArray(catalog, key); | |||
for( CUINamedImage *image in images ) | |||
{ | |||
if( CGSizeEqualToSize(image.size, CGSizeZero) ) | |||
if ( ![image respondsToSelector:@selector(size)]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if
statement is kinda sloppy — I wish I could do something like if ( ![image isKindOfClass:[CGPDFDocument class]])
, but of course CGPDFDocument
isn't a class and I don't think there's any way to check the struct type at runtime. Wonder if you know of anything better.
This change adds PDF extraction support.
I only tested it on one
Assets.car
file and it extracted the PDFs successfully. Could use some extra testing. Feedback welcome or feel free to push directly to my fork.