blob: e20129c6b078601cc3c02cb274559079dda3ff95 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/* HBAttributedStringAdditions.m $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#import "HBAttributedStringAdditions.h"
static NSDictionary *_monospacedAttr = nil;
static NSDictionary *_normalMonospacedAttr = nil;
@implementation NSMutableAttributedString (HBAttributedStringAdditions)
- (void)appendString:(NSString *)aString withAttributes:(NSDictionary *)aDictionary
{
NSAttributedString *s = [[NSAttributedString alloc] initWithString:aString
attributes:aDictionary];
[self appendAttributedString:s];
}
@end
@implementation NSString (HBAttributedStringAdditions)
- (NSAttributedString *)HB_monospacedString
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_normalMonospacedAttr = @{NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:15 weight:NSFontWeightRegular]};
});
return [[NSAttributedString alloc] initWithString:self attributes:_normalMonospacedAttr];
}
- (NSAttributedString *)HB_smallMonospacedString
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_monospacedAttr = @{NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightRegular]};
});
return [[NSAttributedString alloc] initWithString:self attributes:_monospacedAttr];
}
@end
|