home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 13.3 KB | 466 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWTxtShp.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWTXTSHP_H
- #include "FWTxtShp.h"
- #endif
-
- #ifndef SLRENDER_H
- #include "SLRender.h"
- #endif
-
- #ifndef FWCHARIT_H
- #include "FWCharIt.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _TRANSFORM_
- #include <Trnsform.xh>
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_BaseTextShape
- #endif
-
- //========================================================================================
- // class FW_CTextShape
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CTextShape)
- FW_DEFINE_CLASS_M1(FW_CTextShape, FW_CBaseTextShape)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::FW_CTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextShape::FW_CTextShape(const FW_CTextShape& other) :
- FW_CBaseTextShape(other),
- fPosition(other.fPosition),
- fTextAlignment(other.fTextAlignment)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::FW_CTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextShape::FW_CTextShape(const FW_CString& string,
- FW_Fixed xPos,
- FW_Fixed yPos,
- const FW_CFont& font,
- FW_TextAlignment textAlignment,
- const FW_CInk& ink) :
- FW_CBaseTextShape(string, ink, font),
- fPosition(xPos, yPos),
- fTextAlignment(textAlignment)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::FW_CTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextShape::FW_CTextShape() :
- FW_CBaseTextShape(),
- fTextAlignment(kDefaultAlignment)
- // fPosition is set to 0's by the default constructor
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::FW_CTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextShape::FW_CTextShape(FW_CTextReader& textReader,
- FW_Fixed xPos, FW_Fixed yPos,
- const FW_CFont& font,
- FW_TextAlignment textAlignment,
- const FW_CInk& ink) :
- FW_CBaseTextShape(textReader, ink, font),
- fPosition(xPos, yPos),
- fTextAlignment(textAlignment)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::FW_CTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextShape::FW_CTextShape(FW_CReadableStream& stream) :
- FW_CBaseTextShape(stream)
- {
- stream >> fPosition;
- stream >> fTextAlignment;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::~FW_CTextShape
- //----------------------------------------------------------------------------------------
-
- FW_CTextShape::~FW_CTextShape()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CTextShape& FW_CTextShape::operator=(const FW_CTextShape& other)
- {
- if (this != &other)
- {
- FW_CBaseTextShape::operator=(other);
-
- fPosition = other.fPosition;
- fTextAlignment = other.fTextAlignment;
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::Render
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::Render(FW_CGraphicContext& gc) const
- {
- FW_PrivRenderTextString(gc.GetEnvironment(),
- gc,
- fString,
- fPosition,
- fTextAlignment,
- GetRenderVerb(),
- fInk,
- fFont);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::RenderText
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::RenderText(FW_CGraphicContext& gc,
- FW_CTextReader& textReader,
- const FW_CPoint& position,
- const FW_CFont& font,
- FW_TextAlignment textAlignment,
- const FW_CInk& ink)
- {
- FW_PrivRenderTextReader(gc.GetEnvironment(),
- gc,
- textReader,
- position,
- textAlignment,
- FW_kFill,
- ink,
- font);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::RenderString
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::RenderText(FW_CGraphicContext& gc,
- const FW_CString& string,
- const FW_CPoint& position,
- const FW_CFont& font,
- FW_TextAlignment textAlignment,
- const FW_CInk& ink)
- {
- FW_PrivRenderTextString(gc.GetEnvironment(),
- gc,
- string,
- position,
- textAlignment,
- FW_kFill,
- ink,
- font);
- FW_FailOnEvError(gc.GetEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::Transform
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::Transform(Environment* ev, ODTransform* odTransform)
- {
- fPosition.Transform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::InverseTransform
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::InverseTransform(Environment* ev, ODTransform* odTransform)
- {
- fPosition.InverseTransform(ev, odTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::Inset
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::Inset(FW_Fixed x, FW_Fixed y)
- {
- FW_UNUSED(x);
- FW_UNUSED(y);
-
- // Nothing to do
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CShape* FW_CTextShape::Copy() const
- {
- return FW_NEW(FW_CTextShape, (*this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::MoveShape
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
- {
- fPosition.x += deltaX;
- fPosition.y += deltaY;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::MoveShapeTo
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
- {
- fPosition.x = x;
- fPosition.y = y;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::CalcExtent
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CTextShape::CalcExtent(FW_CGraphicContext& gc) const
- {
- FW_CPoint textExtent;
- FW_PrivCalcTextExtentString(gc.GetEnvironment(),
- gc,
- fString,
- fFont,
- textExtent);
- FW_FailOnEvError(gc.GetEnvironment());
- return textExtent;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::CalcTextExtent
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CTextShape::CalcTextExtent(FW_CGraphicContext& gc,
- FW_CTextReader& textReader,
- const FW_CFont& font)
- {
- FW_CPoint textExtent;
- FW_PrivCalcTextExtentReader(gc.GetEnvironment(),
- gc,
- textReader,
- font,
- textExtent);
- FW_FailOnEvError(gc.GetEnvironment());
- return textExtent;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::CalcTextExtent
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CTextShape::CalcTextExtent(FW_CGraphicContext& gc,
- const FW_CString& string,
- const FW_CFont& font)
- {
- FW_CPoint textExtent;
- FW_PrivCalcTextExtentString(gc.GetEnvironment(),
- gc,
- string,
- font,
- textExtent);
- FW_FailOnEvError(gc.GetEnvironment());
- return textExtent;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::GetBounds
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
- {
- FW_CPlatformRect plfmRect;
-
- FW_CPlatformPoint position = gc.LogicalToDevice(fPosition);
- FW_CPoint textExtent;
- FW_PrivCalcTextExtentString(gc.GetEnvironment(), gc, fString, fFont, textExtent);
- FW_FailOnEvError(gc.GetEnvironment());
-
- FW_CPlatformPoint plfmExtent = gc.LogicalToDevice(textExtent);
-
- switch (fTextAlignment & FW_kPrivTextAlignHorzAlignMask)
- {
- case FW_kTextAlignLeft:
- plfmRect.left = position.X();
- plfmRect.right = plfmRect.left + plfmExtent.X();
- break;
-
- case FW_kTextAlignRight:
- plfmRect.right = position.X();
- plfmRect.left = plfmRect.right - plfmExtent.X();
- break;
-
- case FW_kTextAlignHCenter:
- plfmRect.left = position.X() - (plfmExtent.X() / 2);
- plfmRect.right = plfmRect.left + plfmExtent.X();
- break;
- }
-
- FW_CFontMetrics fontMetrics;
- switch (fTextAlignment & FW_kPrivTextAlignVertAlignMask)
- {
- case FW_kTextAlignTop:
- plfmRect.top = position.Y();
- plfmRect.bottom = plfmRect.top + plfmExtent.Y();
- break;
-
- case FW_kTextAlignBottom:
- plfmRect.bottom = position.Y();
- plfmRect.top = plfmRect.bottom - plfmExtent.Y();
- break;
-
- case FW_kTextAlignVCenter:
- fFont.GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);
- plfmRect.top = position.Y() - (fontMetrics.GetFontHeight() / 2);
- plfmRect.bottom = plfmRect.top + fontMetrics.GetFontHeight();
- break;
-
- case FW_kTextAlignBaseLine:
- fFont.GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);
- plfmRect.top = position.Y() - fontMetrics.GetAscent();
- plfmRect.bottom = plfmRect.top + fontMetrics.GetFontHeight();
- break;
- }
-
- rect = gc.DeviceToLogical(plfmRect);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::GetAnchorPoint
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CTextShape::GetAnchorPoint() const
- {
- return fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::Flatten(FW_CWritableStream& stream) const
- {
- FW_CBaseTextShape::Flatten(stream);
-
- stream << fPosition;
- stream << fTextAlignment;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTextShape::GetBaseLine
- //----------------------------------------------------------------------------------------
-
- void FW_CTextShape::GetBaseLine(FW_CGraphicContext& gc,
- FW_CPoint& start, FW_CPoint& end) const
- {
- FW_CPlatformPoint pt1, pt2;
-
- FW_CPlatformPoint plfmPos = gc.LogicalToDevice(fPosition);
-
- FW_CFontMetrics fontMetrics;
- fFont.GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);
-
- switch (fTextAlignment & FW_kPrivTextAlignVertAlignMask)
- {
- case FW_kTextAlignTop:
- plfmPos.Y() += fontMetrics.GetAscent();
- break;
-
- case FW_kTextAlignBottom:
- plfmPos.Y() -= fontMetrics.GetDescent();
- break;
-
- case FW_kTextAlignVCenter:
- plfmPos.Y() += fontMetrics.GetAscent() - (fontMetrics.GetFontHeight() / 2);
- break;
-
- case FW_kTextAlignBaseLine:
- break;
- }
-
- FW_CPoint textExtent;
- FW_PrivCalcTextExtentString(gc.GetEnvironment(), gc, fString, fFont, textExtent);
- FW_FailOnEvError(gc.GetEnvironment());
-
- FW_CPlatformPoint plfmExtent = gc.LogicalToDevice(textExtent);
-
- switch (fTextAlignment & FW_kPrivTextAlignHorzAlignMask)
- {
- case FW_kTextAlignLeft:
- pt1 = plfmPos;
- pt2.Set(pt1.X() + plfmExtent.X(), pt1.Y());
- break;
-
- case FW_kTextAlignRight:
- pt2 = plfmPos;
- pt1.Set(pt2.X() - plfmExtent.X(), pt2.Y());
- break;
-
- case FW_kTextAlignHCenter:
- pt1.Set(plfmPos.X() - (plfmExtent.X() / 2), plfmPos.Y());
- pt2.Set(pt1.X() + plfmExtent.X(), plfmPos.Y());
- break;
- }
-
- start = gc.DeviceToLogical(pt1);
- end = gc.DeviceToLogical(pt2);
- }
-
-