font.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/x11/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. class wxXFont;
  13. // Font
  14. class WXDLLIMPEXP_CORE wxFont : public wxFontBase
  15. {
  16. public:
  17. // ctors and such
  18. wxFont() { }
  19. wxFont(const wxFontInfo& info)
  20. {
  21. Create(info.GetPointSize(),
  22. info.GetFamily(),
  23. info.GetStyle(),
  24. info.GetWeight(),
  25. info.IsUnderlined(),
  26. info.GetFaceName(),
  27. info.GetEncoding());
  28. if ( info.IsUsingSizeInPixels() )
  29. SetPixelSize(info.GetPixelSize());
  30. }
  31. #if FUTURE_WXWIN_COMPATIBILITY_3_0
  32. wxFont(int size,
  33. int family,
  34. int style,
  35. int weight,
  36. bool underlined = false,
  37. const wxString& face = wxEmptyString,
  38. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  39. {
  40. (void)Create(size, (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding);
  41. }
  42. #endif
  43. wxFont(int size,
  44. wxFontFamily family,
  45. wxFontStyle style,
  46. wxFontWeight weight,
  47. bool underlined = false,
  48. const wxString& face = wxEmptyString,
  49. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  50. {
  51. Create(size, family, style, weight, underlined, face, encoding);
  52. }
  53. wxFont(const wxSize& pixelSize,
  54. wxFontFamily family,
  55. wxFontStyle style,
  56. wxFontWeight weight,
  57. bool underlined = false,
  58. const wxString& face = wxEmptyString,
  59. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  60. {
  61. Create(10, family, style, weight, underlined, face, encoding);
  62. SetPixelSize(pixelSize);
  63. }
  64. bool Create(int size,
  65. wxFontFamily family,
  66. wxFontStyle style,
  67. wxFontWeight weight,
  68. bool underlined = false,
  69. const wxString& face = wxEmptyString,
  70. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  71. wxFont(const wxNativeFontInfo& info);
  72. // FIXME: I added the ! to make it compile;
  73. // is this right? - JACS
  74. #if !wxUSE_UNICODE
  75. bool Create(const wxString& fontname,
  76. wxFontEncoding fontenc = wxFONTENCODING_DEFAULT);
  77. #endif
  78. // DELETEME: no longer seems to be implemented.
  79. // bool Create(const wxNativeFontInfo& fontinfo);
  80. virtual ~wxFont();
  81. // implement base class pure virtuals
  82. virtual int GetPointSize() const;
  83. virtual wxFontStyle GetStyle() const;
  84. virtual wxFontWeight GetWeight() const;
  85. virtual bool GetUnderlined() const;
  86. virtual wxString GetFaceName() const;
  87. virtual wxFontEncoding GetEncoding() const;
  88. virtual const wxNativeFontInfo *GetNativeFontInfo() const;
  89. virtual bool IsFixedWidth() const;
  90. virtual void SetPointSize(int pointSize);
  91. virtual void SetFamily(wxFontFamily family);
  92. virtual void SetStyle(wxFontStyle style);
  93. virtual void SetWeight(wxFontWeight weight);
  94. virtual bool SetFaceName(const wxString& faceName);
  95. virtual void SetUnderlined(bool underlined);
  96. virtual void SetEncoding(wxFontEncoding encoding);
  97. wxDECLARE_COMMON_FONT_METHODS();
  98. // Implementation
  99. #if wxUSE_PANGO
  100. #else
  101. // Find an existing, or create a new, XFontStruct
  102. // based on this wxFont and the given scale. Append the
  103. // font to list in the private data for future reference.
  104. // TODO This is a fairly basic implementation, that doesn't
  105. // allow for different facenames, and also doesn't do a mapping
  106. // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.)
  107. // and the fonts that are available on a particular system.
  108. // Maybe we need to scan the user's machine to build up a profile
  109. // of the fonts and a mapping file.
  110. // Return font struct, and optionally the Motif font list
  111. wxXFont *GetInternalFont(double scale = 1.0,
  112. WXDisplay* display = NULL) const;
  113. // Helper function for convenient access of the above.
  114. WXFontStructPtr GetFontStruct(double scale = 1.0,
  115. WXDisplay* display = NULL) const;
  116. #endif
  117. protected:
  118. virtual wxGDIRefData *CreateGDIRefData() const;
  119. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  120. virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info );
  121. virtual wxFontFamily DoGetFamily() const;
  122. void Unshare();
  123. private:
  124. DECLARE_DYNAMIC_CLASS(wxFont)
  125. };
  126. #endif
  127. // _WX_FONT_H_