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.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.3 KB  |  296 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFont.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWFONT_H
  13. #include "FWFont.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef FWPOINT_H
  21. #include "FWPoint.h"
  22. #endif
  23.  
  24. #ifndef FWFXMATH_H
  25. #include "FWFxMath.h"
  26. #endif
  27.  
  28. #ifndef FWGRUTIL_H
  29. #include "FWGrUtil.h"
  30. #endif
  31.  
  32. #ifndef FWSTRMRW_H
  33. #include "FWStrmRW.h"
  34. #endif
  35.  
  36. // ----- Macintosh Includes -----
  37.  
  38. #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
  39. #include <TextUtils.h>
  40. #endif
  41.  
  42. #if defined(FW_BUILD_MAC) && !defined(__FONTS__)
  43. #include <Fonts.h>
  44. #endif
  45.  
  46. #ifdef FW_BUILD_MAC
  47. #pragma segment FWGraphics_Font
  48. #endif
  49.  
  50. //========================================================================================
  51. //    Template instantiation
  52. //========================================================================================
  53.  
  54. #include "FWGrRef.tpp"
  55.  
  56. FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HFont)
  57.  
  58. #ifdef FW_USE_TEMPLATE_PRAGMAS
  59.  
  60. #pragma template_access public
  61. #pragma template FW_TGrRefPtr<FW_HFont>
  62.  
  63. #else
  64.  
  65. template class FW_TGrRefPtr<FW_HFont>;
  66.  
  67. #endif
  68.  
  69. //========================================================================================
  70. //    class FW_CFont
  71. //========================================================================================
  72.  
  73. FW_DEFINE_AUTO(FW_CFont)
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_PrivAcquireGrRep
  77. //----------------------------------------------------------------------------------------
  78.  
  79. void FW_PrivAcquireGrRep(FW_HFont rep)
  80. {
  81.     if (rep != 0)
  82.         FW_PrivFont_Acquire(rep);
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    FW_PrivReleaseGrRep
  87. //----------------------------------------------------------------------------------------
  88.  
  89. void FW_PrivReleaseGrRep(FW_HFont rep)
  90. {
  91.     if (rep != 0)
  92.         FW_PrivFont_Release(rep);
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. //    FW_CFont::FW_CFont
  97. //----------------------------------------------------------------------------------------
  98.  
  99. FW_CFont::FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize)
  100. {
  101.     FW_PlatformError error;
  102.     FW_HFont rep = FW_PrivFont_Create(fontName, fontStyle, fontSize, &error);
  103.     FW_FailOnError(error);
  104.     SetRep(rep);
  105.     FW_END_CONSTRUCTOR
  106. }
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    FW_CFont::FW_CFont
  110. //----------------------------------------------------------------------------------------
  111.  
  112. FW_CFont::FW_CFont(const FW_CFont& other) :
  113.     FW_TGrRefPtr<FW_HFont>(other)
  114. {
  115.     FW_END_CONSTRUCTOR
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    FW_CFont::FW_CFont
  120. //----------------------------------------------------------------------------------------
  121.  
  122. FW_CFont::FW_CFont(FW_EStandardFonts std)
  123. {
  124.     FW_PlatformError error;
  125.     FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
  126.     FW_FailOnError(error);
  127.     SetRep(rep);
  128.     FW_END_CONSTRUCTOR
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CFont::FW_CFont
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CFont::~FW_CFont()
  136. {
  137.     FW_START_DESTRUCTOR
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CFont::operator=
  142. //----------------------------------------------------------------------------------------
  143.  
  144. FW_CFont& FW_CFont::operator=(const FW_CFont& other)
  145. {
  146.     FW_TGrRefPtr<FW_HFont>::operator=(other);
  147.     return *this;
  148. }
  149.  
  150. //----------------------------------------------------------------------------------------
  151. //    FW_CFont::operator=
  152. //----------------------------------------------------------------------------------------
  153.  
  154. FW_CFont& FW_CFont::operator=(FW_EStandardFonts std)
  155. {
  156.     FW_PlatformError error;
  157.     FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
  158.     FW_FailOnError(error);
  159.     SetRep(rep);
  160.     return *this;
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CFont::GetFontName
  165. //----------------------------------------------------------------------------------------
  166.  
  167. void FW_CFont::GetFontName(FW_CString& fontName) const
  168. {
  169.     FW_PlatformError error;
  170.     FW_PrivFont_GetName(fRep, fontName, &error);
  171.     FW_FailOnError(error);
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    FW_CFont::SetFontName
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void FW_CFont::SetFontName(const FW_CString& fontName)
  179. {
  180.     FW_PlatformError error;
  181.     FW_PrivFont_SetName(fRep, fontName, &error);
  182.     FW_FailOnError(error);
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. //    FW_CFont::GetFontMetrics
  187. //----------------------------------------------------------------------------------------
  188.  
  189. void FW_CFont::GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const
  190. {    
  191.     FW_FailOnError(FW_PrivGDev_GetFontMetrics(device, *this, fontMetrics));
  192. }
  193.  
  194. //----------------------------------------------------------------------------------------
  195. //    FW_CFont::GetFontMetrics
  196. //----------------------------------------------------------------------------------------
  197.  
  198. void FW_CFont::GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const
  199. {
  200.     GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. //    FW_CFont::Copy
  205. //----------------------------------------------------------------------------------------
  206.  
  207. FW_CFont FW_CFont::Copy() const
  208. {
  209.     FW_PlatformError error;
  210.     FW_HFont rep = FW_PrivFont_Copy(fRep, &error);
  211.     FW_FailOnError(error);
  212.     
  213.     FW_CFont font;
  214.     font.SetRep(rep);
  215.     return font;
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_CFont::PlatformToODFFontStyle
  220. //----------------------------------------------------------------------------------------
  221. //    It is a const& because on windows FW_PlatformFontStyle is a LOGFONT
  222.  
  223. FW_FontStyle FW_CFont::PlatformToODFFontStyle(const FW_PlatformFontStyle& platformStyle)
  224. {
  225.     FW_FontStyle fontStyle = FW_kPlain;
  226.  
  227. #ifdef FW_BUILD_MAC
  228.     if (platformStyle & bold)
  229.         fontStyle += FW_kBold;
  230.     if (platformStyle & italic)
  231.         fontStyle += FW_kItalic;
  232.     if (platformStyle & underline)
  233.         fontStyle += FW_kUnderline;
  234.     if (platformStyle & outline)
  235.         fontStyle += FW_kOutline;
  236.     if (platformStyle & shadow)
  237.         fontStyle += FW_kShadow;
  238.     if (platformStyle & extend)
  239.         fontStyle += FW_kExtended;
  240.     if (platformStyle & condense)
  241.         fontStyle += FW_kCondensed;
  242. #endif
  243.  
  244. #ifdef FW_BUILD_WIN
  245.     if (platformStyle.lfItalic != 0)
  246.         fontStyle += FW_kItalic;
  247.     if (logFont.lfUnderline != 0)
  248.         fontStyle += FW_kUnderline;
  249.     if (logFont.lfStrikeOut != 0)
  250.         fontStyle += FW_kStrikeOut;
  251.     if (logFont.lfWeight == FW_BOLD)
  252.         fontStyle += FW_kBold;
  253. #endif
  254.  
  255.     return fontStyle;
  256. }
  257.  
  258. #ifdef FW_BUILD_MAC
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CFont::MacSetFontID
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void FW_CFont::MacSetFontID(short macFontID)
  264. {
  265.     FW_PlatformError error;
  266.     FW_PrivFont_MacSetFontID(fRep, macFontID, &error);
  267.     FW_FailOnError(error);
  268. }
  269. #endif
  270.  
  271. //----------------------------------------------------------------------------------------
  272. //    operator <<
  273. //----------------------------------------------------------------------------------------
  274.  
  275. FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font)
  276. {
  277.     FW_PlatformError error;
  278.     FW_PrivFont_Write(font.fRep, stream, &error);
  279.     FW_FailOnError(error);
  280.     return stream;
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    operator >>
  285. //----------------------------------------------------------------------------------------
  286.  
  287. FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font)
  288. {
  289.     FW_PlatformError error;
  290.     FW_HFont rep = FW_PrivFont_Read(stream, &error);
  291.     FW_FailOnError(error);
  292.     font.SetRep(rep);
  293.     return stream;
  294. }
  295.  
  296.