1.1 --- a/Source/GGBTextLayer.m Mon Mar 10 17:30:57 2008 -0700
1.2 +++ b/Source/GGBTextLayer.m Wed Mar 12 15:51:32 2008 -0700
1.3 @@ -18,17 +18,36 @@
1.4 fontSize: (float) fontSize
1.5 alignment: (enum CAAutoresizingMask) align
1.6 {
1.7 +#if TARGET_OS_ASPEN
1.8 + UIFont *font = [UIFont systemFontOfSize: fontSize];
1.9 +#else
1.10 + NSFont *font = [NSFont systemFontOfSize: fontSize];
1.11 +#endif
1.12 + return [self textLayerInSuperlayer: superlayer
1.13 + withText: text
1.14 + font: font
1.15 + alignment: align];
1.16 +}
1.17 +
1.18 +
1.19 ++ (GGBTextLayer*) textLayerInSuperlayer: (CALayer*)superlayer
1.20 + withText: (NSString*)text
1.21 + font: (id)inputFont
1.22 + alignment: (enum CAAutoresizingMask) align
1.23 +{
1.24 GGBTextLayer *label = [[self alloc] init];
1.25 label.string = text;
1.26
1.27 #if TARGET_OS_ASPEN
1.28 - UIFont *font = [UIFont systemFontOfSize: fontSize];
1.29 + UIFont *font = inputFont;
1.30 + [label setNeedsDisplay];
1.31 + label.needsDisplayOnBoundsChange = YES;
1.32 #else
1.33 - NSFont *font = [NSFont systemFontOfSize: fontSize];
1.34 - label.font = font;
1.35 + NSFont *font = inputFont;
1.36 + label.fontSize = font.pointSize;
1.37 #endif
1.38
1.39 - label.fontSize = fontSize;
1.40 + label.font = font;
1.41 label.foregroundColor = kBlackColor;
1.42
1.43 NSString *mode;
1.44 @@ -45,29 +64,116 @@
1.45 if( [superlayer respondsToSelector: @selector(borderWidth)] )
1.46 inset += ((GGBLayer*)superlayer).borderWidth;
1.47 CGRect bounds = CGRectInset(superlayer.bounds, inset, inset);
1.48 + if( mode==@"center" )
1.49 + bounds = CGRectInset(bounds,-inset,0);
1.50 CGFloat height = font.ascender;
1.51 + float descender = font.descender;
1.52 +#if TARGET_OS_ASPEN
1.53 + descender = -descender;
1.54 +#endif
1.55 CGFloat y = bounds.origin.y;
1.56 - if( align & kCALayerHeightSizable )
1.57 + if( align & kCALayerHeightSizable ) {
1.58 y += (bounds.size.height-height)/2.0;
1.59 - else if( align & kCALayerMinYMargin )
1.60 +#if TARGET_OS_ASPEN
1.61 + y -= descender/2.0;
1.62 +#endif
1.63 + } else if( align & kCALayerMinYMargin )
1.64 y += bounds.size.height - height;
1.65 align &= ~kCALayerHeightSizable;
1.66 - label.bounds = CGRectMake(0, font.descender,
1.67 - bounds.size.width, height - font.descender);
1.68 - label.position = CGPointMake(bounds.origin.x,y+font.descender);
1.69 + label.bounds = CGRectMake(0, descender,
1.70 + bounds.size.width, height - descender);
1.71 + label.position = CGPointMake(bounds.origin.x,y+descender);
1.72 label.anchorPoint = CGPointMake(0,0);
1.73
1.74 +#if ! TARGET_OS_ASPEN
1.75 label.autoresizingMask = align;
1.76 +#endif
1.77 [superlayer addSublayer: label];
1.78 [label release];
1.79 +
1.80 + //label.borderWidth = 1;
1.81 + //label.borderColor = kBlackColor;
1.82 +
1.83 return label;
1.84 }
1.85
1.86
1.87 #if TARGET_OS_ASPEN
1.88 -@synthesize string=_string, fontSize=_fontSize,
1.89 +@synthesize string=_string, font=_font,
1.90 foregroundColor=_foregroundColor, alignmentMode=_alignmentMode;
1.91 +
1.92 +
1.93 +- (id) copyWithZone: (NSZone*)zone
1.94 +{
1.95 + GGBTextLayer *clone = [super copyWithZone: zone];
1.96 + clone.string = _string;
1.97 + clone.font = _font;
1.98 + clone.foregroundColor = _foregroundColor;
1.99 + clone.alignmentMode = _alignmentMode;
1.100 + return clone;
1.101 +}
1.102 +
1.103 +
1.104 +- (void)drawInContext:(CGContextRef)ctx
1.105 +{
1.106 + [super drawInContext: ctx];
1.107 +
1.108 + if( _string.length > 0 ) {
1.109 + CGContextSaveGState(ctx);
1.110 + UIGraphicsPushContext(ctx);
1.111 +
1.112 + if( _foregroundColor )
1.113 + CGContextSetFillColorWithColor(ctx, _foregroundColor);
1.114 +
1.115 + UITextAlignment align;
1.116 + if( [_alignmentMode isEqualToString: @"center"] )
1.117 + align = UITextAlignmentCenter;
1.118 + else if( [_alignmentMode isEqualToString: @"right"] )
1.119 + align = UITextAlignmentRight;
1.120 + else
1.121 + align = UITextAlignmentLeft;
1.122 +
1.123 + CGRect bounds = self.bounds;
1.124 + bounds.origin.y += _font.ascender+_font.descender - _font.leading;
1.125 + [_string drawInRect: bounds
1.126 + withFont: _font
1.127 + lineBreakMode: UILineBreakModeClip
1.128 + alignment: align];
1.129 +
1.130 + UIGraphicsPopContext();
1.131 + CGContextRestoreGState(ctx);
1.132 + }
1.133 +}
1.134 +
1.135 +
1.136 #endif
1.137
1.138
1.139 @end
1.140 +
1.141 +
1.142 +/*
1.143 + .times lt mm: (TimesLTMM)
1.144 + times new roman: (TimesNewRomanBoldItalic, TimesNewRomanItalic, TimesNewRoman, TimesNewRomanBold)
1.145 + phonepadtwo: (PhonepadTwo)
1.146 + hiragino kaku gothic pron w3: (HiraKakuProN-W3)
1.147 + helvetica neue: (HelveticaNeueBold, HelveticaNeue)
1.148 + trebuchet ms: (TrebuchetMSItalic, TrebuchetMSBoldItalic, TrebuchetMSBold, TrebuchetMS)
1.149 + courier new: (CourierNewBoldItalic, CourierNewBold, CourierNewItalic, CourierNew)
1.150 + arial unicode ms: (arialuni)
1.151 + georgia: (Georgia, GeorgiaBold, GeorgiaBoldItalic, GeorgiaItalic)
1.152 + zapfino: (Zapfino)
1.153 + arial rounded mt bold: (ArialRoundedMTBold)
1.154 + db lcd temp: (DB_LCD_Temp-Black)
1.155 + verdana: (Verdana, VerdanaItalic, VerdanaBoldItalic, VerdanaBold)
1.156 + american typewriter: (AmericanTypewriterCondensedBold, AmericanTypewriter)
1.157 + helvetica: (HelveticaBoldOblique, Helvetica, HelveticaOblique, HelveticaBold)
1.158 + lock clock: (LockClock)
1.159 + courier: (CourierBoldOblique, CourierOblique)
1.160 + hiragino kaku gothic pron w6: (HiraKakuProN-W6)
1.161 + arial: (ArialItalic, ArialBold, Arial, ArialBoldItalic)
1.162 + .helvetica lt mm: (HelveticaLTMM)
1.163 + stheiti: (STHeiti, STXihei)
1.164 + applegothic: (AppleGothicRegular)
1.165 + marker felt: (MarkerFeltThin)
1.166 +*/
1.167 \ No newline at end of file