API
0.9.7
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Macros
Groups
Pages
CPStringDrawing.j
Go to the documentation of this file.
1
/*
2
* CPStringDrawing.j
3
* AppKit
4
*
5
* Created by Francisco Tolmasky.
6
* Copyright 2008, 280 North, Inc.
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
12
*
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
*/
22
23
24
25
26
var
CPStringSizeWithFontInWidthCache
= {};
27
28
CPStringSizeCachingEnabled
= YES;
29
30
@implementation
CPString (CPStringDrawing)
31
35
+ (
CPDictionary
)metricsOfFont:(
CPFont
)aFont
36
{
37
return
[
CPPlatformString
metricsOfFont
:aFont];
38
}
39
43
- (
CPString
)cssString
44
{
45
return
self
;
46
}
47
48
- (CGSize)sizeWithFont:(
CPFont
)aFont
49
{
50
return
[
self
sizeWithFont:aFont inWidth:NULL];
51
}
52
53
- (CGSize)sizeWithFont:(
CPFont
)aFont inWidth:(
float
)aWidth
54
{
55
if
(!
CPStringSizeCachingEnabled
)
56
return
[
CPPlatformString
sizeOfString
:self
withFont
:aFont
forWidth
:aWidth];
57
58
var cacheKey =
self
+ [aFont
cssString
] + aWidth,
59
size =
CPStringSizeWithFontInWidthCache
[cacheKey];
60
61
if
(size === undefined)
62
{
63
size = [
CPPlatformString
sizeOfString
:self
withFont
:aFont
forWidth
:aWidth];
64
CPStringSizeWithFontInWidthCache
[cacheKey] = size;
65
}
66
67
return
CGSizeMakeCopy(size);
68
}
69
70
@end
AppKit
CPStringDrawing.j
Generated on Thu Nov 28 2013 20:43:43 for API by
1.8.4