Skip to content

Commit 4570e53

Browse files
committed
Improvements to the thumbnail generation
1 parent 1aa8136 commit 4570e53

File tree

4 files changed

+822
-2530
lines changed

4 files changed

+822
-2530
lines changed

GenerateThumbnailForURL.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
4848
NSUInteger numRows = ceilf(thumbnailSize / rowHeight);
4949

5050
CSVDocument *csvDoc = [CSVDocument csvDoc];
51-
[csvDoc numRowsFromCSVString:fileString maxRows:numRows error:NULL];
51+
NSUInteger gotRows = [csvDoc numRowsFromCSVString:fileString maxRows:numRows error:NULL];
5252

5353

5454
// Draw an icon if still interested in the thumbnail
5555
if(false == QLThumbnailRequestIsCancelled(thumbnail)) {
56-
CGRect myBounds = CGRectMake(0.0, 0.0, thumbnailSize, thumbnailSize);
56+
CGFloat startY = 0.0;
57+
if(gotRows < numRows) {
58+
startY = thumbnailSize - gotRows * rowHeight;
59+
}
60+
CGRect myBounds = CGRectMake(0.0, startY, thumbnailSize, thumbnailSize);
5761
CGContextRef context = QLThumbnailRequestCreateContext(thumbnail, myBounds.size, false, NULL);
5862

5963
// Draw a mini table
@@ -81,12 +85,15 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
8185
blackColor, NSForegroundColorAttributeName, nil];
8286

8387
CGFloat textXPadding = 5.0;
84-
CGFloat cellX = -2 * textXPadding;
88+
CGFloat cellX = 0.0;
8589
CGFloat maxCellStringWidth = 0.0;
8690

8791
// We loop each cell, row by row for each column
8892
for(NSString *colKey in csvDoc.columnKeys) {
89-
cellX += maxCellStringWidth + 2 * textXPadding;
93+
if(cellX > myBounds.size.width) {
94+
break;
95+
}
96+
9097
CGRect rowRect = CGRectMake(cellX, 0.0, myBounds.size.width - cellX, rowHeight);
9198
maxCellStringWidth = 0.0;
9299
BOOL altRow = NO;
@@ -117,6 +124,17 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
117124
altRow = !altRow;
118125
rowRect.origin.y += rowHeight;
119126
}
127+
128+
cellX += maxCellStringWidth + 2 * textXPadding;
129+
}
130+
131+
// Crop the thumbnail if we didn't use the whole width
132+
if(cellX < myBounds.size.width) {
133+
myBounds.size.width -= cellX;
134+
CGRect clearRect = CGRectMake(cellX, 0.0, myBounds.size.width, myBounds.size.height);
135+
CGContextClearRect(context, clearRect);
136+
137+
// we should now center the thumbnail in our context or crop the context somehow...
120138
}
121139
}
122140

Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<key>QLPreviewWidth</key>
5757
<real>800</real>
5858
<key>QLSupportsConcurrentRequests</key>
59-
<false/>
59+
<true/>
6060
<key>QLThumbnailMinimumSize</key>
6161
<real>17</real>
6262
</dict>

0 commit comments

Comments
 (0)