Skip to content

Commit

Permalink
Merge pull request jaketmp#32 from chrisridd/master
Browse files Browse the repository at this point in the history
Correctly handle hrefs containing spaces (issue 31)
  • Loading branch information
jaketmp committed May 6, 2012
2 parents 6ee60aa + cfeca06 commit dd4125a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions JTPepub/JTPepub.m
Expand Up @@ -151,7 +151,8 @@ - (NSString *)textFromManifestItem:(NSUInteger)n
return nil; return nil;


NSString *contentRoot = [rootFilePath stringByDeletingLastPathComponent]; NSString *contentRoot = [rootFilePath stringByDeletingLastPathComponent];
NSArray *textPathArray = [NSArray arrayWithObjects:contentRoot, [manifest objectAtIndex:n], nil]; NSString *relativePath = [[manifest objectAtIndex:n] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSArray *textPathArray = [NSArray arrayWithObjects:contentRoot, relativePath, nil];
NSString *path = [NSString pathWithComponents:textPathArray]; NSString *path = [NSString pathWithComponents:textPathArray];


NSData *content = [epubFile dataForNamedFile:path]; NSData *content = [epubFile dataForNamedFile:path];
Expand Down Expand Up @@ -417,7 +418,7 @@ - (NSImage *)cover




NSError *xmlError = nil; NSError *xmlError = nil;
NSString *coverPath = nil; NSString *coverURI = nil;
//NSString *coverMIME = nil; //NSString *coverMIME = nil;


/* /*
Expand All @@ -436,7 +437,7 @@ - (NSImage *)cover
if (metaElements != nil) { if (metaElements != nil) {


// There may only be one "cover-image" so take the last element of the array. // There may only be one "cover-image" so take the last element of the array.
coverPath = [[[metaElements lastObject] attributeForName:@"href"] stringValue]; coverURI = [[[metaElements lastObject] attributeForName:@"href"] stringValue];
//coverMIME = [[[metaElements lastObject] attributeForName:@"media-type"] stringValue]; //coverMIME = [[[metaElements lastObject] attributeForName:@"media-type"] stringValue];




Expand All @@ -448,8 +449,8 @@ - (NSImage *)cover
* not specified. * not specified.
*/ */


// Don't look for the coverPath if we already found it above. // Don't look for the coverURI if we already found it above.
if (coverPath == nil) { if (coverURI == nil) {
// scan for a <meta> element with name="cover" // scan for a <meta> element with name="cover"
NSArray *metaElements = [opfXML nodesForXPath:@"//opf:meta" NSArray *metaElements = [opfXML nodesForXPath:@"//opf:meta"
namespaces:xmlns namespaces:xmlns
Expand Down Expand Up @@ -483,7 +484,7 @@ - (NSImage *)cover
NSString *itemID = [[item attributeForName:@"id"] stringValue]; NSString *itemID = [[item attributeForName:@"id"] stringValue];


if([itemID caseInsensitiveCompare:coverID] == NSOrderedSame) { if([itemID caseInsensitiveCompare:coverID] == NSOrderedSame) {
coverPath = [[item attributeForName:@"href"] stringValue]; coverURI = [[item attributeForName:@"href"] stringValue];
//coverMIME = [[item attributeForName:@"media-type"] stringValue]; //coverMIME = [[item attributeForName:@"media-type"] stringValue];
break; break;
} }
Expand All @@ -494,14 +495,14 @@ - (NSImage *)cover
* Image loading code is generic for epub2/3 * Image loading code is generic for epub2/3
*/ */


if(coverPath == nil) { if(coverURI == nil) {
haveCheckedForCover = YES; haveCheckedForCover = YES;
return nil; // No cover in this epub. return nil; // No cover in this epub.
} }



// The cover path is relative to the rootfile... // The cover path is relative to the rootfile...
NSString *contentRoot = [rootFilePath stringByDeletingLastPathComponent]; NSString *contentRoot = [rootFilePath stringByDeletingLastPathComponent];
NSString *coverPath = [coverURI stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSArray *coverPathArray = [NSArray arrayWithObjects:contentRoot, coverPath, nil]; NSArray *coverPathArray = [NSArray arrayWithObjects:contentRoot, coverPath, nil];
NSString *fullCoverPath = [NSString pathWithComponents:coverPathArray]; NSString *fullCoverPath = [NSString pathWithComponents:coverPathArray];


Expand Down

0 comments on commit dd4125a

Please sign in to comment.