home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 8.0 KB | 302 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFont.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWFONT_H
- #define FWFONT_H
-
- #ifndef FWGRDEF_H
- #include "FWGrDef.h"
- #endif
-
- #ifndef FWGROBJ_H
- #include "FWGrObj.h"
- #endif
-
- #ifndef FWGRGLOB_H
- #include "FWGrGlob.h"
- #endif
-
- #ifndef FWGCONST_H
- #include "FWGConst.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // Forward Class Declarations
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CFontRep;
- class FW_CLASS_ATTR FW_CGraphicDevice;
-
- //========================================================================================
- // struct FW_SFontMetrics
- //========================================================================================
- // For an explanation of why I divide everything by 20 on Windows, look at
- // FW_SFontMetrics::PrivGetFontMetrics
-
- #ifdef FW_BUILD_MAC
- struct FW_SFontMetrics : public FontInfo
- #endif
- #ifdef FW_BUILD_WIN
- struct FW_CLASS_ATTR FW_SFontMetrics : public TEXTMETRIC
- #endif
- {
- FW_SFontMetrics() {};
-
- short GetAscent() const;
- short GetDescent() const;
- short GetInternalLeading() const;
- short GetExternalLeading() const;
- short GetFontHeight() const;
- short GetLineSpacing() const;
-
- static void PrivGetFontMetrics(FW_CGraphicDevice* device, FW_SFontMetrics& fontMetrics);
- };
-
- //----------------------------------------------------------------------------------------
- // FW_SFontMetrics::GetLineSpacing
- //----------------------------------------------------------------------------------------
- inline short FW_SFontMetrics::GetLineSpacing() const
- {
- #ifdef FW_BUILD_MAC
- return ascent + descent + leading;
- #endif
- #ifdef FW_BUILD_WIN
- return tmHeight / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SFontMetrics::GetAscent
- //----------------------------------------------------------------------------------------
- inline short FW_SFontMetrics::GetAscent() const
- {
- #ifdef FW_BUILD_MAC
- return ascent;
- #endif
- #ifdef FW_BUILD_WIN
- return tmAscent / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SFontMetrics::GetDescent
- //----------------------------------------------------------------------------------------
- inline short FW_SFontMetrics::GetDescent() const
- {
- #ifdef FW_BUILD_MAC
- return descent;
- #endif
- #ifdef FW_BUILD_WIN
- return tmDescent / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SFontMetrics::GetExternalLeading
- //----------------------------------------------------------------------------------------
- inline short FW_SFontMetrics::GetExternalLeading() const
- {
- #ifdef FW_BUILD_MAC
- return 0;
- #endif
- #ifdef FW_BUILD_WIN
- return tmExternalLeading / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SFontMetrics::GetInternalLeading
- //----------------------------------------------------------------------------------------
- inline short FW_SFontMetrics::GetInternalLeading() const
- {
- #ifdef FW_BUILD_MAC
- return leading;
- #endif
- #ifdef FW_BUILD_WIN
- return tmInternalLeading / 20;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SFontMetrics::GetFontHeight
- //----------------------------------------------------------------------------------------
- inline short FW_SFontMetrics::GetFontHeight() const
- {
- #ifdef FW_BUILD_MAC
- return ascent + descent;
- #endif
- #ifdef FW_BUILD_WIN
- return (tmHeight - tmInternalLeading) / 20;
- #endif
- }
-
- //========================================================================================
- // CLASS FW_PFont
- //========================================================================================
-
- class FW_CLASS_ATTR FW_PFont : public FW_CGraphicCountedPtr
- {
- public:
- FW_DECLARE_CLASS
-
- public:
- FW_PFont();
- virtual ~ FW_PFont();
-
-
- FW_PFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_CFixed fontSize);
-
- FW_PFont(const FW_PFont& other);
- FW_PFont& operator=(const FW_PFont& other);
-
- FW_PFont(FW_CFontRep* fontRep);
- FW_PFont& operator=(FW_CFontRep* fontRep);
-
- FW_PFont(FW_EStandardFonts std);
- FW_PFont& operator=(FW_EStandardFonts std);
-
- FW_CFontRep* operator->();
- const FW_CFontRep* operator->() const;
- };
-
- //----------------------------------------------------------------------------------------
- // FW_PFont::operator->
- //----------------------------------------------------------------------------------------
- inline FW_CFontRep* FW_PFont::operator->()
- {
- return (FW_CFontRep*)GetRep();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PFont::operator->
- //----------------------------------------------------------------------------------------
- inline const FW_CFontRep* FW_PFont::operator->() const
- {
- return (const FW_CFontRep*)GetRep();
- }
-
- //========================================================================================
- // class FW_CFontRep
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CFontRep : public FW_CGraphicCountedPtrRep
- {
- friend class FW_CLASS_ATTR FW_PFont;
-
- public:
- FW_DECLARE_CLASS
-
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
- public:
- FW_CFontRep();
- FW_CFontRep(const FW_CString& fontName, FW_FontStyle fontStyle, FW_CFixed fontSize);
- FW_CFontRep(const FW_CFontRep& otherRep);
- FW_CFontRep(FW_CReadableStream& archive);
-
- FW_CFontRep& operator=(const FW_CFontRep& otherRep);
-
- virtual ~FW_CFontRep();
-
- //----------------------------------------------------------------------------------------
- // Memory management
- //
- public:
- void* operator new(size_t size);
- void operator delete(void* p);
-
- //----------------------------------------------------------------------------------------
- // Inherited API
- //
- public:
- virtual void Flatten(FW_CWritableStream& archive) const;
-
- virtual FW_Boolean IsEqual(const FW_CGraphicCountedPtrRep* other) const;
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- // ----- Copying -----
- FW_PFont Copy() const;
-
- // ----- Archiving -----
- static void* Read(FW_CReadableStream& archive);
-
- // ----- Accessors -----
- void SetFontSize(FW_CFixed fontSize)
- {fFontSize = fontSize;}
- FW_CFixed GetFontSize() const
- {return fFontSize;}
-
- void SetFontStyle(FW_FontStyle fontStyle);
- FW_FontStyle GetFontStyle() const
- {return fFontStyle;}
-
- void SetFontName(const FW_CString& fontName);
- void GetFontName(FW_CString& fontName) const
- {fontName = fFontName;}
-
- void GetFontMetrics(FW_CGraphicDevice* device, FW_SFontMetrics& fontMetrics) const;
- void GetFontMetrics(FW_CGraphicContext& gc, FW_SFontMetrics& fontMetrics) const
- {GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);}
-
- //----------------------------------------------------------------------------------------
- // Internal use Only
- //
- public:
- #ifdef FW_BUILD_MAC
- short MacGetFontID() const;
- Style MacGetFontStyle() const;
-
- protected:
- void MacCheckFontCache();
- #endif
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- private:
- FW_CDynamicString fFontName;
- FW_FontStyle fFontStyle;
- FW_CFixed fFontSize; // Font size always in point (1/72")
-
- #ifdef FW_BUILD_MAC
- FW_Boolean fMacValidCache;
- short fMacFontID;
- Style fMacFontStyle;
- FW_Boolean fMacFontNotFound;
- #endif
- };
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-