bool wxTestFontEncoding(const wxNativeEncodingInfo& info) { wxString fontspec; fontspec.Printf(wxT("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"), !info.facename ? wxT("*") : info.facename.c_str(), info.xregistry.c_str(), info.xencoding.c_str()); return wxTestFontSpec(fontspec); }
bool wxTestFontEncoding(const wxNativeEncodingInfo& info) { wxString fontspec; fontspec.Printf(wxT("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"), info.facename.empty() ? wxString("*") : info.facename, info.xregistry, info.xencoding); return wxTestFontSpec(fontspec); }
static wxNativeFont wxLoadQueryFont(float pointSize, wxFontFamily family, wxFontStyle style, int weight, bool WXUNUSED(underlined), const wxString& facename, const wxString& xregistry, const wxString& xencoding, wxString* xFontName) { #if wxUSE_NANOX int xweight; switch (weight) { case wxFONTWEIGHT_BOLD: { xweight = MWLF_WEIGHT_BOLD; break; } case wxFONTWEIGHT_LIGHT: { xweight = MWLF_WEIGHT_LIGHT; break; } case wxFONTWEIGHT_NORMAL: { xweight = MWLF_WEIGHT_NORMAL; break; } default: { xweight = MWLF_WEIGHT_DEFAULT; break; } } GR_SCREEN_INFO screenInfo; GrGetScreenInfo(& screenInfo); int yPixelsPerCM = screenInfo.ydpcm; // A point is 1/72 of an inch. // An inch is 2.541 cm. // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels) // In fact pointSize is 10 * the normal point size so // divide by 10. int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ; // An alternative: assume that the screen is 72 dpi. //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ; //int pixelHeight = (int) ((float)pointSize / 10.0) ; GR_LOGFONT logFont; logFont.lfHeight = pixelHeight; logFont.lfWidth = 0; logFont.lfEscapement = 0; logFont.lfOrientation = 0; logFont.lfWeight = xweight; logFont.lfItalic = (style == wxFONTSTYLE_ITALIC ? 0 : 1) ; logFont.lfUnderline = 0; logFont.lfStrikeOut = 0; logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one logFont.lfOutPrecision = MWLF_TYPE_DEFAULT; logFont.lfClipPrecision = 0; // Not used logFont.lfRoman = (family == wxROMAN ? 1 : 0) ; logFont.lfSerif = (family == wxSWISS ? 0 : 1) ; logFont.lfSansSerif = !logFont.lfSerif ; logFont.lfModern = (family == wxMODERN ? 1 : 0) ; logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ; logFont.lfOblique = 0; logFont.lfSmallCaps = 0; logFont.lfPitch = 0; // 0 = default strcpy(logFont.lfFaceName, facename.c_str()); XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct)); fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont); GrGetFontInfo(fontInfo->fid, & fontInfo->info); return (wxNativeFont) fontInfo; #else wxNativeFontInfo info; info.SetFractionalPointSize(pointSize); if ( !facename.empty() ) { info.SetFaceName(facename); if ( !wxTestFontSpec(info.GetXFontName()) ) { // No such face name, use just the family (we assume this will // never fail). info.SetFamily(family); } } else { info.SetFamily(family); } wxNativeFontInfo infoWithStyle(info); infoWithStyle.SetStyle(style); if ( wxTestFontSpec(infoWithStyle.GetXFontName()) ) info = infoWithStyle; wxNativeFontInfo infoWithWeight(info); infoWithWeight.SetNumericWeight(weight); if ( wxTestFontSpec(infoWithWeight.GetXFontName()) ) info = infoWithWeight; // construct the X font spec from our data wxString fontSpec; fontSpec.Printf("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s", info.GetXFontComponent(wxXLFD_FAMILY), info.GetXFontComponent(wxXLFD_WEIGHT), info.GetXFontComponent(wxXLFD_SLANT), info.GetXFontComponent(wxXLFD_POINTSIZE), xregistry, xencoding); if( xFontName ) *xFontName = fontSpec; return wxLoadFont(fontSpec); #endif // wxUSE_NANOX }
static wxNativeFont wxLoadQueryFont(int pointSize, int family, int style, int weight, bool WXUNUSED(underlined), const wxString& facename, const wxString& xregistry, const wxString& xencoding, wxString* xFontName) { wxString xfamily; switch (family) { case wxDECORATIVE: xfamily = wxT("lucida"); break; case wxROMAN: xfamily = wxT("times"); break; case wxMODERN: xfamily = wxT("courier"); break; case wxSWISS: xfamily = wxT("helvetica"); break; case wxTELETYPE: xfamily = wxT("lucidatypewriter"); break; case wxSCRIPT: xfamily = wxT("utopia"); break; default: xfamily = wxT("*"); } #if wxUSE_NANOX int xweight; switch (weight) { case wxBOLD: { xweight = MWLF_WEIGHT_BOLD; break; } case wxLIGHT: { xweight = MWLF_WEIGHT_LIGHT; break; } case wxNORMAL: { xweight = MWLF_WEIGHT_NORMAL; break; } default: { xweight = MWLF_WEIGHT_DEFAULT; break; } } GR_SCREEN_INFO screenInfo; GrGetScreenInfo(& screenInfo); int yPixelsPerCM = screenInfo.ydpcm; // A point is 1/72 of an inch. // An inch is 2.541 cm. // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels) // In fact pointSize is 10 * the normal point size so // divide by 10. int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ; // An alternative: assume that the screen is 72 dpi. //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ; //int pixelHeight = (int) ((float)pointSize / 10.0) ; GR_LOGFONT logFont; logFont.lfHeight = pixelHeight; logFont.lfWidth = 0; logFont.lfEscapement = 0; logFont.lfOrientation = 0; logFont.lfWeight = xweight; logFont.lfItalic = (style == wxNORMAL ? 0 : 1) ; logFont.lfUnderline = 0; logFont.lfStrikeOut = 0; logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one logFont.lfOutPrecision = MWLF_TYPE_DEFAULT; logFont.lfClipPrecision = 0; // Not used logFont.lfRoman = (family == wxROMAN ? 1 : 0) ; logFont.lfSerif = (family == wxSWISS ? 0 : 1) ; logFont.lfSansSerif = !logFont.lfSerif ; logFont.lfModern = (family == wxMODERN ? 1 : 0) ; logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ; logFont.lfOblique = 0; logFont.lfSmallCaps = 0; logFont.lfPitch = 0; // 0 = default strcpy(logFont.lfFaceName, facename.c_str()); XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct)); fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont); GrGetFontInfo(fontInfo->fid, & fontInfo->info); return (wxNativeFont) fontInfo; #else wxString fontSpec; if (!facename.empty()) { fontSpec.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"), facename.c_str()); if ( wxTestFontSpec(fontSpec) ) { xfamily = facename; } //else: no such family, use default one instead } wxString xstyle; switch (style) { case wxSLANT: fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xstyle = wxT("o"); break; } // fall through - try wxITALIC now case wxITALIC: fontSpec.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xstyle = wxT("i"); } else if ( style == wxITALIC ) // and not wxSLANT { // try wxSLANT fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xstyle = wxT("o"); } else { // no italic, no slant - leave default xstyle = wxT("*"); } } break; default: wxFAIL_MSG(wxT("unknown font style")); // fall back to normal case wxNORMAL: xstyle = wxT("r"); break; } wxString xweight; switch (weight) { case wxBOLD: { fontSpec.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("bold"); break; } fontSpec.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("heavy"); break; } fontSpec.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("extrabold"); break; } fontSpec.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("demibold"); break; } fontSpec.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("black"); break; } fontSpec.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("ultrablack"); break; } } break; case wxLIGHT: { fontSpec.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("light"); break; } fontSpec.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("thin"); break; } } break; case wxNORMAL: { fontSpec.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("medium"); break; } fontSpec.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("normal"); break; } fontSpec.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"), xfamily.c_str()); if ( wxTestFontSpec(fontSpec) ) { xweight = wxT("regular"); break; } xweight = wxT("*"); } break; default: xweight = wxT("*"); break; } // if pointSize is -1, don't specify any wxString sizeSpec; if ( pointSize == -1 ) { sizeSpec = wxT('*'); } else { sizeSpec.Printf(wxT("%d"), pointSize); } // construct the X font spec from our data fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"), xfamily.c_str(), xweight.c_str(), xstyle.c_str(), sizeSpec.c_str(), xregistry.c_str(), xencoding.c_str()); if( xFontName ) *xFontName = fontSpec; return wxLoadFont(fontSpec); #endif // wxUSE_NANOX }