API  0.9.9
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 
27 
29 
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 {
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
Definition: CPFont.h:2
var CPStringSizeWithFontInWidthCache
A mutable key-value pair collection.
Definition: CPDictionary.h:2
CPStringSizeCachingEnabled
An immutable string (collection of characters).
Definition: CPString.h:2
CGSize sizeOfString:withFont:forWidth:(CPString aString, [withFont] CPFont aFont, [forWidth] float aWidth)
CPString cssString()
Definition: CPFont.j:383
CPDictionary metricsOfFont:(CPFont aFont)
CGSize sizeWithFont:inWidth:(CPFont aFont, [inWidth] float aWidth)