// $Revision: 1.3 $ // Copyright (c) 1995 Taligent, Inc. All rights reserved. #ifndef TaligentSamples_SAMPLEPAGENUMBERCOMPOSITOR #include "SamplePageNumberCompositor.h" #endif #ifndef Taligent_ASSERTIONS #include #endif #ifndef Taligent_STANDARDTEXT #include #endif #ifndef Taligent_TEXTDISPLAY #include #endif #ifndef Taligent_NUMBERFORMAT #include #endif MCollectibleDefinitionsMacro(TSamplePageNumberCompositor, kOriginalVersion); TSamplePageNumberCompositor::TSamplePageNumberCompositor( TPageIterator* sourceAlias, ENumberLocation numberLocation) : fSourcePages(sourceAlias), fNumberLocation(numberLocation) { } TSamplePageNumberCompositor::~TSamplePageNumberCompositor() { } unsigned long TSamplePageNumberCompositor::Count() const { Assertion(fSourcePages != NIL); return fSourcePages->Count(); } TPage* TSamplePageNumberCompositor::Seek(unsigned long pageNumber) { Assertion(fSourcePages != NIL); return fSourcePages->Seek(pageNumber) ? (TPage*)this : NIL; } TPage* TSamplePageNumberCompositor::Current() const { Assertion(fSourcePages != NIL); return fSourcePages->Current() ? (TPage*)this : NIL; } unsigned long TSamplePageNumberCompositor::GetPageNumber() const { Assertion(fSourcePages != NIL); TPage* page = fSourcePages->Current(); Assertion(page != NIL); return page->GetPageNumber(); } TPageDescription* TSamplePageNumberCompositor::GetPageDescription() const { Assertion(fSourcePages != NIL); TPage* page = fSourcePages->Current(); Assertion(page != NIL); return page->GetPageDescription(); } void TSamplePageNumberCompositor::Draw(TGrafPort& port) const { Assertion(fSourcePages != NIL); TPage* page = fSourcePages->Current(); page->Draw(port); unsigned long pageNumber = page->GetPageNumber(); TStandardText pageNumberText; TUniversalNumberFormatter formatter; formatter.Format(TFormattableNumber(pageNumber), pageNumberText); TTextDisplay pageNumberDisplay(pageNumberText); TGRect pageNumberBounds = pageNumberDisplay.GetTextBounds(); TPageDescription* pageDescription = page->GetPageDescription(); TGRect printableBounds = pageDescription->GetPrintableRect(); TGPoint offset = TGPoint::kOrigin; switch (fNumberLocation) { case kTopLeft: case kTopCenter: case kTopRight: offset.fY = printableBounds.fTop - pageNumberBounds.fTop; break; case kBottomLeft: case kBottomCenter: case kBottomRight: offset.fY = printableBounds.fBottom - pageNumberBounds.fBottom; break; default: break; } switch (fNumberLocation) { case kTopLeft: case kBottomLeft: offset.fX = printableBounds.fLeft - pageNumberBounds.fLeft; break; case kTopCenter: case kBottomCenter: offset.fX = (printableBounds.fLeft + printableBounds.fRight - pageNumberBounds.fLeft - pageNumberBounds.fRight) / 2.0; break; case kTopRight: case kBottomRight: offset.fX = printableBounds.fRight - pageNumberBounds.fRight; break; default: break; } pageNumberDisplay.SetOrigin(offset); pageNumberDisplay.Draw(port); } TSamplePageNumberCompositor::TSamplePageNumberCompositor() : fSourcePages(NIL), fNumberLocation(kTopLeft) { } TSamplePageNumberCompositor::TSamplePageNumberCompositor(const TSamplePageNumberCompositor& source) : fSourcePages(NIL), fNumberLocation(kTopLeft) { } TSamplePageNumberCompositor& TSamplePageNumberCompositor::operator=(const TSamplePageNumberCompositor& source) { return *this; }