opennurbs_font.h
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #if !defined(OPENNURBS_FONT_INC_)
00018 #define OPENNURBS_FONT_INC_
00019 
00020 class ON_CLASS ON_Font : public ON_Object
00021 {
00022   ON_OBJECT_DECLARE(ON_Font);
00023 public:
00024   ON_Font();
00025   ~ON_Font();
00026   // C++ default copy construction and operator= work fine.
00027 
00028   /*
00029   Description:
00030     Create a font with a specified facename and properties.
00031   Parameters:
00032     face_name - [in]
00033       If face_name is null or empty, then "Arial" is used.
00034     bBold - [in]
00035       True for a bold version of the font.
00036     bItalic - [in]
00037       True for an italic version of the font.
00038   Returns:
00039     True if the font was created.  The name of this font is
00040     the face name with " Bold", " Italic" or " Bold Italic"
00041     appended as
00042  */
00043   bool CreateFontFromFaceName( 
00044     const wchar_t* face_name,
00045     bool bBold,
00046     bool bItalic 
00047     );
00048 
00049 #if defined(ON_OS_WINDOWS_GDI)
00050   ON_Font( const LOGFONT& logfont );
00051   ON_Font& operator=( const LOGFONT& logfont );
00052 #endif
00053 
00055   //
00056   // ON_Object overrides
00057 
00058   /*
00059   Description:
00060     Tests an object to see if its data members are correctly
00061     initialized.
00062   Parameters:
00063     text_log - [in] if the object is not valid and text_log
00064         is not NULL, then a brief englis description of the
00065         reason the object is not valid is appened to the log.
00066         The information appended to text_log is suitable for 
00067         low-level debugging purposes by programmers and is 
00068         not intended to be useful as a high level user 
00069         interface tool.
00070   Returns:
00071     @untitled table
00072     true     object is valid
00073     false    object is invalid, uninitialized, etc.
00074   Remarks:
00075     Overrides virtual ON_Object::IsValid
00076   */
00077   ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
00078 
00079   // virtual
00080   void Dump( ON_TextLog& ) const; // for debugging
00081 
00082   // virtual
00083   ON_BOOL32 Write(
00084          ON_BinaryArchive&  // serialize definition to binary archive
00085        ) const;
00086 
00087   // virtual
00088   ON_BOOL32 Read(
00089          ON_BinaryArchive&  // restore definition from binary archive
00090        );
00091 
00092   // virtual
00093   ON_UUID ModelObjectId() const;
00094 
00096   //
00097   // Interface
00098 
00099   enum 
00100   { 
00101 
00102 #if defined(ON_OS_WINDOWS_GDI)
00103 
00104     // Windows GDI facename length
00105 
00106     // 13 November 2008 - Dale Lear
00107     // Because:
00108     //   * Prior to this date the above "ON_OS_WINDOWS_GDI" 
00109     //     was misspelled and this code did not get compiled.
00110     //   * The Windows headers defines LF_FACESIZE = 32
00111     //   * ON_Font has a member wchar_t m_facename[face_name_size] array
00112     //   * We cannot break the SDK by changing the size of ON_Font
00113     //
00114     //  we cannot define face_name_size = LF_FACESIZE+1.  So, I'm
00115     //  using the same "65" we use below.  It is critical that
00116     //  face_name_size >= LF_FACESIZE+1
00117     //
00118     //face_name_size = LF_FACESIZE+1, // <- prior to 13 Nov but never used
00119     face_name_size = 65,
00120 
00121     // Windows GDI font weights
00122     bold_weight   = FW_BOLD,
00123     medium_weight = FW_MEDIUM,
00124     normal_weight = FW_NORMAL,
00125     light_weight  = FW_LIGHT,
00126 
00127     // Windows GDI character sets
00128     default_charset = DEFAULT_CHARSET,
00129     symbol_charset  = SYMBOL_CHARSET,
00130 
00131 #else
00132 
00133     face_name_size = 65, // must be >= 33
00134 
00135     bold_weight   = 700,
00136     medium_weight = 500,
00137     normal_weight = 400,
00138     light_weight  = 300,
00139 
00140     default_charset = 1,
00141     symbol_charset  = 2,
00142 
00143 #endif
00144 
00145     normal_font_height = 256
00146   }; 
00147 
00148   // Ratio of linefeed to character height (1.6)
00149   static 
00150   const double m_default_linefeed_ratio;
00151 
00152   static
00153   const int m_metrics_char; // ASCII code of character to used
00154                             // to get runtime "default" glyph
00155                             // metrics. (Currently an "I").
00156 
00157   /*
00158   Returns:
00159     True if the font's character set should be SYMBOL_CHARSET;
00160   */
00161   static
00162   bool IsSymbolFontFaceName( 
00163           const wchar_t* facename
00164           );
00165 
00166   void SetFontName( const wchar_t* );
00167   void SetFontName( const char* );
00168   
00169   void GetFontName( ON_wString& ) const;
00170   const wchar_t* FontName() const;
00171 
00172   void SetFontIndex(int);
00173   int FontIndex() const;
00174 
00175   /*
00176   Returns:
00177     The ratio (height of linefeed)/(height of I).
00178   */
00179   double LinefeedRatio() const;
00180 
00181   void SetLinefeedRatio( double linefeed_ratio );
00182 
00183   bool SetFontFaceName( const wchar_t* );
00184   bool SetFontFaceName( const char* );
00185   
00186   void GetFontFaceName( ON_wString& ) const;
00187   const wchar_t* FontFaceName() const;
00188 
00189   int FontWeight() const;
00190   void SetFontWeight( int);
00191 
00192   bool IsItalic() const;
00193   void SetIsItalic( bool );
00194   void SetItalic( bool );
00195 
00196   bool IsBold() const;
00197   void SetBold( bool );
00198 
00199   // Added 7/12/07 LW
00200   bool IsUnderlined() const;
00201   void SetUnderlined( bool );
00202 
00203   void Defaults();
00204 
00205   /*
00206   Returns:
00207     Height of the 'I' character when the font is drawn 
00208     with m_logfont.lfHeight = ON_Font::normal_font_height.
00209   */
00210   int HeightOfI() const;
00211 
00212   /*
00213   Returns:
00214     Height of a linefeed when the font is drawn 
00215     with m_logfont.lfHeight = ON_Font::normal_font_height.
00216   */
00217   int HeightOfLinefeed() const;
00218 
00219   /*
00220     Description:
00221       Returns the ratio of the height of a typical upper case letter 
00222       to the height of a whole character cell.
00223 
00224   Parameters:
00225     none
00226 
00227   Returns:
00228     double - ratio of Windows Font Height / m_HeightOfH
00229   */
00230   double AscentRatio() const;
00231 
00232   /*
00233     Description:
00234       Compare the visible characteristics to another font
00235 
00236     Parameters:
00237       font_to_compare - [in] The cont to compare this one to
00238       bCompareName    - [in] if this is set, test if the names match
00239                              otherwise don't compare the names
00240 
00241     Returns:
00242       true if font_to_compare matches this one
00243       false if font_to_match doesn't match this one
00244 
00245     Added for v5 - 5/20/07
00246   */
00247   bool CompareFontCharacteristics( ON_Font& font_to_compare, bool bCompareName) const;
00248 
00249 #if defined(ON_OS_WINDOWS_GDI)
00250   bool SetLogFont( const LOGFONT& logfont );
00251   const LOGFONT& LogFont() const;
00252 #endif
00253 
00254 public:
00255   ON_wString m_font_name;      // Name of this font in the Rhino UI
00256   int        m_font_weight;    // Same as m_logfont.lfWeight
00257   bool       m_font_italic;    // Same as m_logfont.lfItalic
00258   bool       m_font_underlined;// Same as m_logfont.lfUnderlined (Added 7/12/07 LW)
00259   double     m_linefeed_ratio; // defaults to static s_linefeed_ratio.
00260   int        m_font_index;     // font index in Rhino font table
00261   ON_UUID    m_font_id;
00262   wchar_t    m_facename[face_name_size]; // same as m_logfont.lfFaceName ( 
00263 
00264 public:
00265 
00266   /*  
00267   Description:
00268     Insures the settings in the OS specific information, like 
00269     the Windows m_logfont field, match the persistent m_font_* values 
00270     above that are used for all OSs and used in UI code.
00271   */
00272   void UpdateImplementationSettings();
00273 #if defined(ON_OS_WINDOWS_GDI)
00274   // Windows specific settins
00275   LOGFONT m_logfont;
00276 #endif
00277 
00278 private:
00279   // volitile - can be changed by ON_Font::HeightOfI() const.
00280   int m_I_height; // height of the 'I' character when the font is drawn 
00281                   // with m_logfont.lfHeight = 256.
00282 };
00283 
00284 #endif


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:01