home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 11.8 KB | 443 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWStyle.cpp
- // Release Version: $ 1.0d1 $
- //
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSTYLE_H
- #include "FWStyle.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
- #include <TextUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__FONTS__)
- #include <Fonts.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(mathRoutinesIncludes)
- #include <math routines.h>
- #endif
-
- //==============================================================================
- // •• RunTime Info
- //==============================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphx
- #endif
-
- //==============================================================================
- // •• class FW_CStyle
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // FW_CStyle::FW_CStyle
- //------------------------------------------------------------------------------
-
- FW_CStyle::FW_CStyle() :
- FW_CGraphicObjectPtr()
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CStyle::FW_CStyle
- //------------------------------------------------------------------------------
-
- FW_CStyle::FW_CStyle(XMPCoordinate penSize, const FW_CPattern& pattern) :
- FW_CGraphicObjectPtr()
- {
- SetRep(new FW_CStyleRep(penSize, pattern));
- }
-
- //------------------------------------------------------------------------------
- // FW_CStyle::FW_CStyle
- //------------------------------------------------------------------------------
-
- FW_CStyle::FW_CStyle(const FW_CDynamicString& fontName, FW_FontStyle fontStyle, XMPCoordinate fontSize) :
- FW_CGraphicObjectPtr()
- {
- SetRep(new FW_CStyleRep(fontName, fontStyle, fontSize));
- }
-
- //------------------------------------------------------------------------------
- // FW_CStyle::FW_CStyle
- //------------------------------------------------------------------------------
-
- FW_CStyle::FW_CStyle(XMPCoordinate penSize,
- const FW_CPattern& pattern,
- const FW_CDynamicString& fontName,
- FW_FontStyle fontStyle,
- XMPCoordinate fontSize) :
- FW_CGraphicObjectPtr()
- {
- SetRep(new FW_CStyleRep(penSize, pattern, fontName, fontStyle, fontSize));
- }
-
- //------------------------------------------------------------------------------
- // FW_CStyle::FW_CStyle
- //------------------------------------------------------------------------------
-
- FW_CStyle::FW_CStyle(const FW_CStyle& other) :
- FW_CGraphicObjectPtr(other)
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CStyle::FW_CStyle
- //------------------------------------------------------------------------------
-
- FW_CStyle::FW_CStyle(FW_CStyleRep* rep) :
- FW_CGraphicObjectPtr(rep)
- {
- }
-
- //------------------------------------------------------------------------------
- // FW_CStyle::operator=
- //------------------------------------------------------------------------------
-
- FW_CStyle& FW_CStyle::operator=(const FW_CStyle& other)
- {
- SetRep(other.GetRep());
- return *this;
- }
-
- //==============================================================================
- // •• class FW_CStyleRep
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::FW_CStyleRep
- //------------------------------------------------------------------------------
-
- FW_CStyleRep::FW_CStyleRep() :
- fPenSize(ff(1)),
- fPattern(FW_kBlackPat),
- fFontName(""),
- fFontStyle(FW_kPlain),
- fFontSize(ff(12)),
- #ifdef FW_BUILD_MAC
- fMacTextFont(applFont),
- fMacTextFace(normal),
- fMacCacheValid(TRUE)
- #endif
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::FW_CStyleRep
- //------------------------------------------------------------------------------
-
- FW_CStyleRep::FW_CStyleRep(XMPCoordinate penSize, const FW_CPattern& pattern) :
- fPenSize(penSize),
- fPattern(pattern),
- fFontName(""),
- fFontStyle(FW_kPlain),
- fFontSize(ff(12)),
- #ifdef FW_BUILD_MAC
- fMacTextFont(applFont),
- fMacTextFace(normal),
- fMacCacheValid(TRUE)
- #endif
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::FW_CStyleRep
- //------------------------------------------------------------------------------
-
- FW_CStyleRep::FW_CStyleRep(const FW_CDynamicString& fontName, FW_FontStyle fontStyle, XMPCoordinate fontSize) :
- fPenSize(ff(1)),
- fPattern(FW_kBlackPat),
- fFontName(fontName),
- fFontStyle(FW_kPlain),
- fFontSize(ff(12)),
- #ifdef FW_BUILD_MAC
- fMacTextFont(applFont),
- fMacTextFace(normal),
- fMacCacheValid(FALSE)
- #endif
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::FW_CStyleRep
- //------------------------------------------------------------------------------
-
- FW_CStyleRep::FW_CStyleRep(XMPCoordinate penSize,
- const FW_CPattern& pattern,
- const FW_CDynamicString& fontName,
- FW_FontStyle fontStyle,
- XMPCoordinate fontSize) :
- fPenSize(penSize),
- fPattern(pattern),
- fFontName(fontName),
- fFontStyle(fontStyle),
- fFontSize(fontSize),
- #ifdef FW_BUILD_MAC
- fMacTextFont(applFont),
- fMacTextFace(normal),
- fMacCacheValid(FALSE)
- #endif
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::~FW_CStyleRep
- //------------------------------------------------------------------------------
-
- FW_CStyleRep::~FW_CStyleRep()
- {
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::AsPlatformSize
- //------------------------------------------------------------------------------
-
- FW_SPlatformPoint FW_CStyleRep::AsPlatformSize(FW_CGraphicContext* graphicContext, XMPCoordinate aSize)
- {
- FW_CPoint s(aSize, aSize);
- FW_SPlatformPoint qdSize = graphicContext->AsPlatformPoint(s);
- return qdSize;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::SelectInGC
- //------------------------------------------------------------------------------
-
- void FW_CStyleRep::SelectInGC(FW_CGraphicContext* gc, FW_ShapeCategory shapeCategory)
- {
- #ifdef FW_BUILD_MAC
- if (shapeCategory == FW_kGeometricShape)
- {
- FW_SPlatformPoint penSize = AsPlatformSize(gc, fPenSize);
- ::PenSize(penSize.h, penSize.v);
- ::PenPat(fPattern);
- }
- else if (shapeCategory == FW_kTypographicShape)
- {
- CheckMacCache();
- ::TextFont(fMacTextFont);
- ::TextFace(fMacTextFace);
- ::TextSize(FixedToInt(fFontSize));
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CStyleRep::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CStyle FW_CStyleRep::Copy() const
- {
- FW_CStyle style(fPenSize, fPattern, fFontName, fFontStyle, fFontSize);
- return style;
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::SetPenSize
- //------------------------------------------------------------------------------
-
- void FW_CStyleRep::SetPenSize(XMPCoordinate penSize)
- {
- fPenSize = penSize;
- Changed();
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::SetPattern
- //------------------------------------------------------------------------------
-
- void FW_CStyleRep::SetPattern(const FW_CPattern& pattern)
- {
- fPattern = pattern;
- Changed();
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::SetFontName
- //------------------------------------------------------------------------------
-
- void FW_CStyleRep::SetFontName(const FW_CDynamicString& fontName)
- {
- fFontName = fontName;
-
- #ifdef FW_BUILD_MAC
- fMacCacheValid = FALSE;
- #endif
-
- Changed();
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::SetFontStyle
- //------------------------------------------------------------------------------
-
- void FW_CStyleRep::SetFontStyle(FW_FontStyle fontStyle)
- {
- fFontStyle = fontStyle;
-
- #ifdef FW_BUILD_MAC
- fMacCacheValid = FALSE;
- #endif
-
- Changed();
- }
-
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::SetFontSize
- //------------------------------------------------------------------------------
-
- void FW_CStyleRep::SetFontSize(XMPCoordinate fontSize)
- {
- fFontSize = fontSize;
- Changed();
- }
-
- #ifdef FW_BUILD_MAC
- //------------------------------------------------------------------------------
- // • FW_CStyleRep::GetMacFontInfo
- //------------------------------------------------------------------------------
-
- void FW_CStyleRep::GetMacFontInfo(short& textFont,
- Style& textFace,
- XMPCoordinate& textSize) const
- {
- textFont = fMacTextFont;
- textFace = fMacTextFace;
- textSize = fFontSize;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // • FW_CStyleRep::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CStyleRep::Flatten(FW_CWritableStream& stream)
- {
- stream.Write(&fPenSize, sizeof(fPenSize));
- fPattern.Flatten(stream);
- FW_ByteCount count = fFontName.GetByteLength();
- stream << count;
- if (count != 0)
- stream.Write(fFontName, count);
- stream.Write((char*)&fFontStyle, sizeof(fFontStyle));
- stream << fFontSize;
- }
-
- //----------------------------------------------------------------------------------------
- // • FW_CStyleRep::Unflatten
- //----------------------------------------------------------------------------------------
-
- void FW_CStyleRep::Unflatten(FW_CReadableStream& stream)
- {
- stream.Read(&fPenSize, sizeof(fPenSize));
- fPattern.Unflatten(stream);
-
- FW_ByteCount count;
- stream >> count;
-
- if (count != 0)
- {
- char temp[256];
- stream.Read(temp, count);
- fFontName.ReplaceAll(temp);
- }
- else
- {
- fFontName = "";
- }
-
- stream.Read((char*)&fFontStyle, sizeof(fFontStyle));
- stream >> fFontSize;
-
- #ifdef FW_BUILD_MAC
- fMacCacheValid = FALSE;
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // • FW_CStyleRep::CheckMacCache
- //----------------------------------------------------------------------------------------
-
- void FW_CStyleRep::CheckMacCache()
- {
- if (!fMacCacheValid)
- {
- // ----- fMacTextFace -----
- switch (fFontStyle)
- {
- case FW_kPlain:
- fMacTextFace = normal;
- break;
- case FW_kBold:
- fMacTextFace = bold;
- break;
- case FW_kItalic:
- fMacTextFace = italic;
- break;
- case FW_kUnderline:
- fMacTextFace = underline;
- break;
- case FW_kStrikeThrough:
- fMacTextFace = normal;
- break;
- case FW_kOutline:
- fMacTextFace = outline;
- break;
- case FW_kShadow:
- fMacTextFace = shadow;
- break;
- case FW_kExtended:
- fMacTextFace = extend;
- break;
- case FW_kCondensed:
- fMacTextFace = condense;
- break;
- };
-
- // ----- fMacTextFont -----
- short fontNumber;
- Str255 pascalFontName;
-
- fFontName.ExportPascal(pascalFontName);
- ::GetFNum(pascalFontName, &fontNumber);
-
- if (fontNumber == systemFont)
- {
- // fontNum is set to sysFont if fontName is not found.
- // We must check for the special case where the system
- // font is indeed being retrieved, by comparing the
- // name of the font with that of the system font.
- Str255 sysFontName;
- ::GetFontName(systemFont, sysFontName);
- if (!::EqualString(pascalFontName, sysFontName, FALSE, FALSE))
- {
- // // font was not found
- // BR_THROW(BR_XFontNameNotFound(fFaceName));
- }
- }
- fMacTextFont = fontNumber;
-
- fMacCacheValid = TRUE;
- }
- }
-
- #endif