[Drawkit] SVG / other file format support

Brad Larson larson at sonoplot.com
Tue May 13 16:11:33 PDT 2008


On May 13, 2008, at 4:33 PM, Ken Ferry wrote:

> You might want to look to NSAttributedString as a model.  It's been
> through a few iterations as people needed more from it.  The most
> generic methods are
>
> - (id)initWithURL:(NSURL *)url options:(NSDictionary *)options
> documentAttributes:(NSDictionary **)dict error:(NSError **)error;
> - (id)initWithData:(NSData *)data options:(NSDictionary *)options
> documentAttributes:(NSDictionary **)dict error:(NSError **)error;
>
> - (NSData *)dataFromRange:(NSRange)range
> documentAttributes:(NSDictionary *)dict error:(NSError **)error;
> - (NSFileWrapper *)fileWrapperFromRange:(NSRange)range
> documentAttributes:(NSDictionary *)dict error:(NSError **)error;
>
> The options control how the file or data is read, while the document
> attributes describe metadata and other information about the document.
> File type is one of the document attributes, identified by UTI.
>

Unless I'm missing something, it seems like placing the file input  
processing in readFromURL:ofType:error: would accomplish the same  
things as the NSAttributedString methods you cite.  We would use the  
readFromURL method as a jumping-off point based on the file type or  
extension (I'm starting to lean more toward file type, as that might  
be more robust).  By using a selector that's determined at runtime, a  
user could easily add their file type via a category.

Also, I now see that you can do a performSelector to get to class  
methods, so we should be able to do class-based convenience  
constructors like is done in DrawKit now.

> A file wrapper lets you deal with bundle-based file formats.  The
> NSErrors provide nice user-presentable explanations of problems
> reading or writing the specified format.
>
> -Ken
>


Good call on the file bundles.  I know that Lineform uses them to deal  
with images or other external resources.  Again, that should be able  
to be handled by passing the URL to the filetype-specific category  
methods.

You also have a point with NSError.  I just retrofitted NSError  
handling capabilities into an application and found that it does a  
beautiful job at presenting errors to the end user and recovering from  
those errors.  It's best to add this in early, rather than have to  
shoehorn it in later on.  Aside from file loading / saving, I'd have  
to think of where else you'd run into errors in the course of normal  
drawing operations.

______________________
Brad Larson
SonoPlot, Inc.
3030 Laura Lane, Suite 120
Middleton, WI 53562





More information about the Drawkit mailing list