5 // Created by Christian Brunschen on 22/05/2008.
7 * Copyright 2008 ZXing authors
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
22 #import "ParsedResult.h"
24 #import "TextParsedResult.h"
25 #import "TelParsedResult.h"
26 #import "EmailParsedResult.h"
27 #import "BusinessCardParsedResult.h"
28 #import "URIParsedResult.h"
29 #import "GeoParsedResult.h"
31 #import "UIKit/UIStringDrawing.h"
34 @implementation ParsedResult
36 static NSMutableDictionary *iconsByClass = nil;
38 + (NSString *)typeName {
39 return NSStringFromClass(self);
42 - (NSString *)stringForDisplay {
47 #define ICON_INSIDE 36
50 if (iconsByClass == nil) {
51 iconsByClass = [[NSMutableDictionary alloc] initWithCapacity:16];
53 UIImage *icon = [iconsByClass objectForKey:[self class]];
55 UIGraphicsBeginImageContext(CGSizeMake(ICON_SIZE, ICON_SIZE));
56 CGContextRef ctx = UIGraphicsGetCurrentContext();
58 [[UIColor lightGrayColor] set];
59 UIRectFill(CGRectMake(0, 0, ICON_SIZE, ICON_SIZE));
61 [[UIColor blackColor] set];
62 NSString *s = [[self class] typeName];
63 UIFont *font = [UIFont systemFontOfSize:16];
64 CGSize stringSize = [s sizeWithFont:font];
65 float xScale = fminf(1.0, ICON_INSIDE / stringSize.width);
66 float yScale = fminf(1.0, ICON_INSIDE / stringSize.height);
68 CGContextTranslateCTM(ctx, (ICON_SIZE / 2), (ICON_SIZE / 2));
69 CGContextRotateCTM(ctx, -M_PI / 6.0);
70 CGContextScaleCTM(ctx, xScale, yScale);
71 CGContextTranslateCTM(ctx,
72 -(stringSize.width)/2.0,
73 -(stringSize.height)/2.0);
75 [s drawAtPoint:CGPointMake(0, 0) withFont:font];
77 icon = [UIGraphicsGetImageFromCurrentImageContext() retain];
78 [iconsByClass setObject:icon forKey:[self class]];
79 UIGraphicsEndImageContext();
85 return [[self class] icon];
88 - (NSArray *)actions {
90 actions = [[NSMutableArray alloc] init];
91 [self populateActions];
96 - (void) populateActions {