home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks96
/
FontMancer.sit
/
FontMancer
/
Common
/
FontDisplay.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-21
|
5KB
|
197 lines
#include "FontMancer.h"
#include "FontDisplay.h"
#include "StandardMenu.h"
extern WindowPtr gMainWindow;
extern Str255 gSamplePhrase;
void UpdateMisc(WindowPtr theWindow)
{
FMStuff *FMStore;
Str255 updateText;
FMStore = (FMStuff *) GetWRefCon(theWindow);
if (RectInRgn(&(FMStore->itemRects[iTextRect1]),theWindow->visRgn)) {
MoveTo(FMStore->itemRects[iTextRect1].left,FMStore->itemRects[iTextRect1].bottom);
GetIndString(updateText,rDisplayStrings,1);
DrawString(updateText);
}
if (RectInRgn(&(FMStore->itemRects[iTextRect2]),theWindow->visRgn)) {
MoveTo(FMStore->itemRects[iTextRect2].left,FMStore->itemRects[iTextRect2].bottom);
GetIndString(updateText,rDisplayStrings,2);
DrawString(updateText);
}
if (RectInRgn(&(FMStore->itemRects[iMenuNameRect]),theWindow->visRgn)) {
MoveTo(FMStore->itemRects[iMenuNameRect].left,FMStore->itemRects[iMenuNameRect].bottom);
GetIndString(updateText,rDisplayStrings,3);
DrawString(updateText);
}
if (RectInRgn(&(FMStore->itemRects[iLineRect]),theWindow->visRgn))
FrameRect(&(FMStore->itemRects[iLineRect]));
if (RectInRgn(&(FMStore->itemRects[iSampleRect]),theWindow->visRgn)) {
FrameRect(&(FMStore->itemRects[iSampleRect]));
UpdateSampleRect(FMStore);
}
}
void UpdateSampleRect(FMStuff *FMStore)
{
Rect sampleRect;
RgnHandle oldClipRgn,clipRgn;
FontInfo fInfo;
Fixed textWidth;
short lineDots, textVertical;
long textOffset,textStart, textLength, textEnd;
StyledLineBreakCode breakCode;
Ptr textPtr;
const short sizeMenu[7] = {9,10,12,14,18,24,36};
TextFont(FMStore->fontDisplayed);
TextFace(FMStore->fontStyle);
TextSize(sizeMenu[FMStore->fontSize]);
SetRect(&sampleRect,FMStore->itemRects[iSampleRect].left,FMStore->itemRects[iSampleRect].top,
FMStore->itemRects[iSampleRect].right,FMStore->itemRects[iSampleRect].bottom);
InsetRect(&sampleRect,4,4);
EraseRect(&sampleRect);
GetFontInfo(&fInfo);
lineDots = fInfo.ascent + fInfo.descent + fInfo.leading;
textVertical = sampleRect.top + fInfo.ascent;
MoveTo(sampleRect.left, textVertical);
clipRgn = NewRgn();
oldClipRgn = NewRgn();
RectRgn(clipRgn,&sampleRect);
GetClip(oldClipRgn);
SetClip(clipRgn);
textPtr = (Ptr) &gSamplePhrase[1];
textOffset = 1;
textStart = 0;
textLength = textEnd = gSamplePhrase[0];
textWidth = sampleRect.right - sampleRect.left;
textWidth <<= 16;
do {
breakCode = StyledLineBreak(textPtr,textEnd, textStart,
textEnd,0,&textWidth, &textOffset);
textLength = textOffset - textStart;
DrawText(&gSamplePhrase[1],textStart,textLength);
textStart += textLength;
textOffset = 1;
textVertical += lineDots;
MoveTo(sampleRect.left, textVertical);
textWidth = sampleRect.right - sampleRect.left;
textWidth <<= 16;
} while ((breakCode != smBreakOverflow) && (textVertical < sampleRect.bottom));
SetClip(oldClipRgn);
DisposeRgn(clipRgn);
DisposeRgn(oldClipRgn);
TextFont(systemFont);
TextFace(0);
TextSize(0);
}
void SetStyleDisplay(short iMenuItem, short iButton, Style fontStyle)
{
FMStuff *FMStore;
Style styleCheck;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
styleCheck = (FMStore->fontStyle & fontStyle);
FMStore->fontStyle ^= fontStyle;
if (FMStore->fontStyle) {
SetControlValue(FMStore->ctlHandles[iPlainButton],0);
ToggleMenu(FALSE,iPlain,mStyle);
}
else {
SetControlValue(FMStore->ctlHandles[iPlainButton],1);
ToggleMenu(TRUE,iPlain,mStyle);
}
if (styleCheck == fontStyle) {
SetControlValue(FMStore->ctlHandles[iButton],0);
ToggleMenu(FALSE,iMenuItem,mStyle);
}
else {
SetControlValue(FMStore->ctlHandles[iButton],1);
ToggleMenu(TRUE,iMenuItem,mStyle);
}
UpdateSampleRect(FMStore);
}
void SetPlainDisplay()
{
FMStuff *FMStore;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
SetControlValue(FMStore->ctlHandles[iPlainButton],1);
ToggleMenu(TRUE,iPlain,mStyle);
SetControlValue(FMStore->ctlHandles[iBoldButton],0);
ToggleMenu(FALSE,iBold,mStyle);
SetControlValue(FMStore->ctlHandles[iItalicButton],0);
ToggleMenu(FALSE,iItalic,mStyle);
SetControlValue(FMStore->ctlHandles[iUnderlineButton],0);
ToggleMenu(FALSE,iUnderline,mStyle);
SetControlValue(FMStore->ctlHandles[iOutlineButton],0);
ToggleMenu(FALSE,iOutline,mStyle);
SetControlValue(FMStore->ctlHandles[iShadowButton],0);
ToggleMenu(FALSE,iShadow,mStyle);
FMStore->fontStyle = 0;
UpdateSampleRect(FMStore);
}
void SetBoldDisplay()
{
SetStyleDisplay(iBold,iBoldButton,bold);
}
void SetItalicDisplay()
{
SetStyleDisplay(iItalic,iItalicButton,italic);
}
void SetUnderlineDisplay()
{
SetStyleDisplay(iUnderline,iUnderlineButton,underline);
}
void SetOutlineDisplay()
{
SetStyleDisplay(iOutline,iOutlineButton,outline);
}
void SetShadowDisplay()
{
SetStyleDisplay(iShadow,iShadowButton,shadow);
}
void HandleSizePopUp()
{
FMStuff *FMStore;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
FMStore->fontSize = GetControlValue(FMStore->ctlHandles[iSizePopUp]) - 1;
UpdateSampleRect(FMStore);
}
void SetSizeDisplay(Boolean increase)
{
FMStuff *FMStore;
short size;
FMStore = (FMStuff *) GetWRefCon(gMainWindow);
size = FMStore->fontSize;
if (increase) {
if (size < 6)
size++;
}
else
if (size > 0)
size--;
SetControlValue(FMStore->ctlHandles[iSizePopUp],size + 1);
FMStore->fontSize = size;
UpdateSampleRect(FMStore);
}