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 / PRShAttr.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  42.4 KB  |  1,480 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PRShAttr.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 PRSHATTR_H
  13. #include "PRShAttr.h"
  14. #endif
  15.  
  16. #ifndef FWGCONST_H
  17. #include "FWGConst.h"
  18. #endif
  19.  
  20. #ifndef FWWINDIB_H
  21. #include "FWWinDIB.h"
  22. #endif
  23.  
  24. #ifndef FWSTREAM_H
  25. #include "FWStream.h"
  26. #endif
  27.  
  28. #ifndef FWMEMHLP_H
  29. #include "FWMemHlp.h"
  30. #endif
  31.  
  32. #ifndef FWCOLOR_H
  33. #include "FWColor.h"
  34. #endif
  35.  
  36. #ifndef FWEXCEPT_H
  37. #include "FWExcept.h"
  38. #endif
  39.  
  40. //========================================================================================
  41. //    CLASS FW_CPrivPatternRep
  42. //========================================================================================
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment FWGraphics_PrivPatternRep
  46. #endif
  47.  
  48. FW_DEFINE_CLASS_M0(FW_CPrivPatternRep)
  49.  
  50. //----------------------------------------------------------------------------------------
  51. //    FW_CPrivPatternRep::FW_CPrivPatternRep
  52. //----------------------------------------------------------------------------------------
  53.  
  54. FW_CPrivPatternRep::FW_CPrivPatternRep()
  55. {
  56. }
  57.  
  58. //----------------------------------------------------------------------------------------
  59. //    FW_CPrivPatternRep::~FW_CPrivPatternRep
  60. //----------------------------------------------------------------------------------------
  61.  
  62. FW_CPrivPatternRep::~FW_CPrivPatternRep()
  63. {
  64. }
  65.  
  66. //----------------------------------------------------------------------------------------
  67. //    FW_CPrivPatternRep::Write
  68. //----------------------------------------------------------------------------------------
  69.  
  70. void FW_CPrivPatternRep::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
  71. {
  72. FW_UNUSED(type);
  73.     FW_CPrivPatternRep* rep = (FW_CPrivPatternRep*) object;
  74.     rep->Flatten(stream);
  75. }
  76.  
  77. //========================================================================================
  78. //    CLASS FW_CPrivBWPatternRep
  79. //========================================================================================
  80.  
  81. #ifdef FW_BUILD_MAC
  82. #pragma segment FWGraphics_PrivBWPatternRep
  83. #endif
  84.  
  85. FW_DEFINE_AUTO(FW_CPrivBWPatternRep)
  86. FW_DEFINE_CLASS_M1(FW_CPrivBWPatternRep, FW_CPrivPatternRep)
  87.  
  88. const FW_ClassTypeConstant FW_LPrivBWPatternRep = FW_TYPE_CONSTANT('b','w','p','t');
  89. FW_REGISTER_ARCHIVABLE_CLASS(FW_LPrivBWPatternRep, FW_CPrivBWPatternRep, FW_CPrivBWPatternRep::Read, 0, 0, FW_CPrivPatternRep::Write)
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CPrivBWPatternRep::FW_CPrivBWPatternRep()
  96. {
  97.     unsigned char black[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
  98.  
  99.     MoveBitPattern(black, &fBitPattern);
  100.     FW_END_CONSTRUCTOR
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_CPrivBWPatternRep::FW_CPrivBWPatternRep(const FW_BitPattern& bits)
  108. {
  109.     MoveBitPattern(&bits, &fBitPattern);
  110.     FW_END_CONSTRUCTOR
  111. }
  112.  
  113. //----------------------------------------------------------------------------------------
  114. //    FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
  115. //----------------------------------------------------------------------------------------
  116.  
  117. FW_CPrivBWPatternRep::FW_CPrivBWPatternRep(FW_CReadableStream& stream)
  118. {
  119.     stream.Read(fBitPattern.fData, 8);    
  120.     FW_END_CONSTRUCTOR
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_CPrivBWPatternRep::~FW_CPrivBWPatternRep
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_CPrivBWPatternRep::~FW_CPrivBWPatternRep()
  128. {
  129.     FW_START_DESTRUCTOR
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. //    FW_CPrivBWPatternRep::Invert
  134. //----------------------------------------------------------------------------------------
  135.  
  136. void FW_CPrivBWPatternRep::Invert()
  137. {
  138.     *((long*)&fBitPattern.fData[0]) ^= 0xFFFFFFFFL;
  139.     *((long*)&fBitPattern.fData[4]) ^= 0xFFFFFFFFL;
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    FW_CPrivBWPatternRep::FlipVertically
  144. //----------------------------------------------------------------------------------------
  145.  
  146. void FW_CPrivBWPatternRep::FlipVertically()
  147. {
  148.     for (short i = 0; i<4; i++)
  149.     {
  150.         unsigned char temp = fBitPattern.fData[i];
  151.         fBitPattern.fData[i] = fBitPattern.fData[7-i];
  152.         fBitPattern.fData[7-i] = temp;
  153.     }
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. //    FW_CPrivBWPatternRep::FlipHorizontally
  158. //----------------------------------------------------------------------------------------
  159. // This is not the best implementation
  160.  
  161. void FW_CPrivBWPatternRep::FlipHorizontally()
  162. {    
  163.     for (short j = 0; j<8; j++)
  164.     {
  165.         unsigned char leftMask = 0x80;
  166.         unsigned char rightMask = 0x01;
  167.         unsigned char theChar = fBitPattern.fData[j];
  168.         for (short i = 0; i<4; i++)
  169.         {
  170.             unsigned char left = theChar & leftMask;
  171.             unsigned char right = theChar & rightMask;
  172.             
  173.             if (left)
  174.                 theChar |= rightMask;    // Set
  175.             else
  176.                 theChar ^= right;        // Clear
  177.                 
  178.             if (right)
  179.                 theChar |= leftMask;    // Set
  180.             else
  181.                 theChar ^= left;        // Clear
  182.                 
  183.             leftMask >>= 1;
  184.             rightMask <<= 1;
  185.         }
  186.         fBitPattern.fData[j] = theChar;
  187.     }
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    FW_CPrivBWPatternRep::ShiftRight
  192. //----------------------------------------------------------------------------------------
  193.  
  194. void FW_CPrivBWPatternRep::ShiftRight()
  195. {
  196.     for (short i = 0; i<8; i++)
  197.     {
  198.         unsigned char theChar = fBitPattern.fData[i];
  199.         theChar >>= 1;
  200.         if (fBitPattern.fData[i] & 0x01)
  201.             theChar |= 0x80;
  202.         fBitPattern.fData[i] = theChar;
  203.     }    
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    FW_CPrivBWPatternRep::ShiftLeft
  208. //----------------------------------------------------------------------------------------
  209.  
  210. void FW_CPrivBWPatternRep::ShiftLeft()
  211. {
  212.     for (short i = 0; i<8; i++)
  213.     {
  214.         unsigned char theChar = fBitPattern.fData[i];
  215.         theChar <<= 1;
  216.         if (fBitPattern.fData[i] & 0x80)
  217.             theChar |= 0x01;            
  218.         fBitPattern.fData[i] = theChar;
  219.     }    
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. //    FW_CPrivBWPatternRep::ShiftUp
  224. //----------------------------------------------------------------------------------------
  225.  
  226. void FW_CPrivBWPatternRep::ShiftUp()
  227. {
  228.     unsigned char temp = fBitPattern.fData[0];
  229.     for (short i = 0; i<7; i++)
  230.         fBitPattern.fData[i] = fBitPattern.fData[i+1];
  231.     fBitPattern.fData[7] = temp;
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    FW_CPrivBWPatternRep::ShiftDown
  236. //----------------------------------------------------------------------------------------
  237.  
  238. void FW_CPrivBWPatternRep::ShiftDown()
  239. {
  240.     unsigned char temp = fBitPattern.fData[7];
  241.     for (short i = 7; i>0; i--)
  242.         fBitPattern.fData[i] = fBitPattern.fData[i-1];
  243.     fBitPattern.fData[0] = temp;
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_CPrivBWPatternRep::IsEqual
  248. //----------------------------------------------------------------------------------------
  249.  
  250. FW_Boolean FW_CPrivBWPatternRep::IsEqual(const FW_CPrivPatternRep* other) const
  251. {
  252.     if (other == this)
  253.         return TRUE;
  254.         
  255.     const FW_CPrivBWPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CPrivBWPatternRep, (FW_CPrivPatternRep*)other);
  256.     
  257.     if (patternRep)
  258.     {
  259.         for (short i=0; i<7; i++)
  260.             if (fBitPattern.fData[i] != patternRep->fBitPattern.fData[i])
  261.                 return FALSE;
  262.         return TRUE;
  263.     }
  264.     
  265.     return FALSE;
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. //    FW_CPrivBWPatternRep::IsBlack
  270. //----------------------------------------------------------------------------------------
  271.  
  272. FW_Boolean FW_CPrivBWPatternRep::IsBlack() const
  273. {
  274.     return fBitPattern.fDataLongs[0] == 0xFFFFFFFFL && fBitPattern.fDataLongs[1] == 0xFFFFFFFFL;
  275. }
  276.  
  277. #ifdef FW_BUILD_WIN
  278. //----------------------------------------------------------------------------------------
  279. //    FW_CPrivBWPatternRep::WinCreatePatternBrush
  280. //----------------------------------------------------------------------------------------
  281.  
  282. HBRUSH FW_CPrivBWPatternRep::WinCreatePatternBrush() const
  283. {
  284.     unsigned char temp[16];    // 16 because rowbytes has to be even
  285.     for (short i=0; i<8; i++)
  286.         temp[2*i] = fBitPattern.fData[i] ^ 0xFF;
  287.         
  288.     HBRUSH hBrush = NULL;
  289.     
  290.     HBITMAP hbmp = ::CreateBitmap(8, 8, 1, 1, temp);
  291.     if(hbmp != NULL)
  292.     {
  293.         hBrush = ::CreatePatternBrush(hbmp);
  294.         ::DeleteObject(hbmp);
  295.     }
  296.     
  297.     return hBrush;
  298. }
  299. #endif
  300.  
  301. //----------------------------------------------------------------------------------------
  302. //    FW_CPrivBWPatternRep::Copy
  303. //----------------------------------------------------------------------------------------
  304.  
  305. FW_CPrivPatternRep* FW_CPrivBWPatternRep::Copy() const
  306. {
  307.     return FW_NEW(FW_CPrivBWPatternRep, (fBitPattern));
  308. }
  309.  
  310. #ifdef FW_BUILD_MAC
  311. //----------------------------------------------------------------------------------------
  312. //    FW_CPrivBWPatternRep::MacSetInCurPort
  313. //----------------------------------------------------------------------------------------
  314.  
  315. void FW_CPrivBWPatternRep::MacSetInCurPort() const
  316. {
  317.     ::PenPat((const Pattern*)&fBitPattern);
  318. }
  319. #endif
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    FW_CPrivBWPatternRep::Flatten
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void FW_CPrivBWPatternRep::Flatten(FW_CWritableStream& stream) const
  326. {
  327.     stream.Write(fBitPattern.fData, 8);
  328. }
  329.  
  330. //----------------------------------------------------------------------------------------
  331. //    FW_CPrivBWPatternRep::Read
  332. //----------------------------------------------------------------------------------------
  333.  
  334. void* FW_CPrivBWPatternRep::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  335. {
  336. FW_UNUSED(type);
  337.     return FW_NEW(FW_CPrivBWPatternRep, (stream));
  338. }
  339.  
  340. //========================================================================================
  341. //    CLASS FW_CPrivColorPatternRep
  342. //========================================================================================
  343.  
  344. #ifdef FW_BUILD_MAC
  345. #pragma segment FWGraphics_PrivColorPatternRep
  346. #endif
  347.  
  348. FW_DEFINE_AUTO(FW_CPrivColorPatternRep)
  349. FW_DEFINE_CLASS_M1(FW_CPrivColorPatternRep, FW_CPrivPatternRep)
  350.  
  351. const FW_ClassTypeConstant FW_LPrivColorPatternRep = FW_TYPE_CONSTANT('c','o','p','t');
  352. FW_REGISTER_ARCHIVABLE_CLASS(FW_LPrivColorPatternRep, FW_CPrivColorPatternRep, FW_CPrivColorPatternRep::Read, 0, 0, FW_CPrivPatternRep::Write)
  353.  
  354. //----------------------------------------------------------------------------------------
  355. //    FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
  356. //----------------------------------------------------------------------------------------
  357.  
  358. FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(FW_PlatformColorPattern platformColorPattern) :
  359.     fPlatformColorPattern(platformColorPattern)
  360. {
  361.     FW_ASSERT(fPlatformColorPattern != NULL);
  362.     FW_END_CONSTRUCTOR
  363. }
  364.  
  365. //----------------------------------------------------------------------------------------
  366. //    FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
  367. //----------------------------------------------------------------------------------------
  368.  
  369. FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(FW_CReadableStream& stream) :
  370.     fPlatformColorPattern(NULL)
  371. {
  372.     // Pattern data
  373.     FW_PixelPattern patData;
  374.     stream.Read(patData.fData, sizeof(patData));
  375.     
  376.     // Color count
  377.     unsigned short nbColors;
  378.     stream >> nbColors;
  379.     
  380.     // Colors
  381.     FW_CColor* colors = new FW_CColor[nbColors];
  382.     FW_TRY
  383.     {
  384.         for(int i = 0; i < nbColors; i ++)
  385.             stream >> colors[i];
  386.  
  387.         // Create the pattern
  388.         MakePixelPattern(patData, nbColors, colors);
  389.     }
  390.     FW_CATCH_BEGIN
  391.     FW_CATCH_EVERYTHING()
  392.     {
  393.         delete[] colors;
  394.         FW_THROW_SAME();
  395.     }
  396.     FW_CATCH_END
  397.     
  398.     // Clean up
  399.     delete[] colors;
  400.     FW_END_CONSTRUCTOR
  401. }
  402.  
  403. //----------------------------------------------------------------------------------------
  404. //    FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
  405. //----------------------------------------------------------------------------------------
  406.  
  407. FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(const FW_PixelPattern& pixels, short nbColors, const FW_SColor* colorTable) :
  408.     fPlatformColorPattern(NULL)
  409. {
  410. #ifdef FW_BUILD_WIN
  411.     fWinCachedBitmap = NULL;
  412. #endif
  413.     
  414.     MakePixelPattern(pixels, nbColors, colorTable);
  415.     FW_END_CONSTRUCTOR
  416. }
  417.  
  418. //----------------------------------------------------------------------------------------
  419. //    FW_CPrivColorPatternRep::~FW_CPrivColorPatternRep
  420. //----------------------------------------------------------------------------------------
  421.  
  422. FW_CPrivColorPatternRep::~FW_CPrivColorPatternRep()
  423. {
  424.     FW_START_DESTRUCTOR
  425.  
  426. #ifdef FW_BUILD_MAC
  427.     if (fPlatformColorPattern)
  428.         ::DisposePixPat(fPlatformColorPattern);
  429. #endif
  430.  
  431. #ifdef FW_BUILD_WIN
  432.     if (fPlatformColorPattern != NULL)
  433.         FW_DIBFree(fPlatformColorPattern);
  434.         
  435.     WinForgetCachedBitmap();
  436. #endif
  437. }
  438.  
  439. //----------------------------------------------------------------------------------------
  440. //    FW_CPrivColorPatternRep::IsBlack
  441. //----------------------------------------------------------------------------------------
  442.  
  443. FW_Boolean FW_CPrivColorPatternRep::IsBlack() const
  444. {
  445.     return FALSE;
  446. }
  447.  
  448. //----------------------------------------------------------------------------------------
  449. //    FW_CPrivColorPatternRep::IsEqual
  450. //----------------------------------------------------------------------------------------
  451.  
  452. FW_Boolean FW_CPrivColorPatternRep::IsEqual(const FW_CPrivPatternRep* other) const
  453. {
  454.     if (other == this)
  455.         return TRUE;
  456.  
  457.     const FW_CPrivColorPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CPrivColorPatternRep, (FW_CPrivPatternRep*)other);
  458.     if (patternRep == NULL)
  459.         return FALSE;
  460.  
  461.     // Compare the pixels        
  462.     FW_PixelPattern pixData1;
  463.     GetPixelData(pixData1);
  464.  
  465.     FW_PixelPattern pixData2;
  466.     patternRep->GetPixelData(pixData2);
  467.     
  468.     if(::memcmp(pixData1.fData, pixData2.fData, sizeof(FW_PixelPattern)) != 0)
  469.         return FALSE;
  470.     
  471.     // Compare the color tables
  472.     FW_SColor* colors1 = NULL;
  473.     unsigned short nbColors1 = GetColorTable(colors1);
  474.  
  475.     FW_SColor* colors2 = NULL;
  476.     unsigned short nbColors2 = patternRep->GetColorTable(colors2);
  477.         
  478.     if(nbColors1 != nbColors2 || ::memcmp(colors1, colors2, sizeof(FW_SColor) * nbColors1) != 0)
  479.     {
  480.         delete[] colors1;
  481.         delete[] colors2;
  482.         return FALSE;
  483.     }
  484.  
  485.     return TRUE;
  486. }
  487.  
  488. //----------------------------------------------------------------------------------------
  489. //    FW_CPrivColorPatternRep::Copy
  490. //----------------------------------------------------------------------------------------
  491.  
  492. FW_CPrivPatternRep* FW_CPrivColorPatternRep::Copy() const
  493. {
  494.     FW_PlatformColorPattern platformColorPattern;
  495.     
  496. #ifdef FW_BUILD_MAC
  497.     platformColorPattern = ::NewPixPat();
  498.     ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
  499. #endif
  500.  
  501. #ifdef FW_BUILD_WIN
  502.     platformColorPattern = FW_DIBCreateCopy(fPlatformColorPattern);
  503. #endif
  504.  
  505.     return FW_NEW(FW_CPrivColorPatternRep, (platformColorPattern));
  506. }
  507.  
  508. //----------------------------------------------------------------------------------------
  509. //    FW_CPrivColorPatternRep::Flatten
  510. //----------------------------------------------------------------------------------------
  511.  
  512. void FW_CPrivColorPatternRep::Flatten(FW_CWritableStream& stream) const
  513. {
  514.     // Pixel data
  515.     FW_PixelPattern pixData;
  516.     GetPixelData(pixData);
  517.     stream.Write(pixData.fData, sizeof(pixData));
  518.     
  519.     // ----- Colors
  520.     FW_SColor* colors = NULL;
  521.     unsigned short nbColors = GetColorTable(colors);
  522.     FW_TRY
  523.     {
  524.         stream << nbColors;
  525.         for(int i = 0; i < nbColors; i++)
  526.             stream << FW_CColor(colors[i]);    // [HLX] added the cast
  527.     }
  528.     FW_CATCH_BEGIN
  529.     FW_CATCH_EVERYTHING()
  530.     {
  531.         // Clean up
  532.         delete[] colors;
  533.  
  534.         FW_THROW_SAME();
  535.     }
  536.     FW_CATCH_END
  537.     
  538.     // Clean up
  539.     delete[] colors;
  540. }
  541.  
  542. //----------------------------------------------------------------------------------------
  543. //    FW_CPrivColorPatternRep::Invert
  544. //----------------------------------------------------------------------------------------
  545.  
  546. void FW_CPrivColorPatternRep::Invert()
  547. {
  548.     // Get current pattern info
  549.     FW_PixelPattern pixData;
  550.     GetPixelData(pixData);
  551.  
  552.     // ----- Look for minimum and maximun -----
  553.     unsigned char max = 0x00;
  554.     int i;
  555.     
  556.     for (i = 0; i < 8 * 8; i++)
  557.     {
  558.         unsigned char c = pixData.fDataRaw[i];
  559.         if (c > max)
  560.             max = c;            
  561.     }
  562.  
  563.     // ----- Invert it -----
  564.     for (i = 0; i < 8 * 8; i++)
  565.         pixData.fDataRaw[i] = max - pixData.fDataRaw[i];
  566.  
  567.     // Update the pattern
  568.     SetPixelData(pixData);
  569. }
  570.  
  571. //----------------------------------------------------------------------------------------
  572. //    FW_CPrivColorPatternRep::FlipVertically
  573. //----------------------------------------------------------------------------------------
  574.  
  575. void FW_CPrivColorPatternRep::FlipVertically()
  576. {
  577.     // Get current pattern info
  578.     FW_PixelPattern pixData;
  579.     GetPixelData(pixData);
  580.     
  581.     // Flip it
  582.     for (short i = 0; i < 4; i++)
  583.         for (short j = 0; j < 2; j++)
  584.         {
  585.             unsigned long l = pixData.fDataLongs[i][j];
  586.             pixData.fDataLongs[i][j] = pixData.fDataLongs[7 - i][j];
  587.             pixData.fDataLongs[7 - i][j] = l;
  588.         }
  589.  
  590.     // Update the pattern
  591.     SetPixelData(pixData);
  592. }
  593.  
  594. //----------------------------------------------------------------------------------------
  595. //    FW_CPrivColorPatternRep::FlipHorizontally
  596. //----------------------------------------------------------------------------------------
  597.  
  598. void FW_CPrivColorPatternRep::FlipHorizontally()
  599. {    
  600.     // Get current pattern info
  601.     FW_PixelPattern pixData;
  602.     GetPixelData(pixData);
  603.     
  604.     // Flip it
  605.     for (short i = 0; i < 8; i++)
  606.         for (short j = 0; j < 4; j++)
  607.         {
  608.             unsigned char c = pixData.fData[i][j];
  609.             pixData.fData[i][j] = pixData.fData[i][7 - j];
  610.             pixData.fData[i][7 - j] = c;
  611.         }
  612.  
  613.     // Update the pattern
  614.     SetPixelData(pixData);
  615. }
  616.  
  617. //----------------------------------------------------------------------------------------
  618. //    FW_CPrivColorPatternRep::ShiftRight
  619. //----------------------------------------------------------------------------------------
  620.  
  621. void FW_CPrivColorPatternRep::ShiftRight()
  622. {
  623.     // Get current pattern info
  624.     FW_PixelPattern pixData;
  625.     GetPixelData(pixData);
  626.  
  627.     // Shift it
  628.     for (short i = 0; i < 8; i++)
  629.     {
  630.         unsigned char c = pixData.fData[i][7];
  631.         for(short j = 7; j > 0; j--)
  632.             pixData.fData[i][j] = pixData.fData[i][j - 1];
  633.         pixData.fData[i][0] = c;
  634.     }
  635.  
  636.     // Update the pattern
  637.     SetPixelData(pixData);
  638. }
  639.  
  640. //----------------------------------------------------------------------------------------
  641. //    FW_CPrivColorPatternRep::ShiftLeft
  642. //----------------------------------------------------------------------------------------
  643.  
  644. void FW_CPrivColorPatternRep::ShiftLeft()
  645. {
  646.     // Get current pattern info
  647.     FW_PixelPattern pixData;
  648.     GetPixelData(pixData);
  649.     
  650.     // Shift it
  651.     for (short i = 0; i < 8; i++)
  652.     {
  653.         unsigned char c = pixData.fData[i][0];
  654.         for(short j = 0; j < 7; j++)
  655.             pixData.fData[i][j] = pixData.fData[i][j + 1];
  656.         pixData.fData[i][7] = c;
  657.     }
  658.  
  659.     // Update the pattern
  660.     SetPixelData(pixData);
  661. }
  662.  
  663. //----------------------------------------------------------------------------------------
  664. //    FW_CPrivColorPatternRep::ShiftUp
  665. //----------------------------------------------------------------------------------------
  666.  
  667. void FW_CPrivColorPatternRep::ShiftUp()
  668. {
  669.     // Get current pattern info
  670.     FW_PixelPattern pixData;
  671.     GetPixelData(pixData);
  672.     
  673.     // Shift it
  674.     unsigned long temp0 = pixData.fDataLongs[0][0];
  675.     unsigned long temp1 = pixData.fDataLongs[0][1];
  676.     
  677.     for (short i = 0; i < 7; i++)
  678.     {
  679.         pixData.fDataLongs[i][0] = pixData.fDataLongs[i + 1][0];
  680.         pixData.fDataLongs[i][1] = pixData.fDataLongs[i + 1][1];
  681.     }
  682.         
  683.     pixData.fDataLongs[7][0] = temp0;
  684.     pixData.fDataLongs[7][1] = temp1;
  685.  
  686.     // Update the pattern
  687.     SetPixelData(pixData);
  688. }
  689.  
  690. //----------------------------------------------------------------------------------------
  691. //    FW_CPrivColorPatternRep::ShiftDown
  692. //----------------------------------------------------------------------------------------
  693.  
  694. void FW_CPrivColorPatternRep::ShiftDown()
  695. {
  696.     // Get current pattern info
  697.     FW_PixelPattern pixData;
  698.     GetPixelData(pixData);
  699.     
  700.     // Shift it
  701.     unsigned long temp0 = pixData.fDataLongs[7][0];
  702.     unsigned long temp1 = pixData.fDataLongs[7][1];
  703.     
  704.     for (short i = 7; i > 0; i--)
  705.     {
  706.         pixData.fDataLongs[i][0] = pixData.fDataLongs[i - 1][0];
  707.         pixData.fDataLongs[i][1] = pixData.fDataLongs[i - 1][1];
  708.     }
  709.  
  710.     pixData.fDataLongs[0][0] = temp0;
  711.     pixData.fDataLongs[0][1] = temp1;
  712.  
  713.     // Update the pattern
  714.     SetPixelData(pixData);
  715. }
  716.  
  717. //----------------------------------------------------------------------------------------
  718. //    FW_CPrivColorPatternRep::Read
  719. //----------------------------------------------------------------------------------------
  720.  
  721. void* FW_CPrivColorPatternRep::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  722. {
  723. FW_UNUSED(type);
  724.     return FW_NEW(FW_CPrivColorPatternRep, (stream));
  725. }
  726.  
  727. #ifdef FW_BUILD_MAC
  728. //----------------------------------------------------------------------------------------
  729. //    FW_CPrivColorPatternRep::MacSetInCurPort
  730. //----------------------------------------------------------------------------------------
  731.  
  732. void FW_CPrivColorPatternRep::MacSetInCurPort() const
  733. {
  734.     FW_ASSERT(fPlatformColorPattern != NULL);
  735.  
  736. //    FW_PlatformColorPattern platformColorPattern = ::NewPixPat();
  737. //    ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
  738. //    ::PenPixPat(platformColorPattern);
  739.     // [HLX] We should not have to make a copy. Quickdraw won't dispose it. If we dispose it
  740.     // Quickdraw will reset the 'standard pattern'
  741.     ::PenPixPat(fPlatformColorPattern);
  742. }
  743. #endif
  744.  
  745. #ifdef FW_BUILD_WIN
  746. //----------------------------------------------------------------------------------------
  747. //    FW_CPrivColorPatternRep::WinCreatePatternBrush
  748. //----------------------------------------------------------------------------------------
  749.  
  750. HBRUSH FW_CPrivColorPatternRep::WinCreatePatternBrush() const
  751. {
  752.     HBRUSH hBrush = NULL;
  753.  
  754.     // Convert into a DDB for effeciency
  755.     if (fWinCachedBitmap == NULL)
  756.         ((FW_CPrivColorPatternRep*) this)->fWinCachedBitmap = FW_DIBConvertToBitmap(fPlatformColorPattern, NULL);
  757.  
  758.     // Create the brush
  759.     if(fWinCachedBitmap != NULL)
  760.         hBrush = ::CreatePatternBrush(fWinCachedBitmap);
  761.  
  762.     return hBrush;
  763. }
  764. #endif
  765.  
  766. #ifdef FW_BUILD_WIN
  767. //----------------------------------------------------------------------------------------
  768. //    FW_CPrivColorPatternRep::WinForgetCachedBitmap
  769. //----------------------------------------------------------------------------------------
  770.  
  771. void FW_CPrivColorPatternRep::WinForgetCachedBitmap()
  772. {
  773.     if (fWinCachedBitmap != NULL)
  774.     {
  775.         ::DeleteObject(fWinCachedBitmap);
  776.         fWinCachedBitmap = NULL;
  777.     }
  778. }
  779. #endif
  780.  
  781. #ifdef FW_BUILD_MAC
  782. //----------------------------------------------------------------------------------------
  783. //    FW_CPrivColorPatternRep::MacNewPixPat
  784. //----------------------------------------------------------------------------------------
  785.  
  786. PixPatHandle FW_CPrivColorPatternRep::MacNewPixPat(const void* pixels, 
  787.                                                 short rowBytes, short pixelSize,
  788.                                                 short withPower, short heightPower,
  789.                                                 short nbColors, const FW_SColor* colorTable)
  790. {
  791.     FW_ASSERT(pixels != NULL);
  792.     FW_ASSERT(colorTable != NULL);
  793.     FW_ASSERT((rowBytes & 0x0001) == 0);
  794.     FW_ASSERT(pixelSize == 1 || pixelSize == 2 || pixelSize == 4 || pixelSize == 8);
  795.     FW_ASSERT(withPower != 0);
  796.     FW_ASSERT(heightPower != 0);
  797.     FW_ASSERT(nbColors <= (1 << pixelSize));
  798.  
  799.     PixPatHandle pixPat = ::NewPixPat();
  800.     
  801.     (*pixPat)->patType = 1;
  802.         
  803.     // ----- Creates the pixMap -----
  804.     PixMapHandle pixMap = (*pixPat)->patMap;
  805.     
  806.     (*pixMap)->rowBytes = rowBytes | 0x8000;
  807.     (*pixMap)->bounds.left = 0;
  808.     (*pixMap)->bounds.top = 0;
  809.     (*pixMap)->bounds.right = 1 << withPower;
  810.     (*pixMap)->bounds.bottom = 1 << heightPower;
  811.     (*pixMap)->pixelSize = pixelSize;
  812.     (*pixMap)->cmpCount = 1;
  813.     (*pixMap)->cmpSize = pixelSize;
  814.     
  815.     // ----- Set up the color table -----
  816.     CTabHandle hColors = (*pixMap)->pmTable;    
  817.     Size colorTabSize = sizeof(ColorTable) + (nbColors * sizeof(ColorSpec));    
  818.     ::SetHandleSize((Handle)hColors, colorTabSize);
  819.     
  820.     ::HLock((Handle)hColors);
  821.     CTabPtr pColors = *hColors;
  822.     pColors->ctSeed = ::GetCTSeed();
  823.     pColors->ctFlags = 0;
  824.     pColors->ctSize = nbColors - 1;
  825.     
  826.     for (short i = 0; i<nbColors; i++)
  827.     {
  828.         pColors->ctTable[i].value = i;
  829.         FW_MacColorToRGB(colorTable[i], &pColors->ctTable[i].rgb);
  830.     }
  831.     ::HUnlock((Handle)hColors);
  832.     
  833.     // ----- Creates the pattern data -----
  834.     Size dataSize = (Size)rowBytes * 8;
  835.     Handle patData = (*pixPat)->patData;
  836.     ::SetHandleSize(patData, dataSize);
  837.         
  838.     ::HLock(patData);
  839.     ::BlockMove(pixels, *patData, dataSize);
  840.     ::HUnlock(patData);
  841.     
  842.     return pixPat;
  843. }
  844. #endif
  845.  
  846. #ifdef FW_BUILD_WIN
  847.  
  848. //----------------------------------------------------------------------------------------
  849. //    FW_CPrivColorPatternRep::WinFlipPixelCopy
  850. //----------------------------------------------------------------------------------------
  851.  
  852. void FW_CPrivColorPatternRep::WinFlipPixelCopy(const void* source, void* dest)
  853. {
  854.     unsigned long* sourceL = (unsigned long*) source;
  855.     unsigned long* destL = (unsigned long*) dest;
  856.     
  857.     for(int i = 0; i < 16; i += 2)
  858.     {
  859.         destL[14 - i] = sourceL[i];
  860.         destL[15 - i] = sourceL[i + 1];
  861.     }
  862. }
  863.  
  864. #endif
  865.  
  866. //----------------------------------------------------------------------------------------
  867. //    FW_CPrivColorPatternRep::MakePixelPattern
  868. //----------------------------------------------------------------------------------------
  869.  
  870. void FW_CPrivColorPatternRep::MakePixelPattern(const FW_PixelPattern& pixels, short nbColors, const FW_SColor* colorTable)
  871. {
  872. #ifdef FW_BUILD_MAC
  873.     fPlatformColorPattern = MacNewPixPat(pixels.fData, 8, 8, 3, 3, nbColors, colorTable);
  874. #endif
  875.  
  876. #ifdef FW_BUILD_WIN
  877.     // We need to flip the bits because DIBs are stored bottom-to-top
  878.     FW_PixelPattern pixData;
  879.     WinFlipPixelCopy(pixels.fData, pixData.fData);
  880.     
  881.     // Create the DIB
  882.     fPlatformColorPattern = FW_DIBCreate(8, 8, 8, nbColors, colorTable, pixData.fData);
  883. #endif
  884. }
  885.  
  886. //----------------------------------------------------------------------------------------
  887. //    FW_CPrivColorPatternRep::GetPixelData
  888. //----------------------------------------------------------------------------------------
  889.  
  890. void FW_CPrivColorPatternRep::GetPixelData(FW_PixelPattern& pixData) const
  891. {
  892. #ifdef FW_BUILD_MAC
  893.     Handle patData = (*fPlatformColorPattern)->patData;
  894.  
  895.     ::HLock(patData);
  896.     BlockMove((FW_PixelPattern*)*patData, pixData.fDataRaw, 64);
  897.     ::HUnlock(patData);
  898. #endif
  899. #ifdef FW_BUILD_WIN
  900.     FW_WinPixelBufferPtr pixels = FW_DIBGetPixelBuffer(fPlatformColorPattern);
  901.     WinFlipPixelCopy(pixels, pixData.fData);
  902. #endif
  903. }
  904.  
  905. //----------------------------------------------------------------------------------------
  906. //    FW_CPrivColorPatternRep::SetPixelData
  907. //----------------------------------------------------------------------------------------
  908.  
  909. void FW_CPrivColorPatternRep::SetPixelData(const FW_PixelPattern& pixData)
  910. {
  911. #ifdef FW_BUILD_MAC
  912.     Handle patData = (*fPlatformColorPattern)->patData;
  913.  
  914.     ::HLock(patData);
  915.     ::BlockMove(pixData.fDataRaw, (FW_PixelPattern*)*patData, 64);
  916.     ::HUnlock(patData);
  917.  
  918.     ::PixPatChanged(fPlatformColorPattern);
  919. #endif
  920. #ifdef FW_BUILD_WIN
  921.     FW_WinPixelBufferPtr pixels = FW_DIBGetPixelBuffer(fPlatformColorPattern);
  922.     WinFlipPixelCopy(pixData.fData, pixels);
  923.  
  924.     WinForgetCachedBitmap();
  925. #endif
  926. }
  927.  
  928. //----------------------------------------------------------------------------------------
  929. //    FW_CPrivColorPatternRep::GetColorTable
  930. //----------------------------------------------------------------------------------------
  931.  
  932. unsigned short FW_CPrivColorPatternRep::GetColorTable(FW_SColor*& colors) const
  933. {
  934. #ifdef FW_BUILD_MAC
  935.     PixMapHandle pixMap = (*fPlatformColorPattern)->patMap;
  936.  
  937.     CTabHandle hColors = (*pixMap)->pmTable;    
  938.     FW_CAcquireLockedSystemHandle lock((FW_PlatformHandle)hColors);
  939.     CTabPtr pColors = *hColors;
  940.  
  941.     unsigned short nbColors = pColors->ctSize + 1;
  942.     colors = new FW_SColor[nbColors];
  943.     for (unsigned short i = 0; i<nbColors; i++)
  944.         colors[i] = FW_MacRGBToColor(&pColors->ctTable[i].rgb);
  945.  
  946.     return nbColors;
  947. #endif
  948. #ifdef FW_BUILD_WIN
  949.     FW_SColor* rgbColors = NULL;
  950.     unsigned short nColors = FW_DIBAcquireColorTable(fPlatformColorPattern, &rgbColors);
  951.     
  952.     // Convert RGB colors to C++ colors
  953.     colors = new FW_SColor[nColors];
  954.     for (unsigned short i = 0; i < nColors; ++ i)
  955.         colors[i] = rgbColors[i];
  956.         
  957.     FW_DIBReleaseColorTable(rgbColors);
  958.     
  959.     return nColors;
  960. #endif
  961. }
  962.  
  963. //========================================================================================
  964. //    class FW_CPrivInkRep
  965. //========================================================================================
  966.  
  967. #ifdef FW_BUILD_MAC
  968. #pragma segment FWGraphics_PrivInkRep
  969. #endif
  970.  
  971. //----------------------------------------------------------------------------------------
  972. //    FW_CPrivInkRep::FW_CPrivInkRep
  973. //----------------------------------------------------------------------------------------
  974.  
  975. FW_CPrivInkRep::FW_CPrivInkRep(FW_SColor fore, FW_SColor back, FW_TransferModes mode):
  976.     fForeColor(fore),
  977.     fBackColor(back),
  978.     fTransferMode(mode)
  979. {
  980. }
  981.  
  982. //----------------------------------------------------------------------------------------
  983. //    FW_CPrivInkRep::FW_CPrivInkRep
  984. //----------------------------------------------------------------------------------------
  985.  
  986. FW_CPrivInkRep::FW_CPrivInkRep(FW_EStandardInks std) :
  987.     fForeColor(FW_kRGBBlack),
  988.     fBackColor(FW_kRGBWhite)
  989. {
  990.     switch (std)
  991.     {
  992.     default:
  993.     case FW_kNormalInk:
  994.         fTransferMode = FW_kCopy;
  995.         break;
  996.  
  997.     case FW_kNormalTextInk:
  998.         fTransferMode = FW_kOr;
  999.         break;
  1000.  
  1001.     case FW_kInvertInk:
  1002.         fTransferMode = FW_kInvert;
  1003.         break;
  1004.  
  1005.     case FW_kWhiteEraseInk:
  1006.         fTransferMode = FW_kErase;
  1007.         break;
  1008.     }
  1009. }
  1010.  
  1011. //----------------------------------------------------------------------------------------
  1012. //    FW_CPrivInkRep::FW_CPrivInkRep
  1013. //----------------------------------------------------------------------------------------
  1014.  
  1015. FW_CPrivInkRep::FW_CPrivInkRep(const FW_CPrivInkRep& otherRep):
  1016.     fForeColor(otherRep.fForeColor),
  1017.     fBackColor(otherRep.fBackColor),
  1018.     fTransferMode(otherRep.fTransferMode)
  1019. {
  1020. }
  1021.  
  1022. //----------------------------------------------------------------------------------------
  1023. //    FW_CPrivInkRep::FW_CPrivInkRep
  1024. //----------------------------------------------------------------------------------------
  1025.  
  1026. FW_CPrivInkRep::FW_CPrivInkRep(FW_CReadableStream& stream)
  1027. {
  1028.     stream >> fForeColor;
  1029.     stream >> fBackColor;
  1030.     stream >> fTransferMode;
  1031. }
  1032.  
  1033. //----------------------------------------------------------------------------------------
  1034. //    FW_CPrivInkRep::~FW_CPrivInkRep
  1035. //----------------------------------------------------------------------------------------
  1036.  
  1037. FW_CPrivInkRep::~FW_CPrivInkRep()
  1038. {
  1039. }
  1040.  
  1041. //----------------------------------------------------------------------------------------
  1042. //    FW_CPrivInkRep::IsEqual
  1043. //----------------------------------------------------------------------------------------
  1044.  
  1045. FW_Boolean FW_CPrivInkRep::IsEqual(const FW_CPrivInkRep* other) const
  1046. {
  1047.     if (other == this)
  1048.         return TRUE;
  1049.  
  1050.     return    fTransferMode == other->fTransferMode &&
  1051.             fForeColor == other->fForeColor && 
  1052.             fBackColor == other->fBackColor;
  1053. }
  1054.  
  1055. //----------------------------------------------------------------------------------------
  1056. //    FW_CPrivInkRep::Write
  1057. //----------------------------------------------------------------------------------------
  1058.  
  1059. void FW_CPrivInkRep::Write(FW_CWritableStream& stream) const
  1060. {
  1061.     stream << fForeColor;
  1062.     stream << fBackColor;
  1063.     stream << fTransferMode;
  1064. }
  1065.  
  1066. //========================================================================================
  1067. //    class FW_CPrivStyleRep
  1068. //========================================================================================
  1069.  
  1070. FW_DEFINE_AUTO(FW_CPrivStyleRep)
  1071.  
  1072. //----------------------------------------------------------------------------------------
  1073. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1074. //----------------------------------------------------------------------------------------
  1075.  
  1076. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_Fixed penSize, FW_EStyleDash dash) :
  1077.     fPenSize(penSize),
  1078.     fDash(dash),
  1079.     fPattern(FW_NEW(FW_CPrivBWPatternRep, ()))
  1080. {
  1081.     FW_END_CONSTRUCTOR
  1082. }
  1083.  
  1084. //----------------------------------------------------------------------------------------
  1085. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1086. //----------------------------------------------------------------------------------------
  1087.  
  1088. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_Fixed penSize, FW_HPattern pattern) :
  1089.     fPenSize(penSize),
  1090.     fDash(FW_kSolidLine),
  1091.     fPattern(pattern)
  1092. {
  1093.     FW_END_CONSTRUCTOR
  1094. }
  1095.  
  1096. //----------------------------------------------------------------------------------------
  1097. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1098. //----------------------------------------------------------------------------------------
  1099.  
  1100. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_CReadableStream& stream)
  1101. {
  1102.     stream >> fPenSize;
  1103.     
  1104.     short nDash;
  1105.     stream >> nDash;
  1106.     fDash = (FW_EStyleDash) nDash;
  1107.     
  1108.     FW_CPrivPatternRep* pattern;
  1109.     FW_READ_DYNAMIC_OBJECT(stream, &pattern, FW_CPrivPatternRep);
  1110.     fPattern = pattern;
  1111.  
  1112.     FW_END_CONSTRUCTOR
  1113. }
  1114.  
  1115. //----------------------------------------------------------------------------------------
  1116. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1117. //----------------------------------------------------------------------------------------
  1118.  
  1119. FW_CPrivStyleRep::FW_CPrivStyleRep(FW_EStandardStyles std) :
  1120.     fPenSize(FW_kFixedPos1),
  1121.     fPattern(FW_NEW(FW_CPrivBWPatternRep, ()))
  1122. {
  1123.     switch(std)
  1124.     {
  1125.     default:
  1126.         FW_ASSERT(FALSE);        // Invalid standard style
  1127.                                 // fall-through
  1128.     case FW_kNormalStyle:
  1129.         fDash = FW_kSolidLine;
  1130.         break;
  1131.  
  1132.     case FW_kDashStyle:
  1133.         fDash = FW_kDash;
  1134.         break;
  1135.  
  1136.     case FW_kDotStyle:
  1137.         fDash = FW_kDot;
  1138.         break;
  1139.  
  1140.     case FW_kDashDotStyle:
  1141.         fDash = FW_kDashDot;
  1142.         break;
  1143.  
  1144.     case FW_kDashDotDotStyle:
  1145.         fDash = FW_kDashDotDot;
  1146.         break;
  1147.     }
  1148.  
  1149.     FW_END_CONSTRUCTOR
  1150. }
  1151.  
  1152. //----------------------------------------------------------------------------------------
  1153. //    FW_CPrivStyleRep::FW_CPrivStyleRep
  1154. //----------------------------------------------------------------------------------------
  1155.  
  1156. FW_CPrivStyleRep::FW_CPrivStyleRep(const FW_CPrivStyleRep& otherRep) :
  1157.     fPenSize (otherRep.fPenSize),
  1158.     fDash    (otherRep.fDash),
  1159.     fPattern (otherRep.fPattern)
  1160. {
  1161.     FW_END_CONSTRUCTOR
  1162. }
  1163.  
  1164. //----------------------------------------------------------------------------------------
  1165. //    FW_CPrivStyleRep::~FW_CPrivStyleRep
  1166. //----------------------------------------------------------------------------------------
  1167.  
  1168. FW_CPrivStyleRep::~FW_CPrivStyleRep()
  1169. {    
  1170.     FW_START_DESTRUCTOR
  1171. }
  1172.  
  1173. //----------------------------------------------------------------------------------------
  1174. //    FW_CPrivStyleRep::GetUnSharedPattern
  1175. //----------------------------------------------------------------------------------------
  1176.  
  1177. FW_HPattern FW_CPrivStyleRep::GetUnSharedPattern()
  1178. {
  1179.     if (fPattern->GetRefCount() > 1)
  1180.         fPattern = fPattern->Copy();
  1181.  
  1182.     return fPattern;
  1183. }
  1184.  
  1185. //----------------------------------------------------------------------------------------
  1186. //    FW_CPrivStyleRep::Write
  1187. //----------------------------------------------------------------------------------------
  1188.  
  1189. void FW_CPrivStyleRep::Write(FW_CWritableStream& stream) const
  1190. {
  1191.     stream << fPenSize;
  1192.     stream << (short) fDash;
  1193.     
  1194.     const FW_CPrivPatternRep* rep = fPattern;
  1195.     FW_WRITE_DYNAMIC_OBJECT(stream, rep, FW_CPrivPatternRep);
  1196. }
  1197.  
  1198. //----------------------------------------------------------------------------------------
  1199. //    FW_CPrivStyleRep::IsEqual
  1200. //----------------------------------------------------------------------------------------
  1201.  
  1202. FW_Boolean FW_CPrivStyleRep::IsEqual(const FW_CPrivStyleRep* other) const
  1203. {
  1204.     if (other == this)
  1205.         return TRUE;
  1206.         
  1207.     return fPenSize == other->fPenSize &&
  1208.             fDash == other->fDash &&
  1209.             fPattern->IsEqual(other->fPattern);
  1210. }
  1211.  
  1212. //========================================================================================
  1213. //    class FW_CPrivFontRep
  1214. //========================================================================================
  1215.  
  1216. FW_DEFINE_AUTO(FW_CPrivFontRep)
  1217.  
  1218. //----------------------------------------------------------------------------------------
  1219. //    FW_CPrivFontRep::FW_CPrivFontRep
  1220. //----------------------------------------------------------------------------------------
  1221.  
  1222. FW_CPrivFontRep::FW_CPrivFontRep() :
  1223.     fFontStyle(FW_kPlain),
  1224.     fFontSize(FW_IntToFixed(12)),
  1225.     fFontName()
  1226. #ifdef FW_BUILD_MAC
  1227.     ,fMacValidCache(FALSE)
  1228. #endif
  1229. {
  1230.     FW_END_CONSTRUCTOR
  1231. }
  1232.  
  1233. //----------------------------------------------------------------------------------------
  1234. //    FW_CPrivFontRep::FW_CPrivFontRep
  1235. //----------------------------------------------------------------------------------------
  1236.  
  1237. FW_CPrivFontRep::FW_CPrivFontRep(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize) :
  1238.     fFontStyle(fontStyle),
  1239.     fFontSize(fontSize),
  1240.     fFontName(fontName)
  1241. #ifdef FW_BUILD_MAC
  1242.     ,fMacValidCache(FALSE)
  1243. #endif
  1244. {
  1245.     FW_END_CONSTRUCTOR
  1246. }
  1247.  
  1248. //----------------------------------------------------------------------------------------
  1249. //    FW_CPrivFontRep::FW_CPrivFontRep
  1250. //----------------------------------------------------------------------------------------
  1251.  
  1252. FW_CPrivFontRep::FW_CPrivFontRep(const FW_CPrivFontRep& otherRep):
  1253.     fFontStyle(otherRep.fFontStyle),
  1254.     fFontSize(otherRep.fFontSize),
  1255.     fFontName(otherRep.fFontName)
  1256. #ifdef FW_BUILD_MAC
  1257.     ,fMacValidCache(FALSE)
  1258. #endif
  1259. {
  1260.     FW_END_CONSTRUCTOR
  1261. }
  1262.  
  1263. //----------------------------------------------------------------------------------------
  1264. //    FW_CPrivFontRep::FW_CPrivFontRep
  1265. //----------------------------------------------------------------------------------------
  1266.  
  1267. FW_CPrivFontRep::FW_CPrivFontRep(FW_CReadableStream& stream)
  1268. #ifdef FW_BUILD_MAC
  1269.     : fMacValidCache(FALSE)
  1270. #endif
  1271. {
  1272.     stream >> fFontSize;
  1273.     stream >> fFontStyle;
  1274.     stream >> fFontName;
  1275.     FW_END_CONSTRUCTOR
  1276. }
  1277.  
  1278. //----------------------------------------------------------------------------------------
  1279. //    FW_CPrivFontRep::FW_CPrivFontRep
  1280. //----------------------------------------------------------------------------------------
  1281.  
  1282. FW_CPrivFontRep::FW_CPrivFontRep(FW_EStandardFonts std) :
  1283.     fFontSize(FW_IntToFixed(12)),
  1284.     fFontStyle(FW_kPlain)
  1285. #ifdef FW_BUILD_MAC
  1286.     , fMacValidCache(FALSE)
  1287. #endif
  1288. {
  1289.     switch (std) 
  1290.     {
  1291.         case FW_kNormalFont:
  1292.             fFontName = FW_GetDefaultFontName();
  1293. #ifdef FW_BUILD_MAC
  1294.             fFontSize = FW_IntToFixed(::GetDefFontSize());
  1295. #endif
  1296. #ifdef FW_BUILD_WIN
  1297.             FW_DEBUG_MESSAGE("FW_CPrivFontRep::FW_CPrivFontRep");
  1298. #endif
  1299.             break;
  1300.         case FW_kSystemFont:
  1301.             fFontName = FW_GetSystemFontName();
  1302. #ifdef FW_BUILD_MAC
  1303.             fFontSize = FW_IntToFixed(::GetDefFontSize());
  1304. #endif
  1305. #ifdef FW_BUILD_WIN
  1306.             FW_DEBUG_MESSAGE("FW_CPrivFontRep::FW_CPrivFontRep");
  1307. #endif
  1308.             break;
  1309.         case FW_kHelvetica12:
  1310.             fFontName = FW_GetHelveticaFontName();
  1311.             break;
  1312.         case FW_kTimes12:
  1313.             fFontName = FW_GetTimesFontName();
  1314.             break;
  1315.         case FW_kPalatino12:
  1316.             fFontName = FW_GetPalatinoFontName();
  1317.             break;
  1318.         case FW_kCourier12:
  1319.             fFontName = FW_GetCourierFontName();
  1320.             break;            
  1321.     }
  1322.     FW_END_CONSTRUCTOR
  1323. }
  1324.     
  1325. //----------------------------------------------------------------------------------------
  1326. //    FW_CPrivFontRep::~FW_CPrivFontRep
  1327. //----------------------------------------------------------------------------------------
  1328.  
  1329. FW_CPrivFontRep::~FW_CPrivFontRep()
  1330. {
  1331.     FW_START_DESTRUCTOR
  1332. }
  1333.  
  1334. //----------------------------------------------------------------------------------------
  1335. //    FW_CPrivFontRep::SetFontName
  1336. //----------------------------------------------------------------------------------------
  1337.  
  1338. void FW_CPrivFontRep::SetFontName(const FW_CString& fontName)
  1339. {
  1340.     fFontName = fontName;
  1341. #ifdef FW_BUILD_MAC
  1342.     fMacValidCache = FALSE;
  1343. #endif
  1344. }
  1345.  
  1346. //----------------------------------------------------------------------------------------
  1347. //    FW_CPrivFontRep::SetFontStyle
  1348. //----------------------------------------------------------------------------------------
  1349.  
  1350. void FW_CPrivFontRep::SetFontStyle(FW_FontStyle fontStyle)
  1351. {
  1352.     fFontStyle = fontStyle;
  1353. #ifdef FW_BUILD_MAC
  1354.     fMacValidCache = FALSE;
  1355. #endif
  1356. }
  1357.  
  1358. //----------------------------------------------------------------------------------------
  1359. //    FW_CPrivFontRep::Write
  1360. //----------------------------------------------------------------------------------------
  1361.  
  1362. void FW_CPrivFontRep::Write(FW_CWritableStream& stream) const
  1363. {
  1364.     stream << fFontSize;
  1365.     stream << fFontStyle;
  1366.     stream << fFontName;
  1367. }
  1368.  
  1369. #ifdef FW_BUILD_MAC
  1370. //----------------------------------------------------------------------------------------
  1371. //    FW_CPrivFontRep::MacGetFontID
  1372. //----------------------------------------------------------------------------------------
  1373.  
  1374. short FW_CPrivFontRep::MacGetFontID() const
  1375. {
  1376.     ((FW_CPrivFontRep*)this)->MacCheckFontCache();
  1377.     return fMacFontID;
  1378. }
  1379. #endif
  1380.  
  1381. #ifdef FW_BUILD_MAC
  1382. //----------------------------------------------------------------------------------------
  1383. //    FW_CPrivFontRep::MacGetFontStyle
  1384. //----------------------------------------------------------------------------------------
  1385.  
  1386. Style FW_CPrivFontRep::MacGetFontStyle() const
  1387. {
  1388.     ((FW_CPrivFontRep*)this)->MacCheckFontCache();
  1389.     return fMacFontStyle;
  1390. }
  1391. #endif
  1392.  
  1393. #ifdef FW_BUILD_MAC
  1394. //----------------------------------------------------------------------------------------
  1395. //    FW_CPrivFontRep::MacSetFontID
  1396. //----------------------------------------------------------------------------------------
  1397.  
  1398. void FW_CPrivFontRep::MacSetFontID(short macFontID)
  1399. {
  1400.     FW_CString255 fontName;
  1401.     
  1402.     if (macFontID == 0)
  1403.         fontName = FW_GetSystemFontName();
  1404.     else if (macFontID == 1)
  1405.         fontName = FW_GetDefaultFontName();
  1406.     else
  1407.     {
  1408.         Str255 pstr;
  1409.         ::GetFontName(macFontID, pstr);
  1410.         fontName.Append((char*)&pstr[1], pstr[0]);
  1411.     }
  1412.     SetFontName(fontName);
  1413. }
  1414. #endif
  1415.  
  1416. #ifdef FW_BUILD_MAC
  1417. //----------------------------------------------------------------------------------------
  1418. //    FW_CPrivFontRep::MacCheckFontCache
  1419. //----------------------------------------------------------------------------------------
  1420.  
  1421. void FW_CPrivFontRep::MacCheckFontCache()
  1422. {
  1423.     if (!fMacValidCache)
  1424.     {
  1425.         fMacFontStyle = normal;
  1426.         if (fFontStyle & FW_kBold)
  1427.             fMacFontStyle += bold;
  1428.         if (fFontStyle & FW_kItalic)
  1429.             fMacFontStyle += italic;
  1430.         if (fFontStyle & FW_kUnderline)
  1431.             fMacFontStyle += underline;
  1432.         if (fFontStyle & FW_kStrikeOut)
  1433.             fMacFontStyle += normal;
  1434.         if (fFontStyle & FW_kOutline)
  1435.             fMacFontStyle += outline;
  1436.         if (fFontStyle & FW_kShadow)
  1437.             fMacFontStyle += shadow;
  1438.         if (fFontStyle & FW_kExtended)
  1439.             fMacFontStyle += extend;
  1440.         if (fFontStyle & FW_kCondensed)
  1441.             fMacFontStyle += condense;
  1442.                     
  1443.         // ----- fMacFontID -----
  1444.         
  1445.         // Special case of System and Application Fonts
  1446.         if (fFontName == FW_GetSystemFontName())
  1447.             fMacFontID = 0;
  1448.         else if (fFontName == FW_GetDefaultFontName())
  1449.             fMacFontID = 1;
  1450.         else 
  1451.         {
  1452.             short fontNumber;
  1453.             Str255 pascalFontName;
  1454.             
  1455.             fFontName.ExportPascal(pascalFontName);
  1456.             ::GetFNum(pascalFontName, &fontNumber);
  1457.             fMacFontID = fontNumber;
  1458.         }
  1459.         fMacValidCache = TRUE;
  1460.     }
  1461. }
  1462.  
  1463. #endif
  1464.  
  1465. //----------------------------------------------------------------------------------------
  1466. //    FW_CPrivFontRep::IsEqual
  1467. //----------------------------------------------------------------------------------------
  1468.  
  1469. FW_Boolean FW_CPrivFontRep::IsEqual(const FW_CPrivFontRep* other) const
  1470. {
  1471.     if (other == this)
  1472.         return TRUE;
  1473.         
  1474.     return
  1475.         fFontStyle == other->fFontStyle &&
  1476.         fFontSize == other->fFontSize &&
  1477.         fFontName == other->fFontName;
  1478. }
  1479.  
  1480.