2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
|
|
|
string pFont::serif(unsigned size, string style) {
|
|
|
|
if(size == 0) size = 8;
|
|
|
|
if(style == "") style = "Normal";
|
|
|
|
return {"Georgia, ", size, ", ", style};
|
|
|
|
}
|
|
|
|
|
|
|
|
string pFont::sans(unsigned size, string style) {
|
|
|
|
if(size == 0) size = 8;
|
|
|
|
if(style == "") style = "Normal";
|
|
|
|
return {"Tahoma, ", size, ", ", style};
|
|
|
|
}
|
|
|
|
|
|
|
|
string pFont::monospace(unsigned size, string style) {
|
|
|
|
if(size == 0) size = 8;
|
|
|
|
if(style == "") style = "Normal";
|
|
|
|
return {"Lucida Console, ", 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
|
|
|
HFONT hfont = pFont::create(font);
|
|
|
|
Size size = pFont::size(hfont, text);
|
2011-09-05 03:48:23 +00:00
|
|
|
pFont::free(hfont);
|
2013-03-15 13:11:33 +00:00
|
|
|
return size;
|
2011-09-05 03:48:23 +00:00
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
HFONT pFont::create(string description) {
|
2011-09-05 03:48:23 +00:00
|
|
|
lstring part;
|
|
|
|
part.split(",", description);
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& item : part) item.trim(" ");
|
2011-09-05 03:48:23 +00:00
|
|
|
|
2011-10-16 09:44:48 +00:00
|
|
|
string family = "Sans";
|
|
|
|
unsigned size = 8u;
|
|
|
|
bool bold = false;
|
|
|
|
bool italic = false;
|
|
|
|
|
|
|
|
if(part[0] != "") family = part[0];
|
|
|
|
if(part.size() >= 2) size = decimal(part[1]);
|
2014-02-09 05:59:46 +00:00
|
|
|
if(part.size() >= 3) bold = (bool)part[2].find("Bold");
|
|
|
|
if(part.size() >= 3) italic = (bool)part[2].find("Italic");
|
2011-09-05 03:48:23 +00:00
|
|
|
|
2011-02-24 09:25:20 +00:00
|
|
|
return CreateFont(
|
|
|
|
-(size * 96.0 / 72.0 + 0.5),
|
2011-09-05 03:48:23 +00:00
|
|
|
0, 0, 0, bold == false ? FW_NORMAL : FW_BOLD, italic, 0, 0, 0, 0, 0, 0, 0,
|
2011-02-24 09:25:20 +00:00
|
|
|
utf16_t(family)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-09-05 03:48:23 +00:00
|
|
|
void pFont::free(HFONT hfont) {
|
|
|
|
DeleteObject(hfont);
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
Size pFont::size(HFONT hfont, string text) {
|
2011-09-05 03:48:23 +00:00
|
|
|
//temporary fix: empty text string returns height of zero; bad for eg Button height
|
2013-07-29 09:42:45 +00:00
|
|
|
if(text.empty()) text = " ";
|
2011-09-05 03:48:23 +00:00
|
|
|
|
2011-03-22 12:56:49 +00:00
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
SelectObject(hdc, hfont);
|
2013-03-15 13:11:33 +00:00
|
|
|
RECT rc = {0, 0, 0, 0};
|
2011-03-22 12:56:49 +00:00
|
|
|
DrawText(hdc, utf16_t(text), -1, &rc, DT_CALCRECT);
|
|
|
|
ReleaseDC(0, hdc);
|
2013-03-15 13:11:33 +00:00
|
|
|
return {rc.right, rc.bottom};
|
|
|
|
}
|
|
|
|
|
2011-03-22 12:56:49 +00:00
|
|
|
}
|