@@ -48,12 +48,16 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
48
48
NSUInteger numRows = ceilf (thumbnailSize / rowHeight);
49
49
50
50
CSVDocument *csvDoc = [CSVDocument csvDoc ];
51
- [csvDoc numRowsFromCSVString: fileString maxRows: numRows error: NULL ];
51
+ NSUInteger gotRows = [csvDoc numRowsFromCSVString: fileString maxRows: numRows error: NULL ];
52
52
53
53
54
54
// Draw an icon if still interested in the thumbnail
55
55
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);
57
61
CGContextRef context = QLThumbnailRequestCreateContext (thumbnail, myBounds.size , false , NULL );
58
62
59
63
// Draw a mini table
@@ -81,12 +85,15 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
81
85
blackColor, NSForegroundColorAttributeName , nil ];
82
86
83
87
CGFloat textXPadding = 5.0 ;
84
- CGFloat cellX = - 2 * textXPadding ;
88
+ CGFloat cellX = 0.0 ;
85
89
CGFloat maxCellStringWidth = 0.0 ;
86
90
87
91
// We loop each cell, row by row for each column
88
92
for (NSString *colKey in csvDoc.columnKeys ) {
89
- cellX += maxCellStringWidth + 2 * textXPadding;
93
+ if (cellX > myBounds.size .width ) {
94
+ break ;
95
+ }
96
+
90
97
CGRect rowRect = CGRectMake (cellX, 0.0 , myBounds.size .width - cellX, rowHeight);
91
98
maxCellStringWidth = 0.0 ;
92
99
BOOL altRow = NO ;
@@ -117,6 +124,17 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
117
124
altRow = !altRow;
118
125
rowRect.origin .y += rowHeight;
119
126
}
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...
120
138
}
121
139
}
122
140
0 commit comments