home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.5 KB | 300 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFont.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWFONT_H
- #define FWFONT_H
-
- #ifndef SLGRDEF_H
- #include "SLGrDef.h"
- #endif
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWGCONST_H
- #include "FWGConst.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef SLGDEV_H
- #include "SLGDev.h"
- #endif
-
- #ifndef SLSHATTR_H
- #include "SLShAttr.h"
- #endif
-
- #ifndef FWGRREF_H
- #include "FWGrRef.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- //========================================================================================
- // Forward Class Declarations
- //========================================================================================
-
- class FW_CReadableStream;
- class FW_CWritableStream;
-
- //========================================================================================
- // class FW_CFontMetrics
- //========================================================================================
- // For an explanation of why I divide everything by 20 on Windows, look at
- // FW_CFontMetrics::PrivGetFontMetrics
-
- class FW_CFontMetrics : public FW_PlatformFontMetrics
- {
- public:
- short GetAscent() const;
- short GetDescent() const;
- short GetInternalLeading() const;
- short GetExternalLeading() const;
- short GetFontHeight() const;
- short GetLineSpacing() const;
-
- static void PrivGetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics);
- };
-
- //========================================================================================
- // CLASS FW_CFont
- //========================================================================================
-
- class FW_CFont : public FW_TGrRefPtr<FW_HFont>
- {
- public:
- FW_DECLARE_AUTO(FW_CFont)
-
- //----------------------------------------------------------------------------------------
- // Constructors/Destructor
- //
- public:
- FW_CFont(FW_EStandardFonts std = FW_kNormalFont);
- FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize);
- FW_CFont(const FW_CFont& other);
-
- ~FW_CFont();
-
- //----------------------------------------------------------------------------------------
- // operators
- //
- public:
- FW_CFont& operator=(const FW_CFont& other);
-
- FW_CFont& operator=(FW_EStandardFonts std);
-
- friend FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font);
- friend FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font);
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- // ----- Copy -----
- FW_CFont Copy() const;
-
- // ----- Font Metrics -----
- void GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const;
- void GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const;
-
- // ----- Delegation
- long GetRefCount() const;
-
- // Attributes
-
- FW_Fixed GetFontSize() const;
- FW_FontStyle GetFontStyle() const;
- void GetFontName(FW_CString& fontName) const;
-
- // Comparison
-
- FW_Boolean IsEqual(const FW_CFont& font2) const;
-
- // Operations
-
- void SetFontSize(FW_Fixed size);
- void SetFontStyle(FW_FontStyle style);
- void SetFontName(const FW_CString& fontName);
-
- // ----- Conversion -----
- static FW_FontStyle PlatformToODFFontStyle(const FW_PlatformFontStyle& platformStyle);
-
- // Macintosh-only
- #ifdef FW_BUILD_MAC
- short MacGetFontID() const;
- FW_PlatformFontStyle MacGetFontStyle() const;
-
- void MacSetFontID(short macFontID);
- #endif
- };
-
- //========================================================================================
- // Inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::GetRefCount
- //----------------------------------------------------------------------------------------
- inline long FW_CFont::GetRefCount() const
- {
- return FW_PrivFont_GetRefCount(fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::GetFontSize
- //----------------------------------------------------------------------------------------
- inline FW_Fixed FW_CFont::GetFontSize() const
- {
- return FW_PrivFont_GetSize(fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::GetFontStyle
- //----------------------------------------------------------------------------------------
- inline FW_FontStyle FW_CFont::GetFontStyle() const
- {
- return FW_PrivFont_GetStyle(fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::IsEqual
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CFont::IsEqual(const FW_CFont& font2) const
- {
- return FW_PrivFont_IsEqual(fRep, font2.fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::SetFontSize
- //----------------------------------------------------------------------------------------
- inline void FW_CFont::SetFontSize(FW_Fixed size)
- {
- FW_PrivFont_SetSize(fRep, size);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::SetFontStyle
- //----------------------------------------------------------------------------------------
- inline void FW_CFont::SetFontStyle(FW_FontStyle style)
- {
- FW_PrivFont_SetStyle(fRep, style);
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CFont::MacGetFontID
- //----------------------------------------------------------------------------------------
- inline short FW_CFont::MacGetFontID() const
- {
- return FW_PrivFont_MacGetFontID(fRep);
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CFont::MacGetFontStyle
- //----------------------------------------------------------------------------------------
- inline Style FW_CFont::MacGetFontStyle() const
- {
- return FW_PrivFont_MacGetFontStyle(fRep);
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CFontMetrics::GetLineSpacing
- //----------------------------------------------------------------------------------------
- inline short FW_CFontMetrics::GetLineSpacing() const
- {
- #ifdef FW_BUILD_MAC
- return ascent + descent + leading;
- #endif
- #ifdef FW_BUILD_WIN
- return tmHeight / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontMetrics::GetAscent
- //----------------------------------------------------------------------------------------
- inline short FW_CFontMetrics::GetAscent() const
- {
- #ifdef FW_BUILD_MAC
- return ascent;
- #endif
- #ifdef FW_BUILD_WIN
- return tmAscent / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontMetrics::GetDescent
- //----------------------------------------------------------------------------------------
- inline short FW_CFontMetrics::GetDescent() const
- {
- #ifdef FW_BUILD_MAC
- return descent;
- #endif
- #ifdef FW_BUILD_WIN
- return tmDescent / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontMetrics::GetExternalLeading
- //----------------------------------------------------------------------------------------
- inline short FW_CFontMetrics::GetExternalLeading() const
- {
- #ifdef FW_BUILD_MAC
- return 0;
- #endif
- #ifdef FW_BUILD_WIN
- return tmExternalLeading / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontMetrics::GetInternalLeading
- //----------------------------------------------------------------------------------------
- inline short FW_CFontMetrics::GetInternalLeading() const
- {
- #ifdef FW_BUILD_MAC
- return leading;
- #endif
- #ifdef FW_BUILD_WIN
- return tmInternalLeading / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFontMetrics::GetFontHeight
- //----------------------------------------------------------------------------------------
- inline short FW_CFontMetrics::GetFontHeight() const
- {
- #ifdef FW_BUILD_MAC
- return ascent + descent;
- #endif
- #ifdef FW_BUILD_WIN
- return (tmHeight - tmInternalLeading) / 20;
- #endif
- }
-
- #endif
-