Point Cloud Library (PCL)  1.10.1-dev
opennurbs_font.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_FONT_INC_)
18 #define OPENNURBS_FONT_INC_
19 
20 class ON_CLASS ON_Font : public ON_Object
21 {
22  ON_OBJECT_DECLARE(ON_Font);
23 public:
24  ON_Font();
25  ~ON_Font();
26  // C++ default copy construction and operator= work fine.
27 
28  /*
29  Description:
30  Create a font with a specified facename and properties.
31  Parameters:
32  face_name - [in]
33  If face_name is null or empty, then "Arial" is used.
34  bBold - [in]
35  True for a bold version of the font.
36  bItalic - [in]
37  True for an italic version of the font.
38  Returns:
39  True if the font was created. The name of this font is
40  the face name with " Bold", " Italic" or " Bold Italic"
41  appended as
42  */
43  bool CreateFontFromFaceName(
44  const wchar_t* face_name,
45  bool bBold,
46  bool bItalic
47  );
48 
49 #if defined(ON_OS_WINDOWS_GDI)
50  ON_Font( const LOGFONT& logfont );
51  ON_Font& operator=( const LOGFONT& logfont );
52 #endif
53 
54  //////////////////////////////////////////////////////////////////////
55  //
56  // ON_Object overrides
57 
58  /*
59  Description:
60  Tests an object to see if its data members are correctly
61  initialized.
62  Parameters:
63  text_log - [in] if the object is not valid and text_log
64  is not NULL, then a brief englis description of the
65  reason the object is not valid is appened to the log.
66  The information appended to text_log is suitable for
67  low-level debugging purposes by programmers and is
68  not intended to be useful as a high level user
69  interface tool.
70  Returns:
71  @untitled table
72  true object is valid
73  false object is invalid, uninitialized, etc.
74  Remarks:
75  Overrides virtual ON_Object::IsValid
76  */
77  ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
78 
79  // virtual
80  void Dump( ON_TextLog& ) const; // for debugging
81 
82  // virtual
83  ON_BOOL32 Write(
84  ON_BinaryArchive& // serialize definition to binary archive
85  ) const;
86 
87  // virtual
88  ON_BOOL32 Read(
89  ON_BinaryArchive& // restore definition from binary archive
90  );
91 
92  // virtual
93  ON_UUID ModelObjectId() const;
94 
95  //////////////////////////////////////////////////////////////////////
96  //
97  // Interface
98 
99  enum
100  {
101 
102 #if defined(ON_OS_WINDOWS_GDI)
103 
104  // Windows GDI facename length
105 
106  // 13 November 2008 - Dale Lear
107  // Because:
108  // * Prior to this date the above "ON_OS_WINDOWS_GDI"
109  // was misspelled and this code did not get compiled.
110  // * The Windows headers defines LF_FACESIZE = 32
111  // * ON_Font has a member wchar_t m_facename[face_name_size] array
112  // * We cannot break the SDK by changing the size of ON_Font
113  //
114  // we cannot define face_name_size = LF_FACESIZE+1. So, I'm
115  // using the same "65" we use below. It is critical that
116  // face_name_size >= LF_FACESIZE+1
117  //
118  //face_name_size = LF_FACESIZE+1, // <- prior to 13 Nov but never used
119  face_name_size = 65,
120 
121  // Windows GDI font weights
122  bold_weight = FW_BOLD,
123  medium_weight = FW_MEDIUM,
124  normal_weight = FW_NORMAL,
125  light_weight = FW_LIGHT,
126 
127  // Windows GDI character sets
128  default_charset = DEFAULT_CHARSET,
129  symbol_charset = SYMBOL_CHARSET,
130 
131 #else
132 
133  face_name_size = 65, // must be >= 33
134 
135  bold_weight = 700,
136  medium_weight = 500,
137  normal_weight = 400,
138  light_weight = 300,
139 
140  default_charset = 1,
141  symbol_charset = 2,
142 
143 #endif
144 
145  normal_font_height = 256
146  };
147 
148  // Ratio of linefeed to character height (1.6)
149  static
151 
152  static
153  const int m_metrics_char; // ASCII code of character to used
154  // to get runtime "default" glyph
155  // metrics. (Currently an "I").
156 
157  /*
158  Returns:
159  True if the font's character set should be SYMBOL_CHARSET;
160  */
161  static
162  bool IsSymbolFontFaceName(
163  const wchar_t* facename
164  );
165 
166  void SetFontName( const wchar_t* );
167  void SetFontName( const char* );
168 
169  void GetFontName( ON_wString& ) const;
170  const wchar_t* FontName() const;
171 
172  void SetFontIndex(int);
173  int FontIndex() const;
174 
175  /*
176  Returns:
177  The ratio (height of linefeed)/(height of I).
178  */
179  double LinefeedRatio() const;
180 
181  void SetLinefeedRatio( double linefeed_ratio );
182 
183  bool SetFontFaceName( const wchar_t* );
184  bool SetFontFaceName( const char* );
185 
186  void GetFontFaceName( ON_wString& ) const;
187  const wchar_t* FontFaceName() const;
188 
189  int FontWeight() const;
190  void SetFontWeight( int);
191 
192  bool IsItalic() const;
193  void SetIsItalic( bool );
194  void SetItalic( bool );
195 
196  bool IsBold() const;
197  void SetBold( bool );
198 
199  // Added 7/12/07 LW
200  bool IsUnderlined() const;
201  void SetUnderlined( bool );
202 
203  void Defaults();
204 
205  /*
206  Returns:
207  Height of the 'I' character when the font is drawn
208  with m_logfont.lfHeight = ON_Font::normal_font_height.
209  */
210  int HeightOfI() const;
211 
212  /*
213  Returns:
214  Height of a linefeed when the font is drawn
215  with m_logfont.lfHeight = ON_Font::normal_font_height.
216  */
217  int HeightOfLinefeed() const;
218 
219  /*
220  Description:
221  Returns the ratio of the height of a typical upper case letter
222  to the height of a whole character cell.
223 
224  Parameters:
225  none
226 
227  Returns:
228  double - ratio of Windows Font Height / m_HeightOfH
229  */
230  double AscentRatio() const;
231 
232  /*
233  Description:
234  Compare the visible characteristics to another font
235 
236  Parameters:
237  font_to_compare - [in] The cont to compare this one to
238  bCompareName - [in] if this is set, test if the names match
239  otherwise don't compare the names
240 
241  Returns:
242  true if font_to_compare matches this one
243  false if font_to_match doesn't match this one
244 
245  Added for v5 - 5/20/07
246  */
247  bool CompareFontCharacteristics( ON_Font& font_to_compare, bool bCompareName) const;
248 
249 #if defined(ON_OS_WINDOWS_GDI)
250  bool SetLogFont( const LOGFONT& logfont );
251  const LOGFONT& LogFont() const;
252 #endif
253 
254 public:
255  ON_wString m_font_name; // Name of this font in the Rhino UI
256  int m_font_weight; // Same as m_logfont.lfWeight
257  bool m_font_italic; // Same as m_logfont.lfItalic
258  bool m_font_underlined;// Same as m_logfont.lfUnderlined (Added 7/12/07 LW)
259  double m_linefeed_ratio; // defaults to static s_linefeed_ratio.
260  int m_font_index; // font index in Rhino font table
262  wchar_t m_facename[face_name_size]; // same as m_logfont.lfFaceName (
263 
264 public:
265 
266  /*
267  Description:
268  Insures the settings in the OS specific information, like
269  the Windows m_logfont field, match the persistent m_font_* values
270  above that are used for all OSs and used in UI code.
271  */
272  void UpdateImplementationSettings();
273 #if defined(ON_OS_WINDOWS_GDI)
274  // Windows specific settins
275  LOGFONT m_logfont;
276 #endif
277 
278 private:
279  // volitile - can be changed by ON_Font::HeightOfI() const.
280  int m_I_height; // height of the 'I' character when the font is drawn
281  // with m_logfont.lfHeight = 256.
282 };
283 
284 #endif
virtual ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const =0
int m_font_index
ON_wString m_font_name
static const int m_metrics_char
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
int m_font_weight
ON_UUID m_font_id
virtual ON_BOOL32 Read(ON_BinaryArchive &binary_archive)
virtual void Dump(ON_TextLog &) const
ON_Object & operator=(const ON_Object &)
bool m_font_underlined
double m_linefeed_ratio
bool m_font_italic
virtual ON_UUID ModelObjectId() const
static const double m_default_linefeed_ratio