opennurbs_text_style.h
1 //
2 // Copyright (c) 1993-2015 Robert McNeel & Associates. All rights reserved.
3 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
4 // McNeel & Associates.
5 //
6 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
7 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
8 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
9 //
10 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
11 //
12 ////////////////////////////////////////////////////////////////
13 
14 
15 #if !defined(OPENNURBS_TEXT_STYLE_INC_)
16 #define OPENNURBS_TEXT_STYLE_INC_
17 
18 
19 class ON_CLASS ON_TextStyle : public ON_ModelComponent
20 {
21  ON_OBJECT_DECLARE(ON_TextStyle);
22 
23 public:
24  static const ON_TextStyle Unset; // All values not set
25  static const ON_TextStyle Default; // index = -1, font set
26  static const ON_TextStyle ByLayer; // index = -2, no font
27  static const ON_TextStyle ByParent; // index = -3, no font
28 
29  /*
30  Parameters:
31  model_component_reference - [in]
32  none_return_value - [in]
33  value to return if ON_TextStyle::Cast(model_component_ref.ModelComponent())
34  is nullptr
35  Returns:
36  If ON_TextStyle::Cast(model_component_ref.ModelComponent()) is not nullptr,
37  that pointer is returned. Otherwise, none_return_value is returned.
38  */
39  static const ON_TextStyle* FromModelComponentRef(
40  const class ON_ModelComponentReference& model_component_reference,
41  const ON_TextStyle* none_return_value
42  );
43 
44  ON_TextStyle();
45  ~ON_TextStyle() = default;
46  ON_TextStyle(const ON_TextStyle&);
48 
49 private:
50  void Internal_Copy(
51  const ON_TextStyle& src
52  );
53 
54 public:
55  /*
56  Returns:
57  The managed font for this text style.
58  Returns ON_Font::Default if the font is not set.
59  */
60  const ON_Font& Font() const;
61 
62  const ON_wString& FontDescription() const;
63 
64  const wchar_t* FontDescriptionAsPointer() const;
65 
66  const ON_wString& AppleFontName() const;
67 
68  const wchar_t* AppleFontNameAsPointer() const;
69 
70  /*
71  Parameters:
72  font_characteristics - [in]
73  */
74  void SetFont(
75  const ON_Font* font_characteristics
76  );
77  void SetFont(
78  const ON_Font& font_characteristics
79  );
80 
81  /*
82  Parameters:
83  font_description - [in]
84  If font_description is an empty string, then SetFont( alternate_font )
85  is called.
86  alternate_font - [in]
87  Font to use if the current runtime environment does not have a
88  font with a matching font description.
89  When alternate_font is nullptr, ON_Font::Default will be used as
90  the alternate font.
91  */
92  void SetFontFromDescription(
93  const wchar_t* font_description,
94  const wchar_t* apple_font_name,
95  const ON_Font* alternate_font
96  );
97 
98  void ClearFont();
99 
100  bool FontIsSet() const;
101 
102  void LockFont();
103  bool FontIsLocked() const;
104 
105  /*
106  Description:
107  Get a string with the text style name and font description.
108  Parameters:
109  sSeparator - [in]
110  string that separates the text style name and the font description.
111  For example, if sSeparator = " - ", then
112  name_and_font_description = "<text style name> - <font description>".
113  name_and_font_description - [out]
114  Returns:
115  A pointer to the string in name_and_font_description. This pointer is never
116  nullptr.
117  */
118  const wchar_t* GetNameAndFontDescription(
119  const wchar_t* sSeparator,
120  ON_wString& name_and_font_description
121  ) const;
122 
123  static bool EqualTextStyleFontAndName(
124  const ON_TextStyle& a,
125  const ON_TextStyle& b
126  );
127 
128 private:
129  // V5 files had a single string used for different purposes
130  // on Windows and Apple platforms. These two strings are runtime
131  // information.
132  ON_wString m_font_description;
133 
134  ON_wString m_apple_font_name;
135 
136  // m_managed_font points to a managed ON_Font and is the font returned by Font().
137  const ON_Font* m_managed_font = nullptr;
138 
139  enum : unsigned char {
140  font_bit = 1
141  };
142 
143  unsigned char m_is_set_bits = 0;
144  unsigned char m_is_locked_bits = 0;
145 
146  unsigned char m_reserved1 = 0;
147  unsigned int m_reserved2 = 0;
148  ON__UINT_PTR m_reserved_ptr_1 = 0;
149  ON__UINT_PTR m_reserved_ptr_2 = 0;
150  double m_reserved_double_0 = 0.0;
151  double m_reserved_double_1 = 0.0;
152 
153 public:
154  // overrides virtual ON_Object::IsValid
155  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
157  // overrides virtual ON_Object::IsValid
158  void Dump( ON_TextLog& ) const override;
159 
160  // On September 16, 2015 the "V5" ON_Font was split into
161  // ON_TextStyle (a document object) and
162  // ON_Font (a current runtime resource)
163  // = ON_VersionNumberConstruct(6, 0, 2015, 9, 16, 0)
164  // Versions of opennurbs before binary_archive_opennurbs_version
165  // serialized ON_TextStyle information in the V5 ON_Font format.
166  static const unsigned int binary_archive_opennurbs_version;
167 
168  // overrides virtual ON_Object::Write
169  bool Write( ON_BinaryArchive& ) const override;
170 
171  // overrides virtual ON_Object::Read
172  bool Read( ON_BinaryArchive& ) override;
173 
174 };
175 
176 #if defined(ON_DLL_TEMPLATE)
177 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_TextStyle*>;
178 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_TextStyle>;
179 #endif
180 
181 #endif
static const ON_TextStyle Unset
Definition: opennurbs_text_style.h:24
The ON_ModelComponent class is a base class for all components in a model and manages the index...
Definition: opennurbs_model_component.h:24
void Dump(ON_TextLog &) const override
Creates a text dump of the object.
static const ON_TextStyle ByLayer
Definition: opennurbs_text_style.h:26
bool IsValid(class ON_TextLog *text_log=nullptr) const override
Tests an object to see if its data members are correctly initialized.
ON_Object array is used to store lists of classes that are derived from ON_Object. It differs from ON_ClassArray in that the virtual ON_Object::MemoryRelocate function is called when growing the dynamic array requires changing the location of the memory buffer used to store the elements in the array.
Definition: opennurbs_array.h:725
Definition: opennurbs_string.h:2020
An ON_Font is a face in a font family. It corresponds to a Windows LOGFONT, a .NET System...
Definition: opennurbs_font.h:225
static const ON_TextStyle Default
Definition: opennurbs_text_style.h:25
static const ON_TextStyle ByParent
Definition: opennurbs_text_style.h:27
Definition: opennurbs_text_style.h:19
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
ON_ModelComponent & operator=(const ON_ModelComponent &source)
virtual bool Read(ON_BinaryArchive &binary_archive)
Low level archive writing tool used by ON_BinaryArchive::ReadObject().
Definition: opennurbs_model_component.h:1622
virtual bool Write(ON_BinaryArchive &binary_archive) const
Low level archive writing tool used by ON_BinaryArchive::WriteObject().