2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
|
|
|
string pFont::serif(unsigned size, string style) {
|
|
|
|
if(size == 0) size = 12;
|
|
|
|
if(style == "") style = "Normal";
|
|
|
|
return {"Georgia, ", size, ", ", style};
|
|
|
|
}
|
|
|
|
|
|
|
|
string pFont::sans(unsigned size, string style) {
|
|
|
|
if(size == 0) size = 12;
|
|
|
|
if(style == "") style = "Normal";
|
|
|
|
return {"Lucida Grande, ", size, ", ", style};
|
|
|
|
}
|
|
|
|
|
|
|
|
string pFont::monospace(unsigned size, string style) {
|
|
|
|
if(size == 0) size = 12;
|
|
|
|
if(style == "") style = "Normal";
|
|
|
|
return {"Menlo, ", size, ", ", style};
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
Size pFont::size(string font, string text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
if(NSFont* nsFont = cocoaFont(font)) {
|
2013-03-15 13:11:33 +00:00
|
|
|
return size(nsFont, text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {0, 0};
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
NSFont* pFont::cocoaFont(string description) {
|
|
|
|
lstring part = description.split<2>(",").strip();
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
NSString* family = @"Lucida Grande";
|
2013-03-15 13:11:33 +00:00
|
|
|
NSFontTraitMask traits = 0;
|
|
|
|
CGFloat size = 12;
|
|
|
|
|
|
|
|
if(!part(0).empty()) family = [NSString stringWithUTF8String:part(0)];
|
2013-07-29 09:42:45 +00:00
|
|
|
if(!part(1).empty()) size = real(part(1));
|
|
|
|
if(part(2).ifind("bold")) traits |= NSBoldFontMask;
|
|
|
|
if(part(2).ifind("italic")) traits |= NSItalicFontMask;
|
|
|
|
if(part(2).ifind("narrow")) traits |= NSNarrowFontMask;
|
|
|
|
if(part(2).ifind("expanded")) traits |= NSExpandedFontMask;
|
|
|
|
if(part(2).ifind("condensed")) traits |= NSCondensedFontMask;
|
|
|
|
if(part(2).ifind("smallcaps")) traits |= NSSmallCapsFontMask;
|
2013-03-15 13:11:33 +00:00
|
|
|
|
|
|
|
return [[NSFontManager sharedFontManager] fontWithFamily:family traits:traits weight:5 size:size];
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
Size pFont::size(NSFont* font, string text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
@autoreleasepool {
|
2013-05-02 11:25:45 +00:00
|
|
|
NSString* cocoaText = [NSString stringWithUTF8String:text];
|
|
|
|
NSDictionary* fontAttributes = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil];
|
2013-03-15 13:11:33 +00:00
|
|
|
NSSize size = [cocoaText sizeWithAttributes:fontAttributes];
|
|
|
|
return {size.width, size.height};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|