font.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/cocoa/font.h
  3. // Purpose: wxFont class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_FONT_H_
  11. #define _WX_FONT_H_
  12. // ----------------------------------------------------------------------------
  13. // wxFont
  14. // ----------------------------------------------------------------------------
  15. DECLARE_WXCOCOA_OBJC_CLASS(NSFont);
  16. // Internal class that bridges us with code like wxSystemSettings
  17. class wxCocoaFontFactory;
  18. // We have c-tors/methods taking pointers of these
  19. class wxFontRefData;
  20. /*! @discussion
  21. wxCocoa's implementation of wxFont is very incomplete. In particular,
  22. a lot of work needs to be done on wxNativeFontInfo which is currently
  23. using the totally generic implementation.
  24. See the documentation in src/cocoa/font.mm for more implementatoin details.
  25. */
  26. class WXDLLIMPEXP_CORE wxFont : public wxFontBase
  27. {
  28. friend class wxCocoaFontFactory;
  29. public:
  30. /*! @abstract Default construction of invalid font for 2-step construct then Create process.
  31. */
  32. wxFont() { }
  33. wxFont(const wxFontInfo& info)
  34. {
  35. Create(info.GetPointSize(),
  36. info.GetFamily(),
  37. info.GetStyle(),
  38. info.GetWeight(),
  39. info.IsUnderlined(),
  40. info.GetFaceName(),
  41. info.GetEncoding());
  42. if ( info.IsUsingSizeInPixels() )
  43. SetPixelSize(info.GetPixelSize());
  44. }
  45. /*! @abstract Platform-independent construction with individual properties
  46. */
  47. #if FUTURE_WXWIN_COMPATIBILITY_3_0
  48. wxFont(int size,
  49. int family,
  50. int style,
  51. int weight,
  52. bool underlined = FALSE,
  53. const wxString& face = wxEmptyString,
  54. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  55. {
  56. (void)Create(size, (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding);
  57. }
  58. #endif
  59. wxFont(int size,
  60. wxFontFamily family,
  61. wxFontStyle style,
  62. wxFontWeight weight,
  63. bool underlined = FALSE,
  64. const wxString& face = wxEmptyString,
  65. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  66. {
  67. (void)Create(size, family, style, weight, underlined, face, encoding);
  68. }
  69. wxFont(const wxSize& pixelSize,
  70. wxFontFamily family,
  71. wxFontStyle style,
  72. wxFontWeight weight,
  73. bool underlined = false,
  74. const wxString& face = wxEmptyString,
  75. wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
  76. {
  77. Create(10, family, style, weight, underlined, face, encoding);
  78. SetPixelSize(pixelSize);
  79. }
  80. /*! @abstract Construction with opaque wxNativeFontInfo
  81. */
  82. wxFont(const wxNativeFontInfo& info)
  83. {
  84. (void)Create(info);
  85. }
  86. /*! @abstract Construction with platform-dependent font descriptor string.
  87. @param fontDesc Usually the result of wxNativeFontInfo::ToUserString()
  88. */
  89. wxFont(const wxString& fontDesc);
  90. // NOTE: Copy c-tor and assignment from wxObject is fine
  91. bool Create(int size,
  92. wxFontFamily family,
  93. wxFontStyle style,
  94. wxFontWeight weight,
  95. bool underlined = FALSE,
  96. const wxString& face = wxEmptyString,
  97. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  98. bool Create(const wxNativeFontInfo& info);
  99. virtual ~wxFont();
  100. // implement base class pure virtuals
  101. virtual int GetPointSize() const;
  102. virtual wxFontStyle GetStyle() const;
  103. virtual wxFontWeight GetWeight() const;
  104. virtual bool GetUnderlined() const;
  105. virtual wxString GetFaceName() const;
  106. virtual wxFontEncoding GetEncoding() const;
  107. virtual const wxNativeFontInfo *GetNativeFontInfo() const;
  108. virtual void SetPointSize(int pointSize);
  109. virtual void SetFamily(wxFontFamily family);
  110. virtual void SetStyle(wxFontStyle style);
  111. virtual void SetWeight(wxFontWeight weight);
  112. virtual bool SetFaceName(const wxString& faceName);
  113. virtual void SetUnderlined(bool underlined);
  114. virtual void SetEncoding(wxFontEncoding encoding);
  115. wxDECLARE_COMMON_FONT_METHODS();
  116. // implementation only from now on
  117. // -------------------------------
  118. /*! @abstract Defined on some ports (not including this one) in wxGDIObject
  119. @discussion
  120. The intention here I suppose is to allow one to create a wxFont without yet
  121. creating the underlying native object. There's no point not to create the
  122. NSFont immediately in wxCocoa so this is useless.
  123. This method came from the stub code copied in the early days of wxCocoa.
  124. FIXME(1): Remove this in trunk. FIXME(2): Is it really a good idea for this to
  125. be part of the public API for wxGDIObject?
  126. */
  127. virtual bool RealizeResource();
  128. protected:
  129. /*! @abstract Internal constructor with ref data
  130. @discussion
  131. Takes ownership of @a refData. That is, it is assumed that refData has either just been
  132. created using new (which initializes its m_refCount to 1) or if you are sharing a ref that
  133. you have called IncRef on it before passing it to this method.
  134. */
  135. explicit wxFont(wxFontRefData *refData)
  136. { Create(refData); }
  137. bool Create(wxFontRefData *refData);
  138. virtual wxGDIRefData *CreateGDIRefData() const;
  139. virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
  140. virtual wxFontFamily DoGetFamily() const;
  141. private:
  142. DECLARE_DYNAMIC_CLASS(wxFont)
  143. };
  144. #endif
  145. // _WX_FONT_H_