font.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/motif/font.h
  3. // Purpose: wxFont class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 17/09/98
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_FONT_H_
  11. #define _WX_FONT_H_
  12. #if __WXMOTIF20__ && !__WXLESSTIF__
  13. #define wxMOTIF_USE_RENDER_TABLE 1
  14. #else
  15. #define wxMOTIF_USE_RENDER_TABLE 0
  16. #endif
  17. #define wxMOTIF_NEW_FONT_HANDLING wxMOTIF_USE_RENDER_TABLE
  18. class wxXFont;
  19. // Font
  20. class WXDLLIMPEXP_CORE wxFont : public wxFontBase
  21. {
  22. public:
  23. // ctors and such
  24. wxFont() { }
  25. wxFont(const wxFontInfo& info)
  26. {
  27. Create(info.GetPointSize(),
  28. info.GetFamily(),
  29. info.GetStyle(),
  30. info.GetWeight(),
  31. info.IsUnderlined(),
  32. info.GetFaceName(),
  33. info.GetEncoding());
  34. if ( info.IsUsingSizeInPixels() )
  35. SetPixelSize(info.GetPixelSize());
  36. }
  37. wxFont(const wxNativeFontInfo& info);
  38. #if FUTURE_WXWIN_COMPATIBILITY_3_0
  39. wxFont(int size,
  40. int family,
  41. int style,
  42. int weight,
  43. bool underlined = false,
  44. const wxString& face = wxEmptyString,
  45. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  46. {
  47. (void)Create(size, (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding);
  48. }
  49. #endif
  50. wxFont(int size,
  51. wxFontFamily family,
  52. wxFontStyle style,
  53. wxFontWeight weight,
  54. bool underlined = false,
  55. const wxString& face = wxEmptyString,
  56. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  57. {
  58. Create(size, family, style, weight, underlined, face, encoding);
  59. }
  60. wxFont(const wxSize& pixelSize,
  61. wxFontFamily family,
  62. wxFontStyle style,
  63. wxFontWeight weight,
  64. bool underlined = false,
  65. const wxString& face = wxEmptyString,
  66. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  67. {
  68. Create(10, family, style, weight, underlined, face, encoding);
  69. SetPixelSize(pixelSize);
  70. }
  71. bool Create(int size,
  72. wxFontFamily family,
  73. wxFontStyle style,
  74. wxFontWeight weight,
  75. bool underlined = false,
  76. const wxString& face = wxEmptyString,
  77. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  78. // wxMOTIF-specific
  79. bool Create(const wxString& fontname,
  80. wxFontEncoding fontenc = wxFONTENCODING_DEFAULT);
  81. bool Create(const wxNativeFontInfo& fontinfo);
  82. virtual ~wxFont();
  83. // implement base class pure virtuals
  84. virtual int GetPointSize() const;
  85. virtual wxFontStyle GetStyle() const;
  86. virtual wxFontWeight GetWeight() const;
  87. virtual bool GetUnderlined() const;
  88. virtual wxString GetFaceName() const;
  89. virtual wxFontEncoding GetEncoding() const;
  90. virtual const wxNativeFontInfo *GetNativeFontInfo() const;
  91. virtual void SetPointSize(int pointSize);
  92. virtual void SetFamily(wxFontFamily family);
  93. virtual void SetStyle(wxFontStyle style);
  94. virtual void SetWeight(wxFontWeight weight);
  95. virtual bool SetFaceName(const wxString& faceName);
  96. virtual void SetUnderlined(bool underlined);
  97. virtual void SetEncoding(wxFontEncoding encoding);
  98. wxDECLARE_COMMON_FONT_METHODS();
  99. // Implementation
  100. // Find an existing, or create a new, XFontStruct
  101. // based on this wxFont and the given scale. Append the
  102. // font to list in the private data for future reference.
  103. // TODO This is a fairly basic implementation, that doesn't
  104. // allow for different facenames, and also doesn't do a mapping
  105. // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.)
  106. // and the fonts that are available on a particular system.
  107. // Maybe we need to scan the user's machine to build up a profile
  108. // of the fonts and a mapping file.
  109. // Return font struct, and optionally the Motif font list
  110. wxXFont *GetInternalFont(double scale = 1.0,
  111. WXDisplay* display = NULL) const;
  112. // These two are helper functions for convenient access of the above.
  113. #if wxMOTIF_USE_RENDER_TABLE
  114. WXFontSet GetFontSet(double scale, WXDisplay* display = NULL) const;
  115. WXRenderTable GetRenderTable(WXDisplay* display) const;
  116. #else // if !wxMOTIF_USE_RENDER_TABLE
  117. WXFontStructPtr GetFontStruct(double scale = 1.0,
  118. WXDisplay* display = NULL) const;
  119. WXFontList GetFontList(double scale = 1.0,
  120. WXDisplay* display = NULL) const;
  121. #endif // !wxMOTIF_USE_RENDER_TABLE
  122. // returns either a XmFontList or XmRenderTable, depending
  123. // on Motif version
  124. WXFontType GetFontType(WXDisplay* display) const;
  125. // like the function above but does a copy for XmFontList
  126. WXFontType GetFontTypeC(WXDisplay* display) const;
  127. static WXString GetFontTag();
  128. protected:
  129. virtual wxGDIRefData *CreateGDIRefData() const;
  130. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  131. virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info );
  132. virtual wxFontFamily DoGetFamily() const;
  133. void Unshare();
  134. private:
  135. DECLARE_DYNAMIC_CLASS(wxFont)
  136. };
  137. #endif // _WX_FONT_H_