]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/fontenum.cpp
c97a533c5db67a24d13999ee84ee4008f2607f1f
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/fontenum.cpp
3 // Purpose: wxFontEnumerator class for X11/GDK
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontenum.h"
25 #include "wx/dynarray.h"
26 #include "wx/string.h"
29 #include "wx/fontenum.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 // compare function for sorted array of strings
38 static int CMPFUNC_CONV
CompareStrings(const char *s1
, const char *s2
);
40 // create the list of all fonts with the given spacing
41 static char **CreateFontList(wxChar spacing
, int *nFonts
);
43 // extract all font families from the given font list and call our
44 // OnFontFamily() for each of them
45 static bool ProcessFamiliesFromFontList(wxFontEnumerator
*This
,
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 WX_DEFINE_SORTED_ARRAY(const char *, wxSortedStringArray
);
56 // ============================================================================
58 // ============================================================================
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 static int CMPFUNC_CONV
CompareStrings(const char *s1
, const char *s2
)
66 return strcmp(s1
, s2
);
69 static char **CreateFontList(wxChar spacing
, int *nFonts
)
72 pattern
.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-%c-*-*-*"), spacing
);
74 // get the list of all fonts
75 return XListFonts((Display
*)wxGetDisplay(), pattern
, 32767, nFonts
);
78 static bool ProcessFamiliesFromFontList(wxFontEnumerator
*This
,
82 // extract the list of (unique) font families
83 wxSortedStringArray
families(CompareStrings
);
84 for ( int n
= 0; n
< nFonts
; n
++ )
86 char *font
= fonts
[n
];
87 if ( !wxString(font
).Matches("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
89 // it's not a full font name (probably an alias)
93 char *dash
= strchr(font
+ 1, '-');
94 char *family
= dash
+ 1;
95 dash
= strchr(family
, '-');
96 *dash
= '\0'; // !NULL because Matches() above succeeded
98 if ( families
.Index(family
) == wxNOT_FOUND
)
100 if ( !This
->OnFontFamily(family
) )
106 families
.Add(family
);
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly
)
123 if ( fixedWidthOnly
)
126 fonts
= CreateFontList(wxT('m'), &nFonts
);
129 cont
= ProcessFamiliesFromFontList(this, fonts
, nFonts
);
131 XFreeFontNames(fonts
);
139 fonts
= CreateFontList(wxT('c'), &nFonts
);
147 fonts
= CreateFontList(wxT('*'), &nFonts
);
151 wxFAIL_MSG(wxT("No fonts at all on this system?"));
157 (void)ProcessFamiliesFromFontList(this, fonts
, nFonts
);
159 XFreeFontNames(fonts
);
164 bool wxFontEnumerator::EnumerateEncodings(const wxString
& family
)
168 pattern
.Printf(wxT("-*-%s-*-*-*-*-*-*-*-*-*-*-*-*"),
169 family
.IsEmpty() ? wxT("*") : family
.c_str());
171 // get the list of all fonts
173 char **fonts
= XListFonts((Display
*)wxGetDisplay(), pattern
,
182 // extract the list of (unique) encodings
183 wxSortedStringArray
families(CompareStrings
);
184 for ( int n
= 0; n
< nFonts
; n
++ )
186 char *font
= fonts
[n
];
187 if ( !wxString(font
).Matches("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
189 // it's not a full font name (probably an alias)
193 // extract the family
194 char *dash
= strchr(font
+ 1, '-');
195 char *family
= dash
+ 1;
196 dash
= strchr(family
, '-');
197 *dash
= '\0'; // !NULL because Matches() above succeeded
199 // now extract the registry/encoding
205 return FALSE
; // TODO