diff --git a/include/wx/defs.h b/include/wx/defs.h index 84037e9938..f78d5e3ba2 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -2583,11 +2583,6 @@ typedef int (* LINKAGEMODE wxListIterateFunction)(void *current); /* miscellaneous */ /* ---------------------------------------------------------------------------- */ -/* define this macro if font handling is done using the X font names */ -#if defined(__X__) - #define _WX_X_FONTLIKE -#endif - /* macro to specify "All Files" on different platforms */ #if defined(__WXMSW__) # define wxALL_FILES_PATTERN wxT("*.*") diff --git a/include/wx/encinfo.h b/include/wx/encinfo.h index 176da52e83..d0c716d0aa 100644 --- a/include/wx/encinfo.h +++ b/include/wx/encinfo.h @@ -47,9 +47,6 @@ struct WXDLLIMPEXP_CORE wxNativeEncodingInfo { } int charset; -#elif defined(_WX_X_FONTLIKE) - wxString xregistry, - xencoding; #elif defined(wxHAS_UTF8_FONTS) // ports using UTF-8 for text don't need encoding information for fonts #else diff --git a/include/wx/fontutil.h b/include/wx/fontutil.h index 744715d99e..bce640489b 100644 --- a/include/wx/fontutil.h +++ b/include/wx/fontutil.h @@ -37,33 +37,6 @@ class WXDLLIMPEXP_FWD_BASE wxArrayString; class WXDLLIMPEXP_FWD_CORE wxWindow; struct WXDLLIMPEXP_FWD_CORE wxNativeEncodingInfo; -#if defined(_WX_X_FONTLIKE) - -// the symbolic names for the XLFD fields (with examples for their value) -// -// NB: we suppose that the font always starts with the empty token (font name -// registry field) as we never use nor generate it anyhow -enum wxXLFDField -{ - wxXLFD_FOUNDRY, // adobe - wxXLFD_FAMILY, // courier, times, ... - wxXLFD_WEIGHT, // black, bold, demibold, medium, regular, light - wxXLFD_SLANT, // r/i/o (roman/italique/oblique) - wxXLFD_SETWIDTH, // condensed, expanded, ... - wxXLFD_ADDSTYLE, // whatever - usually nothing - wxXLFD_PIXELSIZE, // size in pixels - wxXLFD_POINTSIZE, // size in points - wxXLFD_RESX, // 72, 75, 100, ... - wxXLFD_RESY, - wxXLFD_SPACING, // m/p/c (monospaced/proportional/character cell) - wxXLFD_AVGWIDTH, // average width in 1/10 pixels - wxXLFD_REGISTRY, // iso8859, rawin, koi8, ... - wxXLFD_ENCODING, // 1, r, r, ... - wxXLFD_MAX -}; - -#endif // _WX_X_FONTLIKE - // ---------------------------------------------------------------------------- // types // ---------------------------------------------------------------------------- @@ -84,40 +57,6 @@ public: // separately and handle them ourselves in {To,From}String() methods. bool m_underlined; bool m_strikethrough; -#elif defined(_WX_X_FONTLIKE) - // the members can't be accessed directly as we only parse the - // xFontName on demand -private: - // the components of the XLFD - wxString fontElements[wxXLFD_MAX]; - - // the full XLFD - wxString xFontName; - - // true until SetXFontName() is called - bool m_isDefault; - - // return true if we have already initialized fontElements - inline bool HasElements() const; - -public: - // init the elements from an XLFD, return true if ok - bool FromXFontName(const wxString& xFontName); - - // return false if we were never initialized with a valid XLFD - bool IsDefault() const { return m_isDefault; } - - // return the XLFD (using the fontElements if necessary) - wxString GetXFontName() const; - - // get the given XFLD component - wxString GetXFontComponent(wxXLFDField field) const; - - // change the font component - void SetXFontComponent(wxXLFDField field, const wxString& value); - - // set the XFLD - void SetXFontName(const wxString& xFontName); #elif defined(__WXMSW__) // Preserve compatibility in the semi-public (i.e. private, but still // unfortunately used by some existing code outside of the library) API @@ -349,12 +288,4 @@ WXDLLIMPEXP_CORE bool wxGetNativeFontEncoding(wxFontEncoding encoding, // return true if such font(s) exist, false otherwise WXDLLIMPEXP_CORE bool wxTestFontEncoding(const wxNativeEncodingInfo& info); -// ---------------------------------------------------------------------------- -// font-related functions (X and GTK) -// ---------------------------------------------------------------------------- - -#ifdef _WX_X_FONTLIKE - #include "wx/unix/fontutil.h" -#endif // X || GDK - #endif // _WX_FONTUTIL_H_ diff --git a/include/wx/x11/font.h b/include/wx/x11/font.h index 04190445b5..f4c66348b7 100644 --- a/include/wx/x11/font.h +++ b/include/wx/x11/font.h @@ -117,33 +117,12 @@ public: // Implementation -#if wxUSE_PANGO // Set Pango attributes in the specified layout. Currently only // underlined and strike-through attributes are handled by this function. // // If neither of them is specified, returns false, otherwise sets up the // attributes and returns true. bool SetPangoAttrs(PangoLayout* layout) const; -#else - // Find an existing, or create a new, XFontStruct - // based on this wxFont and the given scale. Append the - // font to list in the private data for future reference. - - // TODO This is a fairly basic implementation, that doesn't - // allow for different facenames, and also doesn't do a mapping - // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.) - // and the fonts that are available on a particular system. - // Maybe we need to scan the user's machine to build up a profile - // of the fonts and a mapping file. - - // Return font struct, and optionally the font list - wxXFont *GetInternalFont(double scale = 1.0, - WXDisplay* display = nullptr) const; - - // Helper function for convenient access of the above. - WXFontStructPtr GetFontStruct(double scale = 1.0, - WXDisplay* display = nullptr) const; -#endif protected: virtual wxGDIRefData *CreateGDIRefData() const; diff --git a/include/wx/x11/private.h b/include/wx/x11/private.h index f0912b1eca..9c91adddcb 100644 --- a/include/wx/x11/private.h +++ b/include/wx/x11/private.h @@ -27,9 +27,7 @@ // Include common declarations #include "wx/x11/privx.h" -#if wxUSE_PANGO #include -#endif class WXDLLIMPEXP_FWD_CORE wxMouseEvent; class WXDLLIMPEXP_FWD_CORE wxKeyEvent; diff --git a/src/unix/fontenum.cpp b/src/unix/fontenum.cpp index a6827288ab..e530b5396b 100644 --- a/src/unix/fontenum.cpp +++ b/src/unix/fontenum.cpp @@ -39,8 +39,6 @@ // Pango // ---------------------------------------------------------------------------- -#if wxUSE_PANGO - #include PangoContext* wxGetPangoContext(); @@ -105,249 +103,4 @@ bool wxFontEnumerator::EnumerateEncodings(const wxString& facename) } -#else // !wxUSE_PANGO - -#ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++ - // The resulting warnings are switched off here -#pragma message disable nosimpint -#endif -#include -#ifdef __VMS__ -#pragma message enable nosimpint -#endif - -// ---------------------------------------------------------------------------- -// private functions -// ---------------------------------------------------------------------------- - -// create the list of all fonts with the given spacing and encoding -static char **CreateFontList(wxChar spacing, wxFontEncoding encoding, - int *nFonts); - -// extract all font families from the given font list and call our -// OnFacename() for each of them -static bool ProcessFamiliesFromFontList(wxFontEnumerator *This, - char **fonts, - int nFonts); - - -// ---------------------------------------------------------------------------- -// private types -// ---------------------------------------------------------------------------- - -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// helpers -// ---------------------------------------------------------------------------- - -#if !wxUSE_NANOX -static char **CreateFontList(wxChar spacing, - wxFontEncoding encoding, - int *nFonts) -{ - wxNativeEncodingInfo info; - wxGetNativeFontEncoding(encoding, &info); - -#if wxUSE_FONTMAP - if ( !wxTestFontEncoding(info) ) - { - // ask font mapper for a replacement - (void)wxFontMapper::Get()->GetAltForEncoding(encoding, &info); - } -#endif // wxUSE_FONTMAP - - wxString pattern; - pattern.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-%c-*-%s-%s"), - spacing, - info.xregistry.c_str(), - info.xencoding.c_str()); - - // get the list of all fonts - return XListFonts((Display *)wxGetDisplay(), pattern.mb_str(), 32767, nFonts); -} - -static bool ProcessFamiliesFromFontList(wxFontEnumerator *This, - char **fonts, - int nFonts) -{ -#if wxUSE_REGEX - wxRegEx re(wxT("^(-[^-]*){14}$"), wxRE_NOSUB); -#endif // wxUSE_REGEX - - // extract the list of (unique) font families - wxSortedArrayString families; - for ( int n = 0; n < nFonts; n++ ) - { - char *font = fonts[n]; -#if wxUSE_REGEX - if ( !re.Matches(font) ) -#else // !wxUSE_REGEX - if ( !wxString(font).Matches(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-*-*")) ) -#endif // wxUSE_REGEX/!wxUSE_REGEX - { - // it's not a full font name (probably an alias) - continue; - } - - // coverity[returned_null] - char *dash = strchr(font + 1, '-'); - char *family = dash + 1; - dash = strchr(family, '-'); - *dash = '\0'; // not-null because Matches() above succeeded - wxString fam(family); - - if ( families.Index(fam) == wxNOT_FOUND ) - { - if ( !This->OnFacename(fam) ) - { - // stop enumerating - return false; - } - - families.Add(fam); - } - //else: already seen - } - - return true; -} -#endif - // wxUSE_NANOX - -// ---------------------------------------------------------------------------- -// wxFontEnumerator -// ---------------------------------------------------------------------------- - -bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding, - bool fixedWidthOnly) -{ -#if wxUSE_NANOX - return false; -#else - int nFonts; - char **fonts; - - if ( fixedWidthOnly ) - { - bool cont = true; - fonts = CreateFontList(wxT('m'), encoding, &nFonts); - if ( fonts ) - { - cont = ProcessFamiliesFromFontList(this, fonts, nFonts); - - XFreeFontNames(fonts); - } - - if ( !cont ) - { - return true; - } - - fonts = CreateFontList(wxT('c'), encoding, &nFonts); - if ( !fonts ) - { - return true; - } - } - else - { - fonts = CreateFontList(wxT('*'), encoding, &nFonts); - - if ( !fonts ) - { - // it's ok if there are no fonts in given encoding - but it's not - // ok if there are no fonts at all - wxASSERT_MSG(encoding != wxFONTENCODING_SYSTEM, - wxT("No fonts at all on this system?")); - - return false; - } - } - - (void)ProcessFamiliesFromFontList(this, fonts, nFonts); - - XFreeFontNames(fonts); - return true; -#endif - // wxUSE_NANOX -} - -bool wxFontEnumerator::EnumerateEncodings(const wxString& family) -{ -#if wxUSE_NANOX - return false; -#else - wxString pattern; - pattern.Printf(wxT("-*-%s-*-*-*-*-*-*-*-*-*-*-*-*"), - family.empty() ? wxString("*") : family); - - // get the list of all fonts - int nFonts; - char **fonts = XListFonts((Display *)wxGetDisplay(), pattern.mb_str(), - 32767, &nFonts); - - if ( !fonts ) - { - // unknown family? - return false; - } - - // extract the list of (unique) encodings - wxSortedArrayString encodings; - for ( int n = 0; n < nFonts; n++ ) - { - char *font = fonts[n]; - if ( !wxString(font).Matches(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-*-*")) ) - { - // it's not a full font name (probably an alias) - continue; - } - - // extract the family - char *dash = strchr(font + 1, '-'); - char *familyFont = dash + 1; - dash = strchr(familyFont, '-'); - *dash = '\0'; // not-null because Matches() above succeeded - - if ( !family.empty() && (family != familyFont) ) - { - // family doesn't match - continue; - } - - // now extract the registry/encoding - char *p = dash + 1; // just after the dash after family - dash = strrchr(p, '-'); - - wxString registry(dash + 1); - *dash = '\0'; - - dash = strrchr(p, '-'); - wxString encoding(dash + 1); - - encoding << wxT('-') << registry; - if ( encodings.Index(encoding) == wxNOT_FOUND ) - { - if ( !OnFontEncoding(familyFont, encoding) ) - { - break; - } - - encodings.Add(encoding); - } - //else: already had this one - } - - XFreeFontNames(fonts); - - return true; -#endif - // wxUSE_NANOX -} - -#endif // !wxUSE_PANGO - #endif // wxUSE_FONTENUM diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index d36f7b5794..c627cce29f 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -25,7 +25,6 @@ #ifndef WX_PRECOMP #include "wx/app.h" #include "wx/font.h" // wxFont enums - #include "wx/hash.h" #include "wx/utils.h" // for wxGetDisplay() #include "wx/module.h" #endif // PCH @@ -36,8 +35,6 @@ #include "wx/tokenzr.h" #include "wx/fontenum.h" -#if wxUSE_PANGO - #include PangoContext* wxGetPangoContext(); @@ -415,990 +412,3 @@ wxString wxNativeFontInfo::ToUserString() const { return ToString(); } - -#else // GTK+ 1.x - -#ifdef __X__ - #ifdef __VMS__ - #pragma message disable nosimpint - #endif - - #include - - #ifdef __VMS__ - #pragma message enable nosimpint - #endif - -#elif defined(__WXGTK__) - // we have to declare struct tm to avoid problems with first forward - // declaring it in C code (glib.h included from gdk.h does it) and then - // defining it when time.h is included from the headers below - this is - // known not to work at least with Sun CC 6.01 - #include - - #include -#endif - - -// ---------------------------------------------------------------------------- -// private data -// ---------------------------------------------------------------------------- - -static wxHashTable *g_fontHash = nullptr; - -// ---------------------------------------------------------------------------- -// private functions -// ---------------------------------------------------------------------------- - -// define the functions to create and destroy native fonts for this toolkit -#ifdef __X__ - wxNativeFont wxLoadFont(const wxString& fontSpec) - { - return XLoadQueryFont((Display *)wxGetDisplay(), fontSpec); - } - - inline void wxFreeFont(wxNativeFont font) - { - XFreeFont((Display *)wxGetDisplay(), (XFontStruct *)font); - } -#elif defined(__WXGTK__) - wxNativeFont wxLoadFont(const wxString& fontSpec) - { - // VZ: we should use gdk_fontset_load() instead of gdk_font_load() - // here to be able to display Japanese fonts correctly (at least - // this is what people report) but unfortunately doing it results - // in tons of warnings when using GTK with "normal" European - // languages and so we can't always do it and I don't know enough - // to determine when should this be done... (FIXME) - return gdk_font_load( wxConvertWX2MB(fontSpec) ); - } - - inline void wxFreeFont(wxNativeFont font) - { - gdk_font_unref(font); - } -#else - #error "Unknown GUI toolkit" -#endif - -static bool wxTestFontSpec(const wxString& fontspec); - -static wxNativeFont wxLoadQueryFont(double pointSize, - wxFontFamily family, - wxFontStyle style, - int weight, - bool underlined, - const wxString& facename, - const wxString& xregistry, - const wxString& xencoding, - wxString* xFontName); - -// ============================================================================ -// implementation -// ============================================================================ - -// ---------------------------------------------------------------------------- -// wxNativeEncodingInfo -// ---------------------------------------------------------------------------- - -// convert to/from the string representation: format is -// encodingid;registry;encoding[;facename] -bool wxNativeEncodingInfo::FromString(const wxString& s) -{ - // use ";", not "-" because it may be part of encoding name - wxStringTokenizer tokenizer(s, wxT(";")); - - wxString encid = tokenizer.GetNextToken(); - long enc; - if ( !encid.ToLong(&enc) ) - return false; - encoding = (wxFontEncoding)enc; - - xregistry = tokenizer.GetNextToken(); - if ( !xregistry ) - return false; - - xencoding = tokenizer.GetNextToken(); - if ( !xencoding ) - return false; - - // ok even if empty - facename = tokenizer.GetNextToken(); - - return true; -} - -wxString wxNativeEncodingInfo::ToString() const -{ - wxString s; - s << (long)encoding << wxT(';') << xregistry << wxT(';') << xencoding; - if ( !facename.empty() ) - { - s << wxT(';') << facename; - } - - return s; -} - -// ---------------------------------------------------------------------------- -// wxNativeFontInfo -// ---------------------------------------------------------------------------- - -void wxNativeFontInfo::Init() -{ - m_isDefault = true; -} - -bool wxNativeFontInfo::FromString(const wxString& s) -{ - wxStringTokenizer tokenizer(s, wxT(";")); - - // check the version - wxString token = tokenizer.GetNextToken(); - if ( token != wxT('0') ) - return false; - - xFontName = tokenizer.GetNextToken(); - - // this should be the end - if ( tokenizer.HasMoreTokens() ) - return false; - - return FromXFontName(xFontName); -} - -wxString wxNativeFontInfo::ToString() const -{ - // 0 is the version - return wxString::Format(wxT("%d;%s"), 0, GetXFontName().c_str()); -} - -bool wxNativeFontInfo::FromUserString(const wxString& s) -{ - return FromXFontName(s); -} - -wxString wxNativeFontInfo::ToUserString() const -{ - return GetXFontName(); -} - -bool wxNativeFontInfo::HasElements() const -{ - // we suppose that the foundry is never empty, so if it is it means that we - // had never parsed the XLFD - return !fontElements[0].empty(); -} - -wxString wxNativeFontInfo::GetXFontComponent(wxXLFDField field) const -{ - wxCHECK_MSG( field < wxXLFD_MAX, wxEmptyString, wxT("invalid XLFD field") ); - - if ( !HasElements() ) - { - if ( !const_cast(this)->FromXFontName(xFontName) ) - return wxEmptyString; - } - - return fontElements[field]; -} - -bool wxNativeFontInfo::FromXFontName(const wxString& fontname) -{ - // TODO: we should be able to handle the font aliases here, but how? - wxStringTokenizer tokenizer(fontname, wxT("-")); - - // skip the leading, usually empty field (font name registry) - if ( !tokenizer.HasMoreTokens() ) - return false; - - (void)tokenizer.GetNextToken(); - - for ( size_t n = 0; n < WXSIZEOF(fontElements); n++ ) - { - if ( !tokenizer.HasMoreTokens() ) - { - // not enough elements in the XLFD - or maybe an alias - return false; - } - - wxString field = tokenizer.GetNextToken(); - if ( !field.empty() && field != wxT('*') ) - { - // we're really initialized now - m_isDefault = false; - } - - fontElements[n] = field; - } - - // this should be all - if ( tokenizer.HasMoreTokens() ) - return false; - - return true; -} - -wxString wxNativeFontInfo::GetXFontName() const -{ - if ( xFontName.empty() ) - { - for ( size_t n = 0; n < WXSIZEOF(fontElements); n++ ) - { - // replace the non specified elements with '*' except for the - // additional style which is usually just omitted - wxString elt = fontElements[n]; - if ( elt.empty() && n != wxXLFD_ADDSTYLE ) - { - elt = wxT('*'); - } - - const_cast(this)->xFontName << wxT('-') << elt; - } - } - - return xFontName; -} - -void -wxNativeFontInfo::SetXFontComponent(wxXLFDField field, const wxString& value) -{ - wxCHECK_RET( field < wxXLFD_MAX, wxT("invalid XLFD field") ); - - if ( !HasElements() ) - { - for ( int field = 0; field < wxXLFD_MAX; field++ ) - fontElements[field] = '*'; - } - - fontElements[field] = value; - - // invalidate the XFLD, it doesn't correspond to the font elements any more - xFontName.clear(); -} - -void wxNativeFontInfo::SetXFontName(const wxString& xFontName_) -{ - // invalidate the font elements, GetXFontComponent() will reparse the XLFD - fontElements[0].clear(); - - xFontName = xFontName_; - - m_isDefault = false; -} - -double wxNativeFontInfo::GetFractionalPointSize() const -{ - const wxString s = GetXFontComponent(wxXLFD_POINTSIZE); - - // return -1 to indicate that the size is unknown - long l; - return s.ToLong(&l) ? l : -1; -} - -wxFontStyle wxNativeFontInfo::GetStyle() const -{ - const wxString s = GetXFontComponent(wxXLFD_SLANT); - - if ( s.length() != 1 ) - { - // it is really unknown but we don't have any way to return it from - // here - return wxFONTSTYLE_NORMAL; - } - - switch ( s[0].GetValue() ) - { - default: - // again, unknown but consider normal by default - - case wxT('r'): - return wxFONTSTYLE_NORMAL; - - case wxT('i'): - return wxFONTSTYLE_ITALIC; - - case wxT('o'): - return wxFONTSTYLE_SLANT; - } -} - -int wxNativeFontInfo::GetNumericWeight() const -{ - const wxString weight = GetXFontComponent(wxXLFD_WEIGHT).MakeLower(); - if (weight == wxT("thin") || weight == wxT("ultralight")) - return wxFONTWEIGHT_THIN; - else if (weight == wxT("extralight")) - return wxFONTWEIGHT_EXTRALIGHT; - else if (weight == wxT("light")) - return wxFONTWEIGHT_LIGHT; - else if (weight == wxT("book") || weight == wxT("semilight") || weight == wxT("demilight")) - return 350; - else if (weight == wxT("medium")) - return wxFONTWEIGHT_MEDIUM; - else if (weight == wxT("semibold") || weight == wxT("demibold")) - return wxFONTWEIGHT_SEMIBOLD; - else if (weight == wxT("bold")) - return wxFONTWEIGHT_BOLD; - else if (weight == wxT("extrabold")) - return wxFONTWEIGHT_EXTRABOLD; - else if (weight == wxT("heavy")) - return wxFONTWEIGHT_HEAVY; - else if (weight == wxT("extraheavy") || weight == wxT("black") || weight == wxT("ultrabold")) - return wxFONTWEIGHT_EXTRAHEAVY; - - return wxFONTWEIGHT_NORMAL; -} - -bool wxNativeFontInfo::GetUnderlined() const -{ - // X fonts are never underlined - return false; -} - -wxString wxNativeFontInfo::GetFaceName() const -{ - // wxWidgets facename probably more accurately corresponds to X family - return GetXFontComponent(wxXLFD_FAMILY); -} - -wxFontFamily wxNativeFontInfo::GetFamily() const -{ - // and wxWidgets family -- to X foundry, but we have to translate it to - // wxFontFamily somehow... - wxFAIL_MSG(wxT("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY); - - return wxFONTFAMILY_DEFAULT; -} - -wxFontEncoding wxNativeFontInfo::GetEncoding() const -{ - // we already have the code for this but need to refactor it first - wxFAIL_MSG( wxT("not implemented") ); - - return wxFONTENCODING_MAX; -} - -void wxNativeFontInfo::SetFractionalPointSize(double pointsize) -{ - wxString s; - if ( pointsize < 0 ) - s = '*'; - else - s.Printf("%d", wxRound(10*pointsize)); - - SetXFontComponent(wxXLFD_POINTSIZE, s); -} - -void wxNativeFontInfo::SetStyle(wxFontStyle style) -{ - wxString s; - switch ( style ) - { - case wxFONTSTYLE_ITALIC: - s = wxT('i'); - break; - - case wxFONTSTYLE_SLANT: - s = wxT('o'); - break; - - case wxFONTSTYLE_NORMAL: - s = wxT('r'); - break; - - default: - wxFAIL_MSG( wxT("unknown wxFontStyle in wxNativeFontInfo::SetStyle") ); - return; - } - - SetXFontComponent(wxXLFD_SLANT, s); -} - -void wxNativeFontInfo::SetNumericWeight(int weight) -{ - wxString s; - switch ( wxFontInfo::GetWeightClosestToNumericValue(weight) ) - { - case wxFONTWEIGHT_THIN: - s = "thin"; - break; - - case wxFONTWEIGHT_EXTRALIGHT: - s = "extralight"; - break; - - case wxFONTWEIGHT_LIGHT: - s = "light"; - break; - - case wxFONTWEIGHT_NORMAL: - s = "normal"; - break; - - case wxFONTWEIGHT_MEDIUM: - s = "medium"; - break; - - case wxFONTWEIGHT_SEMIBOLD: - s = "semibold"; - break; - - case wxFONTWEIGHT_BOLD: - s = "bold"; - break; - - case wxFONTWEIGHT_EXTRABOLD: - s = "extrabold"; - break; - - case wxFONTWEIGHT_HEAVY: - s = "heavy"; - break; - - case wxFONTWEIGHT_EXTRAHEAVY: - s = "extraheavy"; - break; - - case wxFONTWEIGHT_INVALID: - wxFAIL_MSG( "Invalid font weight" ); - break; - } - - wxCHECK_RET( !s.empty(), "unknown weight value" ); - - SetXFontComponent(wxXLFD_WEIGHT, s); -} - -void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined)) -{ - // can't do this under X -} - -void wxNativeFontInfo::SetStrikethrough(bool WXUNUSED(strikethrough)) -{ - // this is not supported by Pango fonts either -} - -bool wxNativeFontInfo::SetFaceName(const wxString& facename) -{ - SetXFontComponent(wxXLFD_FAMILY, facename); - return true; -} - -void wxNativeFontInfo::SetFamily(wxFontFamily family) -{ - wxString xfamily; - switch (family) - { - case wxFONTFAMILY_DECORATIVE: xfamily = "lucida"; break; - case wxFONTFAMILY_ROMAN: xfamily = "times"; break; - case wxFONTFAMILY_MODERN: xfamily = "courier"; break; - case wxFONTFAMILY_DEFAULT: - case wxFONTFAMILY_SWISS: xfamily = "helvetica"; break; - case wxFONTFAMILY_TELETYPE: xfamily = "lucidatypewriter"; break; - case wxFONTFAMILY_SCRIPT: xfamily = "utopia"; break; - case wxFONTFAMILY_UNKNOWN: break; - } - - wxCHECK_RET( !xfamily.empty(), "Unknown wxFontFamily" ); - - SetXFontComponent(wxXLFD_FAMILY, xfamily); -} - -void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding) -{ - wxNativeEncodingInfo info; - if ( wxGetNativeFontEncoding(encoding, &info) ) - { - SetXFontComponent(wxXLFD_ENCODING, info.xencoding); - SetXFontComponent(wxXLFD_REGISTRY, info.xregistry); - } -} - -// ---------------------------------------------------------------------------- -// common functions -// ---------------------------------------------------------------------------- - -bool wxGetNativeFontEncoding(wxFontEncoding encoding, - wxNativeEncodingInfo *info) -{ - wxCHECK_MSG( info, false, wxT("bad pointer in wxGetNativeFontEncoding") ); - - if ( encoding == wxFONTENCODING_DEFAULT ) - { - encoding = wxFont::GetDefaultEncoding(); - } - - switch ( encoding ) - { - case wxFONTENCODING_ISO8859_1: - case wxFONTENCODING_ISO8859_2: - case wxFONTENCODING_ISO8859_3: - case wxFONTENCODING_ISO8859_4: - case wxFONTENCODING_ISO8859_5: - case wxFONTENCODING_ISO8859_6: - case wxFONTENCODING_ISO8859_7: - case wxFONTENCODING_ISO8859_8: - case wxFONTENCODING_ISO8859_9: - case wxFONTENCODING_ISO8859_10: - case wxFONTENCODING_ISO8859_11: - case wxFONTENCODING_ISO8859_12: - case wxFONTENCODING_ISO8859_13: - case wxFONTENCODING_ISO8859_14: - case wxFONTENCODING_ISO8859_15: - { - int cp = encoding - wxFONTENCODING_ISO8859_1 + 1; - info->xregistry = wxT("iso8859"); - info->xencoding.Printf(wxT("%d"), cp); - } - break; - - case wxFONTENCODING_UTF8: - info->xregistry = wxT("iso10646"); - info->xencoding = wxT("*"); - break; - - case wxFONTENCODING_GB2312: - info->xregistry = wxT("GB2312"); // or the otherway round? - info->xencoding = wxT("*"); - break; - - case wxFONTENCODING_KOI8: - case wxFONTENCODING_KOI8_U: - info->xregistry = wxT("koi8"); - - // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far) - info->xencoding = wxT("*"); - break; - - case wxFONTENCODING_CP1250: - case wxFONTENCODING_CP1251: - case wxFONTENCODING_CP1252: - case wxFONTENCODING_CP1253: - case wxFONTENCODING_CP1254: - case wxFONTENCODING_CP1255: - case wxFONTENCODING_CP1256: - case wxFONTENCODING_CP1257: - { - int cp = encoding - wxFONTENCODING_CP1250 + 1250; - info->xregistry = wxT("microsoft"); - info->xencoding.Printf(wxT("cp%d"), cp); - } - break; - - case wxFONTENCODING_EUC_JP: - case wxFONTENCODING_SHIFT_JIS: - info->xregistry = "jis*"; - info->xencoding = "*"; - break; - - case wxFONTENCODING_SYSTEM: - info->xregistry = - info->xencoding = wxT("*"); - break; - - default: - // don't know how to translate this encoding into X fontspec - return false; - } - - info->encoding = encoding; - - return true; -} - -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); -} - -// ---------------------------------------------------------------------------- -// X-specific functions -// ---------------------------------------------------------------------------- - -wxNativeFont wxLoadQueryNearestFont(double pointSize, - wxFontFamily family, - wxFontStyle style, - int weight, - bool underlined, - const wxString &facename, - wxFontEncoding encoding, - wxString* xFontName) -{ - if ( encoding == wxFONTENCODING_DEFAULT ) - { - encoding = wxFont::GetDefaultEncoding(); - } - - // first determine the encoding - if the font doesn't exist at all in this - // encoding, it's useless to do all other approximations (i.e. size, - // family &c don't matter much) - wxNativeEncodingInfo info; - if ( encoding == wxFONTENCODING_SYSTEM ) - { - // This will always work so we don't test to save time - wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM, &info); - } - else - { - if ( !wxGetNativeFontEncoding(encoding, &info) || - !wxTestFontEncoding(info) ) - { -#if wxUSE_FONTMAP - if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) ) -#endif // wxUSE_FONTMAP - { - // unspported encoding - replace it with the default - // - // NB: we can't just return 0 from here because wxGTK code doesn't - // check for it (i.e. it supposes that we'll always succeed), - // so it would provoke a crash - wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM, &info); - } - } - } - - // OK, we have the correct xregistry/xencoding in info structure - wxNativeFont font = 0; - - // if we already have the X font name, try to use it - if( xFontName && !xFontName->empty() ) - { - // - // Make sure point size is correct for scale factor. - // - wxStringTokenizer tokenizer(*xFontName, wxT("-"), wxTOKEN_RET_DELIMS); - wxString newFontName; - - for(int i = 0; i < 8; i++) - newFontName += tokenizer.NextToken(); - - (void) tokenizer.NextToken(); - - newFontName += wxString::Format(wxT("%d-"), pointSize); - - while(tokenizer.HasMoreTokens()) - newFontName += tokenizer.GetNextToken(); - - font = wxLoadFont(newFontName); - - if(font) - *xFontName = newFontName; - } - - if ( !font ) - { - // search up and down by stepsize 10 - int max_size = pointSize + 20 * (1 + (pointSize/180)); - int min_size = pointSize - 20 * (1 + (pointSize/180)); - - int i, round; // counters - - // first round: search for equal, then for smaller and for larger size - // with the given weight and style - int testweight = weight; - wxFontStyle teststyle = style; - - for ( round = 0; round < 3; round++ ) - { - // second round: use normal weight - if ( round == 1 ) - { - if ( testweight != wxFONTWEIGHT_NORMAL ) - { - testweight = wxFONTWEIGHT_NORMAL; - } - else - { - ++round; // fall through to third round - } - } - - // third round: ... and use normal style - if ( round == 2 ) - { - if ( teststyle != wxFONTSTYLE_NORMAL ) - { - teststyle = wxFONTSTYLE_NORMAL; - } - else - { - break; - } - } - // Search for equal or smaller size (approx.) - for ( i = pointSize; !font && i >= 10 && i >= min_size; i -= 10 ) - { - font = wxLoadQueryFont(i, family, teststyle, testweight, underlined, - facename, info.xregistry, info.xencoding, - xFontName); - } - - // Search for larger size (approx.) - for ( i = pointSize + 10; !font && i <= max_size; i += 10 ) - { - font = wxLoadQueryFont(i, family, teststyle, testweight, underlined, - facename, info.xregistry, info.xencoding, - xFontName); - } - } - - // Try default family - if ( !font && family != wxFONTFAMILY_DEFAULT ) - { - font = wxLoadQueryFont(pointSize, wxFONTFAMILY_DEFAULT, style, weight, - underlined, facename, - info.xregistry, info.xencoding, - xFontName ); - } - - // ignore size, family, style and weight but try to find font with the - // given facename and encoding - if ( !font ) - { - font = wxLoadQueryFont(120, wxFONTFAMILY_DEFAULT, - wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, - underlined, facename, - info.xregistry, info.xencoding, - xFontName); - - // ignore family as well - if ( !font ) - { - font = wxLoadQueryFont(120, wxFONTFAMILY_DEFAULT, - wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, - underlined, wxEmptyString, - info.xregistry, info.xencoding, - xFontName); - - // if it still failed, try to get the font of any size but - // with the requested encoding: this can happen if the - // encoding is only available in one size which happens to be - // different from 120 - if ( !font ) - { - font = wxLoadQueryFont(-1, wxFONTFAMILY_DEFAULT, - wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, - false, wxEmptyString, - info.xregistry, info.xencoding, - xFontName); - - // this should never happen as we had tested for it in the - // very beginning, but if it does, do return something non - // null or we'd crash in wxFont code - if ( !font ) - { - wxFAIL_MSG( wxT("this encoding should be available!") ); - - font = wxLoadQueryFont(-1, wxFONTFAMILY_DEFAULT, - wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, - false, wxEmptyString, - wxT("*"), wxT("*"), - xFontName); - } - } - } - } - } - - return font; -} - -// ---------------------------------------------------------------------------- -// private functions -// ---------------------------------------------------------------------------- - -// returns true if there are any fonts matching this font spec -static bool wxTestFontSpec(const wxString& fontspec) -{ - // some X servers will fail to load this font because there are too many - // matches so we must test explicitly for this - if ( fontspec == wxT("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") ) - { - return true; - } - - wxNativeFont test = (wxNativeFont) g_fontHash->Get( fontspec ); - if (test) - { - return true; - } - - test = wxLoadFont(fontspec); - g_fontHash->Put( fontspec, (wxObject*) test ); - - if ( test ) - { - wxFreeFont(test); - - return true; - } - else - { - return false; - } -} - -static wxNativeFont wxLoadQueryFont(double 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 == wxFONTFAMILY_ROMAN ? 1 : 0) ; - logFont.lfSerif = (family == wxFONTFAMILY_SWISS ? 0 : 1) ; - logFont.lfSansSerif = !logFont.lfSerif ; - logFont.lfModern = (family == wxFONTFAMILY_MODERN ? 1 : 0) ; - logFont.lfProportional = (family == wxFONTFAMILY_TELETYPE ? 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 -} - -// ---------------------------------------------------------------------------- -// wxFontModule -// ---------------------------------------------------------------------------- - -class wxFontModule : public wxModule -{ -public: - bool OnInit(); - void OnExit(); - -private: - wxDECLARE_DYNAMIC_CLASS(wxFontModule); -}; - -wxIMPLEMENT_DYNAMIC_CLASS(wxFontModule, wxModule); - -bool wxFontModule::OnInit() -{ - g_fontHash = new wxHashTable( wxKEY_STRING ); - - return true; -} - -void wxFontModule::OnExit() -{ - wxDELETE(g_fontHash); -} - -#endif // GTK 2.0/1.x diff --git a/src/x11/font.cpp b/src/x11/font.cpp index 62f7b82f92..6727b484e4 100644 --- a/src/x11/font.cpp +++ b/src/x11/font.cpp @@ -524,13 +524,6 @@ bool wxFont::GetStrikethrough() const return M_FONTDATA->m_nativeFontInfo.GetStrikethrough(); } -#if defined( __WXX11__ ) && ( wxUSE_PANGO == 0 ) -bool wxNativeFontInfo::GetStrikethrough() const -{ - return false; -} -#endif - wxFontEncoding wxFont::GetEncoding() const { wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); @@ -622,7 +615,6 @@ void wxFont::DoSetNativeFontInfo( const wxNativeFontInfo& info ) M_FONTDATA->SetNativeFontInfo( info ); } -#if wxUSE_PANGO // Although we don't use this function yet, but we must create it here. // first, for the prepare the unicode drawing support in wxUniv/x11 port. // If we use pango to draw the text, then we must set some attributes @@ -651,4 +643,3 @@ bool wxFont::SetPangoAttrs(PangoLayout* layout) const return true; } -#endif