home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.7 KB | 189 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWBTxtSh.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWBTXTSH_H
- #include "FWBTxtSh.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphxshape
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CBaseTextShape, FW_CShape)
- FW_DEFINE_AUTO(FW_CBaseTextShape)
-
- //========================================================================================
- // class FW_CBaseTextShape
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::FW_CBaseTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTextShape::FW_CBaseTextShape(const FW_CBaseTextShape& other) :
- FW_CShape(other),
- fString(other.fString)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::FW_CBaseTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTextShape::FW_CBaseTextShape(const FW_CString& string,
- const FW_CInk& ink,
- const FW_CFont& font) :
- FW_CShape(FW_kFill, ink, FW_kNormalStyle, font),
- fString(string)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::FW_CBaseTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTextShape::FW_CBaseTextShape() :
- FW_CShape(FW_kFill, FW_kOr, FW_kNormalStyle, FW_kNormalFont)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::FW_CBaseTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTextShape::FW_CBaseTextShape(FW_CTextReader& textReader,
- const FW_CInk& ink,
- const FW_CFont& font) :
- FW_CShape(FW_kFill, ink, FW_kNormalStyle, font)
- {
- SetText(textReader);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::FW_CBaseTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTextShape::FW_CBaseTextShape(FW_CReadableStream& stream) :
- FW_CShape(stream)
- {
- stream >> fString;
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::~FW_CBaseTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTextShape::~FW_CBaseTextShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTextShape& FW_CBaseTextShape::operator=(const FW_CBaseTextShape& other)
- {
- if (this != &other)
- {
- FW_CShape::operator=(other);
- fString = other.fString;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CBaseTextShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CShape::Flatten(stream);
- stream << fString;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::HitTest
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CBaseTextShape::HitTest(FW_CGraphicContext& gc,
- const FW_CPoint& test,
- FW_Fixed tolerance) const
- {
- FW_CRect bounds;
- GetBounds(gc, bounds);
-
- bounds.Inset(-tolerance, -tolerance);
-
- return bounds.Contains(test);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::GetText
- //----------------------------------------------------------------------------------------
-
- void FW_CBaseTextShape::GetText(FW_CTextWriter& textWriter) const
- {
- // Write string's characters to textWriter's data structure
- FW_CStringReader stringReader(fString);
- FW_ByteCount bytesPerChar;
- FW_LChar ch;
-
- while (true)
- {
- ch = stringReader.GetCharacterAndAdvance(bytesPerChar);
- if (ch == 0)
- break; // end of text
- textWriter.PutCharacterAndAdvance(ch, bytesPerChar);
- }
-
- textWriter.FlushBuffer();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTextShape::SetText
- //----------------------------------------------------------------------------------------
-
- void FW_CBaseTextShape::SetText(FW_CTextReader& textReader)
- {
- // Get locale info
- FW_Locale locale;
- textReader.GetLocale(locale);
- fString.SetEmpty(locale); // empty the string and set its locale
-
- // Read characters from the textReader's data structure into our fString
- const char* start;
- FW_ByteCount length;
-
- do
- {
- textReader.PeekRunAhead(start, length); // get address and length of buffer
- if (length > 0)
- {
- fString.Append(start, length); // append buffer chars to string
- textReader.Advance(length); // advance to next buffer of chars, if any
- }
- }
- while (length > 0);
- }
-
-