diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-06-19 16:43:46 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-06-19 16:43:46 +0000 |
commit | 77d8891b8b3dd3321eac871da0bde6fe1f38ea94 (patch) | |
tree | cce58051c81aaac79f23b7a68832fc682c1217f7 /Source/TableContent.m | |
parent | ad4dd380f0361475badfd33ea9ae9e586d39ed10 (diff) | |
download | sequelpro-77d8891b8b3dd3321eac871da0bde6fe1f38ea94.tar.gz sequelpro-77d8891b8b3dd3321eac871da0bde6fe1f38ea94.tar.bz2 sequelpro-77d8891b8b3dd3321eac871da0bde6fe1f38ea94.zip |
• added: SPDataAdditions.m
- base64EncodingWithLineLength:
• improved printing of blobs which contain image data
- not it supports PDF preview
- set maximum width to 100px or less
Diffstat (limited to 'Source/TableContent.m')
-rw-r--r-- | Source/TableContent.m | 74 |
1 files changed, 8 insertions, 66 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m index 319b46ae..06f7899a 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -38,17 +38,10 @@ #import "SPStringAdditions.h" #import "SPArrayAdditions.h" #import "SPTextViewAdditions.h" +#import "SPDataAdditions.h" #import "QLPreviewPanel.h" -static char encodingTable[64] = { -'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', -'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', -'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', -'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; - - - @implementation TableContent /** @@ -1291,7 +1284,7 @@ static char encodingTable[64] = { [tempRow removeAllObjects]; enumerator = [tableColumns objectEnumerator]; while ( (tableColumn = [enumerator nextObject]) ) { - id o = [[fullResult objectAtIndex:i] objectForKey:[[tableColumn headerCell] stringValue]]; + id o = [NSArrayObjectAtIndex(fullResult, i) objectForKey:[[tableColumn headerCell] stringValue]]; if([o isKindOfClass:[NSNull class]]) [tempRow addObject:@"NULL"]; else if([o isKindOfClass:[NSString class]]) @@ -1299,7 +1292,12 @@ static char encodingTable[64] = { else { NSImage *image = [[NSImage alloc] initWithData:o]; if(image) { - [tempRow addObject:[NSString stringWithFormat:@"<IMG WIDTH='100' SRC=\"data:image/auto;base64,%@\">", [self base64EncodingOfData: o withLineLength:0]]]; + int imageWidth = [image size].width; + if (imageWidth > 100) imageWidth = 100; + [tempRow addObject:[NSString stringWithFormat: + @"<IMG WIDTH='%d' SRC=\"data:image/auto;base64,%@\">", + imageWidth, + [[image TIFFRepresentationUsingCompression:NSTIFFCompressionJPEG factor:0.01] base64EncodingWithLineLength:0]]]; } else { [tempRow addObject:@"<BLOB>"]; } @@ -1311,62 +1309,6 @@ static char encodingTable[64] = { return currentResult; } -- (NSString *) base64EncodingOfData:(NSData*)data withLineLength:(unsigned int)lineLength { - const unsigned char *bytes = [data bytes]; - NSMutableString *result = [NSMutableString stringWithCapacity:[data length]]; - unsigned long ixtext = 0; - unsigned long lentext = [data length]; - long ctremaining = 0; - unsigned char inbuf[3], outbuf[4]; - short i = 0; - short charsonline = 0, ctcopy = 0; - unsigned long ix = 0; - - while( YES ) { - ctremaining = lentext - ixtext; - if( ctremaining <= 0 ) break; - - for( i = 0; i < 3; i++ ) { - ix = ixtext + i; - if( ix < lentext ) inbuf[i] = bytes[ix]; - else inbuf [i] = 0; - } - - outbuf [0] = (inbuf [0] & 0xFC) >> 2; - outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4); - outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6); - outbuf [3] = inbuf [2] & 0x3F; - ctcopy = 4; - - switch( ctremaining ) { - case 1: - ctcopy = 2; - break; - case 2: - ctcopy = 3; - break; - } - - for( i = 0; i < ctcopy; i++ ) - [result appendFormat:@"%c", encodingTable[outbuf[i]]]; - - for( i = ctcopy; i < 4; i++ ) - [result appendFormat:@"%c",'=']; - - ixtext += 3; - charsonline += 4; - - if( lineLength > 0 ) { - if (charsonline >= lineLength) { - charsonline = 0; - [result appendString:@"\n"]; - } - } - } - - return result; -} - //getter methods - (NSArray *)currentResult /* |