Skip to content

Commit

Permalink
Update Core/Source/DTTextAttachment.m
Browse files Browse the repository at this point in the history
Added support for rootPAth
  • Loading branch information
navisingh committed Jan 26, 2013
1 parent ee5a0a2 commit 84e67df
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions Core/Source/DTTextAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ + (DTTextAttachment *)textAttachmentWithElement:(DTHTMLElement *)element options

// get base URL
NSURL *baseURL = [options objectForKey:NSBaseURLDocumentOption];
NSString *rootPath = [options objectForKey:DTRootPath];

// decode URL
NSString *src = [element attributeForKey:@"src"];
Expand Down Expand Up @@ -110,19 +111,33 @@ + (DTTextAttachment *)textAttachmentWithElement:(DTHTMLElement *)element options
if (![contentURL scheme])
{
// possibly a relative url
if (baseURL)
{
contentURL = [NSURL URLWithString:src relativeToURL:baseURL];
}
else
{
do {
if (baseURL)
{
contentURL = [NSURL URLWithString:src relativeToURL:baseURL];

if ([contentURL isFileURL])
if([[NSFileManager defaultManager] fileExistsAtPath:[contentURL path]])
break;
}
if(rootPath)
{
NSString *imageFile = [rootPath stringByAppendingPathComponent:src];
if([[NSFileManager defaultManager] fileExistsAtPath:imageFile]) {
imageFile = [@"file://" stringByAppendingString:imageFile];
imageFile = [imageFile stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imageFile = [imageFile stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
contentURL = [NSURL URLWithString:imageFile];
break;
}
}
// file in app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:src ofType:nil];
if (path) {
// Prevent a crash if path turns up nil.
contentURL = [NSURL fileURLWithPath:path];
contentURL = [NSURL fileURLWithPath:path];
}
}
} while (false);
}
}

Expand All @@ -137,7 +152,8 @@ + (DTTextAttachment *)textAttachmentWithElement:(DTHTMLElement *)element options
// inspect local file
if ([contentURL isFileURL])
{
DTImage *image = [[DTImage alloc] initWithContentsOfFile:[contentURL path]];
NSString *imagePath = [contentURL path];
DTImage *image = [[DTImage alloc] initWithContentsOfFile:imagePath];
originalSize = image.size;

if (!displaySize.width || !displaySize.height)
Expand Down

0 comments on commit 84e67df

Please sign in to comment.