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

  1. //========================================================================================
  2. //
  3. //    File:                FWBTxtSh.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 FWBTXTSH_H
  13. #include "FWBTxtSh.h"
  14. #endif
  15.  
  16. //========================================================================================
  17. //    RunTime Info
  18. //========================================================================================
  19.  
  20. #ifdef FW_BUILD_MAC
  21. #pragma segment fwgraphxshape
  22. #endif
  23.  
  24. FW_DEFINE_CLASS_M1(FW_CBaseTextShape, FW_CShape)
  25. FW_DEFINE_AUTO(FW_CBaseTextShape)
  26.  
  27. //========================================================================================
  28. //    class FW_CBaseTextShape
  29. //========================================================================================
  30.  
  31. //----------------------------------------------------------------------------------------
  32. //    FW_CBaseTextShape::FW_CBaseTextShape
  33. //----------------------------------------------------------------------------------------
  34.  
  35. FW_CBaseTextShape::FW_CBaseTextShape(const FW_CBaseTextShape& other) :
  36.     FW_CShape(other),
  37.     fString(other.fString)
  38. {
  39.     FW_END_CONSTRUCTOR
  40. }
  41.  
  42. //----------------------------------------------------------------------------------------
  43. //    FW_CBaseTextShape::FW_CBaseTextShape
  44. //----------------------------------------------------------------------------------------
  45.  
  46. FW_CBaseTextShape::FW_CBaseTextShape(const FW_CString& string,
  47.                                        const FW_CInk& ink,
  48.                                      const FW_CFont& font) :
  49.     FW_CShape(FW_kFill, ink, FW_kNormalStyle, font),
  50.     fString(string)
  51. {    
  52.     FW_END_CONSTRUCTOR
  53. }
  54.  
  55. //----------------------------------------------------------------------------------------
  56. //    FW_CBaseTextShape::FW_CBaseTextShape
  57. //----------------------------------------------------------------------------------------
  58.  
  59. FW_CBaseTextShape::FW_CBaseTextShape() :
  60.     FW_CShape(FW_kFill, FW_kOr, FW_kNormalStyle, FW_kNormalFont)
  61. {            
  62.     FW_END_CONSTRUCTOR
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    FW_CBaseTextShape::FW_CBaseTextShape
  67. //----------------------------------------------------------------------------------------
  68.  
  69. FW_CBaseTextShape::FW_CBaseTextShape(FW_CTextReader& textReader,
  70.                                        const FW_CInk& ink,
  71.                                      const FW_CFont& font) :
  72.     FW_CShape(FW_kFill, ink, FW_kNormalStyle, font)
  73. {    
  74.     SetText(textReader);
  75.     
  76.     FW_END_CONSTRUCTOR
  77. }
  78.  
  79. //----------------------------------------------------------------------------------------
  80. //    FW_CBaseTextShape::FW_CBaseTextShape
  81. //----------------------------------------------------------------------------------------
  82.  
  83. FW_CBaseTextShape::FW_CBaseTextShape(FW_CReadableStream& stream) :
  84.     FW_CShape(stream)
  85. {
  86.     stream >> fString;
  87.     FW_END_CONSTRUCTOR
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_CBaseTextShape::~FW_CBaseTextShape
  92. //----------------------------------------------------------------------------------------
  93.  
  94. FW_CBaseTextShape::~FW_CBaseTextShape()
  95. {
  96.     FW_START_DESTRUCTOR
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    FW_CBaseTextShape::operator=
  101. //----------------------------------------------------------------------------------------
  102.  
  103. FW_CBaseTextShape& FW_CBaseTextShape::operator=(const FW_CBaseTextShape& other)
  104. {
  105.     if (this != &other)
  106.     {
  107.         FW_CShape::operator=(other);
  108.         fString = other.fString;
  109.     }
  110.     
  111.     return *this;
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_CBaseTextShape::Flatten
  116. //----------------------------------------------------------------------------------------
  117.  
  118. void FW_CBaseTextShape::Flatten(FW_CWritableStream& stream) const
  119. {
  120.     FW_CShape::Flatten(stream);
  121.     stream << fString;
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. //    FW_CBaseTextShape::HitTest
  126. //----------------------------------------------------------------------------------------
  127.  
  128. FW_Boolean FW_CBaseTextShape::HitTest(FW_CGraphicContext& gc,
  129.                                       const FW_CPoint& test,
  130.                                       FW_Fixed tolerance) const
  131. {
  132.     FW_CRect bounds;
  133.     GetBounds(gc, bounds);
  134.     
  135.     bounds.Inset(-tolerance, -tolerance);
  136.  
  137.     return bounds.Contains(test);
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CBaseTextShape::GetText
  142. //----------------------------------------------------------------------------------------
  143.  
  144. void FW_CBaseTextShape::GetText(FW_CTextWriter& textWriter) const
  145. {
  146.     // Write string's characters to textWriter's data structure
  147.     FW_CStringReader stringReader(fString);
  148.     FW_ByteCount bytesPerChar;
  149.     FW_LChar ch;
  150.  
  151.     while (true)
  152.     {
  153.         ch = stringReader.GetCharacterAndAdvance(bytesPerChar);
  154.         if (ch == 0)
  155.             break;        // end of text
  156.         textWriter.PutCharacterAndAdvance(ch, bytesPerChar);
  157.     }
  158.  
  159.     textWriter.FlushBuffer();
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CBaseTextShape::SetText
  164. //----------------------------------------------------------------------------------------
  165.  
  166. void FW_CBaseTextShape::SetText(FW_CTextReader& textReader)
  167. {
  168.     // Get locale info
  169.     FW_Locale locale;
  170.     textReader.GetLocale(locale);
  171.     fString.SetEmpty(locale);                                // empty the string and set its locale
  172.  
  173.     // Read characters from the textReader's data structure into our fString
  174.     const char* start;
  175.     FW_ByteCount length;
  176.  
  177.     do
  178.     {
  179.         textReader.PeekRunAhead(start, length);                // get address and length of buffer
  180.         if (length > 0)
  181.         {
  182.             fString.Append(start, length);                    // append buffer chars to string
  183.             textReader.Advance(length);                        // advance to next buffer of chars, if any
  184.         }
  185.     }
  186.     while (length > 0);
  187. }
  188.  
  189.