home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWTxtBox.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  10.7 KB  |  353 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTxtBox.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWTXTBOX_H
  13. #include "FWTxtBox.h"
  14. #endif
  15.  
  16. #ifndef FWTXTBUF_H
  17. #include "FWTxtBuf.h"
  18. #endif
  19.  
  20. #ifndef FWRASTER_H
  21. #include "FWRaster.h"
  22. #endif
  23.  
  24. // ----- Foundation Includes -----
  25.  
  26. #ifndef FWSTREAM_H
  27. #include "FWStream.h"
  28. #endif
  29.  
  30. // ----- OpenDoc Includes -----
  31.  
  32. #ifndef _TRANSFORM_
  33. #include <Trnsform.xh>
  34. #endif
  35.  
  36. //========================================================================================
  37. //    RunTime Info
  38. //========================================================================================
  39.  
  40. #if FW_LIB_EXPORT_PRAGMAS
  41. #pragma lib_export on
  42. #endif
  43.  
  44. #ifdef FW_BUILD_MAC
  45. #pragma segment FWGraphics_TextBoxShape
  46. #endif
  47.  
  48. FW_DEFINE_CLASS_M1(FW_CTextBoxShape, FW_CBaseTextShape)
  49.  
  50. FW_REGISTER_ARCHIVABLE_CLASS(FW_LTextBoxShape, FW_CTextBoxShape, FW_CTextBoxShape::Read, FW_CShape::Write)
  51.  
  52. //========================================================================================
  53. //    class FW_CTextBoxShape
  54. //========================================================================================
  55.  
  56. //----------------------------------------------------------------------------------------
  57. //    FW_CTextBoxShape::FW_CTextBoxShape
  58. //----------------------------------------------------------------------------------------
  59.  
  60. FW_CTextBoxShape::FW_CTextBoxShape(const FW_CTextBoxShape& other) :
  61.     FW_CBaseTextShape(other),
  62.     fTextBox(other.fTextBox),
  63.     fOptions(other.fOptions)
  64. {
  65.     FW_END_CONSTRUCTOR
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. //    FW_CTextBoxShape::FW_CTextBoxShape
  70. //----------------------------------------------------------------------------------------
  71.  
  72. FW_CTextBoxShape::FW_CTextBoxShape() :
  73.     FW_CBaseTextShape(),
  74.     fOptions(kDefaultJustification)
  75.         // fTextBox is set to 0's to its default constructor
  76. {
  77.     FW_END_CONSTRUCTOR
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    FW_CTextBoxShape::FW_CTextBoxShape
  82. //----------------------------------------------------------------------------------------
  83.  
  84. FW_CTextBoxShape::FW_CTextBoxShape(const FW_CString& string, 
  85.                                    const FW_CRect& box,
  86.                                    const FW_PFont& font,
  87.                                    FW_TextBoxOptions options,
  88.                                    const FW_PInk& ink) :
  89.     FW_CBaseTextShape(string, ink, font),
  90.     fOptions(options),
  91.     fTextBox(box)
  92. {
  93.     FW_END_CONSTRUCTOR
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    FW_CTextBoxShape::FW_CTextBoxShape
  98. //----------------------------------------------------------------------------------------
  99.  
  100. FW_CTextBoxShape::FW_CTextBoxShape(FW_CTextReader* textReader, 
  101.                                   const FW_CRect& box,
  102.                                    const FW_PFont& font,
  103.                                    FW_TextBoxOptions options,
  104.                                    const FW_PInk& ink) :
  105.     FW_CBaseTextShape(textReader, ink, font),
  106.     fOptions(options),
  107.     fTextBox(box)
  108. {
  109.     FW_END_CONSTRUCTOR
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    FW_CTextBoxShape::FW_CTextBoxShape
  114. //----------------------------------------------------------------------------------------
  115.  
  116. FW_CTextBoxShape::FW_CTextBoxShape(FW_CReadableStream& archive) :
  117.     FW_CBaseTextShape(archive)
  118. {
  119.     archive >> fTextBox;
  120.     archive >> fOptions;
  121.  
  122.     FW_END_CONSTRUCTOR
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    FW_CTextBoxShape::~FW_CTextBoxShape
  127. //----------------------------------------------------------------------------------------
  128.  
  129. FW_CTextBoxShape::~FW_CTextBoxShape()
  130. {
  131.     FW_START_DESTRUCTOR
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. //    FW_CTextBoxShape::operator=
  136. //----------------------------------------------------------------------------------------
  137.  
  138. FW_CTextBoxShape& FW_CTextBoxShape::operator=(const FW_CTextBoxShape& other)
  139. {
  140.     if (this != &other)
  141.     {
  142.         FW_CBaseTextShape::operator=(other);
  143.         
  144.         fTextBox = other.fTextBox;
  145.         fOptions = other.fOptions;
  146.     }
  147.     
  148.     return *this;
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    FW_CTextBoxShape::Render
  153. //----------------------------------------------------------------------------------------
  154.  
  155. void FW_CTextBoxShape::Render(FW_CGraphicContext& gc) const
  156. {    
  157.     FW_CPrivTextBuffer textBuffer(&fString);
  158.     gc.GetRasterizer()->RenderTextBox(gc,
  159.                                         &textBuffer,
  160.                                         fTextBox,
  161.                                         fOptions,
  162.                                         GetRenderVerb(),
  163.                                         fInk,
  164.                                         fFont);
  165. }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. //    FW_CTextBoxShape::RenderTextBox
  169. //----------------------------------------------------------------------------------------
  170.  
  171. FW_CFixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc, 
  172.                                               FW_CTextReader *textReader, 
  173.                                             const FW_CRect& box,
  174.                                               const FW_PFont& font,
  175.                                             FW_TextBoxOptions options,
  176.                                               const FW_PInk& ink)
  177. {    
  178.     FW_CPrivTextBuffer textBuffer(textReader);
  179.     return gc.GetRasterizer()->RenderTextBox(gc,
  180.                                             &textBuffer,
  181.                                             box,
  182.                                             options,
  183.                                             FW_kFill,
  184.                                             ink,
  185.                                             font);
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_CTextBoxShape::RenderTextBox
  190. //----------------------------------------------------------------------------------------
  191.  
  192. FW_CFixed FW_CTextBoxShape::RenderTextBox(FW_CGraphicContext& gc, 
  193.                                                   const FW_CString& string, 
  194.                                                 const FW_CRect& box,
  195.                                                   const FW_PFont& font,
  196.                                                 FW_TextBoxOptions options,
  197.                                                   const FW_PInk& ink)
  198. {    
  199.     FW_CPrivTextBuffer textBuffer(&string);
  200.     return gc.GetRasterizer()->RenderTextBox(gc,
  201.                                                 &textBuffer,
  202.                                                 box,
  203.                                                 options,
  204.                                                 FW_kFill,
  205.                                                 ink,
  206.                                                 font);
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    FW_CTextBoxShape::UpdateTextBox
  211. //----------------------------------------------------------------------------------------
  212.  
  213. void FW_CTextBoxShape::UpdateTextBox(FW_CGraphicContext& gc)
  214. {
  215.     FW_CPrivTextBuffer textBuffer(&fString);
  216.     gc.GetRasterizer()->TextBoxSize(gc,
  217.                                     &textBuffer, 
  218.                                     fFont, 
  219.                                     fOptions, 
  220.                                     fTextBox);    
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    FW_CTextBoxShape::CalcTextBox
  225. //----------------------------------------------------------------------------------------
  226.  
  227. void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc, 
  228.                                       FW_CTextReader* textReader, 
  229.                                     FW_TextBoxOptions options,
  230.                                       const FW_PFont& font,
  231.                                     FW_CRect& box)
  232. {
  233.     FW_ByteCount savedPosition = textReader->GetPosition();
  234.     FW_CPrivTextBuffer textBuffer(textReader);
  235.     gc.GetRasterizer()->TextBoxSize(gc,
  236.                                     &textBuffer, 
  237.                                     font, 
  238.                                     options, 
  239.                                     box);    
  240.     textReader->SetPosition(savedPosition);        // restore original textReader position
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. //    FW_CTextBoxShape::CalcTextBox
  245. //----------------------------------------------------------------------------------------
  246.  
  247. void FW_CTextBoxShape::CalcTextBox(FW_CGraphicContext& gc, 
  248.                                       const FW_CString& string, 
  249.                                     FW_TextBoxOptions options,
  250.                                       const FW_PFont& font,
  251.                                     FW_CRect& box)
  252. {
  253.     FW_CPrivTextBuffer textBuffer(&string);
  254.     gc.GetRasterizer()->TextBoxSize(gc,
  255.                                     &textBuffer, 
  256.                                     font, 
  257.                                     options, 
  258.                                     box);    
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    FW_CTextBoxShape::Transform
  263. //----------------------------------------------------------------------------------------
  264.  
  265. void FW_CTextBoxShape::Transform(Environment* ev, ODTransform* odTransform)
  266. {
  267.     fTextBox.Transform(ev, odTransform);
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    FW_CTextBoxShape::InverseTransform
  272. //----------------------------------------------------------------------------------------
  273.  
  274. void FW_CTextBoxShape::InverseTransform(Environment* ev, ODTransform* odTransform)
  275. {
  276.     fTextBox.InverseTransform(ev, odTransform);
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. //    FW_CTextBoxShape::Inset
  281. //----------------------------------------------------------------------------------------
  282.  
  283. void FW_CTextBoxShape::Inset(FW_CFixed x, FW_CFixed y)
  284. {
  285.     fTextBox.Inset(x, y);
  286. }
  287.  
  288. //----------------------------------------------------------------------------------------
  289. //    FW_CTextBoxShape::Copy
  290. //----------------------------------------------------------------------------------------
  291.  
  292. FW_CShape* FW_CTextBoxShape::Copy() const
  293. {
  294.     return FW_NEW(FW_CTextBoxShape, (*this));
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. //    FW_CTextBoxShape::MoveShape
  299. //----------------------------------------------------------------------------------------
  300.  
  301. void FW_CTextBoxShape::MoveShape(FW_CFixed deltaX, FW_CFixed deltaY)
  302. {
  303.     fTextBox.left += deltaX;
  304.     fTextBox.top += deltaY;
  305.     fTextBox.right += deltaX;
  306.     fTextBox.bottom += deltaY;
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. //    FW_CTextBoxShape::MoveShapeTo
  311. //----------------------------------------------------------------------------------------
  312.  
  313. void FW_CTextBoxShape::MoveShapeTo(FW_CFixed x, FW_CFixed y)
  314. {
  315.     fTextBox.right += x - fTextBox.left;
  316.     fTextBox.bottom += y - fTextBox.top;
  317.     fTextBox.left = x;
  318.     fTextBox.top = y;
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    FW_CTextBoxShape::GetBounds
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void FW_CTextBoxShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  326. {
  327. FW_UNUSED(gc);
  328.  
  329.     rect = fTextBox;
  330. }
  331.  
  332. //----------------------------------------------------------------------------------------
  333. //    FW_CTextBoxShape::Flatten
  334. //----------------------------------------------------------------------------------------
  335.  
  336. void FW_CTextBoxShape::Flatten(FW_CWritableStream& archive) const
  337. {
  338.     FW_CBaseTextShape::Flatten(archive);
  339.     
  340.     archive << fTextBox;
  341.     archive << fOptions;
  342. }
  343.  
  344. //----------------------------------------------------------------------------------------
  345. //    FW_CTextBoxShape::Read
  346. //----------------------------------------------------------------------------------------
  347.  
  348. void* FW_CTextBoxShape::Read(FW_CReadableStream& archive)
  349. {
  350.     return FW_NEW(FW_CTextBoxShape, (archive));
  351. }
  352.  
  353.