home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / FWFont.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.5 KB  |  300 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFont.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWFONT_H
  11. #define FWFONT_H
  12.  
  13. #ifndef SLGRDEF_H
  14. #include "SLGrDef.h"
  15. #endif
  16.  
  17. #ifndef FWSTDDEF_H
  18. #include "FWStdDef.h"
  19. #endif
  20.  
  21. #ifndef FWGCONST_H
  22. #include "FWGConst.h"
  23. #endif
  24.  
  25. #ifndef FWCOLOR_H
  26. #include "FWColor.h"
  27. #endif
  28.  
  29. #ifndef FWGC_H
  30. #include "FWGC.h"
  31. #endif
  32.  
  33. #ifndef SLGDEV_H
  34. #include "SLGDev.h"
  35. #endif
  36.  
  37. #ifndef SLSHATTR_H
  38. #include "SLShAttr.h"
  39. #endif
  40.  
  41. #ifndef FWGRREF_H
  42. #include "FWGrRef.h"
  43. #endif
  44.  
  45. // ----- Foundation Includes -----
  46.  
  47. #ifndef FWSTRING_H
  48. #include "FWString.h"
  49. #endif
  50.  
  51. //========================================================================================
  52. //    Forward Class Declarations
  53. //========================================================================================
  54.  
  55. class FW_CReadableStream;
  56. class FW_CWritableStream;
  57.  
  58. //========================================================================================
  59. //    class FW_CFontMetrics
  60. //========================================================================================
  61. //    For an explanation of why I divide everything by 20 on Windows, look at 
  62. //    FW_CFontMetrics::PrivGetFontMetrics
  63.  
  64. class FW_CFontMetrics : public FW_PlatformFontMetrics
  65. {
  66. public:
  67.     short    GetAscent() const;
  68.     short    GetDescent() const;
  69.     short    GetInternalLeading() const;
  70.     short    GetExternalLeading() const;
  71.     short    GetFontHeight() const;
  72.     short    GetLineSpacing() const;
  73.     
  74.     static void    PrivGetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics);
  75. };
  76.  
  77. //========================================================================================
  78. //    CLASS FW_CFont
  79. //========================================================================================
  80.  
  81. class FW_CFont : public FW_TGrRefPtr<FW_HFont>
  82. {
  83. public:
  84.     FW_DECLARE_AUTO(FW_CFont)
  85.  
  86. //----------------------------------------------------------------------------------------
  87. //    Constructors/Destructor
  88. //
  89. public:
  90.     FW_CFont(FW_EStandardFonts std = FW_kNormalFont);
  91.     FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize);
  92.     FW_CFont(const FW_CFont& other);
  93.     
  94.     ~FW_CFont();
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    operators
  98. //
  99. public:
  100.     FW_CFont& operator=(const FW_CFont& other);
  101.  
  102.     FW_CFont& operator=(FW_EStandardFonts std);
  103.     
  104.     friend FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font);
  105.     friend FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font);
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    New API
  109. //
  110. public:
  111.     // ----- Copy -----
  112.     FW_CFont            Copy() const;
  113.  
  114.     // ----- Font Metrics -----
  115.     void                GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const;
  116.     void                GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const;
  117.  
  118.     // ----- Delegation
  119.     long                GetRefCount() const;
  120.  
  121.     // Attributes
  122.     
  123.     FW_Fixed            GetFontSize() const;
  124.     FW_FontStyle        GetFontStyle() const;
  125.     void                GetFontName(FW_CString& fontName) const;
  126.     
  127.     // Comparison
  128.     
  129.     FW_Boolean            IsEqual(const FW_CFont& font2) const;
  130.     
  131.     // Operations
  132.     
  133.     void                SetFontSize(FW_Fixed size);
  134.     void                SetFontStyle(FW_FontStyle style);
  135.     void                SetFontName(const FW_CString& fontName);
  136.     
  137.     // ----- Conversion -----
  138.     static FW_FontStyle    PlatformToODFFontStyle(const FW_PlatformFontStyle& platformStyle);
  139.     
  140.     // Macintosh-only
  141. #ifdef FW_BUILD_MAC
  142.     short                    MacGetFontID() const;
  143.     FW_PlatformFontStyle    MacGetFontStyle() const;
  144.     
  145.     void                    MacSetFontID(short macFontID);
  146. #endif
  147. };
  148.  
  149. //========================================================================================
  150. //    Inlines
  151. //========================================================================================
  152.  
  153. //----------------------------------------------------------------------------------------
  154. //    FW_CFont::GetRefCount
  155. //----------------------------------------------------------------------------------------
  156. inline long FW_CFont::GetRefCount() const
  157. {
  158.     return FW_PrivFont_GetRefCount(fRep);
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    FW_CFont::GetFontSize
  163. //----------------------------------------------------------------------------------------
  164. inline FW_Fixed FW_CFont::GetFontSize() const
  165. {
  166.     return FW_PrivFont_GetSize(fRep);
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. //    FW_CFont::GetFontStyle
  171. //----------------------------------------------------------------------------------------
  172. inline FW_FontStyle FW_CFont::GetFontStyle() const
  173. {
  174.     return FW_PrivFont_GetStyle(fRep);
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    FW_CFont::IsEqual
  179. //----------------------------------------------------------------------------------------
  180. inline FW_Boolean FW_CFont::IsEqual(const FW_CFont& font2) const
  181. {
  182.     return FW_PrivFont_IsEqual(fRep, font2.fRep);
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_CFont::SetFontSize
  187. //----------------------------------------------------------------------------------------
  188. inline void FW_CFont::SetFontSize(FW_Fixed size)
  189. {
  190.     FW_PrivFont_SetSize(fRep, size);
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CFont::SetFontStyle
  195. //----------------------------------------------------------------------------------------
  196. inline void FW_CFont::SetFontStyle(FW_FontStyle style)
  197. {
  198.     FW_PrivFont_SetStyle(fRep, style);
  199. }
  200.  
  201. #ifdef FW_BUILD_MAC
  202. //----------------------------------------------------------------------------------------
  203. //    FW_CFont::MacGetFontID
  204. //----------------------------------------------------------------------------------------
  205. inline short FW_CFont::MacGetFontID() const
  206. {
  207.     return FW_PrivFont_MacGetFontID(fRep);
  208. }
  209. #endif
  210.  
  211. #ifdef FW_BUILD_MAC
  212. //----------------------------------------------------------------------------------------
  213. //    FW_CFont::MacGetFontStyle
  214. //----------------------------------------------------------------------------------------
  215. inline Style FW_CFont::MacGetFontStyle() const
  216. {
  217.     return FW_PrivFont_MacGetFontStyle(fRep);
  218. }
  219. #endif
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CFontMetrics::GetLineSpacing
  223. //----------------------------------------------------------------------------------------
  224. inline short FW_CFontMetrics::GetLineSpacing() const
  225. {
  226. #ifdef FW_BUILD_MAC
  227.     return ascent + descent + leading;
  228. #endif
  229. #ifdef FW_BUILD_WIN
  230.     return tmHeight / 20;
  231. #endif
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    FW_CFontMetrics::GetAscent
  236. //----------------------------------------------------------------------------------------
  237. inline short FW_CFontMetrics::GetAscent() const
  238. {
  239. #ifdef FW_BUILD_MAC
  240.     return ascent;
  241. #endif
  242. #ifdef FW_BUILD_WIN
  243.     return tmAscent / 20;
  244. #endif
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //    FW_CFontMetrics::GetDescent
  249. //----------------------------------------------------------------------------------------
  250. inline short FW_CFontMetrics::GetDescent() const
  251. {
  252. #ifdef FW_BUILD_MAC
  253.     return descent;
  254. #endif
  255. #ifdef FW_BUILD_WIN
  256.     return tmDescent / 20;
  257. #endif
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    FW_CFontMetrics::GetExternalLeading
  262. //----------------------------------------------------------------------------------------
  263. inline short FW_CFontMetrics::GetExternalLeading() const
  264. {
  265. #ifdef FW_BUILD_MAC
  266.     return 0;
  267. #endif
  268. #ifdef FW_BUILD_WIN
  269.     return tmExternalLeading / 20;
  270. #endif
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    FW_CFontMetrics::GetInternalLeading
  275. //----------------------------------------------------------------------------------------
  276. inline short FW_CFontMetrics::GetInternalLeading() const
  277. {
  278. #ifdef FW_BUILD_MAC
  279.     return leading;
  280. #endif
  281. #ifdef FW_BUILD_WIN
  282.     return tmInternalLeading / 20;
  283. #endif
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    FW_CFontMetrics::GetFontHeight
  288. //----------------------------------------------------------------------------------------
  289. inline short FW_CFontMetrics::GetFontHeight() const
  290. {
  291. #ifdef FW_BUILD_MAC
  292.     return ascent + descent;
  293. #endif
  294. #ifdef FW_BUILD_WIN
  295.     return (tmHeight - tmInternalLeading) / 20;
  296. #endif
  297. }
  298.  
  299. #endif
  300.