Fl_FontSize::Fl_FontSize(const char* name) { font = XLoadQueryFont(fl_display, name); if(!font) { Fl::warning("bad font: %s", name); // if fixed fails we crash font = XLoadQueryFont(fl_display, "fixed"); } encoding = 0; encoding_num = -1; append_font(this); }
Fl_FontSize::Fl_FontSize(const char* name, int size, int charset) { fl_fontsize = this; int weight = FW_NORMAL; int italic = 0; // may be efficient, but this is non-obvious switch (*name++) { case 'I': italic = 1; break; case 'P': italic = 1; case 'B': weight = FW_BOLD; break; case ' ': break; default: name--; } HFONT font; LOGFONT lFont; lFont.lfHeight = -size; // use "char size" lFont.lfWidth = 0L; lFont.lfEscapement = 0L; lFont.lfOrientation = 0L; lFont.lfWeight = weight; lFont.lfItalic = italic; lFont.lfUnderline = FALSE; lFont.lfStrikeOut = FALSE; lFont.lfCharSet = charset; lFont.lfClipPrecision = CLIP_DEFAULT_PRECIS; lFont.lfPitchAndFamily = DEFAULT_PITCH & FF_DONTCARE; #ifdef _WIN32_WCE lFont.lfOutPrecision = OUT_DEFAULT_PRECIS; lFont.lfQuality = DEFAULT_QUALITY; #else lFont.lfOutPrecision = OUT_DEVICE_PRECIS; // CE doesn't understand lFont.lfQuality = PROOF_QUALITY; // CE doesn't understand #endif TCHAR *family_name; #ifdef UNICODE int len = fl_utf_nb_char((unsigned char*)name, strlen(name)); family_name = (TCHAR*)malloc((len + 1) * sizeof(TCHAR)); fl_utf2unicode((unsigned char*)name, len, (unsigned short*)family_name); family_name[len] = 0; wcsncpy(lFont.lfFaceName, family_name, LF_FACESIZE); #else family_name = fl_utf82locale(name); strncpy(lFont.lfFaceName, family_name, LF_FACESIZE); #endif font = ::CreateFontIndirect( &lFont ); HDC dc = fl_getDC(); SelectObject(dc, font); for(int i = 0; i < 64; i++) width[i] = 0; GetTextMetrics(dc, &fl_fontsize->metr); this->font = font; this->size = size; this->charset = charset; append_font(this); }