fontenum.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/fontenum.h
  3. // Purpose: wxFontEnumerator class for getting available fonts
  4. // Author: Julian Smart, Vadim Zeitlin
  5. // Modified by: extended to enumerate more than just font facenames and works
  6. // not only on Windows now (VZ)
  7. // Created: 04/01/98
  8. // Copyright: (c) Julian Smart, Vadim Zeitlin
  9. // Licence: wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef _WX_FONTENUM_H_
  12. #define _WX_FONTENUM_H_
  13. #include "wx/defs.h"
  14. #if wxUSE_FONTENUM
  15. #include "wx/fontenc.h"
  16. #include "wx/arrstr.h"
  17. // ----------------------------------------------------------------------------
  18. // wxFontEnumerator enumerates all available fonts on the system or only the
  19. // fonts with given attributes
  20. // ----------------------------------------------------------------------------
  21. class WXDLLIMPEXP_CORE wxFontEnumerator
  22. {
  23. public:
  24. wxFontEnumerator() {}
  25. // virtual dtor for the base class
  26. virtual ~wxFontEnumerator() {}
  27. // start enumerating font facenames (either all of them or those which
  28. // support the given encoding) - will result in OnFacename() being
  29. // called for each available facename (until they are exhausted or
  30. // OnFacename returns false)
  31. virtual bool EnumerateFacenames
  32. (
  33. wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
  34. bool fixedWidthOnly = false
  35. );
  36. // enumerate the different encodings either for given font facename or for
  37. // all facenames - will result in OnFontEncoding() being called for each
  38. // available (facename, encoding) couple
  39. virtual bool EnumerateEncodings(const wxString& facename = wxEmptyString);
  40. // callbacks which are called after one of EnumerateXXX() functions from
  41. // above is invoked - all of them may return false to stop enumeration or
  42. // true to continue with it
  43. // called by EnumerateFacenames
  44. virtual bool OnFacename(const wxString& WXUNUSED(facename))
  45. { return true; }
  46. // called by EnumerateEncodings
  47. virtual bool OnFontEncoding(const wxString& WXUNUSED(facename),
  48. const wxString& WXUNUSED(encoding))
  49. { return true; }
  50. // convenience function that returns array of facenames.
  51. static wxArrayString
  52. GetFacenames(wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
  53. bool fixedWidthOnly = false);
  54. // convenience function that returns array of all available encodings.
  55. static wxArrayString GetEncodings(const wxString& facename = wxEmptyString);
  56. // convenience function that returns true if the given face name exist
  57. // in the user's system
  58. static bool IsValidFacename(const wxString &str);
  59. private:
  60. #ifdef wxHAS_UTF8_FONTS
  61. // helper for ports that only use UTF-8 encoding natively
  62. bool EnumerateEncodingsUTF8(const wxString& facename);
  63. #endif
  64. wxDECLARE_NO_COPY_CLASS(wxFontEnumerator);
  65. };
  66. #endif // wxUSE_FONTENUM
  67. #endif // _WX_FONTENUM_H_