8
8
#define THUMB_SIZE 512.0
9
9
#define ASPECT 0.8 // aspect ratio
10
10
#define NUM_ROWS 18
11
- #define BADGE @" csv"
11
+ #define BADGE_CSV @" csv"
12
+ #define BADGE_TSV @" tab"
12
13
13
14
static CGContextRef createRGBABitmapContext (CGSize pixelSize);
14
15
// static CGContextRef createVectorContext(CGSize pixelSize)
@@ -51,7 +52,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
51
52
// Parse the data if still interested in the thumbnail
52
53
if (false == QLThumbnailRequestIsCancelled (thumbnail)) {
53
54
CGFloat rowHeight = ceilf (THUMB_SIZE / NUM_ROWS);
54
- CGFloat fontSize = roundf (0.666 * rowHeight);
55
+ CGFloat fontSize = roundf (0 .666f * rowHeight);
55
56
56
57
CSVDocument *csvDoc = [CSVDocument csvDoc ];
57
58
csvDoc.autoDetectSeparator = YES ;
@@ -60,8 +61,8 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
60
61
61
62
// Draw an icon if still interested in the thumbnail
62
63
if ((gotRows > 0 ) && (false == QLThumbnailRequestIsCancelled (thumbnail))) {
63
- CGRect maxBounds = CGRectMake (0.0 , 0.0 , THUMB_SIZE, THUMB_SIZE);
64
- CGRect usedBounds = CGRectMake (0.0 , 0.0 , 0.0 , 0.0 );
64
+ CGRect maxBounds = CGRectMake (0 .f , 0 .f , THUMB_SIZE, THUMB_SIZE);
65
+ CGRect usedBounds = CGRectMake (0 .f , 0 .f , 0 .f , 0 .f );
65
66
CGFloat badgeMaxSize = THUMB_SIZE;
66
67
67
68
CGContextRef context = createRGBABitmapContext (maxBounds.size );
@@ -70,27 +71,27 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
70
71
// CGPDFContextBeginPage(context, NULL);
71
72
72
73
// Flip CoreGraphics coordinate system
73
- CGContextScaleCTM (context, 1.0 , -1.0 );
74
+ CGContextScaleCTM (context, 1 .f , -1 .f );
74
75
CGContextTranslateCTM (context, 0 , -maxBounds.size .height );
75
76
76
77
// Create colors
77
- CGColorRef borderColor = CGColorCreateGenericRGB (0.67 , 0.67 , 0.67 , 1.0 );
78
- CGColorRef rowBG = CGColorCreateGenericRGB (1.0 , 1.0 , 1.0 , 1.0 );
79
- CGColorRef altRowBG = CGColorCreateGenericRGB (0.9 , 0.9 , 0.9 , 1.0 );
78
+ CGColorRef borderColor = CGColorCreateGenericRGB (0 .67f , 0 .67f , 0 .67f , 1 .f );
79
+ CGColorRef rowBG = CGColorCreateGenericRGB (1 .f , 1 .f , 1 .f , 1 .f );
80
+ CGColorRef altRowBG = CGColorCreateGenericRGB (0 .9f , 0 .9f , 0 .9f , 1 .f );
80
81
81
- CGFloat borderWidth = 1.0 ;
82
+ CGFloat borderWidth = 1 .f ;
82
83
83
84
// We use NSGraphicsContext for the strings due to easier string drawing :P
84
85
NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWithGraphicsPort: (void *)context flipped: YES ];
85
86
[NSGraphicsContext setCurrentContext: nsContext];
86
87
if (nil != nsContext) {
87
88
NSFont *myFont = [NSFont systemFontOfSize: fontSize];
88
- NSColor *rowTextColor = [NSColor colorWithCalibratedWhite: 0.25 alpha: 1.0 ];
89
+ NSColor *rowTextColor = [NSColor colorWithCalibratedWhite: 0 .25f alpha: 1 .f ];
89
90
NSDictionary *stringAttributes = [NSDictionary dictionaryWithObjectsAndKeys: myFont, NSFontAttributeName ,
90
91
rowTextColor, NSForegroundColorAttributeName , nil ];
91
92
92
- CGFloat textXPadding = 5.0 ;
93
- CGFloat cellX = 0.0 ;
93
+ CGFloat textXPadding = 5 .f ;
94
+ CGFloat cellX = 0 .f ;
94
95
CGFloat maxCellStringWidth;
95
96
96
97
// loop each column
@@ -99,8 +100,8 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
99
100
break ;
100
101
}
101
102
102
- CGRect rowRect = CGRectMake (cellX, 0.0 , maxBounds.size .width - cellX, rowHeight);
103
- maxCellStringWidth = 0.0 ;
103
+ CGRect rowRect = CGRectMake (cellX, 0 .f , maxBounds.size .width - cellX, rowHeight);
104
+ maxCellStringWidth = 0 .f ;
104
105
BOOL isFirstColumn = [csvDoc isFirstColumn: colKey];
105
106
BOOL altRow = NO ;
106
107
@@ -158,7 +159,7 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
158
159
159
160
CGFloat my_height = usedBounds.size .width * ASPECT;
160
161
if (usedBounds.size .height < my_height) {
161
- CGRect missingRect = CGRectMake (0.0 , usedBounds.size .height , ceilf (usedBounds.size .width ), ceilf (my_height - usedBounds.size .height ));
162
+ CGRect missingRect = CGRectMake (0 .f , usedBounds.size .height , ceilf (usedBounds.size .width ), ceilf (my_height - usedBounds.size .height ));
162
163
CGContextSetFillColorWithColor (context, rowBG);
163
164
CGContextFillRect (context, missingRect);
164
165
}
@@ -192,13 +193,13 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
192
193
NSGraphicsContext *thumbNsContext = [NSGraphicsContext graphicsContextWithGraphicsPort: (void *)thumbContext flipped: NO ];
193
194
[NSGraphicsContext setCurrentContext: thumbNsContext];
194
195
if (nil != thumbNsContext) {
195
- NSString *badgeString = BADGE ;
196
- CGFloat badgeFontSize = ceilf (badgeMaxSize * 0.28 );
196
+ NSString *badgeString = [ @" " isEqualToString: csvDoc.separator] ? BADGE_TSV : BADGE_CSV ;
197
+ CGFloat badgeFontSize = ceilf (badgeMaxSize * 0 .28f );
197
198
NSFont *badgeFont = [NSFont boldSystemFontOfSize: badgeFontSize];
198
- NSColor *badgeColor = [NSColor colorWithCalibratedRed: 0.05 green: 0.25 blue: 0.1 alpha: 1.0 ];
199
+ NSColor *badgeColor = [NSColor colorWithCalibratedRed: 0 .05f green: 0 .25f blue: 0 .1f alpha: 1 .f ];
199
200
NSShadow *badgeShadow = [[[NSShadow alloc ] init ] autorelease ];
200
- [badgeShadow setShadowOffset: NSMakeSize (0.0 , 0.0 )];
201
- [badgeShadow setShadowBlurRadius: badgeFontSize * 0.01 ];
201
+ [badgeShadow setShadowOffset: NSMakeSize (0 .f , 0 .f )];
202
+ [badgeShadow setShadowBlurRadius: badgeFontSize * 0 .01f ];
202
203
[badgeShadow setShadowColor: [NSColor whiteColor ]];
203
204
204
205
// Set attributes and draw
@@ -208,8 +209,8 @@ OSStatus GenerateThumbnailForURL(void *thisInterface, QLThumbnailRequestRef thum
208
209
209
210
NSSize badgeSize = [badgeString sizeWithAttributes: badgeAttributes];
210
211
CGFloat badge_x = (usedBounds.size .width / 2 ) - (badgeSize.width / 2 );
211
- CGFloat badge_y = 0.025 * badgeMaxSize;
212
- NSRect badgeRect = NSMakeRect (badge_x, badge_y, 0.0 , 0.0 );
212
+ CGFloat badge_y = 0 .025f * badgeMaxSize;
213
+ NSRect badgeRect = NSMakeRect (badge_x, badge_y, 0 .f , 0 .f );
213
214
badgeRect.size = badgeSize;
214
215
215
216
[badgeString drawWithRect: badgeRect options: NSStringDrawingUsesLineFragmentOrigin attributes: badgeAttributes];
@@ -269,7 +270,7 @@ static CGContextRef createRGBABitmapContext(CGSize pixelSize)
269
270
/*
270
271
static CGContextRef createVectorContext(CGSize pixelSize)
271
272
{
272
- CGRect mediaBox = CGRectMake(0.0 , 0.0 , 0.0 , 0.0 );
273
+ CGRect mediaBox = CGRectMake(0.f , 0.f , 0.f , 0.f );
273
274
mediaBox.size = pixelSize;
274
275
275
276
// allocate needed bytes
0 commit comments