home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hand Held Organizer Toolkit
/
walnutcreekcdrom-handheldorganizertoolkit-march1998.iso
/
PalmPilot
/
development
/
pfc.sit
/
Src
/
CustomFonts.c
next >
Wrap
Text File
|
1997-04-25
|
6KB
|
292 lines
/***********************************************************************
*
* Copyright ⌐ 1997 Ken Hancock
*
* PROJECT: CustomFonts support code
*
* FILE: CustomFonts.c
*
* DESCRIPTION: Routines and trap patch for handling custom fonts
*
* REVISION HISTORY:
* 4/8/97 KSH Initial version
*
**********************************************************************/
#include <Pilot.h>
#include "CustomFonts.h"
#if EMULATION_LEVEL == EMULATION_NONE
#define curFontID ((FontID *) 0x1EE)
#define curFontPtr ((FontPtr *) 0x1CE)
#define curFontTable ((FontPtr *) 0x1D2)
#else
#define curFontID (UICurrentFontID)
#define curFontPtr (UICurrentFontPtr)
#define curFontTable (UIFontTable)
// #define curFontID ((FontID *) &(UICurrentFontID))
// #define curFontPtr ((FontPtr *) &(UICurrentFontPtr))
// #define curFontTable ((FontPtr *) &(UIFontTable))
#endif
typedef struct
{
FontPtr cfSaveFont;
Int cfSwapID;
} CFSwapTable;
CFSwapTable cfSwapTable[UINumFonts];
/***********************************************************************
*
* FUNCTION: CFInit
*
* DESCRIPTION: Initializes the custom font tables
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
void CFInit(void)
{
MemSet(cfSwapTable, sizeof(cfSwapTable), 0);
}
/***********************************************************************
*
* FUNCTION: CFSwapFont
*
* DESCRIPTION: Swaps a custom font with a FONT of resource id fontResID
* If a second font has already been swapped in, it
* restores the system font before swapping in the new
*
* PARAMETERS: FontID, Int
*
* RETURNED: Err
*
***********************************************************************/
Err CFSwapFont(FontID sysFont, Int fontResID)
{
CFSwapTable *stp;
Int lastSwap;
VoidHand fontH;
Err err = 0;
if (sysFont < UINumFonts)
{
// If we're not swapping in the same font, unswap the last font first
stp = &(cfSwapTable[sysFont]);
if ((lastSwap = stp->cfSwapID) != fontResID)
{
if (lastSwap != 0)
CFRestoreFont(sysFont);
fontH = DmGetResource('FONT', fontResID);
if (fontH)
{
stp->cfSwapID = fontResID;
stp->cfSaveFont = curFontTable[sysFont];
curFontTable[sysFont] = MemHandleLock(fontH);
}
else
err = dmErrResourceNotFound;
}
}
return(err);
}
/***********************************************************************
*
* FUNCTION: CFRestoreFont
*
* DESCRIPTION: Restores the specified system font back to its original
*
* PARAMETERS: FontID
*
* RETURNED: Err
*
***********************************************************************/
Err CFRestoreFont(FontID sysFont)
{
Err err;
CFSwapTable *stp;
VoidHand fontH;
if (sysFont < UINumFonts)
{
stp = &(cfSwapTable[sysFont]);
if (stp->cfSwapID)
{
fontH = DmGetResource('FONT', stp->cfSwapID);
if (fontH)
{
curFontTable[sysFont] = stp->cfSaveFont;
stp->cfSwapID = 0;
MemHandleUnlock(fontH);
}
else
err = dmErrResourceNotFound;
}
}
return(err);
}
/***********************************************************************
*
* FUNCTION: CFRestoreAllFonts
*
* DESCRIPTION: Restores all fonts back to their defaults
*
* PARAMETERS:
*
* RETURNED: Nothing.
*
***********************************************************************/
Err CFRestoreAllFonts(void)
{
Err err = 0;
Err newerr;
Word i;
for (i = 0; i < UINumFonts; i++)
{
newerr = CFRestoreFont((FontID) i);
if (newerr && (err == 0))
err = newerr;
}
return(err);
}
/*
#if EMULATION_LEVEL == EMULATION_NONE
#define curFontID (*((FontID *) 0x1EE))
#define curFontPtr (*((FontPtr *) 0x1CE))
#else
Don't even try to run this under emulation!
#endif
FontID CustomFntSetFont (FontID font);
typedef FontID (*FntSetFontProc)(FontID font);
FntSetFontProc *oldFntSetFont;
FontPtr *customFontTable;
Word customFontCount;
*/
/***********************************************************************
*
* FUNCTION: InstallCustomFonts OBSOLETE for 2.0 firmware
*
* DESCRIPTION: Routine counts the number of fonts, creats a font table
* and installs the trap patch.
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
/*
void InstallCustomFonts()
{
short i;
VoidHand h;
// Count how many fonts are installed starting at kCustomFontResBase
i = 0;
while (DmGet1Resource('FONT', kCustomFontResBase + i) != 0)
i++;
customFontCount = i;
// If any fonts were found, generate a FontPtr table and install trap patch
if (customFontCount)
{
customFontTable = (FontPtr *) MemPtrNew(sizeof(FontPtr) * i);
while (i--)
{
h = DmGetResource('FONT', kCustomFontResBase + i);
customFontTable[i] = (FontPtr) MemHandleLock(h);
}
oldFntSetFont = SysGetTrapAddress(sysTrapFntSetFont);
SysSetTrapAddress(sysTrapFntSetFont,CustomFntSetFont);
}
}
*/
/***********************************************************************
*
* FUNCTION: RemoveCustomFonts OBSOLETE for 2.0 firmware
*
* DESCRIPTION: Routine unlocks font resources and
* deinstalls the trap patch.
*
* PARAMETERS: None.
*
* RETURNED: Nothing.
*
***********************************************************************/
/*
void RemoveCustomFonts()
{
Word i;
VoidHand h;
SysSetTrapAddress(sysTrapFntSetFont, oldFntSetFont);
i = 0;
while ((h = DmGet1Resource('FONT', kCustomFontResBase + i)) != 0)
{
MemHandleUnlock(h);
i++;
}
MemPtrFree(customFontTable);
}
*/
/***********************************************************************
*
* FUNCTION: CustomFntSetFont OBSOLETE for 2.0 firmware
*
* DESCRIPTION: Replacement for FntSetFont trap
*
* PARAMETERS: FontID -- ID of font to set; 100+ for custom fonts
*
* RETURNED: Current FontID
*
***********************************************************************/
/*
FontID CustomFntSetFont (FontID font)
{
FontID result;
if (curFontID >= kCustomFontBase)
result = 0;
else
result = ((FntSetFontProc) oldFntSetFont)(font);
if ((font >= kCustomFontBase) && (font < kCustomFontBase + customFontCount))
{
curFontID = font;
curFontPtr = customFontTable[font - kCustomFontBase];
}
return(result);
}
*/